1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
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 */
_tcscpy(Path, testBasePathBackslash);
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 (_tcscmp(Path, testPathOut) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
return -1;
}
/* Base Path: Backslash, More Path: Backslash */
_tcscpy(Path, testBasePathBackslash);
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 (_tcscmp(Path, testPathOut) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
return -1;
}
/* Base Path: No Backslash, More Path: Backslash */
_tcscpy(Path, testBasePathNoBackslash);
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 (_tcscmp(Path, testPathOut) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
return -1;
}
/* Base Path: No Backslash, More Path: No Backslash */
_tcscpy(Path, testBasePathNoBackslash);
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 (_tcscmp(Path, testPathOut) != 0)
{
_tprintf(_T("Path Mismatch: Actual: %s, Expected: %s\n"), Path, testPathOut);
return -1;
}
/* According to msdn a NULL Path is an invalid argument */
status = PathCchAppend(NULL, PATHCCH_MAX_CCH, testMorePathNoBackslash);
if (status != E_INVALIDARG)
{
_tprintf(_T("PathCchAppend with NULL path unexpectedly returned status: 0x%08") _T(
PRIX32) _T("\n"),
status);
return -1;
}
/* According to msdn a NULL pszMore is an invalid argument (although optional !?) */
_tcscpy(Path, testBasePathNoBackslash);
status = PathCchAppend(Path, PATHCCH_MAX_CCH, NULL);
if (status != E_INVALIDARG)
{
_tprintf(_T("PathCchAppend with NULL pszMore unexpectedly returned status: 0x%08") _T(
PRIX32) _T("\n"),
status);
return -1;
}
/* According to msdn cchPath must be > 0 and <= PATHCCH_MAX_CCH */
_tcscpy(Path, testBasePathNoBackslash);
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;
}
_tcscpy(Path, testBasePathNoBackslash);
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 unexepectedly succeeded with status: 0x%08") _T(PRIX32) _T("\n"),
status);
return -1;
}
return 0;
}
|