ReactOS 0.4.16-dev-927-g467dec4
PathProcessCommand.cpp
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API tests
3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later)
4 * PURPOSE: Tests for PathProcessCommand
5 * COPYRIGHT: Copyright 2025 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
6 */
7
8#include "shelltest.h"
9#include <stdio.h>
10
11#define ok_wstri(x, y) \
12 ok(_wcsicmp(x, y) == 0, "Wrong string. Expected '%S', got '%S'\n", y, x)
13
15
17
18static void
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}
117
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 ok_wstri(x, y)
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
#define ok_int(expression, result)
Definition: atltest.h:134
#define NULL
Definition: types.h:112
#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
#define lstrcpynW
Definition: compat.h:738
#define lstrlenW
Definition: compat.h:750
BOOL WINAPI DECLSPEC_HOTPATCH SetEnvironmentVariableW(IN LPCWSTR lpName, IN LPCWSTR lpValue)
Definition: environ.c:259
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
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2249
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 DWORD
Definition: nt_native.h:44
#define L(x)
Definition: ntvdm.h:50
#define PathAppendW
Definition: pathcch.h:309
long LONG
Definition: pedump.c:60
#define INT
Definition: polytest.cpp:20
#define PPCF_FORCEQUALIFY
Definition: shlobj.h:2429
#define PPCF_LONGESTPOSSIBLE
Definition: shlobj.h:2430
LONG WINAPI PathProcessCommand(_In_ LPCWSTR, _Out_writes_(cchDest) LPWSTR, int cchDest, DWORD)
#define PPCF_ADDQUOTES
Definition: shlobj.h:2424
#define PPCF_ADDARGUMENTS
Definition: shlobj.h:2426
#define PPCF_NODIRECTORIES
Definition: shlobj.h:2427
#define _countof(array)
Definition: sndvol32.h:70
#define WINAPI
Definition: msvc.h:6
int WINAPIV wsprintfW(_Out_ LPWSTR, _In_ _Printf_format_string_ LPCWSTR,...)
#define MAKEINTRESOURCEA(i)
Definition: winuser.h:581
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185