ReactOS 0.4.16-dev-927-g467dec4
PathProcessCommand.cpp File Reference
#include "shelltest.h"
#include <stdio.h>
Include dependency graph for PathProcessCommand.cpp:

Go to the source code of this file.

Macros

#define ok_wstri(x, y)    ok(_wcsicmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
 

Typedefs

typedef LONG(WINAPIFN_PathProcessCommand) (LPCWSTR, LPWSTR, INT, DWORD)
 

Functions

static void Test_PathProcessCommand (void)
 
 START_TEST (PathProcessCommand)
 

Variables

static FN_PathProcessCommand s_PathProcessCommand = NULL
 

Macro Definition Documentation

◆ ok_wstri

#define ok_wstri (   x,
  y 
)     ok(_wcsicmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)

Definition at line 11 of file PathProcessCommand.cpp.

Typedef Documentation

◆ FN_PathProcessCommand

typedef LONG(WINAPI * FN_PathProcessCommand) (LPCWSTR, LPWSTR, INT, DWORD)

Definition at line 14 of file PathProcessCommand.cpp.

Function Documentation

◆ START_TEST()

START_TEST ( PathProcessCommand  )

Definition at line 118 of file PathProcessCommand.cpp.

119{
120 WCHAR szCurDir[MAX_PATH], szTempDir[MAX_PATH];
121
123 GetProcAddress(GetModuleHandleW(L"shell32"), "PathProcessCommand");
125 {
128 }
130 {
131 skip("PathProcessCommand not found\n");
132 return;
133 }
134
135 GetCurrentDirectoryW(_countof(szCurDir), szCurDir);
136 GetEnvironmentVariableW(L"TEMP", szTempDir, _countof(szTempDir));
137 SetCurrentDirectoryW(szTempDir);
138
139 SetEnvironmentVariableW(L"PATH", szTempDir);
140
142
143 SetCurrentDirectoryW(szCurDir);
144}
static void Test_PathProcessCommand(void)
static FN_PathProcessCommand s_PathProcessCommand
LONG(WINAPI * FN_PathProcessCommand)(LPCWSTR, LPWSTR, INT, DWORD)
#define skip(...)
Definition: atltest.h:64
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define GetEnvironmentVariableW(x, y, z)
Definition: compat.h:755
#define GetProcAddress(x, y)
Definition: compat.h:753
#define MAX_PATH
Definition: compat.h:34
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpValue)
Definition: environ.c:259
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2249
#define L(x)
Definition: ntvdm.h:50
#define _countof(array)
Definition: sndvol32.h:70
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
__wchar_t WCHAR
Definition: xmlstorage.h:180

◆ Test_PathProcessCommand()

static void Test_PathProcessCommand ( void  )
static

Definition at line 19 of file PathProcessCommand.cpp.

