diff options
| author | Sean Hall <r.sean.hall@gmail.com> | 2020-07-12 17:07:55 +1000 |
|---|---|---|
| committer | Sean Hall <r.sean.hall@gmail.com> | 2020-07-12 17:16:16 +1000 |
| commit | dc558da002794cc07013e8376f3c55c73391aa0e (patch) | |
| tree | faba96f981f1ea0c6888b387cf43cc78d0bc2927 /src/test/DUtilUnitTest | |
| parent | aeddc77fc021f11f68a4c1a093eabf9776866b80 (diff) | |
| download | wix-dc558da002794cc07013e8376f3c55c73391aa0e.tar.gz wix-dc558da002794cc07013e8376f3c55c73391aa0e.tar.bz2 wix-dc558da002794cc07013e8376f3c55c73391aa0e.zip | |
Update Dutil_TraceErrorSource to filter based on the report level.
Diffstat (limited to 'src/test/DUtilUnitTest')
| -rw-r--r-- | src/test/DUtilUnitTest/DUtilTests.cpp | 35 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/DUtilUnitTest.vcxproj | 4 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters | 9 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/DictUtilTest.cpp | 4 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/FileUtilTest.cpp | 3 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/IniUtilTest.cpp | 3 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/MemUtilTest.cpp | 16 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/StrUtilTest.cpp | 16 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/UriUtilTest.cpp | 4 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/error.cpp | 26 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/error.h | 16 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/precomp.h | 1 |
12 files changed, 125 insertions, 12 deletions
diff --git a/src/test/DUtilUnitTest/DUtilTests.cpp b/src/test/DUtilUnitTest/DUtilTests.cpp new file mode 100644 index 00000000..55e81d46 --- /dev/null +++ b/src/test/DUtilUnitTest/DUtilTests.cpp | |||
| @@ -0,0 +1,35 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | #include "precomp.h" | ||
| 4 | |||
| 5 | using namespace System; | ||
| 6 | using namespace Xunit; | ||
| 7 | using namespace WixBuildTools::TestSupport; | ||
| 8 | |||
| 9 | namespace DutilTests | ||
| 10 | { | ||
| 11 | public ref class DUtil | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | [Fact] | ||
| 15 | void DUtilTraceErrorSourceFiltersOnTraceLevel() | ||
| 16 | { | ||
| 17 | DutilInitialize(&DutilTestTraceError); | ||
| 18 | |||
| 19 | CallDutilTraceErrorSource(); | ||
| 20 | |||
| 21 | Dutil_TraceSetLevel(REPORT_DEBUG, FALSE); | ||
| 22 | |||
| 23 | Action^ action = gcnew Action(this, &DUtil::CallDutilTraceErrorSource); | ||
| 24 | Assert::Throws<Exception^>(action); | ||
| 25 | |||
| 26 | DutilUninitialize(); | ||
| 27 | } | ||
| 28 | |||
| 29 | private: | ||
| 30 | void CallDutilTraceErrorSource() | ||
| 31 | { | ||
| 32 | Dutil_TraceErrorSource(__FILE__, __LINE__, REPORT_DEBUG, DUTIL_SOURCE_EXTERNAL, E_FAIL, "Error message"); | ||
| 33 | } | ||
| 34 | }; | ||
| 35 | } | ||
diff --git a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj index b023d74f..c0974780 100644 --- a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj +++ b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj | |||
| @@ -36,6 +36,8 @@ | |||
| 36 | <ClCompile Include="AssemblyInfo.cpp" /> | 36 | <ClCompile Include="AssemblyInfo.cpp" /> |
| 37 | <ClCompile Include="DictUtilTest.cpp" /> | 37 | <ClCompile Include="DictUtilTest.cpp" /> |
| 38 | <ClCompile Include="DirUtilTests.cpp" /> | 38 | <ClCompile Include="DirUtilTests.cpp" /> |
| 39 | <ClCompile Include="DUtilTests.cpp" /> | ||
| 40 | <ClCompile Include="error.cpp" /> | ||
| 39 | <ClCompile Include="FileUtilTest.cpp" /> | 41 | <ClCompile Include="FileUtilTest.cpp" /> |
| 40 | <ClCompile Include="GuidUtilTest.cpp" /> | 42 | <ClCompile Include="GuidUtilTest.cpp" /> |
| 41 | <ClCompile Include="IniUtilTest.cpp" /> | 43 | <ClCompile Include="IniUtilTest.cpp" /> |
| @@ -92,4 +94,4 @@ | |||
| 92 | <Error Condition="!Exists('..\..\..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" /> | 94 | <Error Condition="!Exists('..\..\..\packages\xunit.core.2.4.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.core.2.4.1\build\xunit.core.targets'))" /> |
| 93 | <Error Condition="!Exists('..\..\..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props'))" /> | 95 | <Error Condition="!Exists('..\..\..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.runner.visualstudio.2.4.1\build\net20\xunit.runner.visualstudio.props'))" /> |
| 94 | </Target> | 96 | </Target> |
| 95 | </Project> | 97 | </Project> \ No newline at end of file |
diff --git a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters index 783e18c7..2456558f 100644 --- a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters +++ b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters | |||
| @@ -24,6 +24,12 @@ | |||
| 24 | <ClCompile Include="DirUtilTests.cpp"> | 24 | <ClCompile Include="DirUtilTests.cpp"> |
| 25 | <Filter>Source Files</Filter> | 25 | <Filter>Source Files</Filter> |
| 26 | </ClCompile> | 26 | </ClCompile> |
| 27 | <ClCompile Include="DUtilTests.cpp"> | ||
| 28 | <Filter>Source Files</Filter> | ||
| 29 | </ClCompile> | ||
| 30 | <ClCompile Include="error.cpp"> | ||
| 31 | <Filter>Source Files</Filter> | ||
| 32 | </ClCompile> | ||
| 27 | <ClCompile Include="FileUtilTest.cpp"> | 33 | <ClCompile Include="FileUtilTest.cpp"> |
| 28 | <Filter>Source Files</Filter> | 34 | <Filter>Source Files</Filter> |
| 29 | </ClCompile> | 35 | </ClCompile> |
| @@ -42,6 +48,9 @@ | |||
| 42 | <ClCompile Include="PathUtilTest.cpp"> | 48 | <ClCompile Include="PathUtilTest.cpp"> |
| 43 | <Filter>Source Files</Filter> | 49 | <Filter>Source Files</Filter> |
| 44 | </ClCompile> | 50 | </ClCompile> |
| 51 | <ClCompile Include="precomp.cpp"> | ||
| 52 | <Filter>Source Files</Filter> | ||
| 53 | </ClCompile> | ||
| 45 | <ClCompile Include="StrUtilTest.cpp"> | 54 | <ClCompile Include="StrUtilTest.cpp"> |
| 46 | <Filter>Source Files</Filter> | 55 | <Filter>Source Files</Filter> |
| 47 | </ClCompile> | 56 | </ClCompile> |
diff --git a/src/test/DUtilUnitTest/DictUtilTest.cpp b/src/test/DUtilUnitTest/DictUtilTest.cpp index 4e9d3907..4b4777d7 100644 --- a/src/test/DUtilUnitTest/DictUtilTest.cpp +++ b/src/test/DUtilUnitTest/DictUtilTest.cpp | |||
| @@ -22,6 +22,8 @@ namespace DutilTests | |||
| 22 | [Fact] | 22 | [Fact] |
| 23 | void DictUtilTest() | 23 | void DictUtilTest() |
| 24 | { | 24 | { |
| 25 | DutilInitialize(&DutilTestTraceError); | ||
| 26 | |||
| 25 | EmbeddedKeyTestHelper(DICT_FLAG_NONE, numIterations); | 27 | EmbeddedKeyTestHelper(DICT_FLAG_NONE, numIterations); |
| 26 | 28 | ||
| 27 | EmbeddedKeyTestHelper(DICT_FLAG_CASEINSENSITIVE, numIterations); | 29 | EmbeddedKeyTestHelper(DICT_FLAG_CASEINSENSITIVE, numIterations); |
| @@ -29,6 +31,8 @@ namespace DutilTests | |||
| 29 | StringListTestHelper(DICT_FLAG_NONE, numIterations); | 31 | StringListTestHelper(DICT_FLAG_NONE, numIterations); |
| 30 | 32 | ||
| 31 | StringListTestHelper(DICT_FLAG_CASEINSENSITIVE, numIterations); | 33 | StringListTestHelper(DICT_FLAG_CASEINSENSITIVE, numIterations); |
| 34 | |||
| 35 | DutilUninitialize(); | ||
| 32 | } | 36 | } |
| 33 | 37 | ||
| 34 | private: | 38 | private: |
diff --git a/src/test/DUtilUnitTest/FileUtilTest.cpp b/src/test/DUtilUnitTest/FileUtilTest.cpp index 9bd1d0c0..0087a1d5 100644 --- a/src/test/DUtilUnitTest/FileUtilTest.cpp +++ b/src/test/DUtilUnitTest/FileUtilTest.cpp | |||
| @@ -18,6 +18,8 @@ namespace DutilTests | |||
| 18 | LPWSTR sczTempDir = NULL; | 18 | LPWSTR sczTempDir = NULL; |
| 19 | LPWSTR sczFileDir = NULL; | 19 | LPWSTR sczFileDir = NULL; |
| 20 | 20 | ||
| 21 | DutilInitialize(&DutilTestTraceError); | ||
| 22 | |||
| 21 | try | 23 | try |
| 22 | { | 24 | { |
| 23 | hr = PathExpand(&sczTempDir, L"%TEMP%\\FileUtilTest\\", PATH_EXPAND_ENVIRONMENT); | 25 | hr = PathExpand(&sczTempDir, L"%TEMP%\\FileUtilTest\\", PATH_EXPAND_ENVIRONMENT); |
| @@ -43,6 +45,7 @@ namespace DutilTests | |||
| 43 | { | 45 | { |
| 44 | ReleaseStr(sczTempDir); | 46 | ReleaseStr(sczTempDir); |
| 45 | ReleaseStr(sczFileDir); | 47 | ReleaseStr(sczFileDir); |
| 48 | DutilUninitialize(); | ||
| 46 | } | 49 | } |
| 47 | } | 50 | } |
| 48 | 51 | ||
diff --git a/src/test/DUtilUnitTest/IniUtilTest.cpp b/src/test/DUtilUnitTest/IniUtilTest.cpp index 2edd56ab..946f19c5 100644 --- a/src/test/DUtilUnitTest/IniUtilTest.cpp +++ b/src/test/DUtilUnitTest/IniUtilTest.cpp | |||
| @@ -24,6 +24,8 @@ namespace DutilTests | |||
| 24 | LPWSTR wzIniContents = L" PlainValue = \t Blah \r\n;CommentHere\r\n[Section1]\r\n ;Another Comment With = Equal Sign\r\nSection1ValueA=Foo\r\n\r\nSection1ValueB=Bar\r\n[Section2]\r\nSection2ValueA=Cha\r\nArray[0]=Arr\r\n"; | 24 | LPWSTR wzIniContents = L" PlainValue = \t Blah \r\n;CommentHere\r\n[Section1]\r\n ;Another Comment With = Equal Sign\r\nSection1ValueA=Foo\r\n\r\nSection1ValueB=Bar\r\n[Section2]\r\nSection2ValueA=Cha\r\nArray[0]=Arr\r\n"; |
| 25 | LPWSTR wzScriptContents = L"setf ~PlainValue Blah\r\n;CommentHere\r\n\r\nsetf ~Section1\\Section1ValueA Foo\r\n\r\nsetf ~Section1\\Section1ValueB Bar\r\nsetf ~Section2\\Section2ValueA Cha\r\nsetf ~Section2\\Array[0] Arr\r\n"; | 25 | LPWSTR wzScriptContents = L"setf ~PlainValue Blah\r\n;CommentHere\r\n\r\nsetf ~Section1\\Section1ValueA Foo\r\n\r\nsetf ~Section1\\Section1ValueB Bar\r\nsetf ~Section2\\Section2ValueA Cha\r\nsetf ~Section2\\Array[0] Arr\r\n"; |
| 26 | 26 | ||
| 27 | DutilInitialize(&DutilTestTraceError); | ||
| 28 | |||
| 27 | try | 29 | try |
| 28 | { | 30 | { |
| 29 | hr = PathExpand(&sczTempIniFilePath, L"%TEMP%\\IniUtilTest\\Test.ini", PATH_EXPAND_ENVIRONMENT); | 31 | hr = PathExpand(&sczTempIniFilePath, L"%TEMP%\\IniUtilTest\\Test.ini", PATH_EXPAND_ENVIRONMENT); |
| @@ -58,6 +60,7 @@ namespace DutilTests | |||
| 58 | { | 60 | { |
| 59 | ReleaseStr(sczTempIniFilePath); | 61 | ReleaseStr(sczTempIniFilePath); |
| 60 | ReleaseStr(sczTempIniFileDir); | 62 | ReleaseStr(sczTempIniFileDir); |
| 63 | DutilUninitialize(); | ||
| 61 | } | 64 | } |
| 62 | } | 65 | } |
| 63 | 66 | ||
diff --git a/src/test/DUtilUnitTest/MemUtilTest.cpp b/src/test/DUtilUnitTest/MemUtilTest.cpp index 2621da6d..09692bfb 100644 --- a/src/test/DUtilUnitTest/MemUtilTest.cpp +++ b/src/test/DUtilUnitTest/MemUtilTest.cpp | |||
| @@ -27,6 +27,8 @@ namespace DutilTests | |||
| 27 | ArrayValue *rgValues = NULL; | 27 | ArrayValue *rgValues = NULL; |
| 28 | DWORD cValues = 0; | 28 | DWORD cValues = 0; |
| 29 | 29 | ||
| 30 | DutilInitialize(&DutilTestTraceError); | ||
| 31 | |||
| 30 | try | 32 | try |
| 31 | { | 33 | { |
| 32 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&rgValues), cValues + 1, sizeof(ArrayValue), 5); | 34 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&rgValues), cValues + 1, sizeof(ArrayValue), 5); |
| @@ -101,7 +103,7 @@ namespace DutilTests | |||
| 101 | } | 103 | } |
| 102 | 104 | ||
| 103 | LExit: | 105 | LExit: |
| 104 | return; | 106 | DutilUninitialize(); |
| 105 | } | 107 | } |
| 106 | 108 | ||
| 107 | [Fact] | 109 | [Fact] |
| @@ -111,6 +113,8 @@ namespace DutilTests | |||
| 111 | ArrayValue *rgValues = NULL; | 113 | ArrayValue *rgValues = NULL; |
| 112 | DWORD cValues = 0; | 114 | DWORD cValues = 0; |
| 113 | 115 | ||
| 116 | DutilInitialize(&DutilTestTraceError); | ||
| 117 | |||
| 114 | try | 118 | try |
| 115 | { | 119 | { |
| 116 | hr = MemInsertIntoArray(reinterpret_cast<LPVOID*>(&rgValues), 0, 1, cValues + 1, sizeof(ArrayValue), 5); | 120 | hr = MemInsertIntoArray(reinterpret_cast<LPVOID*>(&rgValues), 0, 1, cValues + 1, sizeof(ArrayValue), 5); |
| @@ -180,6 +184,7 @@ namespace DutilTests | |||
| 180 | finally | 184 | finally |
| 181 | { | 185 | { |
| 182 | ReleaseMem(rgValues); | 186 | ReleaseMem(rgValues); |
| 187 | DutilUninitialize(); | ||
| 183 | } | 188 | } |
| 184 | } | 189 | } |
| 185 | 190 | ||
| @@ -190,6 +195,8 @@ namespace DutilTests | |||
| 190 | ArrayValue *rgValues = NULL; | 195 | ArrayValue *rgValues = NULL; |
| 191 | DWORD cValues = 0; | 196 | DWORD cValues = 0; |
| 192 | 197 | ||
| 198 | DutilInitialize(&DutilTestTraceError); | ||
| 199 | |||
| 193 | try | 200 | try |
| 194 | { | 201 | { |
| 195 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&rgValues), 10, sizeof(ArrayValue), 10); | 202 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&rgValues), 10, sizeof(ArrayValue), 10); |
| @@ -252,6 +259,7 @@ namespace DutilTests | |||
| 252 | finally | 259 | finally |
| 253 | { | 260 | { |
| 254 | ReleaseMem(rgValues); | 261 | ReleaseMem(rgValues); |
| 262 | DutilUninitialize(); | ||
| 255 | } | 263 | } |
| 256 | } | 264 | } |
| 257 | 265 | ||
| @@ -262,6 +270,8 @@ namespace DutilTests | |||
| 262 | ArrayValue *rgValues = NULL; | 270 | ArrayValue *rgValues = NULL; |
| 263 | DWORD cValues = 0; | 271 | DWORD cValues = 0; |
| 264 | 272 | ||
| 273 | DutilInitialize(&DutilTestTraceError); | ||
| 274 | |||
| 265 | try | 275 | try |
| 266 | { | 276 | { |
| 267 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&rgValues), 10, sizeof(ArrayValue), 10); | 277 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&rgValues), 10, sizeof(ArrayValue), 10); |
| @@ -326,6 +336,7 @@ namespace DutilTests | |||
| 326 | finally | 336 | finally |
| 327 | { | 337 | { |
| 328 | ReleaseMem(rgValues); | 338 | ReleaseMem(rgValues); |
| 339 | DutilUninitialize(); | ||
| 329 | } | 340 | } |
| 330 | } | 341 | } |
| 331 | 342 | ||
| @@ -336,6 +347,8 @@ namespace DutilTests | |||
| 336 | ArrayValue *rgValues = NULL; | 347 | ArrayValue *rgValues = NULL; |
| 337 | DWORD cValues = 0; | 348 | DWORD cValues = 0; |
| 338 | 349 | ||
| 350 | DutilInitialize(&DutilTestTraceError); | ||
| 351 | |||
| 339 | try | 352 | try |
| 340 | { | 353 | { |
| 341 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&rgValues), 10, sizeof(ArrayValue), 10); | 354 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&rgValues), 10, sizeof(ArrayValue), 10); |
| @@ -424,6 +437,7 @@ namespace DutilTests | |||
| 424 | finally | 437 | finally |
| 425 | { | 438 | { |
| 426 | ReleaseMem(rgValues); | 439 | ReleaseMem(rgValues); |
| 440 | DutilUninitialize(); | ||
| 427 | } | 441 | } |
| 428 | } | 442 | } |
| 429 | 443 | ||
diff --git a/src/test/DUtilUnitTest/StrUtilTest.cpp b/src/test/DUtilUnitTest/StrUtilTest.cpp index 7c35b7c0..94fee280 100644 --- a/src/test/DUtilUnitTest/StrUtilTest.cpp +++ b/src/test/DUtilUnitTest/StrUtilTest.cpp | |||
| @@ -86,6 +86,8 @@ namespace DutilTests | |||
| 86 | HRESULT hr = S_OK; | 86 | HRESULT hr = S_OK; |
| 87 | LPWSTR sczOutput = NULL; | 87 | LPWSTR sczOutput = NULL; |
| 88 | 88 | ||
| 89 | DutilInitialize(&DutilTestTraceError); | ||
| 90 | |||
| 89 | try | 91 | try |
| 90 | { | 92 | { |
| 91 | hr = StrTrimWhitespace(&sczOutput, wzInput); | 93 | hr = StrTrimWhitespace(&sczOutput, wzInput); |
| @@ -103,7 +105,7 @@ namespace DutilTests | |||
| 103 | } | 105 | } |
| 104 | 106 | ||
| 105 | LExit: | 107 | LExit: |
| 106 | return; | 108 | DutilUninitialize(); |
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | void TestTrimAnsi(LPCSTR szInput, LPCSTR szExpectedResult) | 111 | void TestTrimAnsi(LPCSTR szInput, LPCSTR szExpectedResult) |
| @@ -111,6 +113,8 @@ namespace DutilTests | |||
| 111 | HRESULT hr = S_OK; | 113 | HRESULT hr = S_OK; |
| 112 | LPSTR sczOutput = NULL; | 114 | LPSTR sczOutput = NULL; |
| 113 | 115 | ||
| 116 | DutilInitialize(&DutilTestTraceError); | ||
| 117 | |||
| 114 | try | 118 | try |
| 115 | { | 119 | { |
| 116 | hr = StrAnsiTrimWhitespace(&sczOutput, szInput); | 120 | hr = StrAnsiTrimWhitespace(&sczOutput, szInput); |
| @@ -128,7 +132,7 @@ namespace DutilTests | |||
| 128 | } | 132 | } |
| 129 | 133 | ||
| 130 | LExit: | 134 | LExit: |
| 131 | return; | 135 | DutilUninitialize(); |
| 132 | } | 136 | } |
| 133 | 137 | ||
| 134 | void TestStrAllocStringAnsi(LPCSTR szSource, DWORD cchSource, LPCWSTR wzExpectedResult) | 138 | void TestStrAllocStringAnsi(LPCSTR szSource, DWORD cchSource, LPCWSTR wzExpectedResult) |
| @@ -136,6 +140,8 @@ namespace DutilTests | |||
| 136 | HRESULT hr = S_OK; | 140 | HRESULT hr = S_OK; |
| 137 | LPWSTR sczOutput = NULL; | 141 | LPWSTR sczOutput = NULL; |
| 138 | 142 | ||
| 143 | DutilInitialize(&DutilTestTraceError); | ||
| 144 | |||
| 139 | try | 145 | try |
| 140 | { | 146 | { |
| 141 | hr = StrAllocStringAnsi(&sczOutput, szSource, cchSource, CP_UTF8); | 147 | hr = StrAllocStringAnsi(&sczOutput, szSource, cchSource, CP_UTF8); |
| @@ -153,7 +159,7 @@ namespace DutilTests | |||
| 153 | } | 159 | } |
| 154 | 160 | ||
| 155 | LExit: | 161 | LExit: |
| 156 | return; | 162 | DutilUninitialize(); |
| 157 | } | 163 | } |
| 158 | 164 | ||
| 159 | void TestStrAnsiAllocString(LPWSTR wzSource, DWORD cchSource, LPCSTR szExpectedResult) | 165 | void TestStrAnsiAllocString(LPWSTR wzSource, DWORD cchSource, LPCSTR szExpectedResult) |
| @@ -161,6 +167,8 @@ namespace DutilTests | |||
| 161 | HRESULT hr = S_OK; | 167 | HRESULT hr = S_OK; |
| 162 | LPSTR sczOutput = NULL; | 168 | LPSTR sczOutput = NULL; |
| 163 | 169 | ||
| 170 | DutilInitialize(&DutilTestTraceError); | ||
| 171 | |||
| 164 | try | 172 | try |
| 165 | { | 173 | { |
| 166 | hr = StrAnsiAllocString(&sczOutput, wzSource, cchSource, CP_UTF8); | 174 | hr = StrAnsiAllocString(&sczOutput, wzSource, cchSource, CP_UTF8); |
| @@ -178,7 +186,7 @@ namespace DutilTests | |||
| 178 | } | 186 | } |
| 179 | 187 | ||
| 180 | LExit: | 188 | LExit: |
| 181 | return; | 189 | DutilUninitialize(); |
| 182 | } | 190 | } |
| 183 | }; | 191 | }; |
| 184 | } | 192 | } |
diff --git a/src/test/DUtilUnitTest/UriUtilTest.cpp b/src/test/DUtilUnitTest/UriUtilTest.cpp index 220b3ff5..b3bf87a2 100644 --- a/src/test/DUtilUnitTest/UriUtilTest.cpp +++ b/src/test/DUtilUnitTest/UriUtilTest.cpp | |||
| @@ -17,6 +17,8 @@ namespace CfgTests | |||
| 17 | { | 17 | { |
| 18 | HRESULT hr = S_OK; | 18 | HRESULT hr = S_OK; |
| 19 | 19 | ||
| 20 | DutilInitialize(&DutilTestTraceError); | ||
| 21 | |||
| 20 | LPCWSTR uri = L"https://localhost/"; | 22 | LPCWSTR uri = L"https://localhost/"; |
| 21 | URI_PROTOCOL uriProtocol = URI_PROTOCOL::URI_PROTOCOL_UNKNOWN; | 23 | URI_PROTOCOL uriProtocol = URI_PROTOCOL::URI_PROTOCOL_UNKNOWN; |
| 22 | hr = UriProtocol(uri, &uriProtocol); | 24 | hr = UriProtocol(uri, &uriProtocol); |
| @@ -90,7 +92,7 @@ namespace CfgTests | |||
| 90 | Assert::Equal((int)URI_PROTOCOL::URI_PROTOCOL_FTP, (int)uriProtocol); | 92 | Assert::Equal((int)URI_PROTOCOL::URI_PROTOCOL_FTP, (int)uriProtocol); |
| 91 | 93 | ||
| 92 | LExit: | 94 | LExit: |
| 93 | ; | 95 | DutilUninitialize(); |
| 94 | } | 96 | } |
| 95 | }; | 97 | }; |
| 96 | } | 98 | } |
diff --git a/src/test/DUtilUnitTest/error.cpp b/src/test/DUtilUnitTest/error.cpp new file mode 100644 index 00000000..e51971c3 --- /dev/null +++ b/src/test/DUtilUnitTest/error.cpp | |||
| @@ -0,0 +1,26 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | #include "precomp.h" | ||
| 4 | |||
| 5 | const int ERROR_STRING_BUFFER = 1024; | ||
| 6 | |||
| 7 | static char szMsg[ERROR_STRING_BUFFER]; | ||
| 8 | static WCHAR wzMsg[ERROR_STRING_BUFFER]; | ||
| 9 | |||
| 10 | void CALLBACK DutilTestTraceError( | ||
| 11 | __in_z LPCSTR /*szFile*/, | ||
| 12 | __in int /*iLine*/, | ||
| 13 | __in REPORT_LEVEL /*rl*/, | ||
| 14 | __in UINT source, | ||
| 15 | __in HRESULT hrError, | ||
| 16 | __in_z __format_string LPCSTR szFormat, | ||
| 17 | __in va_list args | ||
| 18 | ) | ||
| 19 | { | ||
| 20 | if (DUTIL_SOURCE_EXTERNAL == source) | ||
| 21 | { | ||
| 22 | ::StringCchPrintfA(szMsg, countof(szMsg), szFormat, args); | ||
| 23 | MultiByteToWideChar(CP_ACP, 0, szMsg, -1, wzMsg, countof(wzMsg)); | ||
| 24 | throw gcnew System::Exception(System::String::Format("hr = 0x{0:X8}, message = {1}", hrError, gcnew System::String(wzMsg))); | ||
| 25 | } | ||
| 26 | } | ||
diff --git a/src/test/DUtilUnitTest/error.h b/src/test/DUtilUnitTest/error.h index a52db56d..b973acaf 100644 --- a/src/test/DUtilUnitTest/error.h +++ b/src/test/DUtilUnitTest/error.h | |||
| @@ -1,8 +1,14 @@ | |||
| 1 | #pragma once | ||
| 1 | // 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. | 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. |
| 2 | 3 | ||
| 3 | const int ERROR_STRING_BUFFER = 1024; | 4 | #define DUTIL_SOURCE_DEFAULT DUTIL_SOURCE_EXTERNAL |
| 4 | 5 | ||
| 5 | static char szMsg[ERROR_STRING_BUFFER]; | 6 | void CALLBACK DutilTestTraceError( |
| 6 | static WCHAR wzMsg[ERROR_STRING_BUFFER]; | 7 | __in_z LPCSTR szFile, |
| 7 | 8 | __in int iLine, | |
| 8 | #define ExitTrace(x, f, ...) { HRESULT hrTemp = x; hr = ::StringCchPrintfA(szMsg, countof(szMsg), f, __VA_ARGS__); MultiByteToWideChar(CP_ACP, 0, szMsg, -1, wzMsg, countof(wzMsg)); throw gcnew System::Exception(System::String::Format("hr = 0x{0:X8}, message = {1}", hrTemp, gcnew System::String(wzMsg))); } | 9 | __in REPORT_LEVEL rl, |
| 10 | __in UINT source, | ||
| 11 | __in HRESULT hrError, | ||
| 12 | __in_z __format_string LPCSTR szFormat, | ||
| 13 | __in va_list args | ||
| 14 | ); | ||
diff --git a/src/test/DUtilUnitTest/precomp.h b/src/test/DUtilUnitTest/precomp.h index 15dfcd1a..284668fe 100644 --- a/src/test/DUtilUnitTest/precomp.h +++ b/src/test/DUtilUnitTest/precomp.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <ShlObj.h> | 7 | #include <ShlObj.h> |
| 8 | 8 | ||
| 9 | // Include error.h before dutil.h | 9 | // Include error.h before dutil.h |
| 10 | #include <dutilsources.h> | ||
| 10 | #include "error.h" | 11 | #include "error.h" |
| 11 | #include <dutil.h> | 12 | #include <dutil.h> |
| 12 | 13 | ||
