From 03dfa332723cd2c40c991f5373c8e57a1d7960e5 Mon Sep 17 00:00:00 2001 From: Thomas Faber Date: Sat, 27 Apr 2013 09:12:20 +0000 Subject: [PATCH] [ADVAPI32_APITEST] - Add basic parameter tests for SaferIdentifyLevel CORE-6942 svn path=/trunk/; revision=58867 --- rostests/apitests/advapi32/CMakeLists.txt | 11 +- .../apitests/advapi32/SaferIdentifyLevel.c | 125 ++++++++++++++++++ rostests/apitests/advapi32/testlist.c | 2 + 3 files changed, 133 insertions(+), 5 deletions(-) create mode 100644 rostests/apitests/advapi32/SaferIdentifyLevel.c diff --git a/rostests/apitests/advapi32/CMakeLists.txt b/rostests/apitests/advapi32/CMakeLists.txt index ca8e6faa7b0..d28d6517881 100644 --- a/rostests/apitests/advapi32/CMakeLists.txt +++ b/rostests/apitests/advapi32/CMakeLists.txt @@ -1,12 +1,13 @@ list(APPEND SOURCE - CreateService.c - LockDatabase.c - QueryServiceConfig2.c - testlist.c) + CreateService.c + LockDatabase.c + QueryServiceConfig2.c + SaferIdentifyLevel.c + testlist.c) add_executable(advapi32_apitest ${SOURCE}) -target_link_libraries(advapi32_apitest wine) +target_link_libraries(advapi32_apitest wine ${PSEH_LIB}) set_module_type(advapi32_apitest win32cui) add_importlibs(advapi32_apitest advapi32 msvcrt kernel32 ntdll) add_cd_file(TARGET advapi32_apitest DESTINATION reactos/bin FOR all) diff --git a/rostests/apitests/advapi32/SaferIdentifyLevel.c b/rostests/apitests/advapi32/SaferIdentifyLevel.c new file mode 100644 index 00000000000..c0aba386f85 --- /dev/null +++ b/rostests/apitests/advapi32/SaferIdentifyLevel.c @@ -0,0 +1,125 @@ +/* + * PROJECT: ReactOS api tests + * LICENSE: GPLv2+ - See COPYING in the top level directory + * PURPOSE: Test for SaferIdentifyLevel + * PROGRAMMER: Thomas Faber + */ + +#define WIN32_NO_STATUS +#include +#include +#include +#include + +#define StartSeh() ExceptionStatus = STATUS_SUCCESS; _SEH2_TRY { +#define EndSeh(ExpectedStatus) } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { ExceptionStatus = _SEH2_GetExceptionCode(); } _SEH2_END; ok(ExceptionStatus == ExpectedStatus, "Exception %lx, expected %lx\n", ExceptionStatus, ExpectedStatus) + +#define InvalidPointer ((PVOID)0x5555555555555555ULL) + +#define SaferIdentifyLevel(c, p, h, r) SaferIdentifyLevel(c, (PSAFER_CODE_PROPERTIES)(p), h, r) + +START_TEST(SaferIdentifyLevel) +{ + NTSTATUS ExceptionStatus; + BOOL ret; + DWORD error; + SAFER_LEVEL_HANDLE handle; + SAFER_CODE_PROPERTIES_V2 props[16]; + + StartSeh() + SetLastError(0xbadbad00); + ret = SaferIdentifyLevel(0, NULL, NULL, NULL); + error = GetLastError(); + ok(ret == FALSE, "ret = %d\n", ret); + ok(error == ERROR_NOACCESS, "error = %lu\n", error); + EndSeh(STATUS_SUCCESS); + + StartSeh() + (VOID)SaferIdentifyLevel(0, NULL, &handle, NULL); + EndSeh(STATUS_ACCESS_VIOLATION); + + StartSeh() + ZeroMemory(props, sizeof(props)); + SetLastError(0xbadbad00); + ret = SaferIdentifyLevel(16, props, &handle, NULL); + error = GetLastError(); + ok(ret == FALSE, "ret = %d\n", ret); + ok(error == ERROR_BAD_LENGTH, "error = %lu\n", error); + EndSeh(STATUS_SUCCESS); + + StartSeh() + ZeroMemory(props, sizeof(props)); + SetLastError(0xbadbad00); + ret = SaferIdentifyLevel(1, props, NULL, NULL); + error = GetLastError(); + ok(ret == FALSE, "ret = %d\n", ret); + ok(error == ERROR_NOACCESS, "error = %lu\n", error); + EndSeh(STATUS_SUCCESS); + + StartSeh() + handle = InvalidPointer; + ZeroMemory(props, sizeof(props)); + SetLastError(0xbadbad00); + ret = SaferIdentifyLevel(1, props, &handle, NULL); + error = GetLastError(); + ok(ret == FALSE, "ret = %d\n", ret); + ok(handle == InvalidPointer, "handle = %p\n", handle); + ok(error == ERROR_BAD_LENGTH, "error = %lu\n", error); + if (handle && handle != InvalidPointer) + SaferCloseLevel(handle); + EndSeh(STATUS_SUCCESS); + + /* Struct sizes */ + StartSeh() + handle = InvalidPointer; + ZeroMemory(props, sizeof(props)); + props[0].cbSize = sizeof(SAFER_CODE_PROPERTIES_V1); + SetLastError(0xbadbad00); + ret = SaferIdentifyLevel(1, props, &handle, NULL); + error = GetLastError(); + ok(ret == TRUE, "ret = %d\n", ret); + ok(handle != NULL && handle != INVALID_HANDLE_VALUE && handle != InvalidPointer, "handle = %p\n", handle); + ok(error == 0xbadbad00, "error = %lu\n", error); + if (handle && handle != InvalidPointer) + { + ret = SaferCloseLevel(handle); + ok(ret == TRUE, "ret = %d\n", ret); + } + EndSeh(STATUS_SUCCESS); + + StartSeh() + handle = InvalidPointer; + ZeroMemory(props, sizeof(props)); + props[0].cbSize = sizeof(SAFER_CODE_PROPERTIES_V2); + SetLastError(0xbadbad00); + ret = SaferIdentifyLevel(1, props, &handle, NULL); + error = GetLastError(); + ok(ret == FALSE, "ret = %d\n", ret); + ok(handle == InvalidPointer, "handle = %p\n", handle); + ok(error == ERROR_BAD_LENGTH, "error = %lu\n", error); + if (handle && handle != InvalidPointer) + SaferCloseLevel(handle); + EndSeh(STATUS_SUCCESS); + + /* Test SaferCloseLevel too */ + StartSeh() + ret = SaferCloseLevel(NULL); + error = GetLastError(); + ok(ret == FALSE, "ret = %d\n", ret); + ok(error == ERROR_INVALID_HANDLE, "error = %lu\n", error); + EndSeh(STATUS_SUCCESS); + + StartSeh() + ret = SaferCloseLevel(INVALID_HANDLE_VALUE); + error = GetLastError(); + ok(ret == FALSE, "ret = %d\n", ret); + ok(error == ERROR_INVALID_HANDLE, "error = %lu\n", error); + EndSeh(STATUS_SUCCESS); + + StartSeh() + ret = SaferCloseLevel(InvalidPointer); + error = GetLastError(); + ok(ret == FALSE, "ret = %d\n", ret); + ok(error == ERROR_INVALID_HANDLE, "error = %lu\n", error); + EndSeh(STATUS_SUCCESS); +} diff --git a/rostests/apitests/advapi32/testlist.c b/rostests/apitests/advapi32/testlist.c index f0301125922..d5debe96f3d 100644 --- a/rostests/apitests/advapi32/testlist.c +++ b/rostests/apitests/advapi32/testlist.c @@ -6,12 +6,14 @@ extern void func_CreateService(void); extern void func_LockDatabase(void); extern void func_QueryServiceConfig2(void); +extern void func_SaferIdentifyLevel(void); const struct test winetest_testlist[] = { { "CreateService", func_CreateService }, { "LockDatabase" , func_LockDatabase }, { "QueryServiceConfig2", func_QueryServiceConfig2 }, + { "SaferIdentifyLevel", func_SaferIdentifyLevel }, { 0, 0 } }; -- 2.17.1