4 #include <winpr/path.h>
5 #include <winpr/tchar.h>
6 #include <winpr/winpr.h>
8 static const TCHAR testExtDot[] = _T(
".exe");
9 static const TCHAR testExtNoDot[] = _T(
"exe");
10 static const TCHAR testPathNoExtension[] = _T(
"C:\\Windows\\System32\\cmd");
11 static const TCHAR testPathExtension[] = _T(
"C:\\Windows\\System32\\cmd.exe");
13 int TestPathCchAddExtension(
int argc,
char* argv[])
16 TCHAR Path[PATHCCH_MAX_CCH] = { 0 };
23 _tcsncpy(Path, testPathNoExtension, ARRAYSIZE(Path));
25 status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
29 _tprintf(_T(
"PathCchAddExtension status: 0x%08") _T(PRIX32) _T(
"\n"), status);
33 if (_tcsncmp(Path, testPathExtension, ARRAYSIZE(Path)) != 0)
35 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
41 _tcsncpy(Path, testPathNoExtension, ARRAYSIZE(Path));
43 status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtNoDot);
47 _tprintf(_T(
"PathCchAddExtension status: 0x%08") _T(PRIX32) _T(
"\n"), status);
51 if (_tcsncmp(Path, testPathExtension, ARRAYSIZE(Path)) != 0)
53 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
59 _tcsncpy(Path, testPathExtension, ARRAYSIZE(Path));
61 status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
63 if (status != S_FALSE)
65 _tprintf(_T(
"PathCchAddExtension status: 0x%08") _T(PRIX32) _T(
"\n"), status);
69 if (_tcsncmp(Path, testPathExtension, ARRAYSIZE(Path)) != 0)
71 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
77 _tcsncpy(Path, testPathExtension, ARRAYSIZE(Path));
79 status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
81 if (status != S_FALSE)
83 _tprintf(_T(
"PathCchAddExtension status: 0x%08") _T(PRIX32) _T(
"\n"), status);
87 if (_tcsncmp(Path, testPathExtension, ARRAYSIZE(Path)) != 0)
89 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
95 status = PathCchAddExtension(NULL, PATHCCH_MAX_CCH, testExtDot);
96 if (status != E_INVALIDARG)
98 _tprintf(_T(
"PathCchAddExtension with null buffer returned status: 0x%08") _T(
99 PRIX32) _T(
" (expected E_INVALIDARG)\n"),
106 status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, NULL);
107 if (status != E_INVALIDARG)
109 _tprintf(_T(
"PathCchAddExtension with null extension returned status: 0x%08") _T(
110 PRIX32) _T(
" (expected E_INVALIDARG)\n"),
117 _tcsncpy(Path, _T(
"C:\\456789"), ARRAYSIZE(Path));
118 status = PathCchAddExtension(Path, 9 + 4, _T(
".jpg"));
119 if (SUCCEEDED(status))
121 _tprintf(_T(
"PathCchAddExtension with insufficient buffer unexpectedly succeeded with ")
122 _T(
"status: 0x%08") _T(PRIX32) _T(
"\n"),
129 _tcsncpy(Path, _T(
"C:\\456789"), ARRAYSIZE(Path));
130 status = PathCchAddExtension(Path, 9 + 4 + 1, _T(
".jpg"));
133 _tprintf(_T(
"PathCchAddExtension with sufficient buffer unexpectedly failed with status: ")
134 _T(
"0x%08") _T(PRIX32) _T(
"\n"),