ReactOS 0.4.15-dev-8393-g61b7fb9
OpenAs_RunDLL.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPLv2.1+ - See COPYING.LIB in the top level directory
4 * PURPOSE: Test for OpenAs_RunDLL
5 * PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
6 */
7
8#include "shelltest.h"
9#include <stdio.h>
10#include <process.h>
11
12// OpenAs_RunDLLA
14// OpenAs_RunDLLW
16
19
20struct TEST_ENTRY
21{
22 int nLine;
25 int nRet;
30};
31
32#define COUNT 5
33#define INTERVAL 200
34
35#define DEATH 999
36#define OPENED 1
37#define NOT_OPENED 0
38
39#define BAD_INST ((HINSTANCE)0xDEAD)
40#define BAD_SZ_A ((LPCSTR)0xDEAD)
41#define BAD_SZ_W ((LPCWSTR)0xDEAD)
42
43static const TEST_ENTRY s_TestEntries[] =
44{
45 // ANSI
46 {__LINE__, FALSE, NULL, OPENED, FALSE, NULL, NULL, 0 },
47 {__LINE__, FALSE, NULL, OPENED, FALSE, "", NULL, 0 },
48 {__LINE__, FALSE, NULL, OPENED, FALSE, "invalid file name.txt", NULL, 0 },
49 {__LINE__, FALSE, NULL, DEATH, FALSE, BAD_SZ_A, NULL, 0 },
50 {__LINE__, FALSE, NULL, OPENED, TRUE, "created file.txt", NULL, 0 },
51 {__LINE__, FALSE, BAD_INST, OPENED, FALSE, NULL, NULL, 0 },
52 {__LINE__, FALSE, BAD_INST, OPENED, FALSE, "invalid file name.txt", NULL, 0 },
53 {__LINE__, FALSE, BAD_INST, DEATH, FALSE, BAD_SZ_A, NULL, 0xDEADFACE },
54 {__LINE__, FALSE, BAD_INST, OPENED, TRUE, "created file.txt", NULL, 0 },
55 // WIDE
56 {__LINE__, TRUE, NULL, OPENED, FALSE, NULL, NULL, 0x80070490 },
57 {__LINE__, TRUE, NULL, OPENED, FALSE, NULL, L"", ERROR_NO_SCROLLBARS },
58 {__LINE__, TRUE, NULL, OPENED, FALSE, NULL, L"invalid file name.txt", ERROR_NO_SCROLLBARS },
59 {__LINE__, TRUE, NULL, OPENED, FALSE, NULL, BAD_SZ_W, 0xDEADFACE },
60 {__LINE__, TRUE, NULL, OPENED, TRUE, NULL, L"created file.txt", ERROR_NO_SCROLLBARS },
61 {__LINE__, TRUE, BAD_INST, OPENED, FALSE, NULL, NULL, 0x80070490 },
62 {__LINE__, TRUE, BAD_INST, OPENED, FALSE, NULL, L"invalid file name.txt", ERROR_NO_SCROLLBARS },
63 {__LINE__, TRUE, BAD_INST, OPENED, FALSE, NULL, BAD_SZ_W, 0xDEADFACE },
64 {__LINE__, TRUE, BAD_INST, OPENED, TRUE, NULL, L"created file.txt", ERROR_NO_SCROLLBARS },
65};
66
69
70static unsigned __stdcall
72{
73 for (int i = 0; i < COUNT; ++i)
74 {
76
77 HWND hwnd = FindWindowA("#32770", "Open With");
78 if (hwnd == NULL)
79 continue;
80
82 {
83 trace("not visible\n");
84 continue;
85 }
86
87 s_nRet = OPENED;
89 break;
90 }
91 return 0;
92}
93
94static void StartWatchGUI(const TEST_ENTRY *pEntry)
95{
98}
99
100static void DoEntry(const TEST_ENTRY *pEntry)
101{
102 if (pEntry->bWide)
103 {
104 if (pEntry->bCreateFile)
105 {
106 FILE *fp = _wfopen(pEntry->pszFileW, L"wb");
107 ok(fp != NULL, "Line %d: Unable to create file '%s'\n", pEntry->nLine, wine_dbgstr_w(pEntry->pszFileW));
108 fclose(fp);
109 }
110
112 SetLastError(0xDEADFACE);
113
115 {
116 (*pOpenAs_RunDLLW)(NULL, pEntry->hInst, pEntry->pszFileW, SW_SHOWDEFAULT);
117 }
119 {
120 s_nRet = DEATH;
121 }
122 _SEH2_END;
123
124 DWORD dwError = GetLastError();
125 ok(pEntry->dwError == dwError, "Line %d: error expected %ld, was %ld\n", pEntry->nLine, pEntry->dwError, dwError);
126
129
130 if (pEntry->bCreateFile)
131 {
132 ok(DeleteFileW(pEntry->pszFileW), "Line %d: DeleteFileA failed\n", pEntry->nLine);
133 }
134 }
135 else
136 {
137 if (pEntry->bCreateFile)
138 {
139 FILE *fp = fopen(pEntry->pszFileA, "wb");
140 ok(fp != NULL, "Line %d: Unable to create file '%s'\n", pEntry->nLine, pEntry->pszFileA);
141 fclose(fp);
142 }
143
145 SetLastError(0xDEADFACE);
146
148 {
149 (*pOpenAs_RunDLLA)(NULL, pEntry->hInst, pEntry->pszFileA, SW_SHOWDEFAULT);
150 }
152 {
153 s_nRet = DEATH;
154 }
155 _SEH2_END;
156
157 DWORD dwError = GetLastError();
158 ok(pEntry->dwError == dwError, "Line %d: error expected %ld, was %ld\n", pEntry->nLine, pEntry->dwError, dwError);
159
162
163 if (pEntry->bCreateFile)
164 {
165 ok(DeleteFileA(pEntry->pszFileA), "Line %d: DeleteFileA failed\n", pEntry->nLine);
166 }
167 }
168
169 // FIXME: This function probably returns void
170 //ok(pEntry->nRet == s_nRet, "Line %d: s_nRet expected %d, was %d\n", pEntry->nLine, pEntry->nRet, s_nRet);
171}
172
173START_TEST(OpenAs_RunDLL)
174{
175 HINSTANCE hShell32 = LoadLibraryA("shell32.dll");
176 if (hShell32 == NULL)
177 {
178 skip("Unable to load shell32.dll\n");
179 return;
180 }
181
183 if (pOpenAs_RunDLLA == NULL)
184 {
185 skip("Unable to get OpenAs_RunDLLA\n");
186 return;
187 }
188
190 if (pOpenAs_RunDLLW == NULL)
191 {
192 skip("Unable to get OpenAs_RunDLLW\n");
193 return;
194 }
195
196 TCHAR szCurDir[MAX_PATH], szTempDir[MAX_PATH];
197
198 ok(GetCurrentDirectory(_countof(szCurDir), szCurDir), "GetCurrentDirectory failed\n");
199 ok(GetTempPath(_countof(szTempDir), szTempDir), "GetTempPath failed\n");
200
201 if (!SetCurrentDirectory(szTempDir))
202 {
203 skip("SetCurrentDirectory failed\n");
204 }
205 else
206 {
207 for (size_t i = 0; i < _countof(s_TestEntries); ++i)
208 {
209 const TEST_ENTRY *pEntry = &s_TestEntries[i];
211 }
212
213 ok(SetCurrentDirectory(szCurDir), "SetCurrentDirectory failed\n");
214 }
215
217}
#define OPENED
#define NOT_OPENED
static OPENAS_RUNDLLA pOpenAs_RunDLLA
void(WINAPI * OPENAS_RUNDLLA)(HWND, HINSTANCE, LPCSTR, int)
#define COUNT
static HANDLE s_hThread
#define DEATH
static OPENAS_RUNDLLW pOpenAs_RunDLLW
void(WINAPI * OPENAS_RUNDLLW)(HWND, HINSTANCE, LPCWSTR, int)
static void DoEntry(const TEST_ENTRY *pEntry)
static void StartWatchGUI(const TEST_ENTRY *pEntry)
#define INTERVAL
#define BAD_SZ_A
static INT s_nRet
static const TEST_ENTRY s_TestEntries[]
static unsigned __stdcall watch_thread_proc(void *arg)
#define BAD_INST
#define BAD_SZ_W
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define SetLastError(x)
Definition: compat.h:752
HANDLE HWND
Definition: compat.h:19
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define INFINITE
Definition: serial.h:102
#define _SEH2_END
Definition: filesup.c:22
#define _SEH2_TRY
Definition: filesup.c:19
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
PLIST_ENTRY pEntry
Definition: fxioqueue.cpp:4484
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
#define wine_dbgstr_w
Definition: kernel32.h:34
static HMODULE hShell32
Definition: string.c:34
#define L(x)
Definition: ntvdm.h:50
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:66
_CRTIMP uintptr_t __cdecl _beginthreadex(_In_opt_ void *_Security, _In_ unsigned _StackSize, _In_ unsigned(__stdcall *_StartAddress)(void *), _In_opt_ void *_ArgList, _In_ unsigned _InitFlag, _Out_opt_ unsigned *_ThrdAddr)
#define _countof(array)
Definition: sndvol32.h:70
Definition: cmd.c:13
LPCSTR pszFileA
BOOL bCreateFile
HINSTANCE hInst
DWORD dwError
BOOL bWide
int nRet
int nLine
LPCWSTR pszFileW
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
HANDLE HINSTANCE
Definition: typedefs.h:77
PVOID HANDLE
Definition: typedefs.h:73
int32_t INT
Definition: typedefs.h:58
#define __stdcall
Definition: typedefs.h:25
#define GetTempPath
Definition: winbase.h:3850
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SetCurrentDirectory
Definition: winbase.h:3903
#define GetCurrentDirectory
Definition: winbase.h:3805
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WINAPI
Definition: msvc.h:6
#define ERROR_NO_SCROLLBARS
Definition: winerror.h:928
#define MAKEWPARAM(l, h)
Definition: winuser.h:4009
#define IDCANCEL
Definition: winuser.h:831
#define WM_COMMAND
Definition: winuser.h:1740
#define SW_SHOWDEFAULT
Definition: winuser.h:780
#define PostMessage
Definition: winuser.h:5841
#define BN_CLICKED
Definition: winuser.h:1925
HWND WINAPI FindWindowA(_In_opt_ LPCSTR, _In_opt_ LPCSTR)
BOOL WINAPI IsWindowVisible(_In_ HWND)
char TCHAR
Definition: xmlstorage.h:189
const char * LPCSTR
Definition: xmlstorage.h:183
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185