4 #include <winpr/path.h>
5 #include <winpr/tchar.h>
6 #include <winpr/winpr.h>
13 static const TCHAR testPathPrefixFileNamespace[] = _T(
"\\\\?\\C:\\Program Files\\");
14 static const TCHAR testPathNoPrefixFileNamespace[] = _T(
"C:\\Program Files\\");
15 static const TCHAR testPathPrefixFileNamespaceMinimum[] = _T(
"\\\\?\\C:");
16 static const TCHAR testPathNoPrefixFileNamespaceMinimum[] = _T(
"C:");
18 static const TCHAR testPathPrefixDeviceNamespace[] = _T(
"\\\\?\\GLOBALROOT");
20 int TestPathCchStripPrefix(
int argc,
char* argv[])
23 TCHAR Path[PATHCCH_MAX_CCH] = { 0 };
35 _tcsncpy(Path, testPathPrefixFileNamespace, ARRAYSIZE(Path));
37 status = PathCchStripPrefix(Path,
sizeof(testPathPrefixFileNamespace) /
sizeof(TCHAR));
41 _tprintf(_T(
"PathCchStripPrefix status: 0x%08") _T(PRIX32) _T(
"\n"), status);
45 if (_tcsncmp(Path, testPathNoPrefixFileNamespace, ARRAYSIZE(Path)) != 0)
47 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path,
48 testPathNoPrefixFileNamespace);
54 _tcsncpy(Path, testPathPrefixDeviceNamespace, ARRAYSIZE(Path));
56 status = PathCchStripPrefix(Path, ARRAYSIZE(testPathPrefixDeviceNamespace));
58 if (status != S_FALSE)
60 _tprintf(_T(
"PathCchStripPrefix status: 0x%08") _T(PRIX32) _T(
"\n"), status);
64 if (_tcsncmp(Path, testPathPrefixDeviceNamespace, ARRAYSIZE(Path)) != 0)
66 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path,
67 testPathPrefixDeviceNamespace);
72 status = PathCchStripPrefix(NULL, PATHCCH_MAX_CCH);
73 if (status != E_INVALIDARG)
76 _T(
"PathCchStripPrefix with null path unexpectedly succeeded with status 0x%08") _T(
83 for (
int i = 0; i < 5; i++)
85 _tcsncpy(Path, testPathPrefixFileNamespace, ARRAYSIZE(Path));
87 i = PATHCCH_MAX_CCH + 1;
88 status = PathCchStripPrefix(Path, i);
89 if (status != E_INVALIDARG)
91 _tprintf(_T(
"PathCchStripPrefix with invalid cchPath value %d unexpectedly succeeded ")
92 _T(
"with status 0x%08") _T(PRIX32) _T(
"\n"),
99 _tcsncpy(Path, testPathPrefixFileNamespaceMinimum, ARRAYSIZE(Path));
100 size_t i = ARRAYSIZE(testPathPrefixFileNamespaceMinimum);
102 status = PathCchStripPrefix(Path, i);
105 _tprintf(_T(
"PathCchStripPrefix with minimum valid strippable path length unexpectedly ")
106 _T(
"returned status 0x%08") _T(PRIX32) _T(
"\n"),
110 if (_tcsncmp(Path, testPathNoPrefixFileNamespaceMinimum, ARRAYSIZE(Path)) != 0)
112 _tprintf(_T(
"Path Mismatch: Actual: %s, Expected: %s\n"), Path,
113 testPathNoPrefixFileNamespaceMinimum);
118 _tcsncpy(Path, _T(
"\\\\?\\5:"), ARRAYSIZE(Path));
119 status = PathCchStripPrefix(Path, 6);
123 _T(
"PathCchStripPrefix with invalid drive letter symbol unexpectedly succeeded\n"));