ReactOS  0.4.14-dev-317-g96040ec
PathFindOnPath.c File Reference
#include <apitest.h>
#include <shlwapi.h>
#include <assert.h>
Include dependency graph for PathFindOnPath.c:

Go to the source code of this file.

Classes

struct  ENTRY
 

Macros

#define EF_FULLPATH   1
 
#define EF_TESTDATA   2
 
#define EF_WIN_DIR   4
 
#define EF_SYS_DIR   8
 
#define EF_TYPE_MASK   0xF
 
#define EF_NAME_ONLY   16
 
#define BEEF   0xBEEF /* Error Code 48879 */
 
#define DEAD   0xDEAD /* Error Code 57005 */
 
#define IGNORE_ERR   0x7F7F7F7F /* Ignore Error Code */
 
#define RAISED   9999 /* exception raised */
 

Typedefs

typedef struct ENTRY ENTRY
 

Functions

static void DoEntry (INT EntryNumber, const ENTRY *pEntry, const WCHAR *PathVar)
 
static void Test_PathFindOnPathW (void)
 
 START_TEST (PathFindOnPath)
 

Variables

static WCHAR s_TestDataPath [MAX_PATH]
 
static LPWSTR s_Dirs [2]
 
static WCHAR s_WinDir [MAX_PATH]
 
static WCHAR s_SysDir [MAX_PATH]
 
static WCHAR s_FontsDir [MAX_PATH]
 
static WCHAR s_NotepadPath [MAX_PATH]
 
static const ENTRY s_Entries []
 

Macro Definition Documentation

◆ BEEF

#define BEEF   0xBEEF /* Error Code 48879 */

Definition at line 43 of file PathFindOnPath.c.

◆ DEAD

#define DEAD   0xDEAD /* Error Code 57005 */

Definition at line 44 of file PathFindOnPath.c.

◆ EF_FULLPATH

#define EF_FULLPATH   1

Definition at line 23 of file PathFindOnPath.c.

◆ EF_NAME_ONLY

#define EF_NAME_ONLY   16

Definition at line 29 of file PathFindOnPath.c.

◆ EF_SYS_DIR

#define EF_SYS_DIR   8

Definition at line 26 of file PathFindOnPath.c.

◆ EF_TESTDATA

#define EF_TESTDATA   2

Definition at line 24 of file PathFindOnPath.c.

◆ EF_TYPE_MASK

#define EF_TYPE_MASK   0xF

Definition at line 27 of file PathFindOnPath.c.

◆ EF_WIN_DIR

#define EF_WIN_DIR   4

Definition at line 25 of file PathFindOnPath.c.

◆ IGNORE_ERR

#define IGNORE_ERR   0x7F7F7F7F /* Ignore Error Code */

Definition at line 45 of file PathFindOnPath.c.

◆ RAISED

#define RAISED   9999 /* exception raised */

Definition at line 46 of file PathFindOnPath.c.

Typedef Documentation

◆ ENTRY

typedef struct ENTRY ENTRY

Function Documentation

◆ DoEntry()

static void DoEntry ( INT  EntryNumber,
const ENTRY pEntry,
const WCHAR PathVar 
)
static

Definition at line 158 of file PathFindOnPath.c.

