6#include <winpr/wtypes.h>
7#include <winpr/string.h>
8#include <winpr/timezone.h>
11static BOOL test_tz(
const char* iana,
const char* expected)
13 char key[128] = WINPR_C_ARRAY_INIT;
17 if (setenv(
"TZ", iana, 1) != 0)
21 (void)GetDynamicTimeZoneInformation(&tzif);
22 if (ConvertWCharNToUtf8(tzif.TimeZoneKeyName, ARRAYSIZE(tzif.TimeZoneKeyName), key,
26 if (strcmp(key, expected) != 0)
28 (void)fprintf(stderr,
"%s: expected time zone key '%s', got '%s'\n", iana, expected, key);
32 const size_t expectedLength = strlen(expected);
33 if (expectedLength >= ARRAYSIZE(tzif.TimeZoneKeyName))
36 const unsigned char* bytes = (
const unsigned char*)tzif.TimeZoneKeyName;
37 for (
size_t index = 0; index <= expectedLength; index++)
39 if ((bytes[2 * index] != (
unsigned char)expected[index]) || (bytes[2 * index + 1] != 0))
41 (void)fprintf(stderr,
"%s: time zone key is not UTF-16LE\n", iana);
49int TestTimeZoneNestedName(
int argc,
char* argv[])
56 if (!test_tz(
"America/Argentina/Salta",
"Argentina Standard Time"))
58 if (!test_tz(
"America/Indiana/Knox",
"Central Standard Time"))
60 if (!test_tz(
"America/North_Dakota/Center",
"Central Standard Time"))
63 if (!test_tz(
"Europe/Berlin",
"W. Europe Standard Time"))