Pick three bugfixes from next branch to trunk for inclusion in 4.5.0 RC2, as discusse...
[sdcc.git] / sdcc / support / regression / tests / wcsnlen.c
blob062fb6c1ba50c69be66fa32b645ecb8e9801cf00
1 /** tests for wcsnlen
2 */
4 #include <testfwk.h>
6 #include <string.h>
7 #include <wchar.h>
9 const wchar_t* hello1 = L"hello1";
10 const wchar_t hello2[] = L"hello2";
11 wchar_t hello3[] = L"hello3";
13 void
14 testStr(void)
16 #if defined(__SDCC) || (_POSIX_C_SOURCE >= 200809L) || (__STDC_VERSION_STRING_H__ > 202311L) // wcsnlen is a C2Y function previously vailable in POSIX.
17 #ifndef __SDCC_pdk14 // lack of RAM
18 const wchar_t hello4[] = L"hello4";
19 const wchar_t hello5[7];
21 memcpy (hello5, hello4, 7 * sizeof(wchar_t));
23 ASSERT(wcsnlen(L"hello0", 23) == wcslen(L"hello0"));
24 ASSERT(wcsnlen(hello1, 23) == wcslen(hello1));
25 ASSERT(wcsnlen(hello2, 23) == wcslen(hello2));
26 ASSERT(wcsnlen(hello3, 23) == wcslen(hello3));
27 ASSERT(wcsnlen(hello4, 23) == wcslen(hello4));
28 ASSERT(wcsnlen(hello5, 23) == wcslen(hello5));
30 ASSERT(wcsnlen(L"hello0", 3) == 3);
31 ASSERT(wcsnlen(hello1, 3) == 3);
32 ASSERT(wcsnlen(hello2, 3) == 3);
33 ASSERT(wcsnlen(hello3, 3) == 3);
34 ASSERT(wcsnlen(hello4, 3) == 3);
35 ASSERT(wcsnlen(hello5, 3) == 3);
37 #if !(defined(__SDCC_pdk15) && defined(__SDCC_STACK_AUTO)) // lack of code memory
38 ASSERT(wcsnlen(L"hello0", 6) == 6);
39 ASSERT(wcsnlen(hello1, 6) == 6);
40 ASSERT(wcsnlen(hello2, 6) == 6);
41 ASSERT(wcsnlen(hello3, 6) == 6);
42 ASSERT(wcsnlen(hello4, 6) == 6);
43 ASSERT(wcsnlen(hello5, 6) == 6);
45 ASSERT(wcsnlen(L"hello0", 7) == 6);
46 ASSERT(wcsnlen(hello1, 7) == 6);
47 ASSERT(wcsnlen(hello2, 7) == 6);
48 ASSERT(wcsnlen(hello3, 7) == 6);
49 ASSERT(wcsnlen(hello4, 7) == 6);
50 ASSERT(wcsnlen(hello5, 7) == 6);
51 #endif
52 #endif
53 #endif