1 /*
2  * PROJECT:     ReactOS API tests
3  * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4  * PURPOSE:     Test for SHIsBadInterfacePtr
5  * COPYRIGHT:   Copyright 2025 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6  */
7 
8 #include "shelltest.h"
9 #include <undocshell.h>
10 
11 typedef BOOL (WINAPI *FN_SHIsBadInterfacePtr)(LPCVOID, UINT_PTR);
12 
13 static HRESULT STDMETHODCALLTYPE dummy_QueryInterface(REFIID riid, LPVOID *ppvObj) { return S_OK; }
14 static ULONG STDMETHODCALLTYPE dummy_AddRef() { return S_OK; }
15 static ULONG STDMETHODCALLTYPE dummy_Release() { return S_OK; }
16 
17 START_TEST(SHIsBadInterfacePtr)
18 {
19     struct CUnknownVtbl
20     {
21         HRESULT (STDMETHODCALLTYPE *QueryInterface)(REFIID riid, LPVOID *ppvObj);
22         ULONG (STDMETHODCALLTYPE *AddRef)();
23         ULONG (STDMETHODCALLTYPE *Release)();
24     };
25     struct CUnknown { CUnknownVtbl *lpVtbl; };
26 
27     BOOL ret;
28     FN_SHIsBadInterfacePtr SHIsBadInterfacePtr =
29         (FN_SHIsBadInterfacePtr)GetProcAddress(GetModuleHandleW(L"shell32"), MAKEINTRESOURCEA(84));
30 
31     if (!SHIsBadInterfacePtr)
32     {
33         skip("There is no SHIsBadInterfacePtr\n");
34         return;
35     }
36 
37     ret = SHIsBadInterfacePtr(NULL, 1);
38     ok_int(ret, TRUE);
39 
40     CUnknown unk1 = { NULL };
41     ret = SHIsBadInterfacePtr(&unk1, 1);
42     ok_int(ret, TRUE);
43 
44     CUnknownVtbl vtbl1 = { dummy_QueryInterface, dummy_AddRef, NULL };
45     CUnknown unk2 = { &vtbl1 };
46     ret = SHIsBadInterfacePtr(&unk2, 1);
47     ok_int(ret, TRUE);
48 
49     CUnknownVtbl vtbl2 = { dummy_QueryInterface, dummy_AddRef, dummy_Release };
50     CUnknown unk3 = { &vtbl2 };
51     ret = SHIsBadInterfacePtr(&unk3, 1);
52     ok_int(ret, FALSE);
53 }
54