d63d65466287335c965ad9f3b64dc03739433ac3
[reactos.git] / rostests / apitests / ntdll / SystemInfo.c
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPL - See COPYING in the top level directory
4 * PURPOSE: Test for NtQuery/SetSystemInformation
5 * PROGRAMMERS: Timo Kreuzer
6 */
7
8 #define WIN32_NO_STATUS
9 #include <wine/test.h>
10 #include <ndk/exfuncs.h>
11
12 void
13 GetPrivilege()
14 {
15 HANDLE hToken;
16 TOKEN_PRIVILEGES tkp;
17
18 OpenProcessToken(GetCurrentProcess(),
19 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
20 &hToken);
21
22 LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
23
24 tkp.PrivilegeCount = 1;
25 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
26
27 AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
28 }
29
30
31 void
32 Test_TimeAdjustment(void)
33 {
34 SYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfoOrg, GetTimeInfo;
35 SYSTEM_SET_TIME_ADJUST_INFORMATION SetTimeInfo;
36 NTSTATUS Status;
37 ULONG ReturnLength;
38
39 GetPrivilege();
40
41 SetTimeInfo.TimeAdjustment = 0;
42 SetTimeInfo.Enable = 0;
43
44 /* Query original values */
45 Status = NtQuerySystemInformation(SystemTimeAdjustmentInformation,
46 &TimeInfoOrg,
47 sizeof(TimeInfoOrg),
48 &ReturnLength);
49
50 /* Test without privilege */
51 Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
52 &SetTimeInfo,
53 sizeof(SetTimeInfo));
54 ok_ntstatus(Status, STATUS_PRIVILEGE_NOT_HELD);
55
56 /* Get the required privilege */
57 GetPrivilege();
58
59 /* Test wrong length */
60 Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
61 &SetTimeInfo,
62 sizeof(SetTimeInfo) + 1);
63 ok_ntstatus(Status, STATUS_INFO_LENGTH_MISMATCH);
64
65 /* Test both members 0 */
66 Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
67 &SetTimeInfo,
68 sizeof(SetTimeInfo));
69 ok_ntstatus(Status, STATUS_INVALID_PARAMETER_2);
70
71 /* Set huge value */
72 SetTimeInfo.TimeAdjustment = -1;
73 SetTimeInfo.Enable = 0;
74 Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
75 &SetTimeInfo,
76 sizeof(SetTimeInfo));
77 ok_ntstatus(Status, STATUS_SUCCESS);
78
79 /* Query the result */
80 Status = NtQuerySystemInformation(SystemTimeAdjustmentInformation,
81 &GetTimeInfo,
82 sizeof(GetTimeInfo),
83 &ReturnLength);
84 ok_ntstatus(Status, STATUS_SUCCESS);
85 ok_long(GetTimeInfo.TimeAdjustment, -1);
86 ok_long(GetTimeInfo.Enable, 0);
87
88 /* set Enable to 1 */
89 SetTimeInfo.TimeAdjustment = -1;
90 SetTimeInfo.Enable = 1;
91 Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
92 &SetTimeInfo,
93 sizeof(SetTimeInfo));
94 ok_ntstatus(Status, STATUS_SUCCESS);
95
96 /* Query the result */
97 Status = NtQuerySystemInformation(SystemTimeAdjustmentInformation,
98 &GetTimeInfo,
99 sizeof(GetTimeInfo),
100 &ReturnLength);
101 ok_ntstatus(Status, STATUS_SUCCESS);
102 ok_long(GetTimeInfo.TimeAdjustment, GetTimeInfo.TimeIncrement);
103 ok_long(GetTimeInfo.Enable, 1);
104
105 /* Restore original values */
106 SetTimeInfo.TimeAdjustment = TimeInfoOrg.TimeAdjustment;
107 SetTimeInfo.Enable = TimeInfoOrg.Enable;;
108 Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
109 &SetTimeInfo,
110 sizeof(SetTimeInfo));
111 ok_ntstatus(Status, STATUS_SUCCESS);
112
113 }
114
115 START_TEST(NtSystemInformation)
116 {
117 Test_TimeAdjustment();
118 }