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