4 #include <winpr/path.h>
5 #include <winpr/tchar.h>
6 #include <winpr/winpr.h>
8 static const TCHAR testBasePathBackslash[] = _T(
"C:\\Program Files\\");
9 static const TCHAR testBasePathNoBackslash[] = _T(
"C:\\Program Files");
10 static const TCHAR testMorePathBackslash[] = _T(
"\\Microsoft Visual Studio 11.0");
11 static const TCHAR testMorePathNoBackslash[] = _T(
"Microsoft Visual Studio 11.0");
12 static const TCHAR testPathOut[] = _T(
"C:\\Program Files\\Microsoft Visual Studio 11.0");
14 int TestPathCchAppend(
int argc,
char* argv[])
17 TCHAR Path[PATHCCH_MAX_CCH];
24 _tcsncpy(Path, testBasePathBackslash, ARRAYSIZE(Path));
26 status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathNoBackslash);
30 _tprintf(_T(
"PathCchAppend status: 0x%08") _T(PRIX32) _T(
"\n"), status);
34 if (_tcsncmp(Path, testPathOut, ARRAYSIZE(Path)) != 0)
36 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
42 _tcsncpy(Path, testBasePathBackslash, ARRAYSIZE(Path));
44 status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathBackslash);
48 _tprintf(_T(
"PathCchAppend status: 0x%08") _T(PRIX32) _T(
"\n"), status);
52 if (_tcsncmp(Path, testPathOut, ARRAYSIZE(Path)) != 0)
54 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
60 _tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
62 status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathBackslash);
66 _tprintf(_T(
"PathCchAppend status: 0x%08") _T(PRIX32) _T(
"\n"), status);
70 if (_tcsncmp(Path, testPathOut, ARRAYSIZE(Path)) != 0)
72 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
78 _tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
80 status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathNoBackslash);
84 _tprintf(_T(
"PathCchAppend status: 0x%08") _T(PRIX32) _T(
"\n"), status);
88 if (_tcsncmp(Path, testPathOut, ARRAYSIZE(Path)) != 0)
90 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
95 status = PathCchAppend(NULL, PATHCCH_MAX_CCH, testMorePathNoBackslash);
96 if (status != E_INVALIDARG)
98 _tprintf(_T(
"PathCchAppend with NULL path unexpectedly returned status: 0x%08") _T(
105 _tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
106 status = PathCchAppend(Path, PATHCCH_MAX_CCH, NULL);
107 if (status != E_INVALIDARG)
109 _tprintf(_T(
"PathCchAppend with NULL pszMore unexpectedly returned status: 0x%08") _T(
116 _tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
117 status = PathCchAppend(Path, 0, testMorePathNoBackslash);
118 if (status != E_INVALIDARG)
120 _tprintf(_T(
"PathCchAppend with cchPath value 0 unexpectedly returned status: 0x%08") _T(
125 _tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
126 status = PathCchAppend(Path, PATHCCH_MAX_CCH + 1, testMorePathNoBackslash);
127 if (status != E_INVALIDARG)
129 _tprintf(_T(
"PathCchAppend with cchPath value > PATHCCH_MAX_CCH unexpectedly returned ")
130 _T(
"status: 0x%08") _T(PRIX32) _T(
"\n"),
137 for (
size_t i = 0; i < PATHCCH_MAX_CCH - 1; i++)
140 Path[PATHCCH_MAX_CCH - 1] = 0;
142 status = PathCchAppend(Path, PATHCCH_MAX_CCH, _T(
"\\This cannot be appended to Path"));
143 if (SUCCEEDED(status))
145 _tprintf(_T(
"PathCchAppend unexepectedly succeeded with status: 0x%08") _T(PRIX32) _T(
"\n"),