reactos/rostests/apitests/ntdll/SystemInfo.c

120 lines
3.9 KiB
C
Raw Normal View History

/*
* 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>
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();
}