159 {
160  WCHAR Path[MAX_PATH], PathExpected[MAX_PATH], OldPathVar[256];
161  INT Ret;
162  DWORD Error;
163 
164  if (pEntry->NameBefore == NULL)
165  {
166  assert(pEntry->NameExpected == NULL);
167  assert(pEntry->PathExpected == NULL);
168  }
169 
170  switch (pEntry->EF_ & EF_TYPE_MASK)
171  {
172  case EF_FULLPATH:
173  if (pEntry->NameBefore)
174  {
175  lstrcpyW(Path, pEntry->NameBefore);
176  }
177  if (pEntry->NameExpected)
178  {
179  lstrcpyW(PathExpected, pEntry->NameExpected);
180  }
181  break;
182 
183  case EF_TESTDATA:
184  if (pEntry->EF_ & EF_NAME_ONLY)
185  {
186  lstrcpyW(Path, pEntry->NameBefore);
187  }
188  else
189  {
191  lstrcatW(Path, L"\\");
192  lstrcatW(Path, pEntry->NameBefore);
193  }
194 
195  if (pEntry->NameExpected)
196  {
197  lstrcpyW(PathExpected, s_TestDataPath);
198  lstrcatW(PathExpected, L"\\");
199  lstrcatW(PathExpected, pEntry->NameExpected);
200  }
201  break;
202 
203  case EF_WIN_DIR:
204  if (pEntry->EF_ & EF_NAME_ONLY)
205  {
206  lstrcpyW(Path, pEntry->NameBefore);
207  }
208  else
209  {
211  lstrcatW(Path, L"\\");
212  lstrcatW(Path, pEntry->NameBefore);
213  }
214 
215  if (pEntry->NameExpected)
216  {
217  GetWindowsDirectoryW(PathExpected, _countof(PathExpected));
218  lstrcatW(PathExpected, L"\\");
219  lstrcatW(PathExpected, pEntry->NameExpected);
220  }
221  break;
222 
223  case EF_SYS_DIR:
224  if (pEntry->EF_ & EF_NAME_ONLY)
225  {
226  lstrcpyW(Path, pEntry->NameBefore);
227  }
228  else
229  {
231  lstrcatW(Path, L"\\");
232  lstrcatW(Path, pEntry->NameBefore);
233  }
234 
235  if (pEntry->NameExpected)
236  {
237  GetSystemDirectoryW(PathExpected, _countof(PathExpected));
238  lstrcatW(PathExpected, L"\\");
239  lstrcatW(PathExpected, pEntry->NameExpected);
240  }
241  break;
242  }
243 
244  if (PathVar)
245  {
246  if (!GetEnvironmentVariableW(L"PATH", OldPathVar, _countof(OldPathVar)))
247  {
248  skip("#%d: GetEnvironmentVariableW failed\n", EntryNumber);
249  return;
250  }
251  if (!SetEnvironmentVariableW(L"PATH", PathVar))
252  {
253  skip("#%d: SetEnvironmentVariableW failed\n", EntryNumber);
254  return;
255  }
256  }
257 
258  _SEH2_TRY
259  {
261  if (pEntry->NameBefore)
262  {
263  Ret = PathFindOnPathW(Path, (LPCWSTR *)pEntry->Dirs);
264  }
265  else
266  {
267  Ret = PathFindOnPathW(NULL, (LPCWSTR *)pEntry->Dirs);
268  }
269  Error = GetLastError();
270  }
272  {
273  Ret = RAISED;
274  Error = DEAD;
275  }
276  _SEH2_END;
277 
278  if (PathVar)
279  {
280  ok(SetEnvironmentVariableW(L"PATH", OldPathVar),
281  "#%d: SetEnvironmentVariableW failed\n", EntryNumber);
282  }
283 
284  ok(Ret == pEntry->Ret, "#%d: Ret expected %d, was %d.\n",
285  EntryNumber, pEntry->Ret, Ret);
286 
287  if (pEntry->Error != IGNORE_ERR)
288  {
289  ok(Error == pEntry->Error, "#%d: last error expected %ld, was %ld.\n",
290  EntryNumber, pEntry->Error, Error);
291  }
292 
293  if (pEntry->PathExpected)
294  {
295  ok(lstrcmpiW(Path, pEntry->PathExpected) == 0, "#%d: Path expected %s, was %s.\n",
296  EntryNumber, wine_dbgstr_w(pEntry->PathExpected), wine_dbgstr_w(Path));
297  }
298  else if (pEntry->NameExpected)
299  {
300  ok(lstrcmpiW(Path, PathExpected) == 0, "#%d: Path expected %s, was %s.\n",
301  EntryNumber, wine_dbgstr_w(PathExpected), wine_dbgstr_w(Path));
302  }
303 }
LPCWSTR NameExpected
Definition: PathResolve.cpp:70
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
UINT EF_
Definition: PathResolve.cpp:68
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: atltest.h:87
#define _countof(array)
Definition: fontsub.cpp:30
#define assert(x)
Definition: debug.h:53
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define EF_TESTDATA
#define RAISED
int32_t INT
Definition: typedefs.h:56
#define IGNORE_ERR
LPWSTR * Dirs
Definition: PathResolve.cpp:72
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
_SEH2_TRY
Definition: create.c:4250
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
LPCWSTR PathExpected
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
smooth NULL
Definition: ftsmooth.c:416
#define DEAD
LPCWSTR NameBefore
Definition: PathResolve.cpp:69
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define EF_SYS_DIR
INT Ret
Definition: PathResolve.cpp:66
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define SetLastError(x)
Definition: compat.h:409
#define EF_FULLPATH
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpValue)
Definition: environ.c:259
static WCHAR s_TestDataPath[MAX_PATH]
static const WCHAR L[]
Definition: oid.c:1250
_SEH2_END
Definition: create.c:4424
PRTL_UNICODE_STRING_BUFFER Path
#define lstrcpyW
Definition: compat.h:406
#define EF_WIN_DIR
#define ok(value,...)
Definition: atltest.h:57
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
#define skip(...)
Definition: atltest.h:64
#define EF_TYPE_MASK
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
#define EF_NAME_ONLY
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:412
BOOL WINAPI PathFindOnPathW(LPWSTR lpszFile, LPCWSTR *lppszOtherDirs)
Definition: path.c:1382
#define BEEF

