diff options
Diffstat (limited to 'src/test/DUtilUnitTest/NativeAssert.h')
-rw-r--r-- | src/test/DUtilUnitTest/NativeAssert.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/test/DUtilUnitTest/NativeAssert.h b/src/test/DUtilUnitTest/NativeAssert.h new file mode 100644 index 00000000..b10910c0 --- /dev/null +++ b/src/test/DUtilUnitTest/NativeAssert.h | |||
@@ -0,0 +1,83 @@ | |||
1 | #pragma once | ||
2 | // 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. | ||
3 | |||
4 | |||
5 | namespace WixTest { | ||
6 | |||
7 | using namespace System; | ||
8 | using namespace System::Collections::Generic; | ||
9 | using namespace System::Linq; | ||
10 | using namespace Xunit; | ||
11 | |||
12 | public ref class NativeAssert : WixAssert | ||
13 | { | ||
14 | public: | ||
15 | static void NotNull(LPCWSTR wz) | ||
16 | { | ||
17 | if (!wz) | ||
18 | { | ||
19 | Assert::NotNull(nullptr); | ||
20 | } | ||
21 | } | ||
22 | |||
23 | // For some reason, naming these NotStringEqual methods "NotEqual" breaks Intellisense in files that call any overload of the NotEqual method. | ||
24 | static void NotStringEqual(LPCWSTR expected, LPCWSTR actual) | ||
25 | { | ||
26 | NativeAssert::NotStringEqual(expected, actual, FALSE); | ||
27 | } | ||
28 | |||
29 | static void NotStringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase) | ||
30 | { | ||
31 | IEqualityComparer<String^>^ comparer = ignoreCase ? StringComparer::InvariantCultureIgnoreCase : StringComparer::InvariantCulture; | ||
32 | Assert::NotEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), comparer); | ||
33 | } | ||
34 | |||
35 | // For some reason, naming these StringEqual methods "Equal" breaks Intellisense in files that call any overload of the Equal method. | ||
36 | static void StringEqual(LPCWSTR expected, LPCWSTR actual) | ||
37 | { | ||
38 | NativeAssert::StringEqual(expected, actual, FALSE); | ||
39 | } | ||
40 | |||
41 | static void StringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase) | ||
42 | { | ||
43 | IEqualityComparer<String^>^ comparer = ignoreCase ? StringComparer::InvariantCultureIgnoreCase : StringComparer::InvariantCulture; | ||
44 | Assert::Equal(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), comparer); | ||
45 | } | ||
46 | |||
47 | static void Succeeded(HRESULT hr, LPCSTR zFormat, LPCSTR zArg, ... array<LPCSTR>^ zArgs) | ||
48 | { | ||
49 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(zArgs->Length + 1); | ||
50 | formatArgs[0] = NativeAssert::LPSTRToString(zArg); | ||
51 | for (int i = 0; i < zArgs->Length; ++i) | ||
52 | { | ||
53 | formatArgs[i + 1] = NativeAssert::LPSTRToString(zArgs[i]); | ||
54 | } | ||
55 | WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); | ||
56 | } | ||
57 | |||
58 | static void Succeeded(HRESULT hr, LPCSTR zFormat, ... array<LPCWSTR>^ wzArgs) | ||
59 | { | ||
60 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(wzArgs->Length); | ||
61 | for (int i = 0; i < wzArgs->Length; ++i) | ||
62 | { | ||
63 | formatArgs[i] = NativeAssert::LPWSTRToString(wzArgs[i]); | ||
64 | } | ||
65 | WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); | ||
66 | } | ||
67 | |||
68 | static void ValidReturnCode(HRESULT hr, ... array<HRESULT>^ validReturnCodes) | ||
69 | { | ||
70 | Assert::Contains(hr, (IEnumerable<HRESULT>^)validReturnCodes); | ||
71 | } | ||
72 | |||
73 | private: | ||
74 | static String^ LPSTRToString(LPCSTR z) | ||
75 | { | ||
76 | return z ? gcnew String(z) : nullptr; | ||
77 | } | ||
78 | static String^ LPWSTRToString(LPCWSTR wz) | ||
79 | { | ||
80 | return wz ? gcnew String(wz) : nullptr; | ||
81 | } | ||
82 | }; | ||
83 | } | ||