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