diff options
| author | Rob Mensching <rob@firegiant.com> | 2022-10-25 11:20:31 -0700 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2022-10-31 10:57:14 -0700 |
| commit | 033f38a28c89945ce4379f5992e8f36943a125ab (patch) | |
| tree | 7feb7700b4bca1c0cff5bdb85af5e2d543e226c2 /src/libs | |
| parent | 217182f85fa737d20fb5846f395cabfa599bf1c6 (diff) | |
| download | wix-033f38a28c89945ce4379f5992e8f36943a125ab.tar.gz wix-033f38a28c89945ce4379f5992e8f36943a125ab.tar.bz2 wix-033f38a28c89945ce4379f5992e8f36943a125ab.zip | |
Loc files were still using inner text, stop doing that
Fixes 6970
Diffstat (limited to 'src/libs')
7 files changed, 183 insertions, 6 deletions
diff --git a/src/libs/dutil/WixToolset.DUtil/locutil.cpp b/src/libs/dutil/WixToolset.DUtil/locutil.cpp index c4567c03..318468b4 100644 --- a/src/libs/dutil/WixToolset.DUtil/locutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/locutil.cpp | |||
| @@ -561,10 +561,10 @@ static HRESULT ParseWxlString( | |||
| 561 | ReleaseNullBSTR(bstrText); | 561 | ReleaseNullBSTR(bstrText); |
| 562 | 562 | ||
| 563 | // Text | 563 | // Text |
| 564 | hr = XmlGetText(pixn, &bstrText); | 564 | hr = XmlGetAttribute(pixn, L"Value", &bstrText); |
| 565 | LocExitOnFailure(hr, "Failed to get Xml text in Wxl file."); | 565 | LocExitOnFailure(hr, "Failed to get Xml attribute Value in Wxl file."); |
| 566 | 566 | ||
| 567 | hr = StrAllocString(&pLocString->wzText, bstrText, 0); | 567 | hr = StrAllocString(&pLocString->wzText, bstrText ? bstrText : L"", 0); |
| 568 | LocExitOnFailure(hr, "Failed to duplicate Xml text in Wxl file."); | 568 | LocExitOnFailure(hr, "Failed to duplicate Xml text in Wxl file."); |
| 569 | 569 | ||
| 570 | LExit: | 570 | LExit: |
| @@ -615,10 +615,10 @@ static HRESULT ParseWxlControl( | |||
| 615 | LocExitOnFailure(hr, "Failed to get control height attribute."); | 615 | LocExitOnFailure(hr, "Failed to get control height attribute."); |
| 616 | 616 | ||
| 617 | // Text | 617 | // Text |
| 618 | hr = XmlGetText(pixn, &bstrText); | 618 | hr = XmlGetAttribute(pixn, L"Text", &bstrText); |
| 619 | LocExitOnFailure(hr, "Failed to get control text in Wxl file."); | 619 | LocExitOnFailure(hr, "Failed to get Xml attribute Text in Wxl file."); |
| 620 | 620 | ||
| 621 | hr = StrAllocString(&pLocControl->wzText, bstrText, 0); | 621 | hr = StrAllocString(&pLocControl->wzText, bstrText ? bstrText : L"", 0); |
| 622 | LocExitOnFailure(hr, "Failed to duplicate control text in Wxl file."); | 622 | LocExitOnFailure(hr, "Failed to duplicate control text in Wxl file."); |
| 623 | 623 | ||
| 624 | LExit: | 624 | LExit: |
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj index 210f50f5..ea66ef46 100644 --- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj +++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj | |||
| @@ -55,6 +55,7 @@ | |||
| 55 | <ClCompile Include="FileUtilTest.cpp" /> | 55 | <ClCompile Include="FileUtilTest.cpp" /> |
| 56 | <ClCompile Include="GuidUtilTest.cpp" /> | 56 | <ClCompile Include="GuidUtilTest.cpp" /> |
| 57 | <ClCompile Include="IniUtilTest.cpp" /> | 57 | <ClCompile Include="IniUtilTest.cpp" /> |
| 58 | <ClCompile Include="LocUtilTests.cpp" /> | ||
| 58 | <ClCompile Include="MemUtilTest.cpp" /> | 59 | <ClCompile Include="MemUtilTest.cpp" /> |
| 59 | <ClCompile Include="MonUtilTest.cpp" /> | 60 | <ClCompile Include="MonUtilTest.cpp" /> |
| 60 | <ClCompile Include="PathUtilTest.cpp" /> | 61 | <ClCompile Include="PathUtilTest.cpp" /> |
| @@ -82,6 +83,8 @@ | |||
| 82 | 83 | ||
| 83 | <ItemGroup> | 84 | <ItemGroup> |
| 84 | <None Include="TestData\ApupUtilTests\FeedBv2.0.xml" CopyToOutputDirectory="PreserveNewest" /> | 85 | <None Include="TestData\ApupUtilTests\FeedBv2.0.xml" CopyToOutputDirectory="PreserveNewest" /> |
| 86 | <None Include="TestData\LocUtilTests\controls.wxl" CopyToOutputDirectory="PreserveNewest" /> | ||
| 87 | <None Include="TestData\LocUtilTests\strings.wxl" CopyToOutputDirectory="PreserveNewest" /> | ||
| 85 | </ItemGroup> | 88 | </ItemGroup> |
| 86 | 89 | ||
| 87 | <ItemGroup> | 90 | <ItemGroup> |
diff --git a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters index f1d9c307..d216f2af 100644 --- a/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters +++ b/src/libs/dutil/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters | |||
| @@ -75,6 +75,9 @@ | |||
| 75 | <ClCompile Include="VerUtilTests.cpp"> | 75 | <ClCompile Include="VerUtilTests.cpp"> |
| 76 | <Filter>Source Files</Filter> | 76 | <Filter>Source Files</Filter> |
| 77 | </ClCompile> | 77 | </ClCompile> |
| 78 | <ClCompile Include="LocUtilTests.cpp"> | ||
| 79 | <Filter>Source Files</Filter> | ||
| 80 | </ClCompile> | ||
| 78 | </ItemGroup> | 81 | </ItemGroup> |
| 79 | <ItemGroup> | 82 | <ItemGroup> |
| 80 | <ResourceCompile Include="UnitTest.rc"> | 83 | <ResourceCompile Include="UnitTest.rc"> |
| @@ -89,4 +92,12 @@ | |||
| 89 | <Filter>Header Files</Filter> | 92 | <Filter>Header Files</Filter> |
| 90 | </ClInclude> | 93 | </ClInclude> |
| 91 | </ItemGroup> | 94 | </ItemGroup> |
| 95 | <ItemGroup> | ||
| 96 | <None Include="$(MSBuildThisFileDirectory)xunit.runner.visualstudio.testadapter.dll" /> | ||
| 97 | <None Include="$(MSBuildThisFileDirectory)xunit.runner.reporters.net452.dll" /> | ||
| 98 | <None Include="$(MSBuildThisFileDirectory)xunit.runner.utility.net452.dll" /> | ||
| 99 | <None Include="$(MSBuildThisFileDirectory)xunit.abstractions.dll" /> | ||
| 100 | <None Include="TestData\ApupUtilTests\FeedBv2.0.xml" /> | ||
| 101 | <None Include="TestData\LocUtilTests\strings.wxl" /> | ||
| 102 | </ItemGroup> | ||
| 92 | </Project> \ No newline at end of file | 103 | </Project> \ No newline at end of file |
diff --git a/src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp b/src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp new file mode 100644 index 00000000..c30ae2e1 --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp | |||
| @@ -0,0 +1,151 @@ | |||
| 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 LocUtil | ||
| 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 | [Fact] | ||
| 94 | void CanLoadControlsWxl() | ||
| 95 | { | ||
| 96 | HRESULT hr = S_OK; | ||
| 97 | WIX_LOCALIZATION* pLoc = NULL; | ||
| 98 | LOC_CONTROL* pLocControl = NULL; | ||
| 99 | |||
| 100 | DutilInitialize(&DutilTestTraceError); | ||
| 101 | |||
| 102 | try | ||
| 103 | { | ||
| 104 | hr = XmlInitialize(); | ||
| 105 | NativeAssert::Succeeded(hr, "Failed to initialize Xml."); | ||
| 106 | |||
| 107 | pin_ptr<const wchar_t> wxlFilePath = PtrToStringChars(TestData::Get("TestData", "LocUtilTests", "controls.wxl")); | ||
| 108 | hr = LocLoadFromFile(wxlFilePath, &pLoc); | ||
| 109 | NativeAssert::Succeeded(hr, "Failed to parse controls.wxl: {0}", wxlFilePath); | ||
| 110 | |||
| 111 | Assert::Equal(3ul, pLoc->cLocControls); | ||
| 112 | |||
| 113 | hr = LocGetControl(pLoc, L"Control1", &pLocControl); | ||
| 114 | NativeAssert::Succeeded(hr, "Failed to get loc control 'Control1' from: {0}", wxlFilePath); | ||
| 115 | NativeAssert::StringEqual(L"Control1", pLocControl->wzControl); | ||
| 116 | NativeAssert::Equal(1, pLocControl->nX); | ||
| 117 | NativeAssert::Equal(2, pLocControl->nY); | ||
| 118 | NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nWidth); | ||
| 119 | NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nHeight); | ||
| 120 | NativeAssert::StringEqual(L"This is control #1", pLocControl->wzText); | ||
| 121 | |||
| 122 | hr = LocGetControl(pLoc, L"Control2", &pLocControl); | ||
| 123 | NativeAssert::Succeeded(hr, "Failed to get loc control 'Control2' from: {0}", wxlFilePath); | ||
| 124 | NativeAssert::StringEqual(L"Control2", pLocControl->wzControl); | ||
| 125 | NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nX); | ||
| 126 | NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nY); | ||
| 127 | NativeAssert::Equal(50, pLocControl->nWidth); | ||
| 128 | NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nHeight); | ||
| 129 | NativeAssert::StringEqual(L"This is control #2", pLocControl->wzText); | ||
| 130 | |||
| 131 | hr = LocGetControl(pLoc, L"Control3", &pLocControl); | ||
| 132 | NativeAssert::Succeeded(hr, "Failed to get loc control 'Control3' from: {0}", wxlFilePath); | ||
| 133 | NativeAssert::StringEqual(L"Control3", pLocControl->wzControl); | ||
| 134 | NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nX); | ||
| 135 | NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nY); | ||
| 136 | NativeAssert::Equal(LOC_CONTROL_NOT_SET, pLocControl->nWidth); | ||
| 137 | NativeAssert::Equal(150, pLocControl->nHeight); | ||
| 138 | NativeAssert::StringEqual(L"", pLocControl->wzText); | ||
| 139 | } | ||
| 140 | finally | ||
| 141 | { | ||
| 142 | if (pLoc) | ||
| 143 | { | ||
| 144 | LocFree(pLoc); | ||
| 145 | } | ||
| 146 | |||
| 147 | DutilUninitialize(); | ||
| 148 | } | ||
| 149 | } | ||
| 150 | }; | ||
| 151 | } | ||
diff --git a/src/libs/dutil/test/DUtilUnitTest/TestData/LocUtilTests/controls.wxl b/src/libs/dutil/test/DUtilUnitTest/TestData/LocUtilTests/controls.wxl new file mode 100644 index 00000000..938ae0a9 --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/TestData/LocUtilTests/controls.wxl | |||
| @@ -0,0 +1,5 @@ | |||
| 1 | <WixLocalization Culture="en-us" xmlns="http://wixtoolset.org/schemas/v4/wxl"> | ||
| 2 | <UI Control="Control1" X="1" Y="2" Text="This is control #1"></UI> | ||
| 3 | <UI Control="Control2" Width="50" Text="This is control #2" /> | ||
| 4 | <UI Control="Control3" Height="150" /> | ||
| 5 | </WixLocalization> | ||
diff --git a/src/libs/dutil/test/DUtilUnitTest/TestData/LocUtilTests/strings.wxl b/src/libs/dutil/test/DUtilUnitTest/TestData/LocUtilTests/strings.wxl new file mode 100644 index 00000000..98e58741 --- /dev/null +++ b/src/libs/dutil/test/DUtilUnitTest/TestData/LocUtilTests/strings.wxl | |||
| @@ -0,0 +1,6 @@ | |||
| 1 | <WixLocalization Culture="en-us" xmlns="http://wixtoolset.org/schemas/v4/wxl"> | ||
| 2 | <String Id="Ex1" Overridable="yes" Value="This is example #1" /> | ||
| 3 | <String Id="Ex2" Overridable="no" Value="This is example #2"></String> | ||
| 4 | <String Id="Ex3" Value="This is example #3"></String> | ||
| 5 | <String Id="Ex4" /> | ||
| 6 | </WixLocalization> | ||
diff --git a/src/libs/dutil/test/DUtilUnitTest/precomp.h b/src/libs/dutil/test/DUtilUnitTest/precomp.h index a5542774..92310b41 100644 --- a/src/libs/dutil/test/DUtilUnitTest/precomp.h +++ b/src/libs/dutil/test/DUtilUnitTest/precomp.h | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | #include <fileutil.h> | 21 | #include <fileutil.h> |
| 22 | #include <guidutil.h> | 22 | #include <guidutil.h> |
| 23 | #include <iniutil.h> | 23 | #include <iniutil.h> |
| 24 | #include <locutil.h> | ||
| 24 | #include <memutil.h> | 25 | #include <memutil.h> |
| 25 | #include <pathutil.h> | 26 | #include <pathutil.h> |
| 26 | #include <procutil.h> | 27 | #include <procutil.h> |
