FreeRDP
Loading...
Searching...
No Matches
TestPathCchAddBackslash.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 TestPathCchAddBackslash(int argc, char* argv[])
12{
13 HRESULT status = 0;
14 TCHAR Path[PATHCCH_MAX_CCH] = WINPR_C_ARRAY_INIT;
15
16 WINPR_UNUSED(argc);
17 WINPR_UNUSED(argv);
18
25 _tcsncpy(Path, testPathNoBackslash, ARRAYSIZE(Path));
26
27 /* Add a backslash to a path without a trailing backslash, expect S_OK */
28
29 status = PathCchAddBackslash(Path, PATHCCH_MAX_CCH);
30
31 if (status != S_OK)
32 {
33 _tprintf(_T("PathCchAddBackslash status: 0x%08") _T(PRIX32) _T("\n"), status);
34 return -1;
35 }
36
37 if (_tcsncmp(Path, testPathBackslash, ARRAYSIZE(Path)) != 0)
38 {
39 _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
40 return -1;
41 }
42
43 /* Add a backslash to a path with a trailing backslash, expect S_FALSE */
44
45 _tcsncpy(Path, testPathBackslash, ARRAYSIZE(Path));
46
47 status = PathCchAddBackslash(Path, PATHCCH_MAX_CCH);
48
49 if (status != S_FALSE)
50 {
51 _tprintf(_T("PathCchAddBackslash status: 0x%08") _T(PRIX32) _T("\n"), status);
52 return -1;
53 }
54
55 if (_tcsncmp(Path, testPathBackslash, ARRAYSIZE(Path)) != 0)
56 {
57 _tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathBackslash);
58 return -1;
59 }
60
61 /* Use insufficient size value, expect FAILED(status) */
62
63 _tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
64
65 status = PathCchAddBackslash(Path, 7);
66
67 if (SUCCEEDED(status))
68 {
69 _tprintf(_T("PathCchAddBackslash unexpectedly succeeded with insufficient buffer size. ")
70 _T("Status: 0x%08") _T(PRIX32) _T("\n"),
71 status);
72 return -1;
73 }
74
75 /* Use minimum required size value, expect S_OK */
76
77 _tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
78
79 status = PathCchAddBackslash(Path, 8);
80
81 if (status != S_OK)
82 {
83 _tprintf(_T("PathCchAddBackslash failed with status: 0x%08") _T(PRIX32) _T("\n"), status);
84 return -1;
85 }
86
87 return 0;
88}