1 /* 2 * PROJECT: ReactOS api tests 3 * LICENSE: GPLv2+ - See COPYING in the top level directory 4 * PURPOSE: Test for SaferIdentifyLevel 5 * PROGRAMMER: Thomas Faber <thomas.faber@reactos.org> 6 */ 7 8 #include "precomp.h" 9 10 #include <winsafer.h> 11 12 #define SaferIdentifyLevel(c, p, h, r) SaferIdentifyLevel(c, (PSAFER_CODE_PROPERTIES)(p), h, r) 13 14 START_TEST(SaferIdentifyLevel) 15 { 16 BOOL ret; 17 DWORD error; 18 SAFER_LEVEL_HANDLE handle; 19 SAFER_CODE_PROPERTIES_V2 props[16]; 20 21 StartSeh() 22 SetLastError(0xbadbad00); 23 ret = SaferIdentifyLevel(0, NULL, NULL, NULL); 24 error = GetLastError(); 25 ok(ret == FALSE, "ret = %d\n", ret); 26 ok(error == ERROR_NOACCESS, "error = %lu\n", error); 27 EndSeh(STATUS_SUCCESS); 28 29 StartSeh() 30 (VOID)SaferIdentifyLevel(0, NULL, &handle, NULL); 31 EndSeh(STATUS_ACCESS_VIOLATION); 32 33 StartSeh() 34 ZeroMemory(props, sizeof(props)); 35 SetLastError(0xbadbad00); 36 ret = SaferIdentifyLevel(16, props, &handle, NULL); 37 error = GetLastError(); 38 ok(ret == FALSE, "ret = %d\n", ret); 39 ok(error == ERROR_BAD_LENGTH, "error = %lu\n", error); 40 EndSeh(STATUS_SUCCESS); 41 42 StartSeh() 43 ZeroMemory(props, sizeof(props)); 44 SetLastError(0xbadbad00); 45 ret = SaferIdentifyLevel(1, props, NULL, NULL); 46 error = GetLastError(); 47 ok(ret == FALSE, "ret = %d\n", ret); 48 ok(error == ERROR_NOACCESS, "error = %lu\n", error); 49 EndSeh(STATUS_SUCCESS); 50 51 StartSeh() 52 handle = InvalidPointer; 53 ZeroMemory(props, sizeof(props)); 54 SetLastError(0xbadbad00); 55 ret = SaferIdentifyLevel(1, props, &handle, NULL); 56 error = GetLastError(); 57 ok(ret == FALSE, "ret = %d\n", ret); 58 ok(handle == InvalidPointer, "handle = %p\n", handle); 59 ok(error == ERROR_BAD_LENGTH, "error = %lu\n", error); 60 if (handle && handle != InvalidPointer) 61 SaferCloseLevel(handle); 62 EndSeh(STATUS_SUCCESS); 63 64 /* Struct sizes */ 65 StartSeh() 66 handle = InvalidPointer; 67 ZeroMemory(props, sizeof(props)); 68 props[0].cbSize = sizeof(SAFER_CODE_PROPERTIES_V1); 69 SetLastError(0xbadbad00); 70 ret = SaferIdentifyLevel(1, props, &handle, NULL); 71 error = GetLastError(); 72 ok(ret == TRUE, "ret = %d\n", ret); 73 ok(handle != NULL && handle != INVALID_HANDLE_VALUE && handle != InvalidPointer, "handle = %p\n", handle); 74 ok(error == 0xbadbad00, "error = %lu\n", error); 75 if (handle && handle != InvalidPointer) 76 { 77 ret = SaferCloseLevel(handle); 78 ok(ret == TRUE, "ret = %d\n", ret); 79 } 80 EndSeh(STATUS_SUCCESS); 81 82 StartSeh() 83 handle = InvalidPointer; 84 ZeroMemory(props, sizeof(props)); 85 props[0].cbSize = sizeof(SAFER_CODE_PROPERTIES_V2); 86 SetLastError(0xbadbad00); 87 ret = SaferIdentifyLevel(1, props, &handle, NULL); 88 error = GetLastError(); 89 ok(ret == FALSE, "ret = %d\n", ret); 90 ok(handle == InvalidPointer, "handle = %p\n", handle); 91 ok(error == ERROR_BAD_LENGTH, "error = %lu\n", error); 92 if (handle && handle != InvalidPointer) 93 SaferCloseLevel(handle); 94 EndSeh(STATUS_SUCCESS); 95 96 /* Test SaferCloseLevel too */ 97 StartSeh() 98 ret = SaferCloseLevel(NULL); 99 error = GetLastError(); 100 ok(ret == FALSE, "ret = %d\n", ret); 101 ok(error == ERROR_INVALID_HANDLE, "error = %lu\n", error); 102 EndSeh(STATUS_SUCCESS); 103 104 StartSeh() 105 ret = SaferCloseLevel(INVALID_HANDLE_VALUE); 106 error = GetLastError(); 107 ok(ret == FALSE, "ret = %d\n", ret); 108 ok(error == ERROR_INVALID_HANDLE, "error = %lu\n", error); 109 EndSeh(STATUS_SUCCESS); 110 111 StartSeh() 112 ret = SaferCloseLevel(InvalidPointer); 113 error = GetLastError(); 114 ok(ret == FALSE, "ret = %d\n", ret); 115 ok(error == ERROR_INVALID_HANDLE, "error = %lu\n", error); 116 EndSeh(STATUS_SUCCESS); 117 } 118