1 // SPDX-License-Identifier: BSD-2-Clause-Patent
3 * test-str.c - test our string functions.
5 #pragma GCC diagnostic ignored "-Wunused-variable"
6 #pragma GCC diagnostic error "-Wnonnull"
7 #pragma GCC diagnostic error "-Wunused-function"
9 #pragma GCC diagnostic warning "-Wcpp"
11 #ifndef SHIM_UNIT_TEST
12 #define SHIM_UNIT_TEST
21 const char s1
[] = "abcd";
24 assert_equal_return(shim_strlen(s1
), 4, -1, "got %d expected %d\n");
25 assert_equal_return(strlen(s1
), 4, -1, "got %d expected %d\n");
26 assert_equal_return(shim_strlen(s2
), 0, -1, "got %d expected %d\n");
27 assert_equal_return(strlen(s2
), 0, -1, "got %d expected %d\n");
35 const char s1
[] = "abcd";
38 assert_equal_return(shim_strnlen(s1
, 0), 0, -1, "got %d expected %d\n");
39 assert_equal_return(strnlen(s1
, 0), 0, -1, "got %d expected %d\n");
40 assert_equal_return(shim_strnlen(s1
, 1), 1, -1, "got %d expected %d\n");
41 assert_equal_return(strnlen(s1
, 1), 1, -1, "got %d expected %d\n");
42 assert_equal_return(shim_strnlen(s1
, 3), 3, -1, "got %d expected %d\n");
43 assert_equal_return(strnlen(s1
, 3), 3, -1, "got %d expected %d\n");
44 assert_equal_return(shim_strnlen(s1
, 4), 4, -1, "got %d expected %d\n");
45 assert_equal_return(strnlen(s1
, 4), 4, -1, "got %d expected %d\n");
46 assert_equal_return(shim_strnlen(s1
, 5), 4, -1, "got %d expected %d\n");
47 assert_equal_return(strnlen(s1
, 5), 4, -1, "got %d expected %d\n");
48 assert_equal_return(shim_strnlen(s2
, 0), 0, -1, "got %d expected %d\n");
49 assert_equal_return(strnlen(s2
, 0), 0, -1, "got %d expected %d\n");
50 assert_equal_return(shim_strnlen(s2
, 1), 0, -1, "got %d expected %d\n");
51 assert_equal_return(strnlen(s2
, 1), 0, -1, "got %d expected %d\n");
56 #pragma GCC diagnostic push
57 #pragma GCC diagnostic ignored "-Wshadow"
60 * these are constants so that the failures are readable if you get
66 #define s1 "sbat,1,2021030218"
69 #define s2 "sbat,1,20210302"
72 #define s3 "sbat,1,20210303"
75 #define s4 "sbat\314\234\014,"
79 * same as s4 but with a UTF8 encoding error; one bit is cleared.
81 #define s5 "sbat\314\034\014,"
85 #define test_strcmp_helper(fn, invert_sign_errors, invert_encoding_errors) \
87 printf("testing %s\n", #fn); \
88 int status_ = 0, rc_; \
90 rc_ = assert_zero_as_expr(fn(s0, s0), -1, "\n"); \
91 status_ = MIN(status_, rc_); \
93 if (invert_sign_errors) \
94 rc_ = assert_positive_as_expr(fn(s0, s1), -1, "\n"); \
96 rc_ = assert_negative_as_expr(fn(s0, s1), -1, "\n"); \
97 status_ = MIN(status_, rc_); \
98 rc_ = assert_positive_as_expr(fn(s1, s0), -1, "\n"); \
99 status_ = MIN(status_, rc_); \
101 rc_ = assert_positive_as_expr(fn(s1, s2), -1, "\n"); \
102 status_ = MIN(status_, rc_); \
103 if (invert_sign_errors) \
104 rc_ = assert_positive_as_expr(fn(s2, s1), -1, "\n"); \
106 rc_ = assert_negative_as_expr(fn(s2, s1), -1, "\n"); \
107 status_ = MIN(status_, rc_); \
109 if (invert_sign_errors) \
110 rc_ = assert_positive_as_expr(fn(s2, s3), -1, "\n"); \
112 rc_ = assert_negative_as_expr(fn(s2, s3), -1, "\n"); \
113 status_ = MIN(status_, rc_); \
114 rc_ = assert_positive_as_expr(fn(s3, s2), -1, "\n"); \
115 status_ = MIN(status_, rc_); \
117 if (invert_encoding_errors) \
118 rc_ = assert_negative_as_expr(fn(s4, s5), -1, "\n"); \
120 rc_ = assert_positive_as_expr(fn(s4, s5), -1, "\n"); \
121 status_ = MIN(status_, rc_); \
124 printf("%s failed\n", #fn); \
137 rc
= test_strcmp_helper(shim_strcmp
, false, false);
138 status
= MIN(rc
, status
);
143 rc
= test_strcmp_helper(strcmp
, false, false);
144 status
= MIN(rc
, status
);
169 * these are constants so that the failures are readable if you get
175 #define s1 "sbaT,1,2021030218"
178 #define s2 "sbAt,1,20210302"
181 #define s3 "sbaT,1,20210303"
184 #define s4 "sbat\314\234\014,"
188 * same as s4 but with a UTF8 encoding error; one bit is cleared.
190 #define s5 "sbat\314\034\014,"
194 #define test_strcasecmp_helper(fn, invert_sign_errors, invert_encoding_errors) \
196 printf("testing %s\n", #fn); \
197 int status_ = 0, rc_; \
199 rc_ = assert_zero_as_expr(fn(s0, s0), -1, "\n"); \
200 status_ = MIN(status_, rc_); \
202 if (invert_sign_errors) \
203 rc_ = assert_positive_as_expr(fn(s0, s1), -1, "\n"); \
205 rc_ = assert_negative_as_expr(fn(s0, s1), -1, "\n"); \
206 status_ = MIN(status_, rc_); \
207 rc_ = assert_positive_as_expr(fn(s1, s0), -1, "\n"); \
208 status_ = MIN(status_, rc_); \
210 rc_ = assert_positive_as_expr(fn(s1, s2), -1, "\n"); \
211 status_ = MIN(status_, rc_); \
212 if (invert_sign_errors) \
213 rc_ = assert_positive_as_expr(fn(s2, s1), -1, "\n"); \
215 rc_ = assert_negative_as_expr(fn(s2, s1), -1, "\n"); \
216 status_ = MIN(status_, rc_); \
218 if (invert_sign_errors) \
219 rc_ = assert_positive_as_expr(fn(s2, s3), -1, "\n"); \
221 rc_ = assert_negative_as_expr(fn(s2, s3), -1, "\n"); \
222 status_ = MIN(status_, rc_); \
223 rc_ = assert_positive_as_expr(fn(s3, s2), -1, "\n"); \
224 status_ = MIN(status_, rc_); \
226 if (invert_encoding_errors) \
227 rc_ = assert_negative_as_expr(fn(s4, s5), -1, "\n"); \
229 rc_ = assert_positive_as_expr(fn(s4, s5), -1, "\n"); \
230 status_ = MIN(status_, rc_); \
233 printf("%s failed\n", #fn); \
238 test_strcasecmp(void)
246 rc
= test_strcasecmp_helper(shim_strcasecmp
, false, false);
247 status
= MIN(rc
, status
);
252 rc
= test_strcasecmp_helper(strcasecmp
, false, false);
253 status
= MIN(rc
, status
);
278 * these are constants so that the failures are readable if you get
284 #define s1 "sbaT,1,2021030218"
287 #define s2 "sbAt,1,20210302"
290 #define s3 "sbaT,1,20210303"
293 #define s4 "sbat\314\234\014,"
297 * same as s4 but with a UTF8 encoding error; one bit is cleared.
299 #define s5 "sbat\314\034\014,"
303 #define test_strncasecmp_helper(fn, test_cmp_magnitude, invert_sign_errors, \
304 invert_encoding_errors) \
306 printf("testing %s\n", #fn); \
307 int status_ = 0, rc_; \
309 rc_ = assert_zero_as_expr(fn(s0, s0, s0len), -1, "\n"); \
310 status_ = MIN(status_, rc_); \
311 rc_ = assert_zero_as_expr(fn(s0, s0, s0sz), -1, "\n"); \
312 status_ = MIN(status_, rc_); \
314 rc_ = assert_zero_as_expr(fn(s0, s1, s0len), -1, "\n"); \
315 status_ = MIN(status_, rc_); \
316 if (invert_sign_errors) \
317 rc_ = assert_positive_as_expr(fn(s0, s1, s0sz), -1, \
320 rc_ = assert_negative_as_expr(fn(s0, s1, s0sz), -1, \
322 status_ = MIN(status_, rc_); \
323 if (test_cmp_magnitude) { \
324 rc_ = assert_equal_as_expr(fn(s0, s1, s0sz), \
325 s0[s0len] - s1[s0len], -1, \
326 "expected %d got %d\n"); \
327 status_ = MIN(status_, rc_); \
329 rc_ = assert_positive_as_expr(fn(s1, s0, s0sz), -1, "\n"); \
330 status_ = MIN(status_, rc_); \
331 if (test_cmp_magnitude) { \
332 rc_ = assert_equal_as_expr(fn(s1, s0, s0sz), \
333 s1[s0len] - s0[s0len], -1, \
334 "expected %d got %d\n"); \
335 status_ = MIN(status_, rc_); \
338 rc_ = assert_positive_as_expr(fn(s1, s2, s1sz), -1, "\n"); \
339 status_ = MIN(status_, rc_); \
340 if (test_cmp_magnitude) { \
341 rc_ = assert_equal_as_expr(fn(s1, s2, s2sz), \
342 s1[s2len] - s2[s2len], -1, \
343 "expected %d got %d\n"); \
344 status_ = MIN(status_, rc_); \
346 rc_ = assert_positive_as_expr(fn(s1, s2, s1len), -1, "\n"); \
347 status_ = MIN(status_, rc_); \
348 if (test_cmp_magnitude) { \
349 rc_ = assert_equal_as_expr( \
351 s1[s2len - 1] - s2[s2len - 1], -1, \
352 "expected %d got %d\n"); \
353 status_ = MIN(status_, rc_); \
355 if (invert_sign_errors) \
356 rc_ = assert_positive_as_expr(fn(s2, s1, s1sz), -1, \
359 rc_ = assert_negative_as_expr(fn(s2, s1, s1sz), -1, \
361 status_ = MIN(status_, rc_); \
362 if (test_cmp_magnitude) { \
363 rc_ = assert_equal_as_expr(fn(s2, s1, s1sz), \
364 s2[s2len] - s1[s2len], -1, \
365 "expected %d got %d\n"); \
366 status_ = MIN(status_, rc_); \
369 rc_ = assert_zero_as_expr(fn(s1, s2, s2len), -1, "\n"); \
370 status_ = MIN(status_, rc_); \
371 rc_ = assert_positive_as_expr(fn(s1, s2, s2sz), -1, "\n"); \
372 status_ = MIN(status_, rc_); \
373 if (test_cmp_magnitude) { \
374 rc_ = assert_equal_as_expr(fn(s1, s2, s2sz), \
375 s1[s2len] - s2[s2len], -1, \
376 "expected %d got %d\n"); \
377 status_ = MIN(status_, rc_); \
380 if (invert_sign_errors) \
381 rc_ = assert_positive_as_expr(fn(s2, s3, s2sz), -1, \
384 rc_ = assert_negative_as_expr(fn(s2, s3, s2sz), -1, \
386 status_ = MIN(status_, rc_); \
387 rc_ = assert_equal_as_expr(fn(s2, s3, s2sz), \
388 s2[s2len - 1] - s3[s2len - 1], -1, \
389 "expected %d got %d\n"); \
390 status_ = MIN(status_, rc_); \
391 rc_ = assert_equal_as_expr(fn(s2, s3, s2len), \
392 s2[s2len - 1] - s3[s2len - 1], -1, \
393 "expected %d got %d\n"); \
394 status_ = MIN(status_, rc_); \
395 if (invert_sign_errors) \
396 rc_ = assert_positive_as_expr(fn(s2, s3, s2len), -1, \
399 rc_ = assert_negative_as_expr(fn(s2, s3, s2len), -1, \
401 status_ = MIN(status_, rc_); \
402 rc_ = assert_zero_as_expr(fn(s2, s3, s2len - 1), -1, "\n"); \
403 status_ = MIN(status_, rc_); \
404 rc_ = assert_false_as_expr(fn(s1, s2, s2len), -1, "\n"); \
405 status_ = MIN(status_, rc_); \
407 if (invert_encoding_errors) \
408 rc_ = assert_negative_as_expr(fn(s4, s5, s4sz), -1, \
411 rc_ = assert_positive_as_expr(fn(s4, s5, s4sz), -1, \
413 status_ = MIN(status_, rc_); \
416 printf("%s failed\n", #fn); \
421 test_strncasecmp(void)
429 rc
= test_strncasecmp_helper(shim_strncasecmp
, true, false, false);
430 status
= MIN(rc
, status
);
435 rc
= test_strncasecmp_helper(strncasecmp
, false, false, false);
436 status
= MIN(rc
, status
);
461 * copy-pasta from gnu-efi
480 return len
? *s1
- *s2
: 0;
484 * This is still broken, and fails the test case as written on arm.
485 * We no longer use this, so we do not strictly need to run it.
487 #if !defined(__arm__) && !defined(__aarch64__)
489 gnuefi_signed_strncmp (
505 return len
? *s1
- *s2
: 0;
510 gnuefi_good_strncmp (
516 CONST UINT8
*s1
= (CONST UINT8
*)s1p
;
517 CONST UINT8
*s2
= (CONST UINT8
*)s2p
;
529 return len
? *s1
- *s2
: 0;
533 * these are constants so that the failures are readable if you get
539 #define s1 "sbat,1,2021030218"
542 #define s2 "sbat,1,20210302"
545 #define s3 "sbat,1,20210303"
548 #define s4 "sbat\314\234\014,"
552 * same as s4 but with a UTF8 encoding error; one bit is cleared.
554 #define s5 "sbat\314\034\014,"
558 #define test_strncmp_helper(fn, test_cmp_magnitude, invert_sign_errors, \
559 invert_encoding_errors) \
561 printf("testing %s\n", #fn); \
562 int status_ = 0, rc_; \
564 rc_ = assert_zero_as_expr(fn(s0, s0, s0len), -1, "\n"); \
565 status_ = MIN(status_, rc_); \
566 rc_ = assert_zero_as_expr(fn(s0, s0, s0sz), -1, "\n"); \
567 status_ = MIN(status_, rc_); \
569 rc_ = assert_zero_as_expr(fn(s0, s1, s0len), -1, "\n"); \
570 status_ = MIN(status_, rc_); \
571 if (invert_sign_errors) \
572 rc_ = assert_positive_as_expr(fn(s0, s1, s0sz), -1, \
575 rc_ = assert_negative_as_expr(fn(s0, s1, s0sz), -1, \
577 status_ = MIN(status_, rc_); \
578 if (test_cmp_magnitude) { \
579 rc_ = assert_equal_as_expr(fn(s0, s1, s0sz), \
580 s0[s0len] - s1[s0len], -1, \
581 "expected %d got %d\n"); \
582 status_ = MIN(status_, rc_); \
584 rc_ = assert_positive_as_expr(fn(s1, s0, s0sz), -1, "\n"); \
585 status_ = MIN(status_, rc_); \
586 if (test_cmp_magnitude) { \
587 rc_ = assert_equal_as_expr(fn(s1, s0, s0sz), \
588 s1[s0len] - s0[s0len], -1, \
589 "expected %d got %d\n"); \
590 status_ = MIN(status_, rc_); \
593 rc_ = assert_positive_as_expr(fn(s1, s2, s1sz), -1, "\n"); \
594 status_ = MIN(status_, rc_); \
595 if (test_cmp_magnitude) { \
596 rc_ = assert_equal_as_expr(fn(s1, s2, s2sz), \
597 s1[s2len] - s2[s2len], -1, \
598 "expected %d got %d\n"); \
599 status_ = MIN(status_, rc_); \
601 rc_ = assert_positive_as_expr(fn(s1, s2, s1len), -1, "\n"); \
602 status_ = MIN(status_, rc_); \
603 if (test_cmp_magnitude) { \
604 rc_ = assert_equal_as_expr( \
606 s1[s2len - 1] - s2[s2len - 1], -1, \
607 "expected %d got %d\n"); \
608 status_ = MIN(status_, rc_); \
610 if (invert_sign_errors) \
611 rc_ = assert_positive_as_expr(fn(s2, s1, s1sz), -1, \
614 rc_ = assert_negative_as_expr(fn(s2, s1, s1sz), -1, \
616 status_ = MIN(status_, rc_); \
617 if (test_cmp_magnitude) { \
618 rc_ = assert_equal_as_expr(fn(s2, s1, s1sz), \
619 s2[s2len] - s1[s2len], -1, \
620 "expected %d got %d\n"); \
621 status_ = MIN(status_, rc_); \
624 rc_ = assert_zero_as_expr(fn(s1, s2, s2len), -1, "\n"); \
625 status_ = MIN(status_, rc_); \
626 rc_ = assert_positive_as_expr(fn(s1, s2, s2sz), -1, "\n"); \
627 status_ = MIN(status_, rc_); \
628 if (test_cmp_magnitude) { \
629 rc_ = assert_equal_as_expr(fn(s1, s2, s2sz), \
630 s1[s2len] - s2[s2len], -1, \
631 "expected %d got %d\n"); \
632 status_ = MIN(status_, rc_); \
635 if (invert_sign_errors) \
636 rc_ = assert_positive_as_expr(fn(s2, s3, s2sz), -1, \
639 rc_ = assert_negative_as_expr(fn(s2, s3, s2sz), -1, \
641 status_ = MIN(status_, rc_); \
642 if (test_cmp_magnitude) { \
643 rc_ = assert_equal_as_expr( \
645 s2[s2len - 1] - s3[s2len - 1], -1, \
646 "expected %d got %d\n"); \
647 status_ = MIN(status_, rc_); \
648 rc_ = assert_equal_as_expr( \
650 s2[s2len - 1] - s3[s2len - 1], -1, \
651 "expected %d got %d\n"); \
652 status_ = MIN(status_, rc_); \
654 if (invert_sign_errors) \
655 rc_ = assert_positive_as_expr(fn(s2, s3, s2len), -1, \
658 rc_ = assert_negative_as_expr(fn(s2, s3, s2len), -1, \
660 status_ = MIN(status_, rc_); \
661 rc_ = assert_zero_as_expr(fn(s2, s3, s2len - 1), -1, "\n"); \
662 status_ = MIN(status_, rc_); \
663 rc_ = assert_false_as_expr(fn(s1, s2, s2len), -1, "\n"); \
664 status_ = MIN(status_, rc_); \
666 if (invert_encoding_errors) \
667 rc_ = assert_negative_as_expr(fn(s4, s5, s4sz), -1, \
670 rc_ = assert_positive_as_expr(fn(s4, s5, s4sz), -1, \
672 status_ = MIN(status_, rc_); \
675 printf("%s failed\n", #fn); \
688 rc
= test_strncmp_helper(shim_strncmp
, true, false, false);
689 status
= MIN(rc
, status
);
695 * Deliberately not testing the difference between these two
696 * comparisons for the symbol named "strncmp":
697 * strncmp("b", "a", 1)
698 * strncmp("c", "a", 1)
699 * glibc, shim_strncmp(), and even the gnuefi ones will give you 1
700 * and 2, respectively, as will glibc's, but valgrind swaps in its
701 * own implementation, in case you're doing something that's both
702 * clever and dumb with the result, and it'll return 1 for both of
705 rc
= test_strncmp_helper(strncmp
, false, false, false);
706 status
= MIN(rc
, status
);
709 * gnu-efi's broken strncmpa
711 #pragma GCC diagnostic push
712 #pragma GCC diagnostic ignored "-Wtype-limits"
713 #pragma GCC diagnostic ignored "-Wsign-compare"
714 rc
= test_strncmp_helper(gnuefi_strncmp
, true, true, false);
715 status
= MIN(rc
, status
);
716 #pragma GCC diagnostic pop
719 * This is still broken, and fails the test case as written on arm.
720 * We no longer use this, so we do not strictly need to run it.
722 #if !defined(__arm__) && !defined(__aarch64__)
724 * gnu-efi's broken strncmpa with the return type fixed
726 rc
= test_strncmp_helper(gnuefi_signed_strncmp
, true, false, true);
727 status
= MIN(rc
, status
);
731 * gnu-efi's strncmpa with the return type fixed and unsigned
732 * comparisons internally
734 rc
= test_strncmp_helper(gnuefi_good_strncmp
, true, false, false);
735 status
= MIN(rc
, status
);
760 * Put -Wshadow back how it was
762 #pragma GCC diagnostic pop
767 char s0
[] = "abcbdbeb\0fbgb";
769 assert_equal_return(strchr(s0
, 'a'), s0
, -1, "got %p expected %p\n");
770 assert_equal_return(strchr(s0
, 'b'), &s0
[1], -1, "got %p expected %p\n");
771 assert_equal_return(strchr(&s0
[1], 'b'), &s0
[1], -1, "got %p expected %p\n");
772 assert_equal_return(strchr(&s0
[2], 'b'), &s0
[3], -1, "got %p expected %p\n");
773 assert_equal_return(strchr(&s0
[4], 'b'), &s0
[5], -1, "got %p expected %p\n");
774 assert_equal_return(strchr(&s0
[6], 'b'), &s0
[7], -1, "got %p expected %p\n");
775 assert_equal_return(strchr(&s0
[8], 'b'), NULL
, -1, "got %p expected %p\n");
777 assert_equal_return(shim_strchr(s0
, 'a'), s0
, -1, "got %p expected %p\n");
778 assert_equal_return(shim_strchr(s0
, 'b'), &s0
[1], -1, "got %p expected %p\n");
779 assert_equal_return(shim_strchr(&s0
[1], 'b'), &s0
[1], -1, "got %p expected %p\n");
780 assert_equal_return(shim_strchr(&s0
[2], 'b'), &s0
[3], -1, "got %p expected %p\n");
781 assert_equal_return(shim_strchr(&s0
[4], 'b'), &s0
[5], -1, "got %p expected %p\n");
782 assert_equal_return(shim_strchr(&s0
[6], 'b'), &s0
[7], -1, "got %p expected %p\n");
783 assert_equal_return(shim_strchr(&s0
[8], 'b'), NULL
, -1, "got %p expected %p\n");
790 char s0
[] = "0123456789abcdef";
791 char s1
[] = "xxxxxxxxxxxxxxxx";
795 assert_equal_return(stpcpy(s1
, s0
), &s1
[0xa], -1, "got %p expected %p\n");
796 assert_zero_return(memcmp(s0
, s1
, 11), -1, "\n");
797 assert_zero_return(memcmp(&s1
[11], "xxxxx", sizeof("xxxxx")), -1, "\n");
799 memset(s1
, 'x', sizeof(s1
));
801 assert_equal_return(shim_stpcpy(s1
, s0
), &s1
[0xa], -1, "got %p expected %p\n");
802 assert_zero_return(memcmp(s0
, s1
, 11), -1, "\n");
803 assert_zero_return(memcmp(&s1
[11], "xxxxx", sizeof("xxxxx")), -1, "\n");
811 char s0
[] = "0123456789abcdef";
815 assert_equal_goto(strcmp(s0
, s
), 0, err
, "\n");
819 assert_equal_goto(strcmp(s0
, s
), 0, err
, "\n");
832 char s0
[] = "0123456789abcdef";
836 assert_equal_goto(strcmp(s0
, s
), 0, err
, "\n");
839 assert_positive_goto(strcmp(s0
, s
), err
, "\n");
842 s
= shim_strndup(s0
, 18);
843 assert_equal_goto(strcmp(s0
, s
), 0, err
, "\n");
846 assert_positive_goto(shim_strcmp(s0
, s
), err
, "\n");
857 test_strchrnul_helper(__typeof__(strchrnul
) fn
)
859 const char s0
[] = "abcd\0fghi";
861 assert_equal_return(fn(s0
, 'a'), &s0
[0], -1, "got %p expected %p\n");
862 assert_equal_return(fn(s0
, 'd'), &s0
[3], -1, "got %p expected %p\n");
863 assert_equal_return(fn(s0
, '\000'), &s0
[4], -1, "got %p expected %p\n");
864 assert_equal_return(fn(s0
, 'i'), &s0
[4], -1, "got %p expected %p\n");
872 const char s0
[] = "abcd\0fghi";
874 assert_equal_return(test_strchrnul_helper(shim_strchrnul
),
875 test_strchrnul_helper(strchrnul
),
876 -1, "got %d expected %d\n");
878 assert_equal_return(strnchrnul(s0
, 0, 'b'), &s0
[0], -1, "got %p expected %p\n");
879 assert_equal_return(strnchrnul(s0
, -1, 'b'), &s0
[1], 1, "got %p expected %p\n");
880 assert_equal_return(strnchrnul(s0
, 2, 'b'), &s0
[1], -1, "got %p expected %p\n");
881 assert_equal_return(strnchrnul(s0
, 4, 'f'), &s0
[3], -1, "got %p expected %p\n");
882 assert_equal_return(strnchrnul(s0
, 5, 'f'), &s0
[4], -1, "got %p expected %p\n");
883 assert_equal_return(strnchrnul(s0
, 8, 'f'), &s0
[4], -1, "got %p expected %p\n");
885 assert_equal_return(strnchrnul(&s0
[4], 1, 'f'), &s0
[4], -1, "got %p expected %p\n");
892 char s0
[] = "abcbebfb";
894 assert_equal_return(shim_strrchr(s0
, '\n'), NULL
, -1, "got %p expected %p\n");
895 assert_equal_return(strrchr(s0
, '\n'), NULL
, -1, "got %p expected %p\n");
896 assert_equal_return(shim_strrchr(s0
, 'b'), &s0
[7], -1, "got %p expected %p\n");
897 assert_equal_return(strrchr(s0
, 'b'), &s0
[7], -1, "got %p expected %p\n");
898 assert_equal_return(shim_strrchr(s0
, 'c'), &s0
[2], -1, "got %p expected %p\n");
899 assert_equal_return(strrchr(s0
, 'c'), &s0
[2], -1, "got %p expected %p\n");
907 char s0
[] = "0123456789abcdef\0000";
910 memset(s1
, 0, sizeof(s1
));
911 assert_equal_return(strcpy(s1
, s0
), s1
, -1, "got %p expected %p\n");
912 assert_equal_return(strlen(s0
), strlen(s1
), -1, "got %d expected %d\n");
914 memset(s1
, 0, sizeof(s1
));
915 assert_equal_return(shim_strcpy(s1
, s0
), s1
, -1, "got %p expected %p\n");
916 assert_equal_return(strlen(s0
), strlen(s1
), -1, "got %d expected %d\n");
918 memset(s1
, 0, sizeof(s1
));
919 assert_equal_return(shim_strcpy(s1
, s0
), s1
, -1, "got %p expected %p\n");
920 assert_equal_return(strlen(s0
), strlen(s1
), -1, "got %d expected %d\n");
928 char s
[] = "0123456789abcdef\0000";
930 char *s1
= &s0
[4096];
932 memset(s0
, 0, sizeof(s0
));
933 memcpy(s0
, s
, sizeof(s
));
936 assert_equal_return(strncpy(s1
, s0
, 0), s1
, -1, "got %p expected %p\n");
937 assert_equal_return(strlen(s1
), 0, -1, "got %d expected %d\n");
939 assert_equal_return(shim_strncpy(s1
, s0
, 0), s1
, -1, "got %p expected %p\n");
940 assert_equal_return(strlen(s1
), 0, -1, "got %d expected %d\n");
943 assert_equal_return(strncpy(s1
, s0
, 1), s1
, -1, "got %p expected %p\n");
944 assert_equal_return(strlen(s1
), 1, -1, "got %d expected %d\n");
945 assert_equal_return(s1
[0], s0
[0], -1, "got %#02hhx, expected %#02hhx\n");
946 assert_equal_return(s0
[1], '1', -1, "got %#02hhx, expected %#02hhx\n");
947 assert_equal_return(s1
[1], '\0', -1, "got %#02hhx, expected %#02hhx\n");
949 assert_equal_return(shim_strncpy(s1
, s0
, 1), s1
, -1, "got %p expected %p\n");
950 assert_equal_return(strlen(s1
), 1, -1, "got %d expected %d\n");
951 assert_equal_return(s1
[0], s0
[0], -1, "got %#02hhx, expected %#02hhx\n");
952 assert_equal_return(s0
[1], '1', -1, "got %#02hhx, expected %#02hhx\n");
953 assert_equal_return(s1
[1], '\0', -1, "got %#02hhx, expected %#02hhx\n");
956 assert_equal_return(strncpy(s1
, s0
, 15), s1
, -1, "got %p expected %p\n");
957 assert_equal_return(s0
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
958 assert_equal_return(s0
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
959 assert_equal_return(s0
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
960 assert_equal_return(s0
[17], '0', -1, "got %#02hhx expected %02hhx\n");
961 assert_equal_return(s0
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
962 assert_equal_return(s1
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
963 assert_equal_return(s1
[15], '\000', -1, "got %#02hhx expected %02hhx\n");
964 assert_equal_return(s1
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
965 assert_equal_return(s1
[17], '\000', -1, "got %#02hhx expected %02hhx\n");
966 assert_equal_return(s1
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
968 assert_equal_return(shim_strncpy(s1
, s0
, 15), s1
, -1, "got %p expected %p\n");
969 assert_equal_return(s0
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
970 assert_equal_return(s0
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
971 assert_equal_return(s0
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
972 assert_equal_return(s0
[17], '0', -1, "got %#02hhx expected %02hhx\n");
973 assert_equal_return(s0
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
974 assert_equal_return(s1
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
975 assert_equal_return(s1
[15], '\000', -1, "got %#02hhx expected %02hhx\n");
976 assert_equal_return(s1
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
977 assert_equal_return(s1
[17], '\000', -1, "got %#02hhx expected %02hhx\n");
978 assert_equal_return(s1
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
981 assert_equal_return(strncpy(s1
, s0
, 16), s1
, -1, "got %p expected %p\n");
982 assert_equal_return(s0
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
983 assert_equal_return(s0
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
984 assert_equal_return(s0
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
985 assert_equal_return(s0
[17], '0', -1, "got %#02hhx expected %02hhx\n");
986 assert_equal_return(s0
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
987 assert_equal_return(s1
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
988 assert_equal_return(s1
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
989 assert_equal_return(s1
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
990 assert_equal_return(s1
[17], '\000', -1, "got %#02hhx expected %02hhx\n");
991 assert_equal_return(s1
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
993 assert_equal_return(shim_strncpy(s1
, s0
, 16), s1
, -1, "got %p expected %p\n");
994 assert_equal_return(s0
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
995 assert_equal_return(s0
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
996 assert_equal_return(s0
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
997 assert_equal_return(s0
[17], '0', -1, "got %#02hhx expected %02hhx\n");
998 assert_equal_return(s0
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
999 assert_equal_return(s1
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
1000 assert_equal_return(s1
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
1001 assert_equal_return(s1
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
1002 assert_equal_return(s1
[17], '\000', -1, "got %#02hhx expected %02hhx\n");
1003 assert_equal_return(s1
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
1005 memset(s1
, 0, 4096);
1008 assert_equal_return(strncpy(s1
, s0
, 4096), s1
, -1, "got %p expected %p\n");
1009 assert_equal_return(s0
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
1010 assert_equal_return(s0
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
1011 assert_equal_return(s0
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
1012 assert_equal_return(s0
[17], '0', -1, "got %#02hhx expected %02hhx\n");
1013 assert_equal_return(s0
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
1014 assert_equal_return(s1
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
1015 assert_equal_return(s1
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
1016 assert_equal_return(s1
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
1017 assert_equal_return(s1
[17], '\000', -1, "got %#02hhx expected %02hhx\n");
1018 assert_equal_return(s1
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
1019 memset(s1
, 0, 4096);
1022 assert_equal_return(shim_strncpy(s1
, s0
, 4096), s1
, -1, "got %p expected %p\n");
1023 assert_equal_return(s0
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
1024 assert_equal_return(s0
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
1025 assert_equal_return(s0
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
1026 assert_equal_return(s0
[17], '0', -1, "got %#02hhx expected %02hhx\n");
1027 assert_equal_return(s0
[18], '\000', -1, "got %#02hhx expected %02hhx\n");
1028 assert_equal_return(s1
[14], 'e', -1, "got %#02hhx expected %02hhx\n");
1029 assert_equal_return(s1
[15], 'f', -1, "got %#02hhx expected %02hhx\n");
1030 assert_equal_return(s1
[16], '\000', -1, "got %#02hhx expected %02hhx\n");
1031 assert_equal_return(s1
[17], '0', -1, "got %#02hhx expected %02hhx\n");
1032 assert_equal_return(s1
[18], '1', -1, "got %#02hhx expected %02hhx\n");
1040 char s
[] = "0123456789abcdef\0000";
1042 char *s1
= &s0
[4096];
1044 char s3
[] = "0123456789abcdef0123456789abcdef\000\000\000\000\000";
1046 memset(s0
, 0, 8192);
1047 memcpy(s0
, s
, sizeof(s
));
1049 memset(s1
, 0, 4096);
1050 assert_equal_return(strcat(s1
, s0
), s1
, -1, "got %p expected %p\n");
1051 /* For unknown reasons, gcc 4.8.5 gives us this here:
1052 * | In file included from shim.h:64:0,
1053 * | from test-str.c:14:
1054 * | test-str.c: In function 'test_strcat':
1055 * | include/test.h:85:10: warning: array subscript is below array bounds [-Warray-bounds]
1056 * | printf("%s:%d:got %lld, expected zero " fmt, __func__, \
1058 * | include/test.h:112:10: warning: array subscript is below array bounds [-Warray-bounds]
1059 * | printf("%s:%d:got %lld, expected < 0 " fmt, __func__, \
1062 * This clearly isn't a useful error message, as it doesn't tell us
1063 * /anything about the problem/, but also it isn't reported on
1064 * later compilers, and it isn't clear that there's any problem
1065 * when examining these functions.
1069 #pragma GCC diagnostic push
1070 #pragma GCC diagnostic ignored "-Warray-bounds"
1071 assert_zero_return(strncmp(s1
, s0
, sizeof(s
)-1), 0, -1, "\n");
1072 assert_negative_return(memcmp(s1
, s0
, sizeof(s
)), 0, -1, "\n");
1073 #pragma GCC diagnostic pop
1075 memset(s1
, 0, 4096);
1076 assert_equal_return(strcat(s1
, s0
), s1
, -1, "got %p expected %p\n");
1077 s2
= s1
+ strlen(s1
);
1078 assert_equal_return(s2
, &s1
[16], -1, "got %p expected %p\n");
1079 assert_equal_return(strcat(s2
, s0
), s2
, -1, "got %p expected %p\n");
1080 assert_zero_return(strncmp(s1
, s0
, strlen(s
)), -1, "got %p expected %p\n");
1081 assert_zero_return(strncmp(s2
, s0
, 2*(sizeof(s
)-1)), -1, "\n");
1082 assert_positive_return(memcmp(s1
, s0
, 2*sizeof(s
)-2), -1, "\n");
1083 assert_equal_return(memcmp(s1
, s3
, sizeof(s3
)), 0, -1, "expected %d got %d\n");
1089 test_strntoken_null(void) {
1094 char *delims
= alloca(3);
1095 memcpy(delims
, ",.", 3);
1097 ret
= strntoken(NULL
, 1, delims
, &token
, &state
);
1098 assert_equal_return(ret
, false, -1, "got %d expected %d\n");
1103 test_strntoken_size_0(void)
1105 const char s1
[] = "abc,def,.,gh,";
1106 char s2
[] = "abc,def,.,gh,";
1114 ret
= strntoken(s
, 0, ",.", &token
, &state
);
1115 assert_equal_return(ret
, false, -1, "got %d expected %d\n");
1116 assert_equal_return(token
, NULL
, -1, "got %p expected %p\n");
1117 assert_equal_return(memcmp(s
, "abc,def,.,gh,", sizeof(s2
)), 0, 1, "got %d expected %d\n");
1123 test_strntoken_empty_size_1(void)
1129 char *prevtok
= NULL
;
1137 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1138 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1139 assert_equal_return(token
[0], '\0', -1, "got %#hhx expected %#hhx\n");
1142 tokensz
= strlen(token
) + 1;
1145 assert_equal_return(s
, &s1
[1], -1, "got %p expected %p\n");
1146 assert_equal_return(max
, 0, -1, "got %d expected %d\n");
1148 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1149 assert_equal_return(ret
, false, -1, "got %d expected %d\n");
1150 assert_equal_return(token
, prevtok
, -1, "got %p expected %p\n");
1156 test_strntoken_size_1(void)
1162 char *prevtok
= NULL
;
1170 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1171 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1172 assert_equal_return(token
[0], '\0', -1, "got %#hhx expected %#hhx\n");
1175 tokensz
= strlen(token
) + 1;
1178 assert_equal_return(s
, &s1
[1], -1, "got %p expected %p\n");
1179 assert_equal_return(max
, 0, -1, "got %d expected %d\n");
1181 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1182 assert_equal_return(ret
, false, -1, "got %d expected %d\n");
1183 assert_equal_return(token
, prevtok
, -1, "got %p expected %p\n");
1184 assert_equal_return(token
[0], '\0', -1, "got %#hhx expected %#hhx\n");
1190 test_strntoken_size_2(void)
1196 char *prevtok
= NULL
;
1204 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1205 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1206 assert_equal_return(token
[0], '\0', -1, "got %#hhx expected %#hhx\n");
1208 tokensz
= strlen(token
) + 1;
1211 assert_equal_return(s
, &s1
[1], -1, "got %p expected %p\n");
1212 assert_equal_return(max
, 1, -1, "got %d expected %d\n");
1214 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1215 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1216 assert_equal_return(token
[0], '\0', -1, "got %#hhx expected %#hhx\n");
1219 tokensz
= strlen(token
) + 1;
1222 assert_equal_return(s
, &s1
[2], -1, "got %p expected %p\n");
1223 assert_equal_return(max
, 0, -1, "got %d expected %d\n");
1225 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1226 assert_equal_return(ret
, false, -1, "got %d expected %d\n");
1227 assert_equal_return(token
, prevtok
, -1, "got %#hhx expected %#hhx\n");
1233 test_strntoken_no_ascii_nul(void)
1235 const char s1
[] = "abc,def,.,gh,";
1236 char s2
[] = "abc,def,.,gh,";
1245 max
= sizeof(s2
) - 1;
1246 assert_equal_return(max
, 13, -1, "got %d expected %d\n");
1248 * s="abc,def,.,gh," -> "abc\0def,.,gh,"
1251 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1252 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1253 assert_equal_return(token
, s
, -1, "got %p expected %p\n");
1254 assert_equal_return(s
[2], 'c', -1, "got %#hhx expected %#hhx\n");
1255 assert_equal_return(s
[3], '\0', -1, "got %#hhx expected %#hhx\n");
1256 assert_equal_return(s
[4], 'd', -1, "got %#hhx expected %#hhx\n");
1258 tokensz
= strnlen(token
, max
) + 1;
1261 assert_equal_return(max
, 9, -1, "got %d expected %d\n");
1264 * s="def,.,gh," -> "def\0.,gh,"
1267 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1268 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1269 assert_equal_return(token
, s
, -1, "got %p expected %p\n");
1270 assert_equal_return(s
[2], 'f', -1, "got %#hhx expected %#hhx\n");
1271 assert_equal_return(s
[3], '\0', -1, "got %#hhx expected %#hhx\n");
1272 assert_equal_return(s
[4], '.', -1, "got %#hhx expected %#hhx\n");
1274 tokensz
= strnlen(token
, max
) + 1;
1277 assert_equal_return(max
, 5, -1, "got %d expected %d\n");
1280 * s=".,gh," -> "\0,gh,"
1283 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1284 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1285 assert_equal_return(token
, s
, -1, "got %p expected %p\n");
1286 assert_equal_return(s
[0], '\0', -1, "got %#hhx expected %#hhx\n");
1287 assert_equal_return(s
[1], ',', -1, "got %#hhx expected %#hhx\n");
1289 tokensz
= strnlen(token
, max
) + 1;
1292 assert_equal_return(max
, 4, -1, "got %d expected %d\n");
1295 * s=",gh," -> "\0gh,"
1298 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1299 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1300 assert_equal_return(token
, s
, -1, "got %p expected %p\n");
1301 assert_equal_return(s
[0], '\0', -1, "got %#hhx expected %#hhx\n");
1302 assert_equal_return(s
[1], 'g', -1, "got %#hhx expected %#hhx\n");
1304 tokensz
= strnlen(token
, max
) + 1;
1307 assert_equal_return(max
, 3, -1, "got %d expected %d\n");
1313 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1314 assert_equal_return(ret
, true, -1, "got %d expected %d\n");
1315 assert_equal_return(token
, s
, -1, "got %p expected %p\n");
1316 assert_equal_return(s
[0], 'g', -1, "got %#hhx expected %#hhx\n");
1317 assert_equal_return(s
[1], 'h', -1, "got %#hhx expected %#hhx\n");
1318 assert_equal_return(s
[2], '\0', -1, "got %#hhx expected %#hhx\n");
1320 tokensz
= strnlen(token
, max
) + 1;
1323 assert_equal_return(max
, 0, -1, "got %d expected %d\n");
1325 char *prevtok
= token
;
1329 * ^ token, but max is 0
1331 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1332 assert_equal_return(ret
, false, -1, "got %d expected %d\n");
1333 assert_equal_return(token
, prevtok
, -1, "got %p expected %p\n");
1334 assert_equal_return(s
[0], '\0', -1, "got %#hhx expected %#hhx\n");
1337 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1338 assert_equal_return(ret
, false, -1, "got %d expected %d\n");
1339 assert_equal_return(token
, prevtok
, -1, "got %p expected %p\n");
1340 assert_equal_return(s
[0], 'x', -1, "got %#hhx expected %#hhx\n");
1346 test_strntoken_with_ascii_nul(void)
1348 const char s1
[] = "abc,def,.,gh,";
1349 char s2
[] = "abc,def,.,gh,";
1355 char s3
[] = "abc,def,.,gh,";
1360 assert_equal_return(max
, 14, 1, "got %d expected %d\n");
1362 * s="abc,def,.,gh," -> "abc\0def,.,gh,"
1365 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1366 assert_equal_return(ret
, true, 1, "got %d expected %d\n");
1367 assert_equal_return(s
[2], 'c', 1, "got %#hhx expected %#hhx\n");
1368 assert_equal_return(s
[3], '\0', 1, "got %#hhx expected %#hhx\n");
1369 assert_equal_return(s
[4], 'd', 1, "got %#hhx expected %#hhx\n");
1371 tokensz
= strnlen(token
, max
) + 1;
1374 assert_equal_return(max
, 10, 1, "got %d expected %d\n");
1377 * s="def,.,gh," -> "def\0.,gh,"
1380 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1381 assert_equal_return(ret
, true, 1, "got %d expected %d\n");
1382 assert_equal_return(token
, s
, 1, "got %p expected %p\n");
1383 assert_equal_return(s
[2], 'f', 1, "got %#hhx expected %#hhx\n");
1384 assert_equal_return(s
[3], '\0', 1, "got %#hhx expected %#hhx\n");
1385 assert_equal_return(s
[4], '.', 1, "got %#hhx expected %#hhx\n");
1387 tokensz
= strnlen(token
, max
) + 1;
1390 assert_equal_return(max
, 6, 1, "got %d expected %d\n");
1393 * s=".,gh," -> "\0,gh,"
1396 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1397 assert_equal_return(ret
, true, 1, "got %d expected %d\n");
1398 assert_equal_return(token
, s
, 1, "got %p expected %p\n");
1399 assert_equal_return(s
[0], '\0', 1, "got %#hhx expected %#hhx\n");
1400 assert_equal_return(s
[1], ',', 1, "got %#hhx expected %#hhx\n");
1402 tokensz
= strnlen(token
, max
) + 1;
1405 assert_equal_return(max
, 5, 1, "got %d expected %d\n");
1408 * s=",gh," -> "\0gh,"
1411 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1412 assert_equal_return(ret
, true, 1, "got %d expected %d\n");
1413 assert_equal_return(token
, s
, 1, "got %p expected %p\n");
1414 assert_equal_return(s
[0], '\0', 1, "got %#hhx expected %#hhx\n");
1415 assert_equal_return(s
[1], 'g', 1, "got %#hhx expected %#hhx\n");
1417 tokensz
= strnlen(token
, max
) + 1;
1420 assert_equal_return(max
, 4, 1, "got %d expected %d\n");
1426 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1427 assert_equal_return(ret
, true, 1, "got %d expected %d\n");
1428 assert_equal_return(token
, s
, 1, "got %p expected %p\n");
1429 assert_equal_return(s
[0], 'g', 1, "got %#hhx expected %#hhx\n");
1430 assert_equal_return(s
[1], 'h', 1, "got %#hhx expected %#hhx\n");
1431 assert_equal_return(s
[2], '\0', 1, "got %#hhx expected %#hhx\n");
1433 tokensz
= strnlen(token
, max
) + 1;
1436 assert_equal_return(max
, 1, 1, "got %d expected %d\n");
1442 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1443 assert_equal_return(ret
, true, 1, "got %d expected %d\n");
1444 assert_equal_return(token
, s
, 1, "got %p expected %p\n");
1445 assert_equal_return(s
[0], '\0', 1, "got %#hhx expected %#hhx\n");
1447 char *prevtok
= token
;
1448 tokensz
= strnlen(token
, max
) + 1;
1451 assert_equal_return(max
, 0, 1, "got %d expected %d\n");
1457 ret
= strntoken(s
, max
, ",.", &token
, &state
);
1458 assert_equal_return(ret
, false, 1, "got %d expected %d\n");
1459 assert_equal_return(token
, prevtok
, 1, "got %p expected %p\n");
1472 test(test_strcasecmp
);
1473 test(test_strncasecmp
);
1482 test(test_strchrnul
);
1483 test(test_strntoken_null
);
1484 test(test_strntoken_size_0
);
1485 test(test_strntoken_empty_size_1
);
1486 test(test_strntoken_size_1
);
1487 test(test_strntoken_size_2
);
1488 test(test_strntoken_no_ascii_nul
);
1489 test(test_strntoken_with_ascii_nul
);
1493 // vim:fenc=utf-8:tw=75:noet