diff options
Diffstat (limited to 'src/internal')
3 files changed, 48 insertions, 0 deletions
diff --git a/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h b/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h index 62ace4a9..b0206b14 100644 --- a/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h +++ b/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h | |||
@@ -64,6 +64,27 @@ namespace TestSupport { | |||
64 | WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); | 64 | WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs); |
65 | } | 65 | } |
66 | 66 | ||
67 | static void SpecificReturnCode(HRESULT hrExpected, HRESULT hr, LPCSTR zFormat, LPCSTR zArg, ... array<LPCSTR>^ zArgs) | ||
68 | { | ||
69 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(zArgs->Length + 1); | ||
70 | formatArgs[0] = NativeAssert::LPSTRToString(zArg); | ||
71 | for (int i = 0; i < zArgs->Length; ++i) | ||
72 | { | ||
73 | formatArgs[i + 1] = NativeAssert::LPSTRToString(zArgs[i]); | ||
74 | } | ||
75 | WixAssert::SpecificReturnCode(hrExpected, hr, gcnew String(zFormat), formatArgs); | ||
76 | } | ||
77 | |||
78 | static void SpecificReturnCode(HRESULT hrExpected, HRESULT hr, LPCSTR zFormat, ... array<LPCWSTR>^ wzArgs) | ||
79 | { | ||
80 | array<Object^>^ formatArgs = gcnew array<Object^, 1>(wzArgs->Length); | ||
81 | for (int i = 0; i < wzArgs->Length; ++i) | ||
82 | { | ||
83 | formatArgs[i] = NativeAssert::LPWSTRToString(wzArgs[i]); | ||
84 | } | ||
85 | WixAssert::SpecificReturnCode(hrExpected, hr, gcnew String(zFormat), formatArgs); | ||
86 | } | ||
87 | |||
67 | static void ValidReturnCode(HRESULT hr, ... array<HRESULT>^ validReturnCodes) | 88 | static void ValidReturnCode(HRESULT hr, ... array<HRESULT>^ validReturnCodes) |
68 | { | 89 | { |
69 | Assert::Contains(hr, (IEnumerable<HRESULT>^)validReturnCodes); | 90 | Assert::Contains(hr, (IEnumerable<HRESULT>^)validReturnCodes); |
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/SpecificReturnCodeException.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SpecificReturnCodeException.cs new file mode 100644 index 00000000..c66890f8 --- /dev/null +++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/SpecificReturnCodeException.cs | |||
@@ -0,0 +1,19 @@ | |||
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 | namespace WixBuildTools.TestSupport | ||
4 | { | ||
5 | using System; | ||
6 | using Xunit.Sdk; | ||
7 | |||
8 | public class SpecificReturnCodeException : XunitException | ||
9 | { | ||
10 | public SpecificReturnCodeException(int hr, string userMessage) | ||
11 | : base(String.Format("WixAssert.SpecificReturnCode() Failure\r\n" + | ||
12 | "HRESULT: 0x{0:X8}\r\n" + | ||
13 | "Message: {1}", | ||
14 | hr, userMessage)) | ||
15 | { | ||
16 | this.HResult = hr; | ||
17 | } | ||
18 | } | ||
19 | } | ||
diff --git a/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs b/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs index 10156547..1ede55b3 100644 --- a/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs +++ b/src/internal/WixBuildTools.TestSupport/XunitExtensions/WixAssert.cs | |||
@@ -52,6 +52,14 @@ namespace WixBuildTools.TestSupport | |||
52 | throw new SkipTestException(message); | 52 | throw new SkipTestException(message); |
53 | } | 53 | } |
54 | 54 | ||
55 | public static void SpecificReturnCode(int hrExpected, int hr, string format, params object[] formatArgs) | ||
56 | { | ||
57 | if (hrExpected != hr) | ||
58 | { | ||
59 | throw new SpecificReturnCodeException(hr, String.Format(format, formatArgs)); | ||
60 | } | ||
61 | } | ||
62 | |||
55 | public static void Succeeded(int hr, string format, params object[] formatArgs) | 63 | public static void Succeeded(int hr, string format, params object[] formatArgs) |
56 | { | 64 | { |
57 | if (0 > hr) | 65 | if (0 > hr) |