[ucsim-z80] Fix #3828: uCsim SM83 flags simulation
[sdcc.git] / sdcc / support / regression / tests / strnlen.c
blobf56ff3640d89da278c98b111b5f7c9d08680fe26
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 #if defined(__SDCC) || (_POSIX_C_SOURCE >= 200809L) || (__STDC_VERSION_STRING_H__ > 202311L) // strnlen is a C2Y function previously vailable in POSIX.
16 const char hello4[] = "hello4";
17 const char hello5[7];
19 memcpy (hello5, hello4, 7);
21 ASSERT(strnlen("hello0", 23) == strlen("hello0"));
22 ASSERT(strnlen(hello1, 23) == strlen(hello1));
23 ASSERT(strnlen(hello2, 23) == strlen(hello2));
24 ASSERT(strnlen(hello3, 23) == strlen(hello3));
25 ASSERT(strnlen(hello4, 23) == strlen(hello4));
26 ASSERT(strnlen(hello5, 23) == strlen(hello5));
28 ASSERT(strnlen("hello0", 3) == 3);
29 ASSERT(strnlen(hello1, 3) == 3);
30 ASSERT(strnlen(hello2, 3) == 3);
31 ASSERT(strnlen(hello3, 3) == 3);
32 ASSERT(strnlen(hello4, 3) == 3);
33 ASSERT(strnlen(hello5, 3) == 3);
35 ASSERT(strnlen("hello0", 6) == 6);
36 ASSERT(strnlen(hello1, 6) == 6);
37 ASSERT(strnlen(hello2, 6) == 6);
38 ASSERT(strnlen(hello3, 6) == 6);
39 ASSERT(strnlen(hello4, 6) == 6);
40 ASSERT(strnlen(hello5, 6) == 6);
42 #if !(defined (__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // Lack of code memory
43 ASSERT(strnlen("hello0", 7) == 6);
44 ASSERT(strnlen(hello1, 7) == 6);
45 ASSERT(strnlen(hello2, 7) == 6);
46 ASSERT(strnlen(hello3, 7) == 6);
47 ASSERT(strnlen(hello4, 7) == 6);
48 ASSERT(strnlen(hello5, 7) == 6);
49 #endif
50 #endif