1 /*
2 * PROJECT: ReactOS API tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Test for RealShellExecuteExA/W
5 * COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8 #include "shelltest.h"
9 #include "closewnd.h"
10 #include <versionhelpers.h>
11
IsWindowsServer2003SP2OrGreater(void)12 BOOL IsWindowsServer2003SP2OrGreater(void)
13 {
14 return IsWindowsVersionOrGreater(5, 2, 2);
15 }
16
17 typedef HINSTANCE (WINAPI *FN_RealShellExecuteExA)(
18 _In_opt_ HWND hwnd,
19 _In_opt_ LPCSTR lpOperation,
20 _In_opt_ LPCSTR lpFile,
21 _In_opt_ LPCSTR lpParameters,
22 _In_opt_ LPCSTR lpDirectory,
23 _In_opt_ LPSTR lpReturn,
24 _In_opt_ LPCSTR lpTitle,
25 _In_opt_ LPVOID lpReserved,
26 _In_ INT nCmdShow,
27 _Out_opt_ PHANDLE lphProcess,
28 _In_ DWORD dwFlags);
29
30 typedef HINSTANCE (WINAPI *FN_RealShellExecuteExW)(
31 _In_opt_ HWND hwnd,
32 _In_opt_ LPCWSTR lpOperation,
33 _In_opt_ LPCWSTR lpFile,
34 _In_opt_ LPCWSTR lpParameters,
35 _In_opt_ LPCWSTR lpDirectory,
36 _In_opt_ LPWSTR lpReturn,
37 _In_opt_ LPCWSTR lpTitle,
38 _In_opt_ LPVOID lpReserved,
39 _In_ INT nCmdShow,
40 _Out_opt_ PHANDLE lphProcess,
41 _In_ DWORD dwFlags);
42
43 static HINSTANCE s_hSHELL32 = NULL;
44 static FN_RealShellExecuteExA s_fnRealShellExecuteExA = NULL;
45 static FN_RealShellExecuteExW s_fnRealShellExecuteExW = NULL;
46
47 static WINDOW_LIST s_List1, s_List2;
48
TEST_Start(void)49 static void TEST_Start(void)
50 {
51 GetWindowList(&s_List1);
52 }
53
TEST_End(void)54 static void TEST_End(void)
55 {
56 Sleep(500);
57 GetWindowList(&s_List2);
58 CloseNewWindows(&s_List1, &s_List2);
59 FreeWindowList(&s_List1);
60 FreeWindowList(&s_List2);
61 }
62
TEST_RealShellExecuteExA(void)63 static void TEST_RealShellExecuteExA(void)
64 {
65 TEST_Start();
66
67 INT_PTR ret;
68
69 ret = (INT_PTR)s_fnRealShellExecuteExA(
70 NULL,
71 NULL,
72 "notepad.exe",
73 NULL,
74 NULL,
75 NULL,
76 NULL,
77 NULL,
78 SW_SHOWDEFAULT,
79 NULL,
80 0);
81 if (IsWindowsServer2003SP2OrGreater())
82 ok_long((LONG)ret, 42);
83 else
84 ok_long((LONG)ret, 2);
85
86 TEST_End();
87 }
88
TEST_RealShellExecuteExW(void)89 static void TEST_RealShellExecuteExW(void)
90 {
91 TEST_Start();
92
93 INT_PTR ret;
94
95 ret = (INT_PTR)s_fnRealShellExecuteExW(
96 NULL,
97 NULL,
98 L"notepad.exe",
99 NULL,
100 NULL,
101 NULL,
102 NULL,
103 NULL,
104 SW_SHOWDEFAULT,
105 NULL,
106 0);
107 ok_long((LONG)ret, 42);
108
109 TEST_End();
110 }
111
START_TEST(RealShellExecuteEx)112 START_TEST(RealShellExecuteEx)
113 {
114 if (IsWindowsVistaOrGreater())
115 {
116 skip("Vista+\n");
117 return;
118 }
119
120 s_hSHELL32 = LoadLibraryW(L"shell32.dll");
121
122 s_fnRealShellExecuteExA = (FN_RealShellExecuteExA)GetProcAddress(s_hSHELL32, MAKEINTRESOURCEA(266));
123 s_fnRealShellExecuteExW = (FN_RealShellExecuteExW)GetProcAddress(s_hSHELL32, MAKEINTRESOURCEA(267));
124
125 if (!s_fnRealShellExecuteExA || !s_fnRealShellExecuteExW)
126 {
127 skip("RealShellExecuteExA/W not found: %p, %p\n",
128 s_fnRealShellExecuteExA, s_fnRealShellExecuteExW);
129 return;
130 }
131
132 TEST_RealShellExecuteExA();
133 TEST_RealShellExecuteExW();
134
135 FreeLibrary(s_hSHELL32);
136 }
137