Reactos
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#include "closewnd.h"
14
15
16// ShellExecuteW(handle, "open", <path_to_executable>, <parameters>, NULL, SW_SHOWNORMAL);
17
18WINDOW_LIST g_winlist;
19
20static void CloseWindow(HINSTANCE hInstance, PCWSTR ClassName, PCWSTR Title)
21{
22 if ((SIZE_T)hInstance <= 32)
23 return;
24
25 HWND hWnd = NULL;
26 for (UINT i = 0; i < 1500; i += 250)
27 {
28 hWnd = FindWindowW(ClassName, Title);
29 if (hWnd && IsWindowVisible(hWnd) && !FindInWindowList(g_winlist, hWnd))
30 break;
31 hWnd = NULL;
32 Sleep(250);
33 }
34
35 if (!hWnd || !PostMessage(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0))
36 CloseNewWindows(&g_winlist);
37}
38
39START_TEST(ShellExecuteW)
40{
41 INT ret;
42 HINSTANCE hInstance;
43 WCHAR WinDir[MAX_PATH], SysDir[MAX_PATH], SysDrive[MAX_PATH];
44
45 if (!GetWindowsDirectoryW(WinDir, _countof(WinDir)))
46 {
47 skip("GetWindowsDirectoryW failed\n");
48 return;
49 }
50 if (!GetSystemDirectoryW(SysDir, _countof(SysDir)))
51 {
52 skip("GetSystemDirectoryW failed\n");
53 return;
54 }
55 if (!GetEnvironmentVariableW(L"SystemDrive", SysDrive, _countof(SysDrive)))
56 {
57 trace("GetEnvironmentVariableW('SystemDrive') failed\n");
58 SysDrive[0] = SysDir[0];
59 SysDrive[1] = L':';
60 SysDrive[2] = 0;
61 }
62 PathAddBackslashW(SysDrive);
63
64 GetWindowList(&g_winlist);
65
66 // TEST #1: Open Control Panel
67 hInstance = ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl",
68 NULL, SW_SHOWNORMAL);
69 ret = (INT)(UINT_PTR)hInstance;
70 ok(ret > 31, "TEST #1: ret:%d, LastError: %ld\n", ret, GetLastError());
71 trace("TEST #1 ret: %d.\n", ret);
72 CloseWindow(hInstance, NULL, L"Properties for Display"); // FIXME: Dynamically determine the window title.
73
74 // TEST #2: Open Notepad
75 hInstance = ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL);
76 ret = (INT)(UINT_PTR)hInstance;
77 ok(ret > 31, "TEST #2: ret:%d, LastError: %ld\n", ret, GetLastError());
78 trace("TEST #2 ret: %d.\n", ret);
79 CloseWindow(hInstance, L"Notepad", L"Untitled - Notepad"); // FIXME: Dynamically determine the window title.
80
81 // TEST #3: Open Windows folder
82 hInstance = ShellExecuteW(NULL, NULL, WinDir, NULL, NULL, SW_SHOWNORMAL);
83 ret = (INT)(UINT_PTR)hInstance;
84 ok(ret > 31, "TEST #3: ret:%d, LastError: %ld\n", ret, GetLastError());
85 trace("TEST #3 ret: %d.\n", ret);
86 CloseWindow(hInstance, L"CabinetWClass", PathFindFileNameW(WinDir));
87
88 // TEST #4: Open system32 folder
89 hInstance = ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL);
90 ret = (INT)(UINT_PTR)hInstance;
91 ok(ret > 31, "TEST #4: ret:%d, LastError: %ld\n", ret, GetLastError());
92 trace("TEST #4 ret: %d.\n", ret);
93 CloseWindow(hInstance, L"CabinetWClass", PathFindFileNameW(SysDir));
94
95 // TEST #5: Open %SystemDrive%
96 hInstance = ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL);
97 ret = (INT)(UINT_PTR)hInstance;
98 ok(ret > 31, "TEST #5: ret:%d, LastError: %ld\n", ret, GetLastError());
99 trace("TEST #5 ret: %d.\n", ret);
100 CloseWindow(hInstance, L"ExploreWClass", NULL);
101
102 // TEST #6: Open Explorer Search on %SYSTEMDRIVE%
103 hInstance = ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL);
104 ret = (INT)(UINT_PTR)hInstance;
105 ok(ret > 31, "TEST #6: ret:%d, LastError: %ld\n", ret, GetLastError());
106 trace("TEST #6 ret: %d.\n", ret);
107 CloseWindow(hInstance, L"CabinetWClass", L"Search Results"); // FIXME: Dynamically determine the window title.
108
109 // TEST #7: Open My Documents ("::{450d8fba-ad25-11d0-98a8-0800361b1103}")
110 hInstance = ShellExecuteW(NULL, NULL, L"::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL, NULL, SW_SHOWNORMAL);
111 ret = (INT)(UINT_PTR)hInstance;
112 ok(ret > 31, "TEST #7: ret:%d, LastError: %ld\n", ret, GetLastError());
113 trace("TEST #7 ret: %d.\n", ret);
114 CloseWindow(hInstance, L"CabinetWClass", NULL);
115
116 // TEST #8: Open My Documents ("shell:::{450d8fba-ad25-11d0-98a8-0800361b1103}")
117 hInstance = ShellExecuteW(NULL, L"open", L"shell:::{450d8fba-ad25-11d0-98a8-0800361b1103}", NULL, NULL, SW_SHOWNORMAL);
118 ret = (INT)(UINT_PTR)hInstance;
119 ok(ret > 31, "TEST #8: ret:%d, LastError: %ld\n", ret, GetLastError());
120 trace("TEST #8 ret: %d.\n", ret);
121 CloseWindow(hInstance, L"CabinetWClass", NULL);
122
123 CloseNewWindows(&g_winlist);
124 FreeWindowList(&g_winlist);
125}
126
127// Windows Server 2003 and Windows XP SP3 return values (Win 7 returns 42 in all cases)
128// ShellExecuteW(NULL, L"open", L"rundll32.exe", L"shell32.dll,Control_RunDLL desk.cpl", NULL, SW_SHOWNORMAL) = 42
129// ShellExecuteW(NULL, L"open", L"notepad.exe", NULL, NULL, SW_SHOWNORMAL) = 42
130// ShellExecuteW(NULL, NULL, WinDir, NULL, NULL, SW_SHOWNORMAL) = 33
131// ShellExecuteW(NULL, L"open", SysDir, NULL, NULL, SW_SHOWNORMAL) = 33
132// ShellExecuteW(NULL, L"explore", SysDrive, NULL, NULL, SW_SHOWNORMAL) = 33
133// ShellExecuteW(NULL, L"find", SysDrive, NULL, NULL, SW_SHOWNORMAL) = 33