struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / strnlen.c
blob2ddda59830c002746d2704b00f6b01a2e3bad26b
1 /** tests for strnlen
2 */
4 #include <testfwk.h>
6 #include <string.h>
8 const char* hello1 = "hello1";
9 const char hello2[] = "hello2";
10 char hello3[] = "hello3";
12 void
13 testStr(void)
15 const char hello4[] = "hello4";
16 const char hello5[7];
18 memcpy (hello5, hello4, 7);
20 ASSERT(strnlen("hello0", 23) == strlen("hello0"));
21 ASSERT(strnlen(hello1, 23) == strlen(hello1));
22 ASSERT(strnlen(hello2, 23) == strlen(hello2));
23 ASSERT(strnlen(hello3, 23) == strlen(hello3));
24 ASSERT(strnlen(hello4, 23) == strlen(hello4));
25 ASSERT(strnlen(hello5, 23) == strlen(hello5));
27 ASSERT(strnlen("hello0", 3) == 3);
28 ASSERT(strnlen(hello1, 3) == 3);
29 ASSERT(strnlen(hello2, 3) == 3);
30 ASSERT(strnlen(hello3, 3) == 3);
31 ASSERT(strnlen(hello4, 3) == 3);
32 ASSERT(strnlen(hello5, 3) == 3);
34 ASSERT(strnlen("hello0", 6) == 6);
35 ASSERT(strnlen(hello1, 6) == 6);
36 ASSERT(strnlen(hello2, 6) == 6);
37 ASSERT(strnlen(hello3, 6) == 6);
38 ASSERT(strnlen(hello4, 6) == 6);
39 ASSERT(strnlen(hello5, 6) == 6);
41 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
42 ASSERT(strnlen("hello0", 7) == 6);
43 ASSERT(strnlen(hello1, 7) == 6);
44 ASSERT(strnlen(hello2, 7) == 6);
45 ASSERT(strnlen(hello3, 7) == 6);
46 ASSERT(strnlen(hello4, 7) == 6);
47 ASSERT(strnlen(hello5, 7) == 6);
48 #endif