1 | // Licensed to the .NET Foundation under one or more agreements. |
2 | // The .NET Foundation licenses this file to you under the MIT license. |
3 | // See the LICENSE file in the project root for more information. |
4 | |
5 | /*===================================================================== |
6 | ** |
7 | ** Source: FILECanonicalizePath.c (test 1) |
8 | ** |
9 | ** Purpose: Tests the PAL implementation of the FILECanonicalizePath function. |
10 | ** |
11 | ** |
12 | **===================================================================*/ |
13 | |
14 | #include <palsuite.h> |
15 | |
16 | extern "C" void FILECanonicalizePath(LPSTR lpUnixPath); |
17 | |
18 | void TestCase(LPSTR input, LPSTR expectedOutput); |
19 | |
20 | int __cdecl main(int argc, char *argv[]) |
21 | { |
22 | if (PAL_Initialize(argc,argv) != 0) |
23 | { |
24 | return FAIL; |
25 | } |
26 | |
27 | // Case 01: /<name> should not change |
28 | TestCase("/Test" , "/Test" ); |
29 | |
30 | // Case 02: /<name>/<name2> should not change |
31 | TestCase("/Test/Foo" , "/Test/Foo" ); |
32 | |
33 | // Case 03: // transforms to / |
34 | TestCase("//" , "/" ); |
35 | |
36 | // Case 04: /./ transforms to / |
37 | TestCase("/./" , "/" ); |
38 | |
39 | // Case 05: /<name>/../ transforms to / |
40 | TestCase("/Test/../" , "/" ); |
41 | |
42 | // Case 06: /Test/Foo/.. transforms to /Test |
43 | TestCase("/Test/Foo/.." , "/Test" ); |
44 | |
45 | // Case 07: /Test/.. transforms to / |
46 | TestCase("/Test/.." , "/" ); |
47 | |
48 | // Case 08: /. transforms to / |
49 | TestCase("/." , "/" ); |
50 | |
51 | // Case 09: /<name/. transforms to /<name> |
52 | TestCase("/Test/." , "/Test" ); |
53 | |
54 | // Case 10: /<name>/../. transforms to / |
55 | TestCase("/Test/../." , "/" ); |
56 | |
57 | // Case 11: /.. transforms to / |
58 | TestCase("/.." , "/" ); |
59 | |
60 | PAL_Terminate(); |
61 | return PASS; |
62 | } |
63 | |
64 | void TestCase(LPSTR input, LPSTR expectedOutput) |
65 | { |
66 | // Save the input for debug logging since the input is edited in-place |
67 | char* pOriginalInput = (char*)malloc(strlen(input) * sizeof(char) + 1); |
68 | strcpy(pOriginalInput, input); |
69 | |
70 | char* pInput = (char*)malloc(strlen(input) * sizeof(char) + 1); |
71 | strcpy(pInput, pOriginalInput); |
72 | |
73 | FILECanonicalizePath(pInput); |
74 | if (strcmp(pInput, expectedOutput) != 0) |
75 | { |
76 | free(pOriginalInput); |
77 | free(pInput); |
78 | Fail("FILECanonicalizePath error: input %s did not match expected output %s; got %s instead" , pOriginalInput, expectedOutput, pInput); |
79 | } |
80 | |
81 | free(pOriginalInput); |
82 | free(pInput); |
83 | } |
84 | |