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 return TRUE;
32}
33#endif
34
35int TestTimeZoneNestedName(int argc, char* argv[])
36{
37 WINPR_UNUSED(argc);
38 WINPR_UNUSED(argv);
39
40#if !defined(_WIN32)
41 /* zone names with more than two parts */
42 if (!test_tz("America/Argentina/Salta", "Argentina Standard Time"))
43 return -1;
44 if (!test_tz("America/Indiana/Knox", "Central Standard Time"))
45 return -1;
46 if (!test_tz("America/North_Dakota/Center", "Central Standard Time"))
47 return -1;
48 /* and with two */
49 if (!test_tz("Europe/Berlin", "W. Europe Standard Time"))
50 return -1;
51#endif
52
53 return 0;
54}