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/dutil/test/DUtilUnitTest/LocUtilTests.cpp | |
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/dutil/test/DUtilUnitTest/LocUtilTests.cpp')
-rw-r--r-- | src/libs/dutil/test/DUtilUnitTest/LocUtilTests.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
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 | } | ||