diff options
Diffstat (limited to 'src/burn/test/BurnUnitTest/BurnTestException.h')
| -rw-r--r-- | src/burn/test/BurnUnitTest/BurnTestException.h | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/burn/test/BurnUnitTest/BurnTestException.h b/src/burn/test/BurnUnitTest/BurnTestException.h new file mode 100644 index 00000000..bd94b4fc --- /dev/null +++ b/src/burn/test/BurnUnitTest/BurnTestException.h | |||
| @@ -0,0 +1,93 @@ | |||
| 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 | |||
| 17 | public ref struct BurnTestException : public System::Exception | ||
| 18 | { | ||
| 19 | public: | ||
| 20 | BurnTestException(HRESULT error) | ||
| 21 | { | ||
| 22 | this->HResult = error; | ||
| 23 | } | ||
| 24 | |||
| 25 | BurnTestException(HRESULT error, String^ message) | ||
| 26 | : Exception(message) | ||
| 27 | { | ||
| 28 | this->HResult = error; | ||
| 29 | } | ||
| 30 | |||
| 31 | property Int32 ErrorCode | ||
| 32 | { | ||
| 33 | Int32 get() | ||
| 34 | { | ||
| 35 | return this->HResult; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | |||
| 39 | }; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | } | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | // this class is used by __TestThrowOnFailure_Format() below to deallocate | ||
| 47 | // the string created after the function call has returned | ||
| 48 | class __TestThrowOnFailure_StringFree | ||
| 49 | { | ||
| 50 | LPWSTR m_scz; | ||
| 51 | |||
| 52 | public: | ||
| 53 | __TestThrowOnFailure_StringFree(LPWSTR scz) | ||
| 54 | { | ||
| 55 | m_scz = scz; | ||
| 56 | } | ||
| 57 | |||
| 58 | ~__TestThrowOnFailure_StringFree() | ||
| 59 | { | ||
| 60 | ReleaseStr(m_scz); | ||
| 61 | } | ||
| 62 | |||
| 63 | operator LPCWSTR() | ||
| 64 | { | ||
| 65 | return m_scz; | ||
| 66 | } | ||
| 67 | }; | ||
| 68 | |||
| 69 | // used by the TestThrowOnFailure macros to format the error string and | ||
| 70 | // return an LPCWSTR that can be used to initialize a System::String | ||
| 71 | #pragma warning (push) | ||
| 72 | #pragma warning (disable : 4793) | ||
| 73 | inline __TestThrowOnFailure_StringFree __TestThrowOnFailure_Format(LPCWSTR wzFormat, ...) | ||
| 74 | { | ||
| 75 | Assert(wzFormat && *wzFormat); | ||
| 76 | |||
| 77 | HRESULT hr = S_OK; | ||
| 78 | LPWSTR scz = NULL; | ||
| 79 | va_list args; | ||
| 80 | |||
| 81 | va_start(args, wzFormat); | ||
| 82 | hr = StrAllocFormattedArgs(&scz, wzFormat, args); | ||
| 83 | va_end(args); | ||
| 84 | ExitOnFailure(hr, "Failed to format message string."); | ||
| 85 | |||
| 86 | LExit: | ||
| 87 | return scz; | ||
| 88 | } | ||
| 89 | #pragma warning (pop) | ||
| 90 | |||
| 91 | #define TestThrowOnFailure(hr, s) if (FAILED(hr)) { throw gcnew Microsoft::Tools::WindowsInstallerXml::Test::Bootstrapper::BurnTestException(hr, gcnew System::String(s)); } | ||
| 92 | #define TestThrowOnFailure1(hr, s, p) if (FAILED(hr)) { throw gcnew Microsoft::Tools::WindowsInstallerXml::Test::Bootstrapper::BurnTestException(hr, gcnew System::String(__TestThrowOnFailure_Format(s, p))); } | ||
| 93 | #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))); } | ||
