FreeRDP
Loading...
Searching...
No Matches
TestPathCchAddBackslashEx.c
1
2#include <stdio.h>
3#include <winpr/crt.h>
4#include <winpr/path.h>
5#include <winpr/tchar.h>
6#include <winpr/winpr.h>
7
8static const TCHAR testPathBackslash[] = _T("C:\\Program Files\\");
9static const TCHAR testPathNoBackslash[] = _T("C:\\Program Files");
10
11int TestPathCchAddBackslashEx(int argc, char* argv[])
12{
13 HRESULT status = 0;
14 LPTSTR pszEnd = nullptr;
15 size_t cchRemaining = 0;
16 TCHAR Path[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
17
18 WINPR_UNUSED(argc);
19 WINPR_UNUSED(argv);
20
27 _tcsncpy(Path, testPathNoBackslash, ARRAYSIZE(Path));
28
29 /* Add a backslash to a path without a trailing backslash, expect S_OK */
30
31 status = PathCchAddBackslashEx(Path, sizeof(Path) / sizeof(TCHAR), &pszEnd, &cchRemaining);
32
33 if (status != S_OK)
34 {
35 _tprintf(_T("PathCchAddBackslash status: 0x%08") _T(PRIX32) _T("\n"), status);
36 return -1;
37 }
38
39 if (_tcsncmp(Path, testPathBackslash, ARRAYSIZE(Path)) != 0)
40 {
41 _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
42 return -1;
43 }
44
45 /* Add a backslash to a path with a trailing backslash, expect S_FALSE */
46
47 _tcsncpy(Path, testPathBackslash, ARRAYSIZE(Path));
48
49 status = PathCchAddBackslashEx(Path, sizeof(Path) / sizeof(TCHAR), &pszEnd, &cchRemaining);
50
51 if (status != S_FALSE)
52 {
53 _tprintf(_T("PathCchAddBackslash status: 0x%08") _T(PRIX32) _T("\n"), status);
54 return -1;
55 }
56
57 if (_tcsncmp(Path, testPathBackslash, ARRAYSIZE(Path)) != 0)
58 {
59 _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
60 return -1;
61 }
62
63 /* Use insufficient size value, expect FAILED(status) */
64
65 _tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
66
67 status = PathCchAddBackslashEx(Path, 7, nullptr, nullptr);
68
69 if (SUCCEEDED(status))
70 {
71 _tprintf(_T("PathCchAddBackslashEx unexpectedly succeeded with insufficient buffer size. ")
72 _T("Status: 0x%08") _T(PRIX32) _T("\n"),
73 status);
74 return -1;
75 }
76
77 /* Use minimum required size value, expect S_OK */
78
79 _tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
80
81 status = PathCchAddBackslashEx(Path, 8, nullptr, nullptr);
82
83 if (status != S_OK)
84 {
85 _tprintf(_T("PathCchAddBackslashEx failed with status: 0x%08") _T(PRIX32) _T("\n"), status);
86 return -1;
87 }
88
89 return 0;
90}