diff options
| author | Rob Mensching <rob@firegiant.com> | 2025-03-18 17:12:42 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2025-03-18 18:01:57 -0700 |
| commit | 32bfb97857041bb4385df3754c3f9eb2f8b23d8e (patch) | |
| tree | f26125a61c3bda97d6f3031c17cb262e404acd0b /src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp | |
| parent | 7133077ecc0ef2ada3746c8a0569b1028b6ff6d1 (diff) | |
| download | wix-32bfb97857041bb4385df3754c3f9eb2f8b23d8e.tar.gz wix-32bfb97857041bb4385df3754c3f9eb2f8b23d8e.tar.bz2 wix-32bfb97857041bb4385df3754c3f9eb2f8b23d8e.zip | |
LocUtil occasionally failed due to XmlInitialization
Split into separate classes to prevent potential parallelism race conditions.
Diffstat (limited to 'src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp')
| -rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp new file mode 100644 index 00000000..1bfc4bb4 --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp | |||
| @@ -0,0 +1,93 @@ | |||
| 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 WixInternal::TestSupport; | ||
| 8 | |||
| 9 | namespace DutilTests | ||
| 10 | { | ||
| 11 | public ref class LocStringsUtil | ||
| 12 | { | ||
| 13 | public: | ||
| 14 | [Fact] | ||
| 15 | void CanLoadStringsWxl() | ||
| 16 | { | ||
| 17 | HRESULT hr = S_OK; | ||
| 18 | WIX_LOCALIZATION* pLoc = NULL; | ||
| 19 | LOC_STRING* pLocString = NULL; | ||
| 20 | LPWSTR sczValue = NULL; | ||
| 21 | |||
| 22 | DutilInitialize(&DutilTestTraceError); | ||
| 23 | |||
| 24 | try | ||
| 25 | { | ||
| 26 | hr = XmlInitialize(); | ||
| 27 | NativeAssert::Succeeded(hr, "Failed to initialize Xml."); | ||
| 28 | |||
| 29 | pin_ptr<const wchar_t> wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "strings.wxl")); | ||
| 30 | hr = LocLoadFromFile(wxlFilePath, &pLoc); | ||
| 31 | NativeAssert::Succeeded(hr, "Failed to parse strings.wxl: {0}", wxlFilePath); | ||
| 32 | |||
| 33 | Assert::Equal(4ul, pLoc->cLocStrings); | ||
| 34 | |||
| 35 | hr = LocGetString(pLoc, L"#(loc.Ex1)", &pLocString); | ||
| 36 | NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex1' from: {0}", wxlFilePath); | ||
| 37 | NativeAssert::StringEqual(L"#(loc.Ex1)", pLocString->wzId); | ||
| 38 | NativeAssert::StringEqual(L"This is example #1", pLocString->wzText); | ||
| 39 | NativeAssert::True(pLocString->bOverridable); | ||
| 40 | |||
| 41 | hr = LocGetString(pLoc, L"#(loc.Ex2)", &pLocString); | ||
| 42 | NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex2' from: {0}", wxlFilePath); | ||
| 43 | NativeAssert::StringEqual(L"#(loc.Ex2)", pLocString->wzId); | ||
| 44 | NativeAssert::StringEqual(L"This is example #2", pLocString->wzText); | ||
| 45 | NativeAssert::False(pLocString->bOverridable); | ||
| 46 | |||
| 47 | hr = LocGetString(pLoc, L"#(loc.Ex3)", &pLocString); | ||
| 48 | NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex3' from: {0}", wxlFilePath); | ||
| 49 | NativeAssert::StringEqual(L"#(loc.Ex3)", pLocString->wzId); | ||
| 50 | NativeAssert::StringEqual(L"This is example #3", pLocString->wzText); | ||
| 51 | NativeAssert::False(pLocString->bOverridable); | ||
| 52 | |||
| 53 | hr = LocGetString(pLoc, L"#(loc.Ex4)", &pLocString); | ||
| 54 | NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex4' from: {0}", wxlFilePath); | ||
| 55 | NativeAssert::StringEqual(L"#(loc.Ex4)", pLocString->wzId); | ||
| 56 | NativeAssert::StringEqual(L"", pLocString->wzText); | ||
| 57 | NativeAssert::False(pLocString->bOverridable); | ||
| 58 | |||
| 59 | hr = StrAllocString(&sczValue, L"Before #(loc.Ex1) After", 0); | ||
| 60 | NativeAssert::Succeeded(hr, "Failed to create localizable Ex1 string"); | ||
| 61 | |||
| 62 | hr = LocLocalizeString(pLoc, &sczValue); | ||
| 63 | NativeAssert::Succeeded(hr, "Failed to localize Ex1 string using: {0}", wxlFilePath); | ||
| 64 | NativeAssert::StringEqual(L"Before This is example #1 After", sczValue); | ||
| 65 | |||
| 66 | hr = StrAllocString(&sczValue, L"Xxx#(loc.Ex3)yyY", 0); | ||
| 67 | NativeAssert::Succeeded(hr, "Failed to create localizable Ex3 string"); | ||
| 68 | |||
| 69 | hr = LocLocalizeString(pLoc, &sczValue); | ||
| 70 | NativeAssert::Succeeded(hr, "Failed to localize Ex3 string using: {0}", wxlFilePath); | ||
| 71 | NativeAssert::StringEqual(L"XxxThis is example #3yyY", sczValue); | ||
| 72 | |||
| 73 | hr = StrAllocString(&sczValue, L"aaa#(loc.Ex4)bbb", 0); | ||
| 74 | NativeAssert::Succeeded(hr, "Failed to create localizable Ex4 string"); | ||
| 75 | |||
| 76 | hr = LocLocalizeString(pLoc, &sczValue); | ||
| 77 | NativeAssert::Succeeded(hr, "Failed to localize Ex4 string using: {0}", wxlFilePath); | ||
| 78 | NativeAssert::StringEqual(L"aaabbb", sczValue); | ||
| 79 | } | ||
| 80 | finally | ||
| 81 | { | ||
| 82 | ReleaseStr(sczValue); | ||
| 83 | |||
| 84 | if (pLoc) | ||
| 85 | { | ||
| 86 | LocFree(pLoc); | ||
| 87 | } | ||
| 88 | |||
| 89 | DutilUninitialize(); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | } | ||
