struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / regression / tests / new_wide.c
blobfcb7baec1b27ac1c159700da7aca585ab8738a30
1 /* Tests new wide character conversion functions.
2 */
3 #include <testfwk.h>
5 #include <string.h>
7 #if defined(__SDCC) || defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && !defined(__APPLE__) && !defined(__OpenBSD__) // As of 2023, macOS and OpenBSD are still not fully C11-compliant: they lack uchar.h.
8 #include <uchar.h>
9 #endif
11 #define BUF_MAX 40
13 void testW(void)
15 #ifndef PORT_HOST
16 #if !(defined (__SDCC_mcs51) && defined (__SDCC_MODEL_SMALL)) && !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) // Not enough memory
17 char mb_buffer[BUF_MAX + 1];
18 char16_t c16_buffer[BUF_MAX + 1];
20 ASSERT(__c16stombs(mb_buffer, u"teststring", BUF_MAX) == strlen("teststring"));
22 ASSERT(!strcmp(mb_buffer, "teststring"));
24 ASSERT(__mbstoc16s(c16_buffer, "teststring2", BUF_MAX) == strlen("teststring2"));
26 ASSERT(!memcmp (c16_buffer, u"teststring2", 12 * 2));
28 ASSERT(__c16stombs(mb_buffer, c16_buffer, BUF_MAX) == strlen("teststring2"));
30 ASSERT(!strcmp(mb_buffer, "teststring2"));
32 __c16stombs(mb_buffer, u"Größere Körbe kosten 10 € mehr", BUF_MAX);
33 ASSERT(!strcmp(mb_buffer, "Größere Körbe kosten 10 € mehr"));
35 __mbstoc16s(c16_buffer, "Größere Körbe kosten 12 € mehr", BUF_MAX);
37 ASSERT(!memcmp (c16_buffer, u"Größere Körbe kosten 12 € mehr", 20 * 2));
39 __c16stombs(mb_buffer, c16_buffer, BUF_MAX);
41 ASSERT(!strcmp(mb_buffer, "Größere Körbe kosten 12 € mehr"));
42 #endif
43 #endif