2 * PROJECT: appshim_apitest
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test to document the hooks used by various shims in AcLayers
5 * COPYRIGHT: Copyright 2018 Mark Jansen (mark.jansen@reactos.org)
9 #define WIN32_NO_STATUS
11 #include <ndk/rtlfuncs.h>
13 #include "wine/test.h"
15 #include "appshim_apitest.h"
17 static DWORD g_WinVersion
;
20 typedef struct expect_shim_hook
26 typedef struct expect_shim_data
28 const WCHAR
* ShimName
;
30 expect_shim_hook hooks
[4];
34 static expect_shim_data data
[] =
37 L
"VerifyVersionInfoLite",
40 { "KERNEL32.DLL", "VerifyVersionInfoA" },
41 { "KERNEL32.DLL", "VerifyVersionInfoW" },
46 static DWORD
count_shims(expect_shim_data
* data
)
49 for (num
= 0; num
< _countof(data
->hooks
) && data
->hooks
[num
].Library
;)
56 static const char* safe_str(const char* ptr
)
58 static char buffer
[2][30];
64 StringCchPrintfA(buffer
[index
], _countof(buffer
[index
]), "#%d", (int)ptr
);
68 START_TEST(layer_hooks
)
70 RTL_OSVERSIONINFOEXW rtlinfo
= {0};
73 tGETHOOKAPIS pGetHookAPIs
= LoadShimDLL2(L
"AcLayers.dll");
77 rtlinfo
.dwOSVersionInfoSize
= sizeof(rtlinfo
);
78 RtlGetVersion((PRTL_OSVERSIONINFOW
)&rtlinfo
);
79 g_WinVersion
= (rtlinfo
.dwMajorVersion
<< 8) | rtlinfo
.dwMinorVersion
;
83 for (n
= 0; n
< _countof(data
); ++n
)
85 expect_shim_data
* current
= data
+ n
;
86 DWORD num_shims
= 0, expected_shims
= count_shims(current
);
88 PHOOKAPI hook
= pGetHookAPIs("", current
->ShimName
, &num_shims
);
90 if (current
->MinVersion
> g_WinVersion
&& !hook
)
93 ok(!!hook
, "Expected a valid pointer, got nothing for %s\n", wine_dbgstr_w(current
->ShimName
));
94 ok(num_shims
== expected_shims
, "Expected %u shims, got %u for %s\n",
95 expected_shims
, num_shims
, wine_dbgstr_w(current
->ShimName
));
96 for (h
= 0; h
< min(num_shims
, expected_shims
); ++h
)
98 expect_shim_hook
* expect_hk
= current
->hooks
+ h
;
99 PHOOKAPI got_hk
= hook
+h
;
100 int lib
= lstrcmpA(expect_hk
->Library
, got_hk
->LibraryName
);
101 int fn
= lstrcmpA(safe_str(expect_hk
->Function
), safe_str(got_hk
->FunctionName
));
102 ok(lib
== 0, "Expected LibraryName to be %s, was: %s for %s\n",
103 expect_hk
->Library
, got_hk
->LibraryName
, wine_dbgstr_w(current
->ShimName
));
104 ok(fn
== 0, "Expected FunctionName to be %s, was: %s for %s\n",
105 safe_str(expect_hk
->Function
), safe_str(got_hk
->FunctionName
), wine_dbgstr_w(current
->ShimName
));
107 if (num_shims
> expected_shims
)
109 for (h
= expected_shims
; h
< num_shims
; ++h
)
111 PHOOKAPI got_hk
= hook
+h
;
113 ok(0, "Extra shim: %s!%s for %s\n",
114 got_hk
->LibraryName
, safe_str(got_hk
->FunctionName
), wine_dbgstr_w(current
->ShimName
));
119 for (h
= num_shims
; h
< expected_shims
; ++h
)
121 expect_shim_hook
* expect_hk
= current
->hooks
+ h
;
123 ok(0, "Missing shim: %s!%s for %s\n",
124 expect_hk
->Library
, safe_str(expect_hk
->Function
), wine_dbgstr_w(current
->ShimName
));