diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:24:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:24:41 +0000 |
commit | a9bcc81f821d7c66f623779fa5147e728eb3c388 (patch) | |
tree | 98676963bcdd537ae5908a067a8eb110b93486a6 /winpr/libwinpr/path/test/TestPathCchStripPrefix.c | |
parent | Initial commit. (diff) | |
download | freerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.tar.xz freerdp3-a9bcc81f821d7c66f623779fa5147e728eb3c388.zip |
Adding upstream version 3.3.0+dfsg1.upstream/3.3.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'winpr/libwinpr/path/test/TestPathCchStripPrefix.c')
-rw-r--r-- | winpr/libwinpr/path/test/TestPathCchStripPrefix.c | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/winpr/libwinpr/path/test/TestPathCchStripPrefix.c b/winpr/libwinpr/path/test/TestPathCchStripPrefix.c new file mode 100644 index 0000000..aaec4bc --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchStripPrefix.c @@ -0,0 +1,128 @@ + +#include <stdio.h> +#include <winpr/crt.h> +#include <winpr/path.h> +#include <winpr/tchar.h> +#include <winpr/winpr.h> + +/** + * Naming Files, Paths, and Namespaces: + * http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247/ + */ + +static const TCHAR testPathPrefixFileNamespace[] = _T("\\\\?\\C:\\Program Files\\"); +static const TCHAR testPathNoPrefixFileNamespace[] = _T("C:\\Program Files\\"); +static const TCHAR testPathPrefixFileNamespaceMinimum[] = _T("\\\\?\\C:"); +static const TCHAR testPathNoPrefixFileNamespaceMinimum[] = _T("C:"); + +static const TCHAR testPathPrefixDeviceNamespace[] = _T("\\\\?\\GLOBALROOT"); + +int TestPathCchStripPrefix(int argc, char* argv[]) +{ + HRESULT status = 0; + TCHAR Path[PATHCCH_MAX_CCH]; + + WINPR_UNUSED(argc); + WINPR_UNUSED(argv); + + /** + * PathCchStripPrefix returns S_OK if the prefix was removed, S_FALSE if + * the path did not have a prefix to remove, or an HRESULT failure code. + */ + + /* Path with prefix (File Namespace) */ + + _tcscpy(Path, testPathPrefixFileNamespace); + + status = PathCchStripPrefix(Path, sizeof(testPathPrefixFileNamespace) / sizeof(TCHAR)); + + if (status != S_OK) + { + _tprintf(_T("PathCchStripPrefix status: 0x%08") _T(PRIX32) _T("\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathNoPrefixFileNamespace) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, + testPathNoPrefixFileNamespace); + return -1; + } + + /* Path with prefix (Device Namespace) */ + + _tcscpy(Path, testPathPrefixDeviceNamespace); + + status = PathCchStripPrefix(Path, sizeof(testPathPrefixDeviceNamespace) / sizeof(TCHAR)); + + if (status != S_FALSE) + { + _tprintf(_T("PathCchStripPrefix status: 0x%08") _T(PRIX32) _T("\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathPrefixDeviceNamespace) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, + testPathPrefixDeviceNamespace); + return -1; + } + + /* NULL Path */ + status = PathCchStripPrefix(NULL, PATHCCH_MAX_CCH); + if (status != E_INVALIDARG) + { + _tprintf( + _T("PathCchStripPrefix with null path unexpectedly succeeded with status 0x%08") _T( + PRIX32) _T("\n"), + status); + return -1; + } + + /* Invalid cchPath values: 0, 1, 2, 3 and > PATHCCH_MAX_CCH */ + for (int i = 0; i < 5; i++) + { + _tcscpy(Path, testPathPrefixFileNamespace); + if (i == 4) + i = PATHCCH_MAX_CCH + 1; + status = PathCchStripPrefix(Path, i); + if (status != E_INVALIDARG) + { + _tprintf(_T("PathCchStripPrefix with invalid cchPath value %d unexpectedly succeeded ") + _T("with status 0x%08") _T(PRIX32) _T("\n"), + i, status); + return -1; + } + } + + /* Minimum Path that would get successfully stripped on windows */ + _tcscpy(Path, testPathPrefixFileNamespaceMinimum); + size_t i = sizeof(testPathPrefixFileNamespaceMinimum) / sizeof(TCHAR); + i = i - 1; /* include testing of a non-null terminated string */ + status = PathCchStripPrefix(Path, i); + if (status != S_OK) + { + _tprintf(_T("PathCchStripPrefix with minimum valid strippable path length unexpectedly ") + _T("returned status 0x%08") _T(PRIX32) _T("\n"), + status); + return -1; + } + if (_tcscmp(Path, testPathNoPrefixFileNamespaceMinimum)) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, + testPathNoPrefixFileNamespaceMinimum); + return -1; + } + + /* Invalid drive letter symbol */ + _tcscpy(Path, _T("\\\\?\\5:")); + status = PathCchStripPrefix(Path, 6); + if (status == S_OK) + { + _tprintf( + _T("PathCchStripPrefix with invalid drive letter symbol unexpectedly succeeded\n")); + return -1; + } + + return 0; +} |