Referenced by Test_PathFindOnPathW().

◆ START_TEST()

START_TEST ( PathFindOnPath  )

Definition at line 315 of file PathFindOnPath.c.

316 {
317  LPWSTR pch;
318 
321 
323  lstrcatW(s_FontsDir, L"\\Fonts");
324 
326  lstrcatW(s_NotepadPath, L"\\notepad.exe");
327 
329  pch = wcsrchr(s_TestDataPath, L'\\');
330  if (pch == NULL)
331  pch = wcsrchr(s_TestDataPath, L'/');
332  if (pch == NULL)
333  {
334  skip("GetModuleFileName and/or wcsrchr are insane.\n");
335  return;
336  }
337  lstrcpyW(pch, L"\\testdata");
339  {
340  skip("testdata is not found.\n");
341  return;
342  }
343 
344  s_Dirs[0] = s_TestDataPath;
345  s_Dirs[1] = NULL;
346 
348 }
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:609
#define _countof(array)
Definition: fontsub.cpp:30
static WCHAR s_FontsDir[MAX_PATH]
static WCHAR s_SysDir[MAX_PATH]
#define pch(ap)
Definition: match.c:418
UINT WINAPI GetWindowsDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2351
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
smooth NULL
Definition: ftsmooth.c:416
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
static WCHAR s_WinDir[MAX_PATH]
static WCHAR s_NotepadPath[MAX_PATH]
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
static WCHAR s_TestDataPath[MAX_PATH]
static const WCHAR L[]
Definition: oid.c:1250
static LPWSTR s_Dirs[2]
#define lstrcpyW
Definition: compat.h:406
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2312
#define skip(...)
Definition: atltest.h:64
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static void Test_PathFindOnPathW(void)

◆ Test_PathFindOnPathW()

static void Test_PathFindOnPathW ( void  )
static

Definition at line 305 of file PathFindOnPath.c.

306 {
307  UINT i;
308 
309  for (i = 0; i < _countof(s_Entries); ++i)
310  {
311  DoEntry(s_Entries[i].EntryNumber, &s_Entries[i], NULL);
312  }
313 }
#define _countof(array)
Definition: fontsub.cpp:30
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
smooth NULL
Definition: ftsmooth.c:416
static void DoEntry(INT EntryNumber, const ENTRY *pEntry, const WCHAR *PathVar)
unsigned int UINT
Definition: ndis.h:50
static const ENTRY s_Entries[]

Referenced by START_TEST().

Variable Documentation

◆ s_Dirs

LPWSTR s_Dirs[2]
static

Definition at line 49 of file PathFindOnPath.c.

Referenced by START_TEST().

◆ s_Entries

const ENTRY s_Entries[]
static

Definition at line 55 of file PathFindOnPath.c.

Referenced by Test_PathFindOnPathW().

◆ s_FontsDir

WCHAR s_FontsDir[MAX_PATH]
static

Definition at line 52 of file PathFindOnPath.c.

Referenced by START_TEST().

◆ s_NotepadPath

WCHAR s_NotepadPath[MAX_PATH]
static

Definition at line 53 of file PathFindOnPath.c.

Referenced by START_TEST().

◆ s_SysDir

WCHAR s_SysDir[MAX_PATH]
static

Definition at line 51 of file PathFindOnPath.c.

Referenced by START_TEST().

◆ s_TestDataPath

WCHAR s_TestDataPath[MAX_PATH]
static

Definition at line 48 of file PathFindOnPath.c.

Referenced by DoEntry(), and START_TEST().

◆ s_WinDir

WCHAR s_WinDir[MAX_PATH]
static

Definition at line 50 of file PathFindOnPath.c.

Referenced by START_TEST().