20{
21 WCHAR buffer[MAX_PATH], szCalcExe[MAX_PATH];
23 FILE *fout;
24 WCHAR szCurDir[MAX_PATH];
25 WCHAR szFull1[MAX_PATH], szFull2[MAX_PATH], szFull3[MAX_PATH], szFull4[MAX_PATH];
26 WCHAR szFull5[MAX_PATH];
27
28 fout = _wfopen(L"_Test.exe", L"wb");
29 fclose(fout);
30 fout = _wfopen(L"test with spaces.exe", L"wb");
31 fclose(fout);
32
33 GetFullPathNameW(L".", _countof(szCurDir), szCurDir, NULL);
34 GetShortPathNameW(szCurDir, szCurDir, _countof(szCurDir));
35
36 lstrcpynW(szFull1, szCurDir, _countof(szFull1));
37 lstrcpynW(szFull2, szCurDir, _countof(szFull2));
38 lstrcpynW(szFull4, szCurDir, _countof(szFull4));
39 lstrcpynW(szFull5, szCurDir, _countof(szFull5));
40
41 lstrcatW(szFull1, L"\\_Test.exe");
42 lstrcatW(szFull2, L"\\test with spaces.exe");
43 wsprintfW(szFull3, L"\"%s\"", szFull2);
44 lstrcatW(szFull4, L"\\_Test.exe arg1 arg2");
45 lstrcatW(szFull5, L"\\_TestDir.exe");
46
47 CreateDirectoryW(L"_TestDir.exe", NULL);
48
49 // Test case 1: Basic functionality (no flags)
52 ok_int(result, lstrlenW(szFull1) + 1);
53 ok_wstri(buffer, szFull1);
54
55 // Test case 2: Quoted path
57 result = s_PathProcessCommand(L"\"test with spaces\"", buffer, _countof(buffer), 0);
58 ok_int(result, lstrlenW(szFull2) + 1);
59 ok_wstri(buffer, szFull2);
60
61 // Test case 3: Add quotes flag
64 ok_int(result, lstrlenW(szFull3) + 1);
65 ok_wstri(buffer, szFull3);
66
67 // Test case 4: Add arguments flag
70 ok_int(result, lstrlenW(szFull4) + 1);
71 ok_wstri(buffer, szFull4);
72
73 // calc.exe
74 GetSystemDirectoryW(szCalcExe, _countof(szCalcExe));
75 PathAppendW(szCalcExe, L"calc.exe");
76
77 // Test case 5: Longest possible flag
80 ok_int(result, lstrlenW(szCalcExe) + 1);
81 ok_wstri(buffer, szCalcExe);
82
83 // Test case 6: Buffer too small
85 result = s_PathProcessCommand(L"_Test.exe", buffer, 5, 0);
86 ok_int(result, -1);
87 ok_wstri(buffer, L"<>");
88
89 // Test case 7: Null input path
92 ok_int(result, -1);
93 ok_wstri(buffer, L"<>");
94
95 // Test case 8: Relative path resolution
98 ok_int(result, lstrlenW(szFull1) + 1);
99 ok_wstri(buffer, szFull1);
100
101 // Test case 9: No directories
104 ok_int(result, -1);
105 ok_wstri(buffer, L"<>");
106
107 // Test case 10: With directories
109 result = s_PathProcessCommand(L"_TestDir.exe", buffer, _countof(buffer), 0);
110 ok_int(result, lstrlenW(szFull5) + 1);
111 ok_wstri(buffer, szFull5);
112
113 RemoveDirectoryW(L"_TestDir.exe");
114 DeleteFileW(L"_Test.exe");
115 DeleteFileW(L"test with spaces.exe");
116}
#define ok_wstri(x, y)
#define ok_int(expression, result)
Definition: atltest.h:134
#define NULL
Definition: types.h:112
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
BOOL WINAPI CreateDirectoryW(IN LPCWSTR lpPathName, IN LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: dir.c:90
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
UINT WINAPI GetSystemDirectoryW(OUT LPWSTR lpBuffer, IN UINT uSize)
Definition: path.c:2313
DWORD WINAPI GetShortPathNameW(IN LPCWSTR lpszLongPath, OUT LPWSTR lpszShortPath, IN DWORD cchBuffer)
Definition: path.c:1833
DWORD WINAPI GetFullPathNameW(IN LPCWSTR lpFileName, IN DWORD nBufferLength, OUT LPWSTR lpBuffer, OUT LPWSTR *lpFilePart)
Definition: path.c:1106
GLuint buffer
Definition: glext.h:5915
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ _CRTIMP FILE *__cdecl _wfopen(_In_z_ const wchar_t *_Filename, _In_z_ const wchar_t *_Mode)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
#define PathAppendW
Definition: pathcch.h:309
long LONG
Definition: pedump.c:60
#define PPCF_FORCEQUALIFY
Definition: shlobj.h:2429
#define PPCF_LONGESTPOSSIBLE
Definition: shlobj.h:2430
#define PPCF_ADDQUOTES
Definition: shlobj.h:2424
#define PPCF_ADDARGUMENTS
Definition: shlobj.h:2426
#define PPCF_NODIRECTORIES
Definition: shlobj.h:2427
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)

Referenced by START_TEST().

Variable Documentation

◆ s_PathProcessCommand

FN_PathProcessCommand s_PathProcessCommand = NULL
static

Definition at line 16 of file PathProcessCommand.cpp.

Referenced by START_TEST(), and Test_PathProcessCommand().