mirror of
https://github.com/reactos/reactos.git
synced 2024-11-18 21:13:52 +00:00
d3b058d4eb
- Fix test failure on Windows. Based on patch by Víctor Martínez ROSTESTS-132 #resolve svn path=/trunk/; revision=62734
118 lines
3.9 KiB
C
118 lines
3.9 KiB
C
/*
|
|
* PROJECT: ReactOS api tests
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
* PURPOSE: Test for NtQuery/SetSystemInformation
|
|
* PROGRAMMERS: Timo Kreuzer
|
|
*/
|
|
|
|
#include <apitest.h>
|
|
|
|
#define WIN32_NO_STATUS
|
|
#include <ndk/exfuncs.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);
|
|
CloseHandle(hToken);
|
|
}
|
|
|
|
|
|
void
|
|
Test_TimeAdjustment(void)
|
|
{
|
|
SYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfoOrg, GetTimeInfo;
|
|
SYSTEM_SET_TIME_ADJUST_INFORMATION SetTimeInfo;
|
|
NTSTATUS Status;
|
|
ULONG ReturnLength;
|
|
|
|
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();
|
|
}
|