[ADVAPI32_APITEST]
authorThomas Faber <thomas.faber@reactos.org>
Sat, 27 Apr 2013 09:12:20 +0000 (09:12 +0000)
committerThomas Faber <thomas.faber@reactos.org>
Sat, 27 Apr 2013 09:12:20 +0000 (09:12 +0000)
- Add basic parameter tests for SaferIdentifyLevel
CORE-6942

svn path=/trunk/; revision=58867

rostests/apitests/advapi32/CMakeLists.txt
rostests/apitests/advapi32/SaferIdentifyLevel.c [new file with mode: 0644]
rostests/apitests/advapi32/testlist.c

index ca8e6fa..d28d651 100644 (file)
@@ -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 (file)
index 0000000..c0aba38
--- /dev/null
@@ -0,0 +1,125 @@
+/*
+ * PROJECT:         ReactOS api tests
+ * LICENSE:         GPLv2+ - See COPYING in the top level directory
+ * PURPOSE:         Test for SaferIdentifyLevel
+ * PROGRAMMER:      Thomas Faber <thfabba@gmx.de>
+ */
+
+#define WIN32_NO_STATUS
+#include <wine/test.h>
+#include <windows.h>
+#include <ndk/ntndk.h>
+#include <winsafer.h>
+
+#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);
+}
index f030112..d5debe9 100644 (file)
@@ -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 }
 };