Author: tkreuzer Date: Tue Oct 11 15:29:25 2011 New Revision: 54079
URL: http://svn.reactos.org/svn/reactos?rev=54079&view=rev Log: [ntdll_apitests] Add tests for NtQuery/SetSystemInformation
Added: trunk/rostests/apitests/ntdll/SystemInfo.c (with props) Modified: trunk/rostests/apitests/ntdll/CMakeLists.txt trunk/rostests/apitests/ntdll/testlist.c
Modified: trunk/rostests/apitests/ntdll/CMakeLists.txt URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/CMakeLists.... ============================================================================== --- trunk/rostests/apitests/ntdll/CMakeLists.txt [iso-8859-1] (original) +++ trunk/rostests/apitests/ntdll/CMakeLists.txt [iso-8859-1] Tue Oct 11 15:29:25 2011 @@ -4,6 +4,7 @@ list(APPEND SOURCE NtFreeVirtualMemory.c RtlInitializeBitMap.c + SystemInfo.c ZwContinue.c testlist.c)
@@ -14,5 +15,5 @@ add_executable(ntdll_apitest ${SOURCE}) target_link_libraries(ntdll_apitest wine) set_module_type(ntdll_apitest win32cui) -add_importlibs(ntdll_apitest msvcrt kernel32 ntdll) +add_importlibs(ntdll_apitest msvcrt advapi32 kernel32 ntdll) add_cd_file(TARGET ntdll_apitest DESTINATION reactos/bin FOR all)
Added: trunk/rostests/apitests/ntdll/SystemInfo.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/SystemInfo.... ============================================================================== --- trunk/rostests/apitests/ntdll/SystemInfo.c (added) +++ trunk/rostests/apitests/ntdll/SystemInfo.c [iso-8859-1] Tue Oct 11 15:29:25 2011 @@ -1,0 +1,126 @@ +/* + * 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(); +}
Propchange: trunk/rostests/apitests/ntdll/SystemInfo.c ------------------------------------------------------------------------------ svn:eol-style = native
Modified: trunk/rostests/apitests/ntdll/testlist.c URL: http://svn.reactos.org/svn/reactos/trunk/rostests/apitests/ntdll/testlist.c?... ============================================================================== --- trunk/rostests/apitests/ntdll/testlist.c [iso-8859-1] (original) +++ trunk/rostests/apitests/ntdll/testlist.c [iso-8859-1] Tue Oct 11 15:29:25 2011 @@ -8,12 +8,14 @@ extern void func_RtlInitializeBitMap(void); extern void func_ZwContinue(void); extern void func_NtFreeVirtualMemory(void); +extern void func_NtSystemInformation(void);
const struct test winetest_testlist[] = { { "RtlInitializeBitMap", func_RtlInitializeBitMap }, { "ZwContinue", func_ZwContinue }, { "NtFreeVirtualMemory", func_NtFreeVirtualMemory }, + { "NtSystemInformation", func_NtSystemInformation },
{ 0, 0 } };