summaryrefslogtreecommitdiffstats
path: root/winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:24:41 +0000
commita9bcc81f821d7c66f623779fa5147e728eb3c388 (patch)
tree98676963bcdd537ae5908a067a8eb110b93486a6 /winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c
parentInitial commit. (diff)
downloadfreerdp3-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/TestPathCchAddBackslashEx.c')
-rw-r--r--winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c103
1 files changed, 103 insertions, 0 deletions
diff --git a/winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c b/winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c
new file mode 100644
index 0000000..4a84200
--- /dev/null
+++ b/winpr/libwinpr/path/test/TestPathCchAddBackslashEx.c
@@ -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 = NULL;
+ size_t cchRemaining = 0;
+ TCHAR Path[PATHCCH_MAX_CCH];
+
+ 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.
+ */
+
+ _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%08") _T(PRIX32) _T("\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%08") _T(PRIX32) _T("\n"), status);
+ return -1;
+ }
+
+ if (_tcscmp(Path, testPathBackslash) != 0)
+ {
+ _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
+ return -1;
+ }
+
+ /* Use NULL PSTR, expect FAILED(status) */
+
+ status = PathCchAddBackslashEx(NULL, PATHCCH_MAX_CCH, NULL, NULL);
+
+ if (SUCCEEDED(status))
+ {
+ _tprintf(
+ _T("PathCchAddBackslashEx unexpectedly succeded with null buffer. Status: 0x%08") _T(
+ PRIX32) _T("\n"),
+ status);
+ return -1;
+ }
+
+ /* Use insufficient size value, expect FAILED(status) */
+
+ _tcscpy(Path, _T("C:\\tmp"));
+
+ status = PathCchAddBackslashEx(Path, 7, NULL, NULL);
+
+ if (SUCCEEDED(status))
+ {
+ _tprintf(_T("PathCchAddBackslashEx unexpectedly succeded with insufficient buffer size. ")
+ _T("Status: 0x%08") _T(PRIX32) _T("\n"),
+ status);
+ return -1;
+ }
+
+ /* Use minimum required size value, expect S_OK */
+
+ _tcscpy(Path, _T("C:\\tmp"));
+
+ status = PathCchAddBackslashEx(Path, 8, NULL, NULL);
+
+ if (status != S_OK)
+ {
+ _tprintf(_T("PathCchAddBackslashEx failed with status: 0x%08") _T(PRIX32) _T("\n"), status);
+ return -1;
+ }
+
+ return 0;
+}