main
h 88 lines 2.34 KB
Raw
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 Microsoft
6 {
7 namespace Tools
8 {
9 namespace WindowsInstallerXml
10 {
11 namespace Test
12 {
13 namespace Bootstrapper
14 {
15 using namespace System;
16 using namespace WixInternal::TestSupport;
17
18 public ref struct BurnTestException : public SucceededException
19 {
20 public:
21 BurnTestException(HRESULT error, String^ message)
22 : SucceededException(error, message)
23 {
24 }
25
26 property Int32 ErrorCode
27 {
28 Int32 get()
29 {
30 return this->HResult;
31 }
32 }
33
34 };
35 }
36 }
37 }
38 }
39 }
40
41 // this class is used by __TestThrowOnFailure_Format() below to deallocate
42 // the string created after the function call has returned
43 class __TestThrowOnFailure_StringFree
44 {
45 LPWSTR m_scz;
46
47 public:
48 __TestThrowOnFailure_StringFree(LPWSTR scz)
49 {
50 m_scz = scz;
51 }
52
53 ~__TestThrowOnFailure_StringFree()
54 {
55 ReleaseStr(m_scz);
56 }
57
58 operator LPCWSTR()
59 {
60 return m_scz;
61 }
62 };
63
64 // used by the TestThrowOnFailure macros to format the error string and
65 // return an LPCWSTR that can be used to initialize a System::String
66 #pragma warning (push)
67 #pragma warning (disable : 4793)
68 inline __TestThrowOnFailure_StringFree __TestThrowOnFailure_Format(LPCWSTR wzFormat, ...)
69 {
70 Assert(wzFormat && *wzFormat);
71
72 HRESULT hr = S_OK;
73 LPWSTR scz = NULL;
74 va_list args;
75
76 va_start(args, wzFormat);
77 hr = StrAllocFormattedArgs(&scz, wzFormat, args);
78 va_end(args);
79 ExitOnFailure(hr, "Failed to format message string.");
80
81 LExit:
82 return scz;
83 }
84 #pragma warning (pop)
85
86 #define TestThrowOnFailure(hr, s) if (FAILED(hr)) { throw gcnew Microsoft::Tools::WindowsInstallerXml::Test::Bootstrapper::BurnTestException(hr, gcnew System::String(s)); }
87 #define TestThrowOnFailure1(hr, s, p) if (FAILED(hr)) { throw gcnew Microsoft::Tools::WindowsInstallerXml::Test::Bootstrapper::BurnTestException(hr, gcnew System::String(__TestThrowOnFailure_Format(s, p))); }
88 #define TestThrowOnFailure2(hr, s, p1, p2) if (FAILED(hr)) { throw gcnew Microsoft::Tools::WindowsInstallerXml::Test::Bootstrapper::BurnTestException(hr, gcnew System::String(__TestThrowOnFailure_Format(s, p1, p2))); }