diff options
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp')
-rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp new file mode 100644 index 00000000..5a1f06fd --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/PathUtilTest.cpp | |||
@@ -0,0 +1,80 @@ | |||
1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
2 | |||
3 | #include "precomp.h" | ||
4 | |||
5 | using namespace System; | ||
6 | using namespace Xunit; | ||
7 | using namespace WixBuildTools::TestSupport; | ||
8 | |||
9 | namespace DutilTests | ||
10 | { | ||
11 | public ref class PathUtil | ||
12 | { | ||
13 | public: | ||
14 | [Fact] | ||
15 | void PathGetHierarchyArrayTest() | ||
16 | { | ||
17 | HRESULT hr = S_OK; | ||
18 | LPWSTR *rgsczPaths = NULL; | ||
19 | UINT cPaths = 0; | ||
20 | |||
21 | try | ||
22 | { | ||
23 | hr = PathGetHierarchyArray(L"c:\\foo\\bar\\bas\\a.txt", &rgsczPaths, &cPaths); | ||
24 | NativeAssert::Succeeded(hr, "Failed to get parent directories array for regular file path"); | ||
25 | Assert::Equal<DWORD>(5, cPaths); | ||
26 | NativeAssert::StringEqual(L"c:\\", rgsczPaths[0]); | ||
27 | NativeAssert::StringEqual(L"c:\\foo\\", rgsczPaths[1]); | ||
28 | NativeAssert::StringEqual(L"c:\\foo\\bar\\", rgsczPaths[2]); | ||
29 | NativeAssert::StringEqual(L"c:\\foo\\bar\\bas\\", rgsczPaths[3]); | ||
30 | NativeAssert::StringEqual(L"c:\\foo\\bar\\bas\\a.txt", rgsczPaths[4]); | ||
31 | ReleaseNullStrArray(rgsczPaths, cPaths); | ||
32 | |||
33 | hr = PathGetHierarchyArray(L"c:\\foo\\bar\\bas\\", &rgsczPaths, &cPaths); | ||
34 | NativeAssert::Succeeded(hr, "Failed to get parent directories array for regular directory path"); | ||
35 | Assert::Equal<DWORD>(4, cPaths); | ||
36 | NativeAssert::StringEqual(L"c:\\", rgsczPaths[0]); | ||
37 | NativeAssert::StringEqual(L"c:\\foo\\", rgsczPaths[1]); | ||
38 | NativeAssert::StringEqual(L"c:\\foo\\bar\\", rgsczPaths[2]); | ||
39 | NativeAssert::StringEqual(L"c:\\foo\\bar\\bas\\", rgsczPaths[3]); | ||
40 | ReleaseNullStrArray(rgsczPaths, cPaths); | ||
41 | |||
42 | hr = PathGetHierarchyArray(L"\\\\server\\share\\subdir\\file.txt", &rgsczPaths, &cPaths); | ||
43 | NativeAssert::Succeeded(hr, "Failed to get parent directories array for UNC file path"); | ||
44 | Assert::Equal<DWORD>(3, cPaths); | ||
45 | NativeAssert::StringEqual(L"\\\\server\\share\\", rgsczPaths[0]); | ||
46 | NativeAssert::StringEqual(L"\\\\server\\share\\subdir\\", rgsczPaths[1]); | ||
47 | NativeAssert::StringEqual(L"\\\\server\\share\\subdir\\file.txt", rgsczPaths[2]); | ||
48 | ReleaseNullStrArray(rgsczPaths, cPaths); | ||
49 | |||
50 | hr = PathGetHierarchyArray(L"\\\\server\\share\\subdir\\", &rgsczPaths, &cPaths); | ||
51 | NativeAssert::Succeeded(hr, "Failed to get parent directories array for UNC directory path"); | ||
52 | Assert::Equal<DWORD>(2, cPaths); | ||
53 | NativeAssert::StringEqual(L"\\\\server\\share\\", rgsczPaths[0]); | ||
54 | NativeAssert::StringEqual(L"\\\\server\\share\\subdir\\", rgsczPaths[1]); | ||
55 | ReleaseNullStrArray(rgsczPaths, cPaths); | ||
56 | |||
57 | hr = PathGetHierarchyArray(L"Software\\Microsoft\\Windows\\ValueName", &rgsczPaths, &cPaths); | ||
58 | NativeAssert::Succeeded(hr, "Failed to get parent directories array for UNC directory path"); | ||
59 | Assert::Equal<DWORD>(4, cPaths); | ||
60 | NativeAssert::StringEqual(L"Software\\", rgsczPaths[0]); | ||
61 | NativeAssert::StringEqual(L"Software\\Microsoft\\", rgsczPaths[1]); | ||
62 | NativeAssert::StringEqual(L"Software\\Microsoft\\Windows\\", rgsczPaths[2]); | ||
63 | NativeAssert::StringEqual(L"Software\\Microsoft\\Windows\\ValueName", rgsczPaths[3]); | ||
64 | ReleaseNullStrArray(rgsczPaths, cPaths); | ||
65 | |||
66 | hr = PathGetHierarchyArray(L"Software\\Microsoft\\Windows\\", &rgsczPaths, &cPaths); | ||
67 | NativeAssert::Succeeded(hr, "Failed to get parent directories array for UNC directory path"); | ||
68 | Assert::Equal<DWORD>(3, cPaths); | ||
69 | NativeAssert::StringEqual(L"Software\\", rgsczPaths[0]); | ||
70 | NativeAssert::StringEqual(L"Software\\Microsoft\\", rgsczPaths[1]); | ||
71 | NativeAssert::StringEqual(L"Software\\Microsoft\\Windows\\", rgsczPaths[2]); | ||
72 | ReleaseNullStrArray(rgsczPaths, cPaths); | ||
73 | } | ||
74 | finally | ||
75 | { | ||
76 | ReleaseStrArray(rgsczPaths, cPaths); | ||
77 | } | ||
78 | } | ||
79 | }; | ||
80 | } | ||