aboutsummaryrefslogtreecommitdiff
path: root/src/burn/test/BurnUnitTest/BurnTestException.h
blob: b9467926b2098bf1b14c0538a2beb0de6c71ed23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#pragma once
// 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.


namespace Microsoft
{
namespace Tools
{
namespace WindowsInstallerXml
{
namespace Test
{
namespace Bootstrapper
{
    using namespace System;
    using namespace WixInternal::TestSupport;

    public ref struct BurnTestException : public SucceededException
    {
    public:
        BurnTestException(HRESULT error, String^ message)
            : SucceededException(error, message)
        {
        }

        property Int32 ErrorCode
        {
            Int32 get()
            {
              return this->HResult;
            }
        }

    };
}
}
}
}
}

// this class is used by __TestThrowOnFailure_Format() below to deallocate
// the string created after the function call has returned
class __TestThrowOnFailure_StringFree
{
    LPWSTR m_scz;

public:
    __TestThrowOnFailure_StringFree(LPWSTR scz)
    {
        m_scz = scz;
    }

    ~__TestThrowOnFailure_StringFree()
    {
        ReleaseStr(m_scz);
    }

    operator LPCWSTR()
    {
        return m_scz;
    }
};

// used by the TestThrowOnFailure macros to format the error string and
// return an LPCWSTR that can be used to initialize a System::String
#pragma warning (push)
#pragma warning (disable : 4793)
inline __TestThrowOnFailure_StringFree __TestThrowOnFailure_Format(LPCWSTR wzFormat, ...)
{
    Assert(wzFormat && *wzFormat);

    HRESULT hr = S_OK;
    LPWSTR scz = NULL;
    va_list args;

    va_start(args, wzFormat);
    hr = StrAllocFormattedArgs(&scz, wzFormat, args);
    va_end(args);
    ExitOnFailure(hr, "Failed to format message string.");

LExit:
    return scz;
}
#pragma warning (pop)

#define TestThrowOnFailure(hr, s) if (FAILED(hr)) { throw gcnew Microsoft::Tools::WindowsInstallerXml::Test::Bootstrapper::BurnTestException(hr, gcnew System::String(s)); }
#define TestThrowOnFailure1(hr, s, p) if (FAILED(hr)) { throw gcnew Microsoft::Tools::WindowsInstallerXml::Test::Bootstrapper::BurnTestException(hr, gcnew System::String(__TestThrowOnFailure_Format(s, p))); }
#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))); }