1 /* 2 * PROJECT: ReactOS API tests 3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) 4 * PURPOSE: Validate the apiset lookup in ApiSetResolveToHost 5 * COPYRIGHT: Copyright 2024 Mark Jansen <mark.jansen@reactos.org> 6 */ 7 8 #include <ndk/umtypes.h> 9 #include <ndk/rtlfuncs.h> 10 #include <apitest.h> 11 #include "apisetsp.h" 12 13 static void 14 resolve_single(PCUNICODE_STRING Apiset) 15 { 16 UNICODE_STRING Tmp = {0}; 17 NTSTATUS Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, Apiset, &Tmp); 18 ok_ntstatus(Status, STATUS_SUCCESS); 19 20 BOOLEAN Resolved = FALSE; 21 UNICODE_STRING Result = {0}; 22 23 Status = ApiSetResolveToHost(~0u, &Tmp, &Resolved, &Result); 24 ok_ntstatus(Status, STATUS_SUCCESS); 25 ok_eq_bool(Resolved, TRUE); 26 ok(Result.Buffer != NULL, "Got NULL\n"); 27 } 28 29 static void 30 resolve_fail_single(PCUNICODE_STRING Apiset) 31 { 32 UNICODE_STRING Tmp = {0}; 33 NTSTATUS Status = RtlDuplicateUnicodeString(RTL_DUPLICATE_UNICODE_STRING_NULL_TERMINATE, Apiset, &Tmp); 34 ok_ntstatus(Status, STATUS_SUCCESS); 35 36 BOOLEAN Resolved = FALSE; 37 UNICODE_STRING Result = {0, 0, (PWSTR)0xbadbeef}; 38 39 Status = ApiSetResolveToHost(~0u, &Tmp, &Resolved, &Result); 40 ok_ntstatus(Status, STATUS_SUCCESS); 41 ok_eq_bool(Resolved, FALSE); 42 ok_ptr(Result.Buffer, (PWSTR)0xbadbeef); 43 } 44 45 static void 46 test_single(PCUNICODE_STRING Apiset) 47 { 48 winetest_push_context("%S", Apiset->Buffer); 49 resolve_single(Apiset); 50 winetest_pop_context(); 51 } 52 53 static void 54 fail_single(PCUNICODE_STRING Apiset) 55 { 56 winetest_push_context("%S", Apiset->Buffer); 57 resolve_fail_single(Apiset); 58 winetest_pop_context(); 59 } 60 61 62 START_TEST(apisets) 63 { 64 // Ensure we can find some manually selected ones (both with and without extension): 65 UNICODE_STRING Console1 = RTL_CONSTANT_STRING(L"api-MS-Win-Core-Console-L1-1-0.dll"); 66 UNICODE_STRING Console2 = RTL_CONSTANT_STRING(L"api-MS-Win-Core-Console-L1-1-0"); 67 UNICODE_STRING Handle1 = RTL_CONSTANT_STRING(L"api-MS-Win-Core-Handle-L1-1-0.dll"); 68 UNICODE_STRING Handle2 = RTL_CONSTANT_STRING(L"api-MS-Win-Core-Handle-L1-1-0"); 69 UNICODE_STRING Heap1 = RTL_CONSTANT_STRING(L"api-MS-Win-Core-Heap-L1-1-0.dll"); 70 UNICODE_STRING Heap2 = RTL_CONSTANT_STRING(L"api-MS-Win-Core-Heap-L1-1-0"); 71 72 test_single(&Console1); 73 test_single(&Console2); 74 test_single(&Handle1); 75 test_single(&Handle2); 76 test_single(&Heap1); 77 test_single(&Heap2); 78 79 // Walk the entire table, to ensure we can find each entry 80 for (DWORD n = 0; n < g_ApisetsCount; ++n) 81 { 82 PCUNICODE_STRING Apiset = &g_Apisets[n].Name; 83 winetest_push_context("%ld: %S", n, Apiset->Buffer); 84 resolve_single(Apiset); 85 winetest_pop_context(); 86 } 87 88 UNICODE_STRING Fail1 = RTL_CONSTANT_STRING(L""); 89 UNICODE_STRING Fail2 = RTL_CONSTANT_STRING(L"api-"); 90 UNICODE_STRING Fail3 = RTL_CONSTANT_STRING(L"ext"); 91 92 fail_single(&Fail1); 93 fail_single(&Fail2); 94 fail_single(&Fail3); 95 } 96