Reactos
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
12BOOL IsWindowsServer2003SP2OrGreater(void)
13{
14 return IsWindowsVersionOrGreater(5, 2, 2);
15}
16
17typedef 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
30typedef 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
43static HINSTANCE s_hSHELL32 = NULL;
44static FN_RealShellExecuteExA s_fnRealShellExecuteExA = NULL;
45static FN_RealShellExecuteExW s_fnRealShellExecuteExW = NULL;
46
47static WINDOW_LIST s_List1, s_List2;
48
49static void TEST_Start(void)
50{
51 GetWindowList(&s_List1);
52}
53
54static void TEST_End(void)
55{
56 // Execution can be asynchronous; you have to wait for it to finish.
57 Sleep(2000);
58
59 // Close newly-opened window(s)
60 GetWindowList(&s_List2);
61 CloseNewWindows(&s_List1, &s_List2);
62 FreeWindowList(&s_List1);
63 FreeWindowList(&s_List2);
64}
65
66static void TEST_RealShellExecuteExA(void)
67{
68 INT_PTR ret;
69
70 ret = (INT_PTR)s_fnRealShellExecuteExA(
71 NULL,
72 NULL,
73 "notepad.exe",
74 NULL,
75 NULL,
76 NULL,
77 NULL,
78 NULL,
79 SW_SHOWDEFAULT,
80 NULL,
81 0);
82 if (IsWindowsServer2003SP2OrGreater())
83 ok_long((LONG)ret, 42);
84 else
85 ok_long((LONG)ret, 2);
86}
87
88static void TEST_RealShellExecuteExW(void)
89{
90 INT_PTR ret;
91
92 ret = (INT_PTR)s_fnRealShellExecuteExW(
93 NULL,
94 NULL,
95 L"notepad.exe",
96 NULL,
97 NULL,
98 NULL,
99 NULL,
100 NULL,
101 SW_SHOWDEFAULT,
102 NULL,
103 0);
104 ok_long((LONG)ret, 42);
105}
106
107START_TEST(RealShellExecuteEx)
108{
109 if (IsWindowsVistaOrGreater())
110 {
111 skip("Vista+\n");
112 return;
113 }
114
115 s_hSHELL32 = LoadLibraryW(L"shell32.dll");
116
117 s_fnRealShellExecuteExA = (FN_RealShellExecuteExA)GetProcAddress(s_hSHELL32, MAKEINTRESOURCEA(266));
118 s_fnRealShellExecuteExW = (FN_RealShellExecuteExW)GetProcAddress(s_hSHELL32, MAKEINTRESOURCEA(267));
119
120 if (!s_fnRealShellExecuteExA || !s_fnRealShellExecuteExW)
121 {
122 skip("RealShellExecuteExA/W not found: %p, %p\n",
123 s_fnRealShellExecuteExA, s_fnRealShellExecuteExW);
124 return;
125 }
126
127 TEST_Start();
128
129 TEST_RealShellExecuteExA();
130 TEST_RealShellExecuteExW();
131
132 TEST_End();
133
134 FreeLibrary(s_hSHELL32);
135}