FreeRDP
Loading...
Searching...
No Matches
TestTimeZoneNestedName.c
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <time.h>
5
6#include <winpr/wtypes.h>
7#include <winpr/string.h>
8#include <winpr/timezone.h>
9
10#if !defined(_WIN32)
11static BOOL test_tz(const char* iana, const char* expected)
12{
13 char key[128] = WINPR_C_ARRAY_INIT;
14 DYNAMIC_TIME_ZONE_INFORMATION tzif = WINPR_C_ARRAY_INIT;
15
16 // NOLINTNEXTLINE(concurrency-mt-unsafe)
17 if (setenv("TZ", iana, 1) != 0)
18 return FALSE;
19 tzset();
20
21 (void)GetDynamicTimeZoneInformation(&tzif);
22 if (ConvertWCharNToUtf8(tzif.TimeZoneKeyName, ARRAYSIZE(tzif.TimeZoneKeyName), key,
23 sizeof(key)) < 0)
24 return FALSE;
25
26 if (strcmp(key, expected) != 0)
27 {
28 (void)fprintf(stderr, "%s: expected time zone key '%s', got '%s'\n", iana, expected, key);
29 return FALSE;
30 }
31
32 const size_t expectedLength = strlen(expected);
33 if (expectedLength >= ARRAYSIZE(tzif.TimeZoneKeyName))
34 return FALSE;
35
36 const unsigned char* bytes = (const unsigned char*)tzif.TimeZoneKeyName;
37 for (size_t index = 0; index <= expectedLength; index++)
38 {
39 if ((bytes[2 * index] != (unsigned char)expected[index]) || (bytes[2 * index + 1] != 0))
40 {
41 (void)fprintf(stderr, "%s: time zone key is not UTF-16LE\n", iana);
42 return FALSE;
43 }
44 }
45 return TRUE;
46}
47#endif
48
49int TestTimeZoneNestedName(int argc, char* argv[])
50{
51 WINPR_UNUSED(argc);
52 WINPR_UNUSED(argv);
53
54#if !defined(_WIN32)
55 /* zone names with more than two parts */
56 if (!test_tz("America/Argentina/Salta", "Argentina Standard Time"))
57 return -1;
58 if (!test_tz("America/Indiana/Knox", "Central Standard Time"))
59 return -1;
60 if (!test_tz("America/North_Dakota/Center", "Central Standard Time"))
61 return -1;
62 /* and with two */
63 if (!test_tz("Europe/Berlin", "W. Europe Standard Time"))
64 return -1;
65#endif
66
67 return 0;
68}