ReactOS  0.4.14-dev-614-gbfd8a84
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 
20 struct TEST_ENTRY
21 {
22  int nLine;
25  int nRet;
29  DWORD dwError;
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 
43 static 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 
70 static unsigned __stdcall
72 {
73  for (int i = 0; i < COUNT; ++i)
74  {
75  Sleep(INTERVAL);
76 
77  HWND hwnd = FindWindowA("#32770", "Open With");
78  if (hwnd == NULL)
79  continue;
80 
81  if (!IsWindowVisible(hwnd))
82  {
83  trace("not visible\n");
84  continue;
85  }
86 
87  s_nRet = OPENED;
89  break;
90  }
91  return 0;
92 }
93 
94 static void StartWatchGUI(const TEST_ENTRY *pEntry)
95 {
98 }
99 
100 static 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 
111  StartWatchGUI(pEntry);
112  SetLastError(0xDEADFACE);
113 
114  _SEH2_TRY
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 
144  StartWatchGUI(pEntry);
145  SetLastError(0xDEADFACE);
146 
147  _SEH2_TRY
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  ok(pEntry->nRet == s_nRet, "Line %d: s_nRet expected %d, was %d\n", pEntry->nLine, pEntry->nRet, s_nRet);
170 }
171 
172 START_TEST(OpenAs_RunDLL)
173 {
174  HINSTANCE hShell32 = LoadLibraryA("shell32.dll");
175  if (hShell32 == NULL)
176  {
177  skip("Unable to load shell32.dll\n");
178  return;
179  }
180 
182  if (pOpenAs_RunDLLA == NULL)
183  {
184  skip("Unable to get OpenAs_RunDLLA\n");
185  return;
186  }
187 
189  if (pOpenAs_RunDLLW == NULL)
190  {
191  skip("Unable to get OpenAs_RunDLLW\n");
192  return;
193  }
194 
195  TCHAR szCurDir[MAX_PATH], szTempDir[MAX_PATH];
196 
197  ok(GetCurrentDirectory(_countof(szCurDir), szCurDir), "GetCurrentDirectory failed\n");
198  ok(GetTempPath(_countof(szTempDir), szTempDir), "GetTempPath failed\n");
199 
200  if (!SetCurrentDirectory(szTempDir))
201  {
202  skip("SetCurrentDirectory failed\n");
203  }
204  else
205  {
206  for (size_t i = 0; i < _countof(s_TestEntries); ++i)
207  {
208  const TEST_ENTRY *pEntry = &s_TestEntries[i];
209  DoEntry(pEntry);
210  }
211 
212  ok(SetCurrentDirectory(szCurDir), "SetCurrentDirectory failed\n");
213  }
214 
216 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL bCreateFile
#define SW_SHOWDEFAULT
Definition: winuser.h:774
static OPENAS_RUNDLLA pOpenAs_RunDLLA
DWORD dwError
#define TRUE
Definition: types.h:120
#define MAKEWPARAM(l, h)
Definition: winuser.h:3984
#define CloseHandle
Definition: compat.h:406
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
struct png_info_def **typedef void(__cdecl typeof(png_destroy_read_struct))(struct png_struct_def **
Definition: typeof.h:49
BOOL bWide
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define OPENED
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
static INT s_nRet
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define COUNT
#define _countof(array)
Definition: fontsub.cpp:30
HANDLE HWND
Definition: compat.h:13
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define NOT_OPENED
_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)
int32_t INT
Definition: typedefs.h:56
LPCSTR pszFileA
_SEH2_TRY
Definition: create.c:4250
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
static unsigned __stdcall watch_thread_proc(void *arg)
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
START_TEST(OpenAs_RunDLL)
LPCWSTR pszFileW
#define BAD_INST
static HANDLE s_hThread
unsigned int BOOL
Definition: ntddk_ex.h:94
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define GetCurrentDirectory
Definition: winbase.h:3639
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define BAD_SZ_W
BOOL WINAPI DeleteFileA(IN LPCSTR lpFileName)
Definition: delete.c:24
static void StartWatchGUI(const TEST_ENTRY *pEntry)
#define GetTempPath
Definition: winbase.h:3684
#define INTERVAL
const char * LPCSTR
Definition: xmlstorage.h:183
int nRet
#define PostMessage
Definition: winuser.h:5807
char TCHAR
Definition: xmlstorage.h:189
#define FreeLibrary(x)
Definition: compat.h:413
#define trace
Definition: atltest.h:70
#define MAX_PATH
Definition: compat.h:26
#define WINAPI
Definition: msvc.h:6
#define ERROR_NO_SCROLLBARS
Definition: winerror.h:928
#define BN_CLICKED
Definition: winuser.h:1907
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:417
#define __stdcall
Definition: typedefs.h:25
void(WINAPI * OPENAS_RUNDLLA)(HWND, HINSTANCE, LPCSTR, int)
HANDLE HINSTANCE
Definition: typedefs.h:75
Definition: cmd.c:12
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
void(WINAPI * OPENAS_RUNDLLW)(HWND, HINSTANCE, LPCWSTR, int)
#define WM_COMMAND
Definition: winuser.h:1722
HINSTANCE hInst
HWND WINAPI FindWindowA(_In_opt_ LPCSTR, _In_opt_ LPCSTR)
_SEH2_END
Definition: create.c:4424
static OPENAS_RUNDLLW pOpenAs_RunDLLW
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
BOOL WINAPI IsWindowVisible(_In_ HWND)
#define GetProcAddress(x, y)
Definition: compat.h:418
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define DEATH
#define IDCANCEL
Definition: winuser.h:825
#define INFINITE
Definition: serial.h:102
static void DoEntry(const TEST_ENTRY *pEntry)
static const TEST_ENTRY s_TestEntries[]
static HMODULE hShell32
Definition: string.c:34
#define SetCurrentDirectory
Definition: winbase.h:3737
#define BAD_SZ_A
int nLine
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31