FreeRDP
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
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] = { 0 };
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 NULL PSTR, expect FAILED(status) */
62
63 status = PathCchAddBackslash(NULL, PATHCCH_MAX_CCH);
64
65 if (SUCCEEDED(status))
66 {
67 _tprintf(
68 _T("PathCchAddBackslash unexpectedly succeeded with null buffer. Status: 0x%08") _T(
69 PRIX32) _T("\n"),
70 status);
71 return -1;
72 }
73
74 /* Use insufficient size value, expect FAILED(status) */
75
76 _tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
77
78 status = PathCchAddBackslash(Path, 7);
79
80 if (SUCCEEDED(status))
81 {
82 _tprintf(_T("PathCchAddBackslash unexpectedly succeeded with insufficient buffer size. ")
83 _T("Status: 0x%08") _T(PRIX32) _T("\n"),
84 status);
85 return -1;
86 }
87
88 /* Use minimum required size value, expect S_OK */
89
90 _tcsncpy(Path, _T("C:\\tmp"), ARRAYSIZE(Path));
91
92 status = PathCchAddBackslash(Path, 8);
93
94 if (status != S_OK)
95 {
96 _tprintf(_T("PathCchAddBackslash failed with status: 0x%08") _T(PRIX32) _T("\n"), status);
97 return -1;
98 }
99
100 return 0;
101}