From 32bfb97857041bb4385df3754c3f9eb2f8b23d8e Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 18 Mar 2025 17:12:42 -0700 Subject: LocUtil occasionally failed due to XmlInitialization Split into separate classes to prevent potential parallelism race conditions. --- .../dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj | 3 +- .../test/DUtilUnitTest/LocControlsUtilTests.cpp | 72 ++++++++++ .../test/DUtilUnitTest/LocStringsUtilTests.cpp | 93 +++++++++++++ src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp | 151 --------------------- 4 files changed, 167 insertions(+), 152 deletions(-) create mode 100644 src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp create mode 100644 src/libs/dutil/test/DUtilUnitTest/LocStringsUtilTests.cpp delete mode 100644 src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp (limited to 'src') diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj index 94826b8f..fccb73c4 100644 --- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj +++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj @@ -55,7 +55,8 @@ - + + diff --git a/src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp new file mode 100644 index 00000000..a558c0c5 --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/LocControlsUtilTests.cpp @@ -0,0 +1,72 @@ +// 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; + +namespace DutilTests +{ + public ref class LocControlsUtil + { + public: + [Fact] + void CanLoadControlsWxl() + { + HRESULT hr = S_OK; + WIX_LOCALIZATION* pLoc = NULL; + LOC_CONTROL* pLocControl = NULL; + + DutilInitialize(&DutilTestTraceError); + + try + { + hr = XmlInitialize(); + NativeAssert::Succeeded(hr, "Failed to initialize Xml."); + + pin_ptr wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "controls.wxl")); + hr = LocLoadFromFile(wxlFilePath, &pLoc); + NativeAssert::Succeeded(hr, "Failed to parse controls.wxl: {0}", wxlFilePath); + + Assert::Equal(3ul, pLoc->cLocControls); + + hr = LocGetControl(pLoc, L"Control1", &pLocControl); + NativeAssert::Succeeded(hr, "Failed to get loc control 'Control1' from: {0}", wxlFilePath); + NativeAssert::StringEqual(L"Control1", pLocControl->wzControl); + NativeAssert::Equal(1, pLocControl->nX); + NativeAssert::Equal(2, pLocControl->nY); + NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nWidth); + NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nHeight); + NativeAssert::StringEqual(L"This is control #1", pLocControl->wzText); + + hr = LocGetControl(pLoc, L"Control2", &pLocControl); + NativeAssert::Succeeded(hr, "Failed to get loc control 'Control2' from: {0}", wxlFilePath); + NativeAssert::StringEqual(L"Control2", pLocControl->wzControl); + NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nX); + NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nY); + NativeAssert::Equal(50, pLocControl->nWidth); + NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nHeight); + NativeAssert::StringEqual(L"This is control #2", pLocControl->wzText); + + hr = LocGetControl(pLoc, L"Control3", &pLocControl); + NativeAssert::Succeeded(hr, "Failed to get loc control 'Control3' from: {0}", wxlFilePath); + NativeAssert::StringEqual(L"Control3", pLocControl->wzControl); + NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nX); + NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nY); + NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nWidth); + NativeAssert::Equal(150, pLocControl->nHeight); + NativeAssert::StringEqual(L"", pLocControl->wzText); + } + finally + { + if (pLoc) + { + LocFree(pLoc); + } + + DutilUninitialize(); + } + } + }; +} 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 @@ +// 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; + +namespace DutilTests +{ + public ref class LocStringsUtil + { + public: + [Fact] + void CanLoadStringsWxl() + { + HRESULT hr = S_OK; + WIX_LOCALIZATION* pLoc = NULL; + LOC_STRING* pLocString = NULL; + LPWSTR sczValue = NULL; + + DutilInitialize(&DutilTestTraceError); + + try + { + hr = XmlInitialize(); + NativeAssert::Succeeded(hr, "Failed to initialize Xml."); + + pin_ptr wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "strings.wxl")); + hr = LocLoadFromFile(wxlFilePath, &pLoc); + NativeAssert::Succeeded(hr, "Failed to parse strings.wxl: {0}", wxlFilePath); + + Assert::Equal(4ul, pLoc->cLocStrings); + + hr = LocGetString(pLoc, L"#(loc.Ex1)", &pLocString); + NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex1' from: {0}", wxlFilePath); + NativeAssert::StringEqual(L"#(loc.Ex1)", pLocString->wzId); + NativeAssert::StringEqual(L"This is example #1", pLocString->wzText); + NativeAssert::True(pLocString->bOverridable); + + hr = LocGetString(pLoc, L"#(loc.Ex2)", &pLocString); + NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex2' from: {0}", wxlFilePath); + NativeAssert::StringEqual(L"#(loc.Ex2)", pLocString->wzId); + NativeAssert::StringEqual(L"This is example #2", pLocString->wzText); + NativeAssert::False(pLocString->bOverridable); + + hr = LocGetString(pLoc, L"#(loc.Ex3)", &pLocString); + NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex3' from: {0}", wxlFilePath); + NativeAssert::StringEqual(L"#(loc.Ex3)", pLocString->wzId); + NativeAssert::StringEqual(L"This is example #3", pLocString->wzText); + NativeAssert::False(pLocString->bOverridable); + + hr = LocGetString(pLoc, L"#(loc.Ex4)", &pLocString); + NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex4' from: {0}", wxlFilePath); + NativeAssert::StringEqual(L"#(loc.Ex4)", pLocString->wzId); + NativeAssert::StringEqual(L"", pLocString->wzText); + NativeAssert::False(pLocString->bOverridable); + + hr = StrAllocString(&sczValue, L"Before #(loc.Ex1) After", 0); + NativeAssert::Succeeded(hr, "Failed to create localizable Ex1 string"); + + hr = LocLocalizeString(pLoc, &sczValue); + NativeAssert::Succeeded(hr, "Failed to localize Ex1 string using: {0}", wxlFilePath); + NativeAssert::StringEqual(L"Before This is example #1 After", sczValue); + + hr = StrAllocString(&sczValue, L"Xxx#(loc.Ex3)yyY", 0); + NativeAssert::Succeeded(hr, "Failed to create localizable Ex3 string"); + + hr = LocLocalizeString(pLoc, &sczValue); + NativeAssert::Succeeded(hr, "Failed to localize Ex3 string using: {0}", wxlFilePath); + NativeAssert::StringEqual(L"XxxThis is example #3yyY", sczValue); + + hr = StrAllocString(&sczValue, L"aaa#(loc.Ex4)bbb", 0); + NativeAssert::Succeeded(hr, "Failed to create localizable Ex4 string"); + + hr = LocLocalizeString(pLoc, &sczValue); + NativeAssert::Succeeded(hr, "Failed to localize Ex4 string using: {0}", wxlFilePath); + NativeAssert::StringEqual(L"aaabbb", sczValue); + } + finally + { + ReleaseStr(sczValue); + + if (pLoc) + { + LocFree(pLoc); + } + + DutilUninitialize(); + } + } + }; +} diff --git a/src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp deleted file mode 100644 index 0376a340..00000000 --- a/src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp +++ /dev/null @@ -1,151 +0,0 @@ -// 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; - -namespace DutilTests -{ - public ref class LocUtil - { - public: - [Fact] - void CanLoadStringsWxl() - { - HRESULT hr = S_OK; - WIX_LOCALIZATION* pLoc = NULL; - LOC_STRING* pLocString = NULL; - LPWSTR sczValue = NULL; - - DutilInitialize(&DutilTestTraceError); - - try - { - hr = XmlInitialize(); - NativeAssert::Succeeded(hr, "Failed to initialize Xml."); - - pin_ptr wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "strings.wxl")); - hr = LocLoadFromFile(wxlFilePath, &pLoc); - NativeAssert::Succeeded(hr, "Failed to parse strings.wxl: {0}", wxlFilePath); - - Assert::Equal(4ul, pLoc->cLocStrings); - - hr = LocGetString(pLoc, L"#(loc.Ex1)", &pLocString); - NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex1' from: {0}", wxlFilePath); - NativeAssert::StringEqual(L"#(loc.Ex1)", pLocString->wzId); - NativeAssert::StringEqual(L"This is example #1", pLocString->wzText); - NativeAssert::True(pLocString->bOverridable); - - hr = LocGetString(pLoc, L"#(loc.Ex2)", &pLocString); - NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex2' from: {0}", wxlFilePath); - NativeAssert::StringEqual(L"#(loc.Ex2)", pLocString->wzId); - NativeAssert::StringEqual(L"This is example #2", pLocString->wzText); - NativeAssert::False(pLocString->bOverridable); - - hr = LocGetString(pLoc, L"#(loc.Ex3)", &pLocString); - NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex3' from: {0}", wxlFilePath); - NativeAssert::StringEqual(L"#(loc.Ex3)", pLocString->wzId); - NativeAssert::StringEqual(L"This is example #3", pLocString->wzText); - NativeAssert::False(pLocString->bOverridable); - - hr = LocGetString(pLoc, L"#(loc.Ex4)", &pLocString); - NativeAssert::Succeeded(hr, "Failed to get loc string 'Ex4' from: {0}", wxlFilePath); - NativeAssert::StringEqual(L"#(loc.Ex4)", pLocString->wzId); - NativeAssert::StringEqual(L"", pLocString->wzText); - NativeAssert::False(pLocString->bOverridable); - - hr = StrAllocString(&sczValue, L"Before #(loc.Ex1) After", 0); - NativeAssert::Succeeded(hr, "Failed to create localizable Ex1 string"); - - hr = LocLocalizeString(pLoc, &sczValue); - NativeAssert::Succeeded(hr, "Failed to localize Ex1 string using: {0}", wxlFilePath); - NativeAssert::StringEqual(L"Before This is example #1 After", sczValue); - - hr = StrAllocString(&sczValue, L"Xxx#(loc.Ex3)yyY", 0); - NativeAssert::Succeeded(hr, "Failed to create localizable Ex3 string"); - - hr = LocLocalizeString(pLoc, &sczValue); - NativeAssert::Succeeded(hr, "Failed to localize Ex3 string using: {0}", wxlFilePath); - NativeAssert::StringEqual(L"XxxThis is example #3yyY", sczValue); - - hr = StrAllocString(&sczValue, L"aaa#(loc.Ex4)bbb", 0); - NativeAssert::Succeeded(hr, "Failed to create localizable Ex4 string"); - - hr = LocLocalizeString(pLoc, &sczValue); - NativeAssert::Succeeded(hr, "Failed to localize Ex4 string using: {0}", wxlFilePath); - NativeAssert::StringEqual(L"aaabbb", sczValue); - } - finally - { - ReleaseStr(sczValue); - - if (pLoc) - { - LocFree(pLoc); - } - - DutilUninitialize(); - } - } - - [Fact] - void CanLoadControlsWxl() - { - HRESULT hr = S_OK; - WIX_LOCALIZATION* pLoc = NULL; - LOC_CONTROL* pLocControl = NULL; - - DutilInitialize(&DutilTestTraceError); - - try - { - hr = XmlInitialize(); - NativeAssert::Succeeded(hr, "Failed to initialize Xml."); - - pin_ptr wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "controls.wxl")); - hr = LocLoadFromFile(wxlFilePath, &pLoc); - NativeAssert::Succeeded(hr, "Failed to parse controls.wxl: {0}", wxlFilePath); - - Assert::Equal(3ul, pLoc->cLocControls); - - hr = LocGetControl(pLoc, L"Control1", &pLocControl); - NativeAssert::Succeeded(hr, "Failed to get loc control 'Control1' from: {0}", wxlFilePath); - NativeAssert::StringEqual(L"Control1", pLocControl->wzControl); - NativeAssert::Equal(1, pLocControl->nX); - NativeAssert::Equal(2, pLocControl->nY); - NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nWidth); - NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nHeight); - NativeAssert::StringEqual(L"This is control #1", pLocControl->wzText); - - hr = LocGetControl(pLoc, L"Control2", &pLocControl); - NativeAssert::Succeeded(hr, "Failed to get loc control 'Control2' from: {0}", wxlFilePath); - NativeAssert::StringEqual(L"Control2", pLocControl->wzControl); - NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nX); - NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nY); - NativeAssert::Equal(50, pLocControl->nWidth); - NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nHeight); - NativeAssert::StringEqual(L"This is control #2", pLocControl->wzText); - - hr = LocGetControl(pLoc, L"Control3", &pLocControl); - NativeAssert::Succeeded(hr, "Failed to get loc control 'Control3' from: {0}", wxlFilePath); - NativeAssert::StringEqual(L"Control3", pLocControl->wzControl); - NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nX); - NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nY); - NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nWidth); - NativeAssert::Equal(150, pLocControl->nHeight); - NativeAssert::StringEqual(L"", pLocControl->wzText); - } - finally - { - if (pLoc) - { - LocFree(pLoc); - } - - DutilUninitialize(); - } - } - }; -} -- cgit v1.2.3-55-g6feb