FreeRDP
Loading...
Searching...
No Matches
TestPathCchCanonicalize.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
8typedef struct
9{
10 const char* what;
11 HRESULT result;
12 const char* expect;
13} test_case_t;
14
15WINPR_ATTR_NODISCARD
16static BOOL test(size_t count, const test_case_t* cur)
17{
18 WINPR_ASSERT(cur);
19 WINPR_ASSERT(cur->what);
20
21 const size_t len = strlen(cur->what);
22 char* out = calloc(len + 1, sizeof(char));
23 if (!out)
24 return FALSE;
25
26 BOOL rc = TRUE;
27 HRESULT hr = PathCchCanonicalize(out, len, cur->what);
28 if (hr != cur->result)
29 {
30 rc = FALSE;
31 (void)fprintf(stderr,
32 "[%s: %" PRIuz ": got result 0x%08" PRIx32 ", expected 0x%08" PRIx32 "\n",
33 __FILE__, count, hr, cur->result);
34 }
35 else if (hr == S_OK)
36 {
37 rc = strcmp(out, cur->expect) == 0;
38 if (!rc)
39 (void)fprintf(stderr, "[%s: %" PRIuz ": got result '%s', expected '%s'\n", __FILE__,
40 count, out, cur->expect);
41 }
42 free(out);
43 return rc;
44}
45
46int TestPathCchCanonicalize(int argc, char* argv[])
47{
48 const test_case_t tests[] = {
49 { "////", S_OK, "/" },
50 { "///foo///bar//..///lala/././///.///.", S_OK, "/foo/lala" },
51 { "////..////.", S_OK, "/" },
52 { "///./gaga////foo/..///bar/..", S_OK, "/gaga" },
53 };
54
55 int rc = 0;
56 for (size_t x = 0; x < ARRAYSIZE(tests); x++)
57 {
58 const test_case_t* cur = &tests[x];
59 if (!test(x, cur))
60 rc = -1;
61 }
62 return rc;
63}