aboutsummaryrefslogtreecommitdiff
path: root/src/libs/dutil/test/DUtilUnitTest/DUtilTests.cpp
blob: dd17a50e0e2b7688bae3ed51f0538938a4a8dba7 (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
// 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.

#include "precomp.h"

using namespace System;
using namespace Xunit;
using namespace WixInternal::TestSupport;
using namespace WixInternal::TestSupport::XunitExtensions;

namespace DutilTests
{
    [Collection("Dutil_TraceErrorSource")]
    public ref class DUtil
    {
    public:
        [SkippableFact]
        void DUtilTraceErrorSourceFiltersOnTraceLevel()
        {
            DutilInitialize(&DutilTestTraceError);

            try
            {
                CallDutilTraceErrorSource();

                Dutil_TraceSetLevel(REPORT_DEBUG, FALSE);

                Exception^ traceErrorException = nullptr;

                try
                {
                    CallDutilTraceErrorSource();
                }
                catch (Exception^ e)
                {
                    traceErrorException = e;
                }

                if (traceErrorException == nullptr)
                {
                    WixAssert::Skip("Dutil_TraceErrorSource did not call the registered callback.");
                }
                else
                {
                    WixAssert::StringEqual("hr = 0x80004005, message = Error message", traceErrorException->Message, false);
                }
            }
            finally
            {
                DutilUninitialize();
            }
        }

    private:
        void CallDutilTraceErrorSource()
        {
            Dutil_TraceErrorSource(__FILE__, __LINE__, REPORT_DEBUG, DUTIL_SOURCE_EXTERNAL, E_FAIL, "Error message");
        }
    };

    [CollectionDefinition("Dutil_TraceErrorSource", DisableParallelization = true)]
    public ref class Dutil_TraceErrorSourceCollectionDefinition
    {
    };
}