ReactOS  0.4.15-dev-1177-g6cb3b62
ShellExecuteW.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: GPLv2+ - See COPYING in the top level directory
4  * PURPOSE: Testing ShellExecuteW
5  * PROGRAMMERS: Doug Lyons <douglyons@douglyons.com>
6  * Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
7  */
8 
9 #include "shelltest.h"
10 #include <stdio.h>
11 #include <winbase.h>
12 #include <shlwapi.h>
13 
14 #define WAIT_SLEEP 700
15 
16 // ShellExecuteW(handle, "open", <path_to_executable>, <parameters>, NULL, SW_SHOWNORMAL);
17 
19 {
20  INT ret;
22  HWND hWnd;
23  WCHAR WinDir[MAX_PATH], SysDir[MAX_PATH], SysDrive[MAX_PATH];
24 
25  if (!GetWindowsDirectoryW(WinDir, _countof(WinDir)))
26  {
27  skip("GetWindowsDirectoryW failed\n");
28  return;
29  }
30  if (!GetSystemDirectoryW(SysDir, _countof(SysDir)))
31  {
32  skip("GetSystemDirectoryW failed\n");
33  return;
34  }
35  if (!GetEnvironmentVariableW(L"SystemDrive", SysDrive, _countof(SysDrive)))
36  {
37  trace("GetEnvironmentVariableW('SystemDrive') failed\n");
38  SysDrive[0] = SysDir[0];
39  SysDrive[1] = L':';
40  SysDrive[2] = 0;
41  }
42  PathAddBackslashW(SysDrive);
43 
44  // TEST #1: Open Control Panel
45  hInstance = ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl",
48  ok(ret > 31, "TEST #1: ret:%d, LastError: %ld\n", ret, GetLastError());
49  trace("TEST #1 ret: %d.\n", ret);
50  if (hInstance)
51  {
53  // Terminate Window
54  hWnd = FindWindowW(NULL, L"Display Properties");
56  }
57 
58  // TEST #2: Open Notepad
59  hInstance = ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL);
61  ok(ret > 31, "TEST #2: ret:%d, LastError: %ld\n", ret, GetLastError());
62  trace("TEST #2 ret: %d.\n", ret);
63  if (hInstance)
64  {
66  // Terminate Window
67  hWnd = FindWindowW(L"Notepad", L"Untitled - Notepad");
69  }
70 
71  // TEST #3: Open Windows folder
74  ok(ret > 31, "TEST #3: ret:%d, LastError: %ld\n", ret, GetLastError());
75  trace("TEST #3 ret: %d.\n", ret);
76  if (hInstance)
77  {
79  // Terminate Window
80  hWnd = FindWindowW(L"CabinetWClass", WinDir);
82  }
83 
84  // TEST #4: Open system32 folder
85  hInstance = ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL);
87  ok(ret > 31, "TEST #4: ret:%d, LastError: %ld\n", ret, GetLastError());
88  trace("TEST #4 ret: %d.\n", ret);
89  if (hInstance)
90  {
92  // Terminate Window
93  hWnd = FindWindowW(L"CabinetWClass", SysDir);
95  }
96 
97  // TEST #5: Open %SystemDrive%
98  hInstance = ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL);
100  ok(ret > 31, "TEST #5: ret:%d, LastError: %ld\n", ret, GetLastError());
101  trace("TEST #5 ret: %d.\n", ret);
102  if (hInstance)
103  {
104  Sleep(WAIT_SLEEP);
105  // Terminate Window
106  hWnd = FindWindowW(L"ExploreWClass", SysDrive);
108  }
109 
110  // TEST #6: Open Explorer Search on %SYSTEMDRIVE%
111  hInstance = ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL);
113  ok(ret > 31, "TEST #6: ret:%d, LastError: %ld\n", ret, GetLastError());
114  trace("TEST #6 ret: %d.\n", ret);
115  if (hInstance)
116  {
117  Sleep(WAIT_SLEEP);
118  // Terminate Window
119  hWnd = FindWindowW(L"CabinetWClass", L"Search Results");
121  }
122 
123  // TEST #7: Open My Documents ("::{450d8fba-ad25-11d0-98a8-0800361b1103}")
124  hInstance = ShellExecuteW(NULL, NULL, L"::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL, NULL, SW_SHOWNORMAL);
126  ok(ret > 31, "TEST #7: ret:%d, LastError: %ld\n", ret, GetLastError());
127  trace("TEST #7 ret: %d.\n", ret);
128  if (hInstance)
129  {
130  Sleep(WAIT_SLEEP);
131  // Terminate Window
132  hWnd = FindWindowW(L"CabinetWClass", NULL);
134  }
135 
136  // TEST #8: Open My Documents ("shell:::{450d8fba-ad25-11d0-98a8-0800361b1103}")
137  hInstance = ShellExecuteW(NULL, L"open", L"shell:::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL, NULL, SW_SHOWNORMAL);
139  ok(ret > 31, "TEST #8: ret:%d, LastError: %ld\n", ret, GetLastError());
140  trace("TEST #8 ret: %d.\n", ret);
141  if (hInstance)
142  {
143  Sleep(WAIT_SLEEP);
144  // Terminate Window
145  hWnd = FindWindowW(L"CabinetWClass", NULL);
147  }
148 }
149 
150 // Windows Server 2003 and Windows XP SP3 return values (Win 7 returns 42 in all cases)
151 // ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl", NULL, SW_SHOWNORMAL) = 42
152 // ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL) = 42
153 // ShellExecuteW(NULL, NULL, WinDir, NULL, NULL, SW_SHOWNORMAL) = 33
154 // ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL) = 33
155 // ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL) = 33
156 // ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL) = 33
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define INT
Definition: polytest.cpp:20
HWND hWnd
Definition: settings.c:17
START_TEST(ShellExecuteW)
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
int32_t INT
Definition: typedefs.h:58
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
HINSTANCE hInstance
Definition: charmap.c:20
LPWSTR WINAPI PathAddBackslashW(LPWSTR lpszPath)
Definition: path.c:289
smooth NULL
Definition: ftsmooth.c:416
#define PostMessage
Definition: winuser.h:5807
#define trace
Definition: atltest.h:70
__wchar_t WCHAR
Definition: xmlstorage.h:180
HWND WINAPI FindWindowW(_In_opt_ LPCWSTR, _In_opt_ LPCWSTR)
#define _countof(array)
Definition: sndvol32.h:68
#define MAX_PATH
Definition: compat.h:34
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
int ret
static const WCHAR L[]
Definition: oid.c:1250
#define SW_SHOWNORMAL
Definition: winuser.h:764
#define ok(value,...)
Definition: atltest.h:57
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
#define WAIT_SLEEP
#define skip(...)
Definition: atltest.h:64
#define SC_CLOSE
Definition: winuser.h:2567
HINSTANCE WINAPI ShellExecuteW(HWND hwnd, LPCWSTR lpVerb, LPCWSTR lpFile, LPCWSTR lpParameters, LPCWSTR lpDirectory, INT nShowCmd)
Definition: shlexec.cpp:2274
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:503
#define WM_SYSCOMMAND
Definition: winuser.h:1723