diff --git a/winpr/include/winpr/error.h b/winpr/include/winpr/error.h index 21f5f05c6..58ffc31d8 100644 --- a/winpr/include/winpr/error.h +++ b/winpr/include/winpr/error.h @@ -25,6 +25,9 @@ #ifndef _WIN32 +#define S_OK ((HRESULT) 0L) +#define S_FALSE ((HRESULT) 1L) + /* System Error Codes (0-499) */ #define ERROR_SUCCESS 0x00000000 diff --git a/winpr/include/winpr/path.h b/winpr/include/winpr/path.h index edcb90314..432c12c20 100644 --- a/winpr/include/winpr/path.h +++ b/winpr/include/winpr/path.h @@ -21,8 +21,29 @@ #define WINPR_PATH_H #include +#include #include +//#define HAVE_PATHCCH_H 1 + +#ifdef HAVE_PATHCCH_H + +#include + +#else + +#define PATHCCH_ALLOW_LONG_PATHS 0x00000001 /* Allow building of \\?\ paths if longer than MAX_PATH */ + +#define VOLUME_PREFIX _T("\\\\?\\Volume") +#define VOLUME_PREFIX_LEN ((sizeof(VOLUME_PREFIX) / sizeof(TCHAR)) - 1) + +/* + * Maximum number of characters we support using the "\\?\" syntax + * (0x7FFF + 1 for NULL terminator) + */ + +#define PATHCCH_MAX_CCH 0x8000 + WINPR_API HRESULT PathCchAddBackslashA(PSTR pszPath, size_t cchPath); WINPR_API HRESULT PathCchAddBackslashW(PWSTR pszPath, size_t cchPath); @@ -137,4 +158,6 @@ WINPR_API HRESULT PathCchRemoveFileSpecW(PWSTR pszPath, size_t cchPath); #define PathCchRemoveFileSpec PathCchRemoveFileSpecA #endif +#endif + #endif /* WINPR_PATH_H */ diff --git a/winpr/libwinpr/path/CMakeLists.txt b/winpr/libwinpr/path/CMakeLists.txt index 1caa7346b..0c19c75fd 100644 --- a/winpr/libwinpr/path/CMakeLists.txt +++ b/winpr/libwinpr/path/CMakeLists.txt @@ -36,3 +36,7 @@ else() endif() set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR") + +if(BUILD_TESTING) + add_subdirectory(test) +endif() diff --git a/winpr/libwinpr/path/test/.gitignore b/winpr/libwinpr/path/test/.gitignore new file mode 100644 index 000000000..7c43324cd --- /dev/null +++ b/winpr/libwinpr/path/test/.gitignore @@ -0,0 +1,3 @@ +TestPath +TestPath.c + diff --git a/winpr/libwinpr/path/test/CMakeLists.txt b/winpr/libwinpr/path/test/CMakeLists.txt new file mode 100644 index 000000000..b8eb05fd0 --- /dev/null +++ b/winpr/libwinpr/path/test/CMakeLists.txt @@ -0,0 +1,48 @@ + +set(MODULE_NAME "TestPath") +set(MODULE_PREFIX "TEST_PATH") + +set(${MODULE_PREFIX}_DRIVER ${MODULE_NAME}.c) + +set(${MODULE_PREFIX}_TESTS + TestPathCchAddBackslash.c + TestPathCchRemoveBackslash.c + TestPathCchAddBackslashEx.c + TestPathCchRemoveBackslashEx.c + TestPathCchAddExtension.c + TestPathCchAppend.c + TestPathCchAppendEx.c + TestPathCchCanonicalize.c + TestPathCchCanonicalizeEx.c + TestPathAllocCanonicalize.c + TestPathCchCombine.c + TestPathCchCombineEx.c + TestPathAllocCombine.c + TestPathCchFindExtension.c + TestPathCchRenameExtension.c + TestPathCchRemoveExtension.c + TestPathCchIsRoot.c + TestPathIsUNCEx.c + TestPathCchSkipRoot.c + TestPathCchStripToRoot.c + TestPathCchStripPrefix.c + TestPathCchRemoveFileSpec.c) + +create_test_sourcelist(${MODULE_PREFIX}_SRCS + ${${MODULE_PREFIX}_DRIVER} + ${${MODULE_PREFIX}_TESTS}) + +add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) + +if(WIN32) + target_link_libraries(${MODULE_NAME} Pathcch) +else() + target_link_libraries(${MODULE_NAME} winpr-path) +endif() + +foreach(test ${${MODULE_PREFIX}_TESTS}) + get_filename_component(TestName ${test} NAME_WE) + add_test(${TestName} ${EXECUTABLE_OUTPUT_PATH}/${MODULE_NAME} ${TestName}) +endforeach() + +set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test") diff --git a/winpr/libwinpr/path/test/TestPathAllocCanonicalize.c b/winpr/libwinpr/path/test/TestPathAllocCanonicalize.c new file mode 100644 index 000000000..81f601432 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathAllocCanonicalize.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathAllocCanonicalize(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathAllocCombine.c b/winpr/libwinpr/path/test/TestPathAllocCombine.c new file mode 100644 index 000000000..a2fd2b069 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathAllocCombine.c @@ -0,0 +1,94 @@ + +#include +#include +#include +#include +#include + +static const TCHAR testBasePathBackslash[] = _T("C:\\Program Files\\"); +static const TCHAR testBasePathNoBackslash[] = _T("C:\\Program Files"); +static const TCHAR testMorePathBackslash[] = _T("\\Microsoft Visual Studio 11.0"); +static const TCHAR testMorePathNoBackslash[] = _T("Microsoft Visual Studio 11.0"); +static const TCHAR testPathOut[] = _T("C:\\Program Files\\Microsoft Visual Studio 11.0"); +static const TCHAR testPathOutMorePathBackslash[] = _T("C:\\Microsoft Visual Studio 11.0"); + +int TestPathAllocCombine(int argc, char* argv[]) +{ + HRESULT status; + LPTSTR PathOut; + + /* Base Path: Backslash, More Path: No Backslash */ + + status = PathAllocCombine(testBasePathBackslash, testMorePathNoBackslash, 0, &PathOut); + + if (status != S_OK) + { + _tprintf(_T("PathAllocCombine status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(PathOut, testPathOut) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), PathOut, testPathOut); + return -1; + } + + HeapFree(GetProcessHeap(), 0, PathOut); + + /* Base Path: Backslash, More Path: Backslash */ + + status = PathAllocCombine(testBasePathBackslash, testMorePathBackslash, 0, &PathOut); + + if (status != S_OK) + { + _tprintf(_T("PathAllocCombine status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(PathOut, testPathOutMorePathBackslash) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), PathOut, testPathOutMorePathBackslash); + return -1; + } + + HeapFree(GetProcessHeap(), 0, PathOut); + + /* Base Path: No Backslash, More Path: Backslash */ + + status = PathAllocCombine(testBasePathNoBackslash, testMorePathBackslash, 0, &PathOut); + + if (status != S_OK) + { + _tprintf(_T("PathAllocCombine status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(PathOut, testPathOutMorePathBackslash) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), PathOut, testPathOutMorePathBackslash); + return -1; + } + + HeapFree(GetProcessHeap(), 0, PathOut); + + /* Base Path: No Backslash, More Path: No Backslash */ + + status = PathAllocCombine(testBasePathNoBackslash, testMorePathNoBackslash, 0, &PathOut); + + if (status != S_OK) + { + _tprintf(_T("PathAllocCombine status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(PathOut, testPathOut) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), PathOut, testPathOut); + return -1; + } + + HeapFree(GetProcessHeap(), 0, PathOut); + + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchAddBackslash.c b/winpr/libwinpr/path/test/TestPathCchAddBackslash.c new file mode 100644 index 000000000..b237b6b27 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchAddBackslash.c @@ -0,0 +1,54 @@ + +#include +#include +#include +#include +#include + +static const TCHAR testPathBackslash[] = _T("C:\\Program Files\\"); +static const TCHAR testPathNoBackslash[] = _T("C:\\Program Files"); + +int TestPathCchAddBackslash(int argc, char* argv[]) +{ + HRESULT status; + TCHAR Path[PATHCCH_MAX_CCH]; + + _tcscpy(Path, testPathNoBackslash); + + /* Add a backslash to a path without a trailing backslash, expect S_OK */ + + status = PathCchAddBackslash(Path, PATHCCH_MAX_CCH); + + if (status != S_OK) + { + _tprintf(_T("PathCchAddBackslash status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathBackslash) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash); + return -1; + } + + /* Add a backslash to a path with a trailing backslash, expect S_FALSE */ + + _tcscpy(Path, testPathBackslash); + + status = PathCchAddBackslash(Path, PATHCCH_MAX_CCH); + + if (status != S_FALSE) + { + _tprintf(_T("PathCchAddBackslash status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathBackslash) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash); + return -1; + } + + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c b/winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c new file mode 100644 index 000000000..9fe39be84 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c @@ -0,0 +1,56 @@ + +#include +#include +#include +#include +#include + +static const TCHAR testPathBackslash[] = _T("C:\\Program Files\\"); +static const TCHAR testPathNoBackslash[] = _T("C:\\Program Files"); + +int TestPathCchAddBackslashEx(int argc, char* argv[]) +{ + HRESULT status; + LPTSTR pszEnd; + size_t cchRemaining; + TCHAR Path[PATHCCH_MAX_CCH]; + + _tcscpy(Path, testPathNoBackslash); + + /* Add a backslash to a path without a trailing backslash, expect S_OK */ + + status = PathCchAddBackslashEx(Path, sizeof(Path) / sizeof(TCHAR), &pszEnd, &cchRemaining); + + if (status != S_OK) + { + _tprintf(_T("PathCchAddBackslash status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathBackslash) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash); + return -1; + } + + /* Add a backslash to a path with a trailing backslash, expect S_FALSE */ + + _tcscpy(Path, testPathBackslash); + + status = PathCchAddBackslashEx(Path, sizeof(Path) / sizeof(TCHAR), &pszEnd, &cchRemaining); + + if (status != S_FALSE) + { + _tprintf(_T("PathCchAddBackslash status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathBackslash) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash); + return -1; + } + + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchAddExtension.c b/winpr/libwinpr/path/test/TestPathCchAddExtension.c new file mode 100644 index 000000000..ef766cffa --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchAddExtension.c @@ -0,0 +1,92 @@ + +#include +#include +#include +#include +#include + +static const TCHAR testExtDot[] = _T(".exe"); +static const TCHAR testExtNoDot[] = _T("exe"); +static const TCHAR testPathNoExtension[] = _T("C:\\Windows\\System32\\cmd"); +static const TCHAR testPathExtension[] = _T("C:\\Windows\\System32\\cmd.exe"); + +int TestPathCchAddExtension(int argc, char* argv[]) +{ + HRESULT status; + TCHAR Path[PATHCCH_MAX_CCH]; + + /* Path: no extension, Extension: dot */ + + _tcscpy(Path, testPathNoExtension); + + status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot); + + if (status != S_OK) + { + _tprintf(_T("PathCchAddExtension status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathExtension) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension); + return -1; + } + + /* Path: no extension, Extension: no dot */ + + _tcscpy(Path, testPathNoExtension); + + status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtNoDot); + + if (status != S_OK) + { + _tprintf(_T("PathCchAddExtension status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathExtension) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension); + return -1; + } + + /* Path: extension, Extension: dot */ + + _tcscpy(Path, testPathExtension); + + status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot); + + if (status != S_FALSE) + { + _tprintf(_T("PathCchAddExtension status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathExtension) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension); + return -1; + } + + /* Path: extension, Extension: no dot */ + + _tcscpy(Path, testPathExtension); + + status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot); + + if (status != S_FALSE) + { + _tprintf(_T("PathCchAddExtension status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathExtension) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension); + return -1; + } + + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchAppend.c b/winpr/libwinpr/path/test/TestPathCchAppend.c new file mode 100644 index 000000000..76053c38a --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchAppend.c @@ -0,0 +1,93 @@ + +#include +#include +#include +#include +#include + +static const TCHAR testBasePathBackslash[] = _T("C:\\Program Files\\"); +static const TCHAR testBasePathNoBackslash[] = _T("C:\\Program Files"); +static const TCHAR testMorePathBackslash[] = _T("\\Microsoft Visual Studio 11.0"); +static const TCHAR testMorePathNoBackslash[] = _T("Microsoft Visual Studio 11.0"); +static const TCHAR testPathOut[] = _T("C:\\Program Files\\Microsoft Visual Studio 11.0"); + +int TestPathCchAppend(int argc, char* argv[]) +{ + HRESULT status; + TCHAR Path[PATHCCH_MAX_CCH]; + + /* Base Path: Backslash, More Path: No Backslash */ + + _tcscpy(Path, testBasePathBackslash); + + status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathNoBackslash); + + if (status != S_OK) + { + _tprintf(_T("PathCchAppend status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathOut) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut); + return -1; + } + + /* Base Path: Backslash, More Path: Backslash */ + + _tcscpy(Path, testBasePathBackslash); + + status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathBackslash); + + if (status != S_OK) + { + _tprintf(_T("PathCchAppend status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathOut) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut); + return -1; + } + + /* Base Path: No Backslash, More Path: Backslash */ + + _tcscpy(Path, testBasePathNoBackslash); + + status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathBackslash); + + if (status != S_OK) + { + _tprintf(_T("PathCchAppend status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathOut) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut); + return -1; + } + + /* Base Path: No Backslash, More Path: No Backslash */ + + _tcscpy(Path, testBasePathNoBackslash); + + status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathNoBackslash); + + if (status != S_OK) + { + _tprintf(_T("PathCchAppend status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathOut) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut); + return -1; + } + + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchAppendEx.c b/winpr/libwinpr/path/test/TestPathCchAppendEx.c new file mode 100644 index 000000000..6f040fad1 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchAppendEx.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchAppendEx(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchCanonicalize.c b/winpr/libwinpr/path/test/TestPathCchCanonicalize.c new file mode 100644 index 000000000..7c5b868dd --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchCanonicalize.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchCanonicalize(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchCanonicalizeEx.c b/winpr/libwinpr/path/test/TestPathCchCanonicalizeEx.c new file mode 100644 index 000000000..13c4d373e --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchCanonicalizeEx.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchCanonicalizeEx(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchCombine.c b/winpr/libwinpr/path/test/TestPathCchCombine.c new file mode 100644 index 000000000..bfe1e86c6 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchCombine.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchCombine(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchCombineEx.c b/winpr/libwinpr/path/test/TestPathCchCombineEx.c new file mode 100644 index 000000000..5c3d0b8be --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchCombineEx.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchCombineEx(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchFindExtension.c b/winpr/libwinpr/path/test/TestPathCchFindExtension.c new file mode 100644 index 000000000..35ce6b576 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchFindExtension.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchFindExtension(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchIsRoot.c b/winpr/libwinpr/path/test/TestPathCchIsRoot.c new file mode 100644 index 000000000..a4e48daf9 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchIsRoot.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchIsRoot(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchRemoveBackslash.c b/winpr/libwinpr/path/test/TestPathCchRemoveBackslash.c new file mode 100644 index 000000000..a7c00ecfd --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchRemoveBackslash.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchRemoveBackslash(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchRemoveBackslashEx.c b/winpr/libwinpr/path/test/TestPathCchRemoveBackslashEx.c new file mode 100644 index 000000000..903341a46 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchRemoveBackslashEx.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchRemoveBackslashEx(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchRemoveExtension.c b/winpr/libwinpr/path/test/TestPathCchRemoveExtension.c new file mode 100644 index 000000000..f52ea8fc3 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchRemoveExtension.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchRemoveExtension(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchRemoveFileSpec.c b/winpr/libwinpr/path/test/TestPathCchRemoveFileSpec.c new file mode 100644 index 000000000..192894e0c --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchRemoveFileSpec.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchRemoveFileSpec(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchRenameExtension.c b/winpr/libwinpr/path/test/TestPathCchRenameExtension.c new file mode 100644 index 000000000..a1816cbcd --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchRenameExtension.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchRenameExtension(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchSkipRoot.c b/winpr/libwinpr/path/test/TestPathCchSkipRoot.c new file mode 100644 index 000000000..4e83ef541 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchSkipRoot.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchSkipRoot(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchStripPrefix.c b/winpr/libwinpr/path/test/TestPathCchStripPrefix.c new file mode 100644 index 000000000..7163c1346 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchStripPrefix.c @@ -0,0 +1,61 @@ + +#include +#include +#include +#include +#include + +/** + * 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 testPathPrefixDeviceNamespace[] = _T("\\\\?\\GLOBALROOT"); + +int TestPathCchStripPrefix(int argc, char* argv[]) +{ + HRESULT status; + TCHAR Path[PATHCCH_MAX_CCH]; + + /* Path with prefix (File Namespace) */ + + _tcscpy(Path, testPathPrefixFileNamespace); + + status = PathCchStripPrefix(Path, sizeof(testPathPrefixFileNamespace) / sizeof(TCHAR)); + + if (status != S_OK) + { + _tprintf(_T("PathCchStripPrefix status: 0x%08X\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%08X\n"), status); + return -1; + } + + if (_tcscmp(Path, testPathPrefixDeviceNamespace) != 0) + { + _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathPrefixDeviceNamespace); + return -1; + } + + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathCchStripToRoot.c b/winpr/libwinpr/path/test/TestPathCchStripToRoot.c new file mode 100644 index 000000000..cc6e13cd9 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathCchStripToRoot.c @@ -0,0 +1,12 @@ + +#include +#include +#include +#include +#include + +int TestPathCchStripToRoot(int argc, char* argv[]) +{ + return 0; +} + diff --git a/winpr/libwinpr/path/test/TestPathIsUNCEx.c b/winpr/libwinpr/path/test/TestPathIsUNCEx.c new file mode 100644 index 000000000..3cea93432 --- /dev/null +++ b/winpr/libwinpr/path/test/TestPathIsUNCEx.c @@ -0,0 +1,50 @@ + +#include +#include +#include +#include +#include + +static const TCHAR testServer[] = _T("server\\share\\path\\file"); +static const TCHAR testPathUNC[] = _T("\\\\server\\share\\path\\file"); +static const TCHAR testPathNotUNC[] = _T("C:\\share\\path\\file"); + +int TestPathIsUNCEx(int argc, char* argv[]) +{ + BOOL status; + LPTSTR Server; + TCHAR Path[PATHCCH_MAX_CCH]; + + /* Path is UNC */ + + _tcscpy(Path, testPathUNC); + + status = PathIsUNCEx(Path, &Server); + + if (!status) + { + _tprintf(_T("PathIsUNCEx status: 0x%08X\n"), status); + return -1; + } + + if (_tcscmp(Server, testServer) != 0) + { + _tprintf(_T("Server Name Mismatch: Actual: %s, Expected: %s\n"), Server, testServer); + return -1; + } + + /* Path is not UNC */ + + _tcscpy(Path, testPathNotUNC); + + status = PathIsUNCEx(Path, &Server); + + if (status) + { + _tprintf(_T("PathIsUNCEx status: 0x%08X\n"), status); + return -1; + } + + return 0; +} +