mirror of
https://github.com/reactos/reactos.git
synced 2024-11-09 16:20:37 +00:00
802e11b708
Add tests for NtQuery/SetSystemInformation svn path=/trunk/; revision=54079
126 lines
4.1 KiB
C
126 lines
4.1 KiB
C
/*
|
|
* PROJECT: ReactOS api tests
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
* PURPOSE: Test for NtQuery/SetSystemInformation
|
|
* PROGRAMMERS: Timo Kreuzer
|
|
*/
|
|
|
|
#define WIN32_NO_STATUS
|
|
#include <stdio.h>
|
|
#include <wine/test.h>
|
|
#include <ndk/ntndk.h>
|
|
|
|
#define ok_long(x, y) \
|
|
ok(x == y, "got %ld, expected %ld\n", (long)x, (long)y);
|
|
|
|
#define ok_ntstatus(status, expected) \
|
|
ok(status == expected, "got 0x%lx, expected 0x%lx\n", status, expected);
|
|
// ok(status == expected, "expected: " ##expected## ", got 0x%lx\n", status)
|
|
|
|
void
|
|
GetPrivilege()
|
|
{
|
|
HANDLE hToken;
|
|
TOKEN_PRIVILEGES tkp;
|
|
|
|
OpenProcessToken(GetCurrentProcess(),
|
|
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
|
|
&hToken);
|
|
|
|
LookupPrivilegeValue(NULL, SE_SYSTEMTIME_NAME, &tkp.Privileges[0].Luid);
|
|
|
|
tkp.PrivilegeCount = 1;
|
|
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
|
|
|
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
|
|
}
|
|
|
|
|
|
void
|
|
Test_TimeAdjustment(void)
|
|
{
|
|
SYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfoOrg, GetTimeInfo;
|
|
SYSTEM_SET_TIME_ADJUST_INFORMATION SetTimeInfo;
|
|
NTSTATUS Status;
|
|
ULONG ReturnLength;
|
|
|
|
GetPrivilege();
|
|
|
|
SetTimeInfo.TimeAdjustment = 0;
|
|
SetTimeInfo.Enable = 0;
|
|
|
|
/* Query original values */
|
|
Status = NtQuerySystemInformation(SystemTimeAdjustmentInformation,
|
|
&TimeInfoOrg,
|
|
sizeof(TimeInfoOrg),
|
|
&ReturnLength);
|
|
|
|
/* Test without privilege */
|
|
Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
|
|
&SetTimeInfo,
|
|
sizeof(SetTimeInfo));
|
|
ok_ntstatus(Status, STATUS_PRIVILEGE_NOT_HELD);
|
|
|
|
/* Get the required privilege */
|
|
GetPrivilege();
|
|
|
|
/* Test wrong length */
|
|
Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
|
|
&SetTimeInfo,
|
|
sizeof(SetTimeInfo) + 1);
|
|
ok_ntstatus(Status, STATUS_INFO_LENGTH_MISMATCH);
|
|
|
|
/* Test both members 0 */
|
|
Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
|
|
&SetTimeInfo,
|
|
sizeof(SetTimeInfo));
|
|
ok_ntstatus(Status, STATUS_INVALID_PARAMETER_2);
|
|
|
|
/* Set huge value */
|
|
SetTimeInfo.TimeAdjustment = -1;
|
|
SetTimeInfo.Enable = 0;
|
|
Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
|
|
&SetTimeInfo,
|
|
sizeof(SetTimeInfo));
|
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
|
|
|
/* Query the result */
|
|
Status = NtQuerySystemInformation(SystemTimeAdjustmentInformation,
|
|
&GetTimeInfo,
|
|
sizeof(GetTimeInfo),
|
|
&ReturnLength);
|
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
|
ok_long(GetTimeInfo.TimeAdjustment, -1);
|
|
ok_long(GetTimeInfo.Enable, 0);
|
|
|
|
/* set Enable to 1 */
|
|
SetTimeInfo.TimeAdjustment = -1;
|
|
SetTimeInfo.Enable = 1;
|
|
Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
|
|
&SetTimeInfo,
|
|
sizeof(SetTimeInfo));
|
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
|
|
|
/* Query the result */
|
|
Status = NtQuerySystemInformation(SystemTimeAdjustmentInformation,
|
|
&GetTimeInfo,
|
|
sizeof(GetTimeInfo),
|
|
&ReturnLength);
|
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
|
ok_long(GetTimeInfo.TimeAdjustment, GetTimeInfo.TimeIncrement);
|
|
ok_long(GetTimeInfo.Enable, 1);
|
|
|
|
/* Restore original values */
|
|
SetTimeInfo.TimeAdjustment = TimeInfoOrg.TimeAdjustment;
|
|
SetTimeInfo.Enable = TimeInfoOrg.Enable;;
|
|
Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
|
|
&SetTimeInfo,
|
|
sizeof(SetTimeInfo));
|
|
ok_ntstatus(Status, STATUS_SUCCESS);
|
|
|
|
}
|
|
|
|
START_TEST(NtSystemInformation)
|
|
{
|
|
Test_TimeAdjustment();
|
|
}
|