[SHELL32_APITEST] Add Regression Test for ShellExecuteW(). (#2166)
[reactos.git] / modules / rostests / apitests / shell32 / ShellExecuteW.cpp
1 /*
2 * PROJECT: ReactOS api tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: Testing ShellExecuteW
5 * PROGRAMMER: Doug Lyons <douglyons@douglyons.com>
6 */
7
8 #include "shelltest.h"
9 #include <stdio.h>
10 #include <winbase.h>
11
12 static
13 VOID
14 TestShellExecuteW()
15 {
16 HINSTANCE hInstance;
17 INT retval;
18 HWND hWnd;
19 const WCHAR *Name = L"ShellExecuteW";
20 WCHAR WindowsDirectory[MAX_PATH];
21 BOOL IsReactOS;
22
23 /* Check if we are running under ReactOS from the SystemRoot directory */
24 if(!GetWindowsDirectoryW(WindowsDirectory, MAX_PATH))
25 printf("GetWindowsDirectoryW failed\n");
26
27 IsReactOS = !_wcsnicmp(&WindowsDirectory[3], L"reactos", 7);
28
29 printf("OSVendor %s ReactOS.\n", IsReactOS ? "is" : "is not");
30
31 // ShellExecuteW(handle, "open", <fully_qualified_path_to_executable>, <parameters>, NULL, SW_SHOWNORMAL);
32
33 hInstance = ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl",
34 NULL, SW_SHOWNORMAL);
35 retval = (UINT_PTR) hInstance;
36
37 printf("Return Value for Open Control Panel is '%d'.\n", retval);
38
39 ok(retval > 31, "ShellExecuteEx lpFile %s failed. Error: %lu\n",
40 wine_dbgstr_w(Name), GetLastError());
41
42 if (hInstance)
43 {
44 LPCWSTR lpWinTitle = L"Display Properties";
45 Sleep(1000);
46 hWnd = FindWindowW(NULL, lpWinTitle);
47 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); // Terminate Window
48 }
49 // End of test #1 - Open Control Panel
50
51
52 // ShellExecuteW(handle, "open", <fully_qualified_path_to_executable>, NULL, NULL, SW_SHOWNORMAL);
53
54 hInstance = ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL);
55 retval = (UINT_PTR) hInstance;
56
57 printf("Return Value for Open notepad.exe is '%d'.\n", retval);
58
59 ok(retval > 31, "ShellExecuteEx lpFile %s failed. Error: %lu\n",
60 wine_dbgstr_w(Name), GetLastError());
61
62 if (hInstance)
63 {
64 LPCWSTR lpWinClass = L"Notepad";
65 LPCWSTR lpWinTitle = L"Untitled - Notepad";
66 Sleep(1000);
67 hWnd = FindWindowW(lpWinClass, lpWinTitle);
68 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); // Terminate Window
69 }
70 // End of test #2 - Open notepad.exe
71
72
73 // ShellExecuteW(handle, NULL, <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);
74
75 if(IsReactOS)
76 hInstance = ShellExecuteW(NULL, NULL, L"C:\\ReactOS", NULL,
77 NULL, SW_SHOWNORMAL);
78 else
79 hInstance = ShellExecuteW(NULL, NULL, L"C:\\Windows", NULL,
80 NULL, SW_SHOWNORMAL);
81
82 retval = (UINT_PTR) hInstance;
83
84 printf("Return Value for Open %s is '%d'.\n", IsReactOS ? "C:\\ReactOS" : "C:\\Windows", retval);
85
86 ok(retval > 31, "ShellExecuteEx lpFile %s failed. Error: %lu\n",
87 wine_dbgstr_w(Name), GetLastError());
88
89 if (hInstance)
90 {
91 LPCWSTR lpWinClass = L"CabinetWClass";
92 LPCWSTR lpWinTitleWindows = L"C:\\Windows";
93 LPCWSTR lpWinTitleReactOS = L"C:\\ReactOS";
94
95 Sleep(1000);
96 if (IsReactOS)
97 hWnd = FindWindowW(lpWinClass, lpWinTitleReactOS);
98 else
99 hWnd = FindWindowW(lpWinClass, lpWinTitleWindows);
100 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); // Terminate Window
101 }
102 // End of test #3 - Open C:\Windows
103
104
105 // ShellExecuteW(handle, "open", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);
106
107 if(IsReactOS)
108 hInstance = ShellExecuteW(NULL, L"open", L"C:\\ReactOS\\system32", NULL,
109 NULL, SW_SHOWNORMAL);
110 else
111 hInstance = ShellExecuteW(NULL, L"open", L"C:\\Windows\\system32", NULL,
112 NULL, SW_SHOWNORMAL);
113
114 retval = (UINT_PTR) hInstance;
115
116 printf("Return Value for C:\\...\\system32 is '%d'.\n", retval);
117
118 ok(retval > 31, "ShellExecuteEx lpFile %s failed. Error: %lu\n",
119 wine_dbgstr_w(Name), GetLastError());
120
121 if (hInstance)
122 {
123 LPCWSTR lpWinClass = L"CabinetWClass";
124 LPCWSTR lpWinTitle = L"C:\\Windows\\system32";
125 Sleep(1000);
126 hWnd = FindWindowW(lpWinClass, lpWinTitle);
127 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); // Terminate Window
128 }
129 // End of test #4 - Open C:\Windows\system32
130
131
132 // ShellExecuteW(handle, "explore", <fully_qualified_path_to_folder>, NULL, NULL, SW_SHOWNORMAL);
133
134 hInstance = ShellExecuteW(NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL);
135 retval = (UINT_PTR) hInstance;
136
137 printf("Return Value for explore c:\\ is '%d'.\n", retval);
138
139 ok(retval > 31, "ShellExecuteEx lpFile %s failed. Error: %lu\n",
140 wine_dbgstr_w(Name), GetLastError());
141
142 if (hInstance)
143 {
144 LPCWSTR lpWinClass = L"ExploreWClass";
145 LPCWSTR lpWinTitle = L"C:\\";
146 Sleep(1000);
147 hWnd = FindWindowW(lpWinClass, lpWinTitle);
148 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); // Terminate Window
149 }
150 // End of test #5 - explore C:
151
152
153 // ShellExecuteW(handle, "find", <fully_qualified_path_to_folder>, NULL, NULL, 0);
154
155 hInstance = ShellExecuteW(NULL, L"find", L"C:\\", NULL, NULL, SW_SHOWNORMAL);
156 retval = (UINT_PTR) hInstance;
157
158 printf("Return Value for find is '%d'.\n", retval);
159
160 ok(retval > 31, "ShellExecuteEx lpFile %s failed. Error: %lu\n",
161 wine_dbgstr_w(Name), GetLastError());
162
163 if (hInstance)
164 {
165 LPCWSTR lpWinClass = L"CabinetWClass";
166 LPCWSTR lpWinTitle = L"Search Results";
167 Sleep(1000);
168 hWnd = FindWindowW(lpWinClass, lpWinTitle);
169 PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0); // Terminate Window
170 }
171 // End of test #6 - find
172 }
173
174 START_TEST(ShellExecuteW)
175 {
176 TestShellExecuteW();
177 }
178
179 // Windows Server 2003 and Windows XP SP3 return values (Win 7 returns 42 in all cases)
180 // ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl", NULL, SW_SHOWNORMAL) = 42
181 // ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL) = 42
182 // ShellExecuteW(NULL, NULL, L"C:\\Windows", NULL, NULL, SW_SHOWNORMAL) = 33
183 // ShellExecuteW(NULL, L"open", L"C:\\Windows\\system32", NULL, NULL, SW_SHOWNORMAL) = 33
184 // ShellExecuteW(NULL, L"explore", L"C:\\", NULL, NULL, SW_SHOWNORMAL) = 33
185 // ShellExecuteW(NULL, L"find", L"C:\\", NULL, NULL, SW_SHOWNORMAL) = 33