Milestone 5: deliver embedded RDP sessions and lifecycle hardening

This commit is contained in:
Keith Smith
2026-03-03 18:59:26 -07:00
parent 230a401386
commit 36006bd4aa
2941 changed files with 724359 additions and 77 deletions

View File

@@ -0,0 +1,48 @@
set(MODULE_NAME "TestPath")
set(MODULE_PREFIX "TEST_PATH")
disable_warnings_for_directory(${CMAKE_CURRENT_BINARY_DIR})
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
TestPathShell.c
TestPathMakePath.c
)
create_test_sourcelist(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_DRIVER} ${${MODULE_PREFIX}_TESTS})
add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
target_link_libraries(${MODULE_NAME} winpr)
set_target_properties(${MODULE_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${TESTING_OUTPUT_DIRECTORY}")
foreach(test ${${MODULE_PREFIX}_TESTS})
get_filename_component(TestName ${test} NAME_WE)
add_test(${TestName} ${TESTING_OUTPUT_DIRECTORY}/${MODULE_NAME} ${TestName})
endforeach()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Test")

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathAllocCanonicalize(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,98 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
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 = 0;
LPTSTR PathOut = nullptr;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/* Base Path: Backslash, More Path: No Backslash */
status = PathAllocCombine(testBasePathBackslash, testMorePathNoBackslash, 0, &PathOut);
if (status != S_OK)
{
_tprintf(_T("PathAllocCombine status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcscmp(PathOut, testPathOut) != 0)
{
_tprintf(_T("Path Mismatch 1: Actual: %s, Expected: %s\n"), PathOut, testPathOut);
return -1;
}
free(PathOut);
/* Base Path: Backslash, More Path: Backslash */
status = PathAllocCombine(testBasePathBackslash, testMorePathBackslash, 0, &PathOut);
if (status != S_OK)
{
_tprintf(_T("PathAllocCombine status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcscmp(PathOut, testPathOutMorePathBackslash) != 0)
{
_tprintf(_T("Path Mismatch 2: Actual: %s, Expected: %s\n"), PathOut,
testPathOutMorePathBackslash);
return -1;
}
free(PathOut);
/* Base Path: No Backslash, More Path: Backslash */
status = PathAllocCombine(testBasePathNoBackslash, testMorePathBackslash, 0, &PathOut);
if (status != S_OK)
{
_tprintf(_T("PathAllocCombine status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcscmp(PathOut, testPathOutMorePathBackslash) != 0)
{
_tprintf(_T("Path Mismatch 3: Actual: %s, Expected: %s\n"), PathOut,
testPathOutMorePathBackslash);
return -1;
}
free(PathOut);
/* Base Path: No Backslash, More Path: No Backslash */
status = PathAllocCombine(testBasePathNoBackslash, testMorePathNoBackslash, 0, &PathOut);
if (status != S_OK)
{
_tprintf(_T("PathAllocCombine status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcscmp(PathOut, testPathOut) != 0)
{
_tprintf(_T("Path Mismatch 4: Actual: %s, Expected: %s\n"), PathOut, testPathOut);
return -1;
}
free(PathOut);
return 0;
}

View File

@@ -0,0 +1,101 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
static const TCHAR testPathBackslash[] = _T("C:\\Program Files\\");
static const TCHAR testPathNoBackslash[] = _T("C:\\Program Files");
int TestPathCchAddBackslash(int argc, char* argv[])
{
HRESULT status = 0;
TCHAR Path[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/**
* PathCchAddBackslash returns S_OK if the function was successful,
* S_FALSE if the path string already ends in a backslash,
* or an error code otherwise.
*/
_tcsncpy(Path, testPathNoBackslash, ARRAYSIZE(Path));
/* 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%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathBackslash, ARRAYSIZE(Path)) != 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 */
_tcsncpy(Path, testPathBackslash, ARRAYSIZE(Path));
status = PathCchAddBackslash(Path, PATHCCH_MAX_CCH);
if (status != S_FALSE)
{
_tprintf(_T("PathCchAddBackslash status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathBackslash, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
return -1;
}
/* Use nullptr PSTR, expect FAILED(status) */
status = PathCchAddBackslash(nullptr, PATHCCH_MAX_CCH);
if (SUCCEEDED(status))
{
_tprintf(
_T("PathCchAddBackslash unexpectedly succeeded with null buffer. Status: 0x%08") _T(
PRIX32) _T("\n"),
status);
return -1;
}
/* Use insufficient size value, expect FAILED(status) */
_tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
status = PathCchAddBackslash(Path, 7);
if (SUCCEEDED(status))
{
_tprintf(_T("PathCchAddBackslash unexpectedly succeeded with insufficient buffer size. ")
_T("Status: 0x%08") _T(PRIX32) _T("\n"),
status);
return -1;
}
/* Use minimum required size value, expect S_OK */
_tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
status = PathCchAddBackslash(Path, 8);
if (status != S_OK)
{
_tprintf(_T("PathCchAddBackslash failed with status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
return 0;
}

View File

@@ -0,0 +1,103 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
static const TCHAR testPathBackslash[] = _T("C:\\Program Files\\");
static const TCHAR testPathNoBackslash[] = _T("C:\\Program Files");
int TestPathCchAddBackslashEx(int argc, char* argv[])
{
HRESULT status = 0;
LPTSTR pszEnd = nullptr;
size_t cchRemaining = 0;
TCHAR Path[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/**
* PathCchAddBackslashEx returns S_OK if the function was successful,
* S_FALSE if the path string already ends in a backslash,
* or an error code otherwise.
*/
_tcsncpy(Path, testPathNoBackslash, ARRAYSIZE(Path));
/* 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%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathBackslash, ARRAYSIZE(Path)) != 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 */
_tcsncpy(Path, testPathBackslash, ARRAYSIZE(Path));
status = PathCchAddBackslashEx(Path, sizeof(Path) / sizeof(TCHAR), &pszEnd, &cchRemaining);
if (status != S_FALSE)
{
_tprintf(_T("PathCchAddBackslash status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathBackslash, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
return -1;
}
/* Use nullptr PSTR, expect FAILED(status) */
status = PathCchAddBackslashEx(nullptr, PATHCCH_MAX_CCH, nullptr, nullptr);
if (SUCCEEDED(status))
{
_tprintf(
_T("PathCchAddBackslashEx unexpectedly succeeded with null buffer. Status: 0x%08") _T(
PRIX32) _T("\n"),
status);
return -1;
}
/* Use insufficient size value, expect FAILED(status) */
_tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
status = PathCchAddBackslashEx(Path, 7, nullptr, nullptr);
if (SUCCEEDED(status))
{
_tprintf(_T("PathCchAddBackslashEx unexpectedly succeeded with insufficient buffer size. ")
_T("Status: 0x%08") _T(PRIX32) _T("\n"),
status);
return -1;
}
/* Use minimum required size value, expect S_OK */
_tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
status = PathCchAddBackslashEx(Path, 8, nullptr, nullptr);
if (status != S_OK)
{
_tprintf(_T("PathCchAddBackslashEx failed with status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
return 0;
}

View File

@@ -0,0 +1,140 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
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 = 0;
TCHAR Path[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/* Path: no extension, Extension: dot */
_tcsncpy(Path, testPathNoExtension, ARRAYSIZE(Path));
status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
if (status != S_OK)
{
_tprintf(_T("PathCchAddExtension status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathExtension, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
return -1;
}
/* Path: no extension, Extension: no dot */
_tcsncpy(Path, testPathNoExtension, ARRAYSIZE(Path));
status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtNoDot);
if (status != S_OK)
{
_tprintf(_T("PathCchAddExtension status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathExtension, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
return -1;
}
/* Path: extension, Extension: dot */
_tcsncpy(Path, testPathExtension, ARRAYSIZE(Path));
status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
if (status != S_FALSE)
{
_tprintf(_T("PathCchAddExtension status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathExtension, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
return -1;
}
/* Path: extension, Extension: no dot */
_tcsncpy(Path, testPathExtension, ARRAYSIZE(Path));
status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, testExtDot);
if (status != S_FALSE)
{
_tprintf(_T("PathCchAddExtension status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathExtension, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathExtension);
return -1;
}
/* Path: nullptr */
status = PathCchAddExtension(nullptr, PATHCCH_MAX_CCH, testExtDot);
if (status != E_INVALIDARG)
{
_tprintf(_T("PathCchAddExtension with null buffer returned status: 0x%08") _T(
PRIX32) _T(" (expected E_INVALIDARG)\n"),
status);
return -1;
}
/* Extension: nullptr */
status = PathCchAddExtension(Path, PATHCCH_MAX_CCH, nullptr);
if (status != E_INVALIDARG)
{
_tprintf(_T("PathCchAddExtension with null extension returned status: 0x%08") _T(
PRIX32) _T(" (expected E_INVALIDARG)\n"),
status);
return -1;
}
/* Insufficient Buffer size */
_tcsncpy(Path, _T("C:\\456789"), ARRAYSIZE(Path));
status = PathCchAddExtension(Path, 9 + 4, _T(".jpg"));
if (SUCCEEDED(status))
{
_tprintf(_T("PathCchAddExtension with insufficient buffer unexpectedly succeeded with ")
_T("status: 0x%08") _T(PRIX32) _T("\n"),
status);
return -1;
}
/* Minimum required buffer size */
_tcsncpy(Path, _T("C:\\456789"), ARRAYSIZE(Path));
status = PathCchAddExtension(Path, 9 + 4 + 1, _T(".jpg"));
if (FAILED(status))
{
_tprintf(_T("PathCchAddExtension with sufficient buffer unexpectedly failed with status: ")
_T("0x%08") _T(PRIX32) _T("\n"),
status);
return -1;
}
return 0;
}

View File

@@ -0,0 +1,151 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
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 = 0;
TCHAR Path[PATHCCH_MAX_CCH];
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/* Base Path: Backslash, More Path: No Backslash */
_tcsncpy(Path, testBasePathBackslash, ARRAYSIZE(Path));
status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathNoBackslash);
if (status != S_OK)
{
_tprintf(_T("PathCchAppend status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathOut, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
return -1;
}
/* Base Path: Backslash, More Path: Backslash */
_tcsncpy(Path, testBasePathBackslash, ARRAYSIZE(Path));
status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathBackslash);
if (status != S_OK)
{
_tprintf(_T("PathCchAppend status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathOut, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
return -1;
}
/* Base Path: No Backslash, More Path: Backslash */
_tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathBackslash);
if (status != S_OK)
{
_tprintf(_T("PathCchAppend status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathOut, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
return -1;
}
/* Base Path: No Backslash, More Path: No Backslash */
_tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
status = PathCchAppend(Path, PATHCCH_MAX_CCH, testMorePathNoBackslash);
if (status != S_OK)
{
_tprintf(_T("PathCchAppend status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathOut, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
return -1;
}
/* According to msdn a nullptr Path is an invalid argument */
status = PathCchAppend(nullptr, PATHCCH_MAX_CCH, testMorePathNoBackslash);
if (status != E_INVALIDARG)
{
_tprintf(_T("PathCchAppend with nullptr path unexpectedly returned status: 0x%08") _T(
PRIX32) _T("\n"),
status);
return -1;
}
/* According to msdn a nullptr pszMore is an invalid argument (although optional !?) */
_tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
status = PathCchAppend(Path, PATHCCH_MAX_CCH, nullptr);
if (status != E_INVALIDARG)
{
_tprintf(_T("PathCchAppend with nullptr pszMore unexpectedly returned status: 0x%08") _T(
PRIX32) _T("\n"),
status);
return -1;
}
/* According to msdn cchPath must be > 0 and <= PATHCCH_MAX_CCH */
_tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
status = PathCchAppend(Path, 0, testMorePathNoBackslash);
if (status != E_INVALIDARG)
{
_tprintf(_T("PathCchAppend with cchPath value 0 unexpectedly returned status: 0x%08") _T(
PRIX32) _T("\n"),
status);
return -1;
}
_tcsncpy(Path, testBasePathNoBackslash, ARRAYSIZE(Path));
status = PathCchAppend(Path, PATHCCH_MAX_CCH + 1, testMorePathNoBackslash);
if (status != E_INVALIDARG)
{
_tprintf(_T("PathCchAppend with cchPath value > PATHCCH_MAX_CCH unexpectedly returned ")
_T("status: 0x%08") _T(PRIX32) _T("\n"),
status);
return -1;
}
/* Resulting file must not exceed PATHCCH_MAX_CCH */
for (size_t i = 0; i < PATHCCH_MAX_CCH - 1; i++)
Path[i] = _T('X');
Path[PATHCCH_MAX_CCH - 1] = 0;
status = PathCchAppend(Path, PATHCCH_MAX_CCH, _T("\\This cannot be appended to Path"));
if (SUCCEEDED(status))
{
_tprintf(_T("PathCchAppend unexpectedly succeeded with status: 0x%08") _T(PRIX32) _T("\n"),
status);
return -1;
}
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchAppendEx(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchCanonicalize(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchCanonicalizeEx(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchCombine(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchCombineEx(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,114 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
static const char testPathExtension[] = "C:\\Windows\\System32\\cmd.exe";
int TestPathCchFindExtension(int argc, char* argv[])
{
PCSTR pszExt = nullptr;
PCSTR pszTmp = nullptr;
HRESULT hr = 0;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/* Test invalid args */
hr = PathCchFindExtensionA(nullptr, sizeof(testPathExtension), &pszExt);
if (SUCCEEDED(hr))
{
printf("PathCchFindExtensionA unexpectedly succeeded with pszPath = nullptr. result: "
"0x%08" PRIX32 "\n",
hr);
return -1;
}
hr = PathCchFindExtensionA(testPathExtension, 0, &pszExt);
if (SUCCEEDED(hr))
{
printf("PathCchFindExtensionA unexpectedly succeeded with cchPath = 0. result: 0x%08" PRIX32
"\n",
hr);
return -1;
}
hr = PathCchFindExtensionA(testPathExtension, sizeof(testPathExtension), nullptr);
if (SUCCEEDED(hr))
{
printf("PathCchFindExtensionA unexpectedly succeeded with ppszExt = nullptr. result: "
"0x%08" PRIX32 "\n",
hr);
return -1;
}
/* Test missing null-termination of pszPath */
hr = PathCchFindExtensionA("c:\\45.789", 9, &pszExt); /* nb: correct would be 10 */
if (SUCCEEDED(hr))
{
printf("PathCchFindExtensionA unexpectedly succeeded with unterminated pszPath. result: "
"0x%08" PRIX32 "\n",
hr);
return -1;
}
/* Test passing of an empty terminated string (must succeed) */
pszExt = nullptr;
pszTmp = "";
hr = PathCchFindExtensionA(pszTmp, 1, &pszExt);
if (hr != S_OK)
{
printf("PathCchFindExtensionA failed with an empty terminated string. result: 0x%08" PRIX32
"\n",
hr);
return -1;
}
/* pszExt must point to the strings terminating 0 now */
if (pszExt != pszTmp)
{
printf("PathCchFindExtensionA failed with an empty terminated string: pszExt pointer "
"mismatch\n");
return -1;
}
/* Test a path without file extension (must succeed) */
pszExt = nullptr;
pszTmp = "c:\\4.678\\";
hr = PathCchFindExtensionA(pszTmp, 10, &pszExt);
if (hr != S_OK)
{
printf("PathCchFindExtensionA failed with a directory path. result: 0x%08" PRIX32 "\n", hr);
return -1;
}
/* The extension must not have been found and pszExt must point to the
* strings terminating nullptr now */
if (pszExt != &pszTmp[9])
{
printf("PathCchFindExtensionA failed with a directory path: pszExt pointer mismatch\n");
return -1;
}
/* Non-special tests */
pszExt = nullptr;
if (PathCchFindExtensionA(testPathExtension, sizeof(testPathExtension), &pszExt) != S_OK)
{
printf("PathCchFindExtensionA failure: expected S_OK\n");
return -1;
}
if (!pszExt || strcmp(pszExt, ".exe") != 0)
{
printf("PathCchFindExtensionA failure: unexpected extension\n");
return -1;
}
printf("Extension: %s\n", pszExt);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchIsRoot(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchRemoveBackslash(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchRemoveBackslashEx(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchRemoveExtension(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchRemoveFileSpec(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchRenameExtension(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchSkipRoot(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -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_C_ARRAY_INIT;
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) */
_tcsncpy(Path, testPathPrefixFileNamespace, ARRAYSIZE(Path));
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 (_tcsncmp(Path, testPathNoPrefixFileNamespace, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path,
testPathNoPrefixFileNamespace);
return -1;
}
/* Path with prefix (Device Namespace) */
_tcsncpy(Path, testPathPrefixDeviceNamespace, ARRAYSIZE(Path));
status = PathCchStripPrefix(Path, ARRAYSIZE(testPathPrefixDeviceNamespace));
if (status != S_FALSE)
{
_tprintf(_T("PathCchStripPrefix status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
if (_tcsncmp(Path, testPathPrefixDeviceNamespace, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path,
testPathPrefixDeviceNamespace);
return -1;
}
/* nullptr Path */
status = PathCchStripPrefix(nullptr, 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++)
{
_tcsncpy(Path, testPathPrefixFileNamespace, ARRAYSIZE(Path));
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 */
_tcsncpy(Path, testPathPrefixFileNamespaceMinimum, ARRAYSIZE(Path));
size_t i = ARRAYSIZE(testPathPrefixFileNamespaceMinimum);
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 (_tcsncmp(Path, testPathNoPrefixFileNamespaceMinimum, ARRAYSIZE(Path)) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path,
testPathNoPrefixFileNamespaceMinimum);
return -1;
}
/* Invalid drive letter symbol */
_tcsncpy(Path, _T("\\\\?\\5:"), ARRAYSIZE(Path));
status = PathCchStripPrefix(Path, 6);
if (status == S_OK)
{
_tprintf(
_T("PathCchStripPrefix with invalid drive letter symbol unexpectedly succeeded\n"));
return -1;
}
return 0;
}

View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathCchStripToRoot(int argc, char* argv[])
{
printf("Warning: %s is not implemented!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,52 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
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 = 0;
LPCTSTR Server = nullptr;
TCHAR Path[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
/* Path is UNC */
_tcsncpy(Path, testPathUNC, ARRAYSIZE(Path));
status = PathIsUNCEx(Path, &Server);
if (!status)
{
_tprintf(_T("PathIsUNCEx status: 0x%d\n"), status);
return -1;
}
if (_tcsncmp(Server, testServer, ARRAYSIZE(testServer)) != 0)
{
_tprintf(_T("Server Name Mismatch: Actual: %s, Expected: %s\n"), Server, testServer);
return -1;
}
/* Path is not UNC */
_tcsncpy(Path, testPathNotUNC, ARRAYSIZE(Path));
status = PathIsUNCEx(Path, &Server);
if (status)
{
_tprintf(_T("PathIsUNCEx status: 0x%08") _T(PRIX32) _T("\n"), status);
return -1;
}
return 0;
}

View File

@@ -0,0 +1,96 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <winpr/crt.h>
#include <winpr/crypto.h>
#include <winpr/file.h>
#include <winpr/path.h>
static UINT32 prand(UINT32 max)
{
UINT32 tmp = 0;
if (max <= 1)
return 1;
if (winpr_RAND(&tmp, sizeof(tmp)) < 0)
{
// NOLINTNEXTLINE(concurrency-mt-unsafe)
exit(-1);
}
return tmp % (max - 1) + 1;
}
int TestPathMakePath(int argc, char* argv[])
{
size_t baseLen = 0;
BOOL success = 0;
char tmp[64] = WINPR_C_ARRAY_INIT;
char* path = nullptr;
char* cur = nullptr;
char delim = PathGetSeparatorA(0);
char* base = GetKnownPath(KNOWN_PATH_TEMP);
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
if (!base)
{
(void)fprintf(stderr, "Failed to get temporary directory!\n");
return -1;
}
baseLen = strlen(base);
for (int x = 0; x < 5; x++)
{
(void)sprintf_s(tmp, ARRAYSIZE(tmp), "%08" PRIX32, prand(UINT32_MAX));
path = GetCombinedPath(base, tmp);
free(base);
if (!path)
{
(void)fprintf(stderr, "GetCombinedPath failed!\n");
return -1;
}
base = path;
}
printf("Creating path %s\n", path);
success = winpr_PathMakePath(path, nullptr);
if (!success)
{
(void)fprintf(stderr, "MakePath failed!\n");
free(path);
return -1;
}
success = winpr_PathFileExists(path);
if (!success)
{
(void)fprintf(stderr, "MakePath lied about success!\n");
free(path);
return -1;
}
while (strlen(path) > baseLen)
{
if (!winpr_RemoveDirectory(path))
{
(void)fprintf(stderr, "winpr_RemoveDirectory %s failed!\n", path);
free(path);
return -1;
}
cur = strrchr(path, delim);
if (cur)
*cur = '\0';
}
free(path);
printf("%s success!\n", __func__);
return 0;
}

View File

@@ -0,0 +1,58 @@
#include <stdio.h>
#include <winpr/crt.h>
#include <winpr/path.h>
#include <winpr/tchar.h>
#include <winpr/winpr.h>
int TestPathShell(int argc, char* argv[])
{
const int paths[] = { KNOWN_PATH_HOME, KNOWN_PATH_TEMP,
KNOWN_PATH_XDG_DATA_HOME, KNOWN_PATH_XDG_CONFIG_HOME,
KNOWN_PATH_XDG_CACHE_HOME, KNOWN_PATH_XDG_RUNTIME_DIR,
KNOWN_PATH_XDG_CONFIG_HOME };
const char* names[] = { "KNOWN_PATH_HOME", "KNOWN_PATH_TEMP",
"KNOWN_PATH_XDG_DATA_HOME", "KNOWN_PATH_XDG_CONFIG_HOME",
"KNOWN_PATH_XDG_CACHE_HOME", "KNOWN_PATH_XDG_RUNTIME_DIR",
"KNOWN_PATH_XDG_CONFIG_HOME" };
int rc = 0;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
for (size_t x = 0; x < sizeof(paths) / sizeof(paths[0]); x++)
{
const int id = paths[x];
const char* name = names[x];
{
char* path = GetKnownPath(id);
if (!path)
{
(void)fprintf(stderr, "GetKnownPath(%d) failed\n", id);
rc = -1;
}
else
{
printf("%s Path: %s\n", name, path);
}
free(path);
}
{
char* path = GetKnownSubPath(id, "freerdp");
if (!path)
{
(void)fprintf(stderr, "GetKnownSubPath(%d) failed\n", id);
rc = -1;
}
else
{
printf("%s SubPath: %s\n", name, path);
}
free(path);
}
}
return rc;
}