Add inttypes.h and missing dependencies.
[sdcc.git] / sdcc / support / regression / tests / wcsto.c
blobb068e551241348b2e077917bd0e4e13b3feafb51
1 /** wcsto.c
2 */
3 #include <testfwk.h>
5 #include <stdlib.h>
6 #include <string.h>
7 #include <limits.h>
8 #include <errno.h>
9 #include <wchar.h>
11 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !defined(__SDCC_mcs51) // Lack of memory
12 wchar_t string0[] = L"-2";
13 wchar_t string1[] = L"-9999999999999999999999";
14 wchar_t string2[] = L"9999999999999999999999";
15 wchar_t string3[] = L"-2test";
16 wchar_t string4[] = L"test";
17 wchar_t string5[] = L"023test";
18 wchar_t string6[] = L"-0x23test";
19 #endif
21 void
22 testWcsto(void)
24 #if !defined(__SDCC_pdk14) && !defined(__SDCC_pdk15) && !defined(__SDCC_mcs51) // Lack of memory
25 char *e;
27 ASSERT(wcstoul(L"", 0, 10) == 0);
28 ASSERT(wcstoul(L"2", 0, 10) == 2);
29 ASSERT(wcstoul(L"3", 0, 10) == 3);
30 ASSERT(wcstoul(L"23", 0, 10) == 23);
32 ASSERT(wcstoul(L"23", 0, 0) == 23);
33 ASSERT(wcstoul(L"023", 0, 0) == 023);
34 ASSERT(wcstoul(L"0x23", 0, 0) == 0x23);
36 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202300L // C2X introduces binary prefix.
37 ASSERT(wcstoul(L"0b11", 0, 0) == 0b11);
38 ASSERT(wcstoul(L"0b11", 0, 2) == 0b11);
39 #endif
41 ASSERT(wcstoul(L"+23", 0, 0) == +23);
42 ASSERT(wcstoul(L"+023", 0, 0) == +023);
43 ASSERT(wcstoul(L"+0x23", 0, 0) == +0x23);
45 ASSERT(wcstol(L"-42", 0, 0) == -42);
46 ASSERT(wcstol(L"-042", 0, 0) == -042);
47 ASSERT(wcstol(L"-0x42", 0, 0) == -0x42);
48 ASSERT(wcstol(L"-0x42", 0, 16) == -0x42);
50 #if ULONG_MAX == 4294967295
51 errno = 0;
52 wcstoul(L"4294967296", 0, 10);
53 ASSERT(errno == ERANGE);
54 #endif
56 errno = 0;
57 ASSERT(wcstol(string1, &e, 10) == LONG_MIN);
58 ASSERT(errno == ERANGE);
59 ASSERT(e == string1 + wcslen(string1));
61 errno = 0;
62 ASSERT(wcstol(string2, &e, 10) == LONG_MAX);
63 ASSERT(errno == ERANGE);
64 ASSERT(e == string2 + wcslen(string2));
66 errno = 0;
67 ASSERT(wcstoul(string0, &e, 10) == (unsigned long int)(-2));
68 ASSERT(errno != ERANGE);
69 ASSERT(e == string0 + wcslen(string0));
71 errno = 0;
72 ASSERT(wcstoul(string2, &e, 10) == ULONG_MAX);
73 ASSERT(errno == ERANGE);
74 ASSERT(e == string2 + wcslen(string2));
76 errno = 0;
77 ASSERT(wcstol(string3, &e, 10) == -2);
78 ASSERT(errno != ERANGE);
79 ASSERT(e == string3 + 2);
81 errno = 0;
82 ASSERT(wcstol(string4, &e, 0) == 0);
83 ASSERT(errno != ERANGE);
84 ASSERT(e == string4);
86 errno = 0;
87 ASSERT(wcstol(string5, &e, 0) == 023);
88 ASSERT(errno != ERANGE);
89 ASSERT(e == string5 + 3);
91 errno = 0;
92 ASSERT(wcstol(string6, &e, 0) == -0x23);
93 ASSERT(errno != ERANGE);
94 ASSERT(e == string6 + 5);
95 #endif