mirror of
https://github.com/reactos/reactos.git
synced 2024-11-07 15:10:53 +00:00
fe6644f895
- No need now to declare a NTSTATUS ExceptionStatus; variable to be able to use StartSeh() / EndSeh() macros; this is done automagically. - Use explicitely unicode macros where it's needed. svn path=/trunk/; revision=60319
119 lines
3.9 KiB
C
119 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);
|
|
}
|
|
|
|
|
|
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();
|
|
}
|