ReactOS 0.4.16-dev-1537-g4e425b5
RtlQueryTimeZoneInfo.c
Go to the documentation of this file.
1/*
2 * PROJECT: ntdll_apitest
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Tests for RtlQueryTimeZoneInformation
5 * COPYRIGHT: Copyright 2018 Doug Lyons
6 */
7
8#include "precomp.h"
9
10static NTSTATUS (WINAPI *pRtlQueryTimeZoneInformation)( RTL_TIME_ZONE_INFORMATION *);
11
13{
16 TIME_ZONE_INFORMATION tziOld, tziNew, tziTest;
17 DWORD dwRet;
18
19 // Retrieve the current time zone information
20
21 dwRet = GetTimeZoneInformation(&tziOld);
22
24 "Get Time Zone Name failed with error = %ld.\n", GetLastError());
25
26 // Adjust the time zone information
27
28 ZeroMemory(&tziNew, sizeof(tziNew));
29 tziNew.Bias = 360;
30 wcscpy(tziNew.StandardName, L"Test Standard Zone");
31 tziNew.StandardDate.wMonth = 11;
32 tziNew.StandardDate.wDayOfWeek = 5;
33 tziNew.StandardDate.wDay = 3;
34 tziNew.StandardDate.wHour = 2;
35 tziNew.StandardBias = 120;
36
37 wcscpy(tziNew.DaylightName, L"Test Daylight Zone");
38 tziNew.DaylightDate.wMonth = 4;
39 tziNew.DaylightDate.wDayOfWeek = 6;
40 tziNew.DaylightDate.wDay = 2;
41 tziNew.DaylightDate.wHour = 2;
42 tziNew.DaylightBias = -60;
43
44 // Set up SetLastError with known value for later testing
45
46 SetLastError(0xDEADBEEF);
47
48 ok(SetTimeZoneInformation(&tziNew) ,
49 "Set Time Zone Information failed with error = %ld.\n", GetLastError());
50
51 // if we got an error the function failed, so there is not much else we can do
52
53 if(GetLastError() != 0xDEADBEEF)
54 {
55 win_skip("SetTimeZoneInformation() is not available, so tests cannot be run.\n");
56 return;
57 }
58
59 // Retrieve and display the newly set time zone information
60
61 dwRet = GetTimeZoneInformation(&tziTest);
62
64 "Get Time Zone Information Returned failed with error = %ld.\n", GetLastError());
65
66 ok(!wcscmp(tziTest.StandardName, tziNew.StandardName),
67 "Standard Time Zone Name = %ls, expected %ls.\n", tziTest.StandardName, tziNew.StandardName);
68
69 ok(!wcscmp(tziTest.DaylightName, tziNew.DaylightName),
70 "Standard Time Zone Name = %ls, expected %ls.\n", tziTest.DaylightName, tziNew.DaylightName);
71
72 /* test RtlQueryTimeZoneInformation returns a TIME_ZONE_INFORMATION structure */
73
74 if (!pRtlQueryTimeZoneInformation)
75 {
76 win_skip("pRtlQueryTimeZoneInformation() fails, so tests cannot be run.\n");
77 return;
78 }
79
80 /* Clear Time Zone Info field */
81 memset(&tzinfo, 0, sizeof(tzinfo));
82
83 /* Read Time Zone Info */
84 status = pRtlQueryTimeZoneInformation(&tzinfo);
85 ok(status == STATUS_SUCCESS, "pRtlQueryTimeZoneInformation failed, got %08lx\n", status);
86
87 /* Check for the Daylight Date Info */
88 ok(tzinfo.DaylightDate.Month == 4, "tzinfo.DaylightDate.wMonth expected '4', got '%d'.\n", tzinfo.DaylightDate.Month);
89 ok(tzinfo.DaylightDate.Day == 2, "tzinfo.DaylightDate.wDay expected '2', got '%d'.\n", tzinfo.DaylightDate.Day);
90 ok(tzinfo.DaylightDate.Weekday == 6, "tzinfo.DaylightDate.wDayOfWeek expected '6', got '%d'.\n", tzinfo.DaylightDate.Weekday);
91 ok(tzinfo.DaylightDate.Year == 0, "tzinfo.DaylightDate.wYear expected '0', got '%d'.\n", tzinfo.DaylightDate.Year);
92
93 /* Check for the Standard Data Info */
94 ok(tzinfo.StandardDate.Month == 11, "tzinfo.StandardDate.wMonth expected '11', got '%d'.\n", tzinfo.StandardDate.Month);
95 ok(tzinfo.StandardDate.Day == 3, "tzinfo.StandardDate.wDay expected '3', got '%d'.\n", tzinfo.StandardDate.Day);
96 ok(tzinfo.StandardDate.Weekday == 5, "tzinfo.StandardDate.wDayOfWeek expected '5', got '%d'.\n", tzinfo.StandardDate.Weekday);
97 ok(tzinfo.StandardDate.Year == 0, "tzinfo.StandardDate.wYear expected '0', got '%d'.\n", tzinfo.StandardDate.Year);
98
99 /* Check for the Bias Info */
100 ok(tzinfo.Bias == 360, "tzinfo.Bias expected '360', got '%ld'.\n", tzinfo.Bias);
101 ok(tzinfo.DaylightBias == -60, "tzinfo.DaylightBias expected '-60', got '%ld'.\n", tzinfo.DaylightBias);
102 ok(tzinfo.StandardBias == 120, "tzinfo.StandardBias expected '120', got '%ld'.\n", tzinfo.StandardBias);
103
104 // Restore the original time zone information and put things back like we found them originally
105 ok(SetTimeZoneInformation(&tziOld),
106 "Set Time Zone Information failed with error = %ld.\n", GetLastError());
107
108}
109
110
112{
113 /* Test modeled after reactos\modules\rostests\winetests\ntdll\time.c for Vista+ */
114 HMODULE mod = GetModuleHandleA("ntdll.dll");
115 pRtlQueryTimeZoneInformation = (void *)GetProcAddress(mod, "RtlQueryTimeZoneInformation");
116
118}
std::map< E_MODULE, HMODULE > mod
Definition: LocaleTests.cpp:66
static void test_RtlQueryTimeZoneInformation(void)
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
LONG NTSTATUS
Definition: precomp.h:26
wcscpy
#define NTSTATUS
Definition: precomp.h:19
#define SetLastError(x)
Definition: compat.h:752
#define GetProcAddress(x, y)
Definition: compat.h:753
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
BOOL WINAPI SetTimeZoneInformation(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation)
Definition: timezone.c:316
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
#define L(x)
Definition: resources.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI NTSTATUS NTAPI RtlQueryTimeZoneInformation(_Out_ PRTL_TIME_ZONE_INFORMATION TimeZoneInformation)
#define TIME_ZONE_ID_UNKNOWN
Definition: rtltypes.h:252
#define TIME_ZONE_ID_STANDARD
Definition: rtltypes.h:253
#define TIME_ZONE_ID_DAYLIGHT
Definition: rtltypes.h:254
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define win_skip
Definition: test.h:164
#define memset(x, y, z)
Definition: compat.h:39
#define STATUS_SUCCESS
Definition: shellext.h:65
WORD wMonth
Definition: winbase.h:947
WORD wHour
Definition: winbase.h:950
WORD wDay
Definition: winbase.h:949
WORD wDayOfWeek
Definition: winbase.h:948
USHORT Weekday
Definition: env_spec_w32.h:718
SYSTEMTIME DaylightDate
Definition: winbase.h:1252
WCHAR DaylightName[32]
Definition: winbase.h:1251
WCHAR StandardName[32]
Definition: winbase.h:1248
SYSTEMTIME StandardDate
Definition: winbase.h:1249
Definition: ps.c:97
#define ZeroMemory
Definition: winbase.h:1753
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6