aboutsummaryrefslogtreecommitdiff
path: root/src/internal/WixBuildTools.TestSupport.Native/NativeAssert.h
blob: 62ace4a9b3a40a202c3d615d2f034a6526c5e112 (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
#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 WixBuildTools {
namespace TestSupport {

    using namespace System;
    using namespace System::Collections::Generic;
    using namespace System::Linq;
    using namespace Xunit;

    public ref class NativeAssert : WixAssert
    {
    public:
        static void NotNull(LPCWSTR wz)
        {
            if (!wz)
            {
                Assert::NotNull(nullptr);
            }
        }

        // For some reason, naming these NotStringEqual methods "NotEqual" breaks Intellisense in files that call any overload of the NotEqual method.
        static void NotStringEqual(LPCWSTR expected, LPCWSTR actual)
        {
            NativeAssert::NotStringEqual(expected, actual, FALSE);
        }

        static void NotStringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase)
        {
            WixAssert::NotStringEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), ignoreCase);
        }

        // For some reason, naming these StringEqual methods "Equal" breaks Intellisense in files that call any overload of the Equal method.
        static void StringEqual(LPCWSTR expected, LPCWSTR actual)
        {
            NativeAssert::StringEqual(expected, actual, FALSE);
        }

        static void StringEqual(LPCWSTR expected, LPCWSTR actual, BOOL ignoreCase)
        {
            WixAssert::StringEqual(NativeAssert::LPWSTRToString(expected), NativeAssert::LPWSTRToString(actual), ignoreCase);
        }

        static void Succeeded(HRESULT hr, LPCSTR zFormat, LPCSTR zArg, ... array<LPCSTR>^ zArgs)
        {
            array<Object^>^ formatArgs = gcnew array<Object^, 1>(zArgs->Length + 1);
            formatArgs[0] = NativeAssert::LPSTRToString(zArg);
            for (int i = 0; i < zArgs->Length; ++i)
            {
                formatArgs[i + 1] = NativeAssert::LPSTRToString(zArgs[i]);
            }
            WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs);
        }

        static void Succeeded(HRESULT hr, LPCSTR zFormat, ... array<LPCWSTR>^ wzArgs)
        {
            array<Object^>^ formatArgs = gcnew array<Object^, 1>(wzArgs->Length);
            for (int i = 0; i < wzArgs->Length; ++i)
            {
                formatArgs[i] = NativeAssert::LPWSTRToString(wzArgs[i]);
            }
            WixAssert::Succeeded(hr, gcnew String(zFormat), formatArgs);
        }

        static void ValidReturnCode(HRESULT hr, ... array<HRESULT>^ validReturnCodes)
        {
            Assert::Contains(hr, (IEnumerable<HRESULT>^)validReturnCodes);
        }

    private:
        static String^ LPSTRToString(LPCSTR z)
        {
            return z ? gcnew String(z) : nullptr;
        }
        static String^ LPWSTRToString(LPCWSTR wz)
        {
            return wz ? gcnew String(wz) : nullptr;
        }
    };
}
}