aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2020-08-29 21:29:28 -0500
committerSean Hall <r.sean.hall@gmail.com>2020-10-24 20:03:38 -0500
commitd1d31466bb9f2e887a277807d60378afef9cc57d (patch)
tree90b0185ce83f4ec5d986205aff2ce2487d3260de /src/test
parent281ad838c5001f988aeea06a6f06ce2cc6c0991d (diff)
downloadwix-d1d31466bb9f2e887a277807d60378afef9cc57d.tar.gz
wix-d1d31466bb9f2e887a277807d60378afef9cc57d.tar.bz2
wix-d1d31466bb9f2e887a277807d60378afef9cc57d.zip
WIXFEAT:6210 Parse and compare bundle versions kind of like SemVer.
Diffstat (limited to 'src/test')
-rw-r--r--src/test/DUtilUnitTest/DUtilUnitTest.vcxproj1
-rw-r--r--src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters3
-rw-r--r--src/test/DUtilUnitTest/VerUtilTests.cpp891
-rw-r--r--src/test/DUtilUnitTest/precomp.h1
4 files changed, 896 insertions, 0 deletions
diff --git a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj
index 4c660aa9..31b5a5c0 100644
--- a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj
+++ b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj
@@ -49,6 +49,7 @@
49 <ClCompile Include="SceUtilTest.cpp" Condition=" Exists('$(SqlCESdkIncludePath)') " /> 49 <ClCompile Include="SceUtilTest.cpp" Condition=" Exists('$(SqlCESdkIncludePath)') " />
50 <ClCompile Include="StrUtilTest.cpp" /> 50 <ClCompile Include="StrUtilTest.cpp" />
51 <ClCompile Include="UriUtilTest.cpp" /> 51 <ClCompile Include="UriUtilTest.cpp" />
52 <ClCompile Include="VerUtilTests.cpp" />
52 </ItemGroup> 53 </ItemGroup>
53 <ItemGroup> 54 <ItemGroup>
54 <ClInclude Include="precomp.h" /> 55 <ClInclude Include="precomp.h" />
diff --git a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
index 0c83e3fa..fdc6d278 100644
--- a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
+++ b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters
@@ -57,6 +57,9 @@
57 <ClCompile Include="UriUtilTest.cpp"> 57 <ClCompile Include="UriUtilTest.cpp">
58 <Filter>Source Files</Filter> 58 <Filter>Source Files</Filter>
59 </ClCompile> 59 </ClCompile>
60 <ClCompile Include="VerUtilTests.cpp">
61 <Filter>Source Files</Filter>
62 </ClCompile>
60 </ItemGroup> 63 </ItemGroup>
61 <ItemGroup> 64 <ItemGroup>
62 <ResourceCompile Include="UnitTest.rc"> 65 <ResourceCompile Include="UnitTest.rc">
diff --git a/src/test/DUtilUnitTest/VerUtilTests.cpp b/src/test/DUtilUnitTest/VerUtilTests.cpp
new file mode 100644
index 00000000..58b561e9
--- /dev/null
+++ b/src/test/DUtilUnitTest/VerUtilTests.cpp
@@ -0,0 +1,891 @@
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
5using namespace System;
6using namespace Xunit;
7using namespace WixBuildTools::TestSupport;
8
9namespace DutilTests
10{
11 public ref class VerUtil
12 {
13 public:
14 [Fact]
15 void VerCompareVersionsTreatsMissingRevisionAsZero()
16 {
17 HRESULT hr = S_OK;
18 VERUTIL_VERSION* pVersion1 = NULL;
19 VERUTIL_VERSION* pVersion2 = NULL;
20 VERUTIL_VERSION* pVersion3 = NULL;
21 LPCWSTR wzVersion1 = L"1.2.3.4";
22 LPCWSTR wzVersion2 = L"1.2.3";
23 LPCWSTR wzVersion3 = L"1.2.3.0";
24
25 try
26 {
27 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
28 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
29
30 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
31 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
32
33 hr = VerParseVersion(wzVersion3, 0, FALSE, &pVersion3);
34 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion3);
35
36 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
37 Assert::Equal<DWORD>(1, pVersion1->dwMajor);
38 Assert::Equal<DWORD>(2, pVersion1->dwMinor);
39 Assert::Equal<DWORD>(3, pVersion1->dwPatch);
40 Assert::Equal<DWORD>(4, pVersion1->dwRevision);
41 Assert::Equal<DWORD>(0, pVersion1->cReleaseLabels);
42 Assert::Equal<DWORD>(7, pVersion1->cchMetadataOffset);
43 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
44
45 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
46 Assert::Equal<DWORD>(1, pVersion2->dwMajor);
47 Assert::Equal<DWORD>(2, pVersion2->dwMinor);
48 Assert::Equal<DWORD>(3, pVersion2->dwPatch);
49 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
50 Assert::Equal<DWORD>(0, pVersion2->cReleaseLabels);
51 Assert::Equal<DWORD>(5, pVersion2->cchMetadataOffset);
52 Assert::Equal<BOOL>(FALSE, pVersion2->fInvalid);
53
54 NativeAssert::StringEqual(wzVersion3, pVersion3->sczVersion);
55 Assert::Equal<DWORD>(1, pVersion3->dwMajor);
56 Assert::Equal<DWORD>(2, pVersion3->dwMinor);
57 Assert::Equal<DWORD>(3, pVersion3->dwPatch);
58 Assert::Equal<DWORD>(0, pVersion3->dwRevision);
59 Assert::Equal<DWORD>(0, pVersion3->cReleaseLabels);
60 Assert::Equal<DWORD>(7, pVersion3->cchMetadataOffset);
61 Assert::Equal<BOOL>(FALSE, pVersion3->fInvalid);
62
63 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1);
64 TestVerutilCompareParsedVersions(pVersion3, pVersion2, 0);
65 }
66 finally
67 {
68 ReleaseVerutilVersion(pVersion1);
69 ReleaseVerutilVersion(pVersion2);
70 ReleaseVerutilVersion(pVersion3);
71 }
72 }
73
74 [Fact]
75 void VerCompareVersionsTreatsNumericReleaseLabelsAsNumbers()
76 {
77 HRESULT hr = S_OK;
78 VERUTIL_VERSION* pVersion1 = NULL;
79 VERUTIL_VERSION* pVersion2 = NULL;
80 LPCWSTR wzVersion1 = L"1.0-2.0";
81 LPCWSTR wzVersion2 = L"1.0-19";
82
83 try
84 {
85 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
86 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
87
88 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
89 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
90
91 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
92 Assert::Equal<DWORD>(1, pVersion1->dwMajor);
93 Assert::Equal<DWORD>(0, pVersion1->dwMinor);
94 Assert::Equal<DWORD>(0, pVersion1->dwPatch);
95 Assert::Equal<DWORD>(0, pVersion1->dwRevision);
96 Assert::Equal<DWORD>(2, pVersion1->cReleaseLabels);
97
98 Assert::Equal<BOOL>(TRUE, pVersion1->rgReleaseLabels[0].fNumeric);
99 Assert::Equal<DWORD>(2, pVersion1->rgReleaseLabels[0].dwValue);
100 Assert::Equal<DWORD>(1, pVersion1->rgReleaseLabels[0].cchLabel);
101 Assert::Equal<DWORD>(4, pVersion1->rgReleaseLabels[0].cchLabelOffset);
102
103 Assert::Equal<BOOL>(TRUE, pVersion1->rgReleaseLabels[1].fNumeric);
104 Assert::Equal<DWORD>(0, pVersion1->rgReleaseLabels[1].dwValue);
105 Assert::Equal<DWORD>(1, pVersion1->rgReleaseLabels[1].cchLabel);
106 Assert::Equal<DWORD>(6, pVersion1->rgReleaseLabels[1].cchLabelOffset);
107
108 Assert::Equal<DWORD>(7, pVersion1->cchMetadataOffset);
109 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
110
111 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
112 Assert::Equal<DWORD>(1, pVersion2->dwMajor);
113 Assert::Equal<DWORD>(0, pVersion2->dwMinor);
114 Assert::Equal<DWORD>(0, pVersion2->dwPatch);
115 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
116 Assert::Equal<DWORD>(1, pVersion2->cReleaseLabels);
117
118 Assert::Equal<BOOL>(TRUE, pVersion2->rgReleaseLabels[0].fNumeric);
119 Assert::Equal<DWORD>(19, pVersion2->rgReleaseLabels[0].dwValue);
120 Assert::Equal<DWORD>(2, pVersion2->rgReleaseLabels[0].cchLabel);
121 Assert::Equal<DWORD>(4, pVersion2->rgReleaseLabels[0].cchLabelOffset);
122
123 Assert::Equal<DWORD>(6, pVersion2->cchMetadataOffset);
124 Assert::Equal<BOOL>(FALSE, pVersion2->fInvalid);
125
126 TestVerutilCompareParsedVersions(pVersion1, pVersion2, -1);
127 }
128 finally
129 {
130 ReleaseVerutilVersion(pVersion1);
131 ReleaseVerutilVersion(pVersion2);
132 }
133 }
134
135 [Fact]
136 void VerCompareVersionsHandlesNormallyInvalidVersions()
137 {
138 HRESULT hr = S_OK;
139 VERUTIL_VERSION* pVersion1 = NULL;
140 VERUTIL_VERSION* pVersion2 = NULL;
141 VERUTIL_VERSION* pVersion3 = NULL;
142 VERUTIL_VERSION* pVersion4 = NULL;
143 VERUTIL_VERSION* pVersion5 = NULL;
144 VERUTIL_VERSION* pVersion6 = NULL;
145 LPCWSTR wzVersion1 = L"10.-4.0";
146 LPCWSTR wzVersion2 = L"10.-2.0";
147 LPCWSTR wzVersion3 = L"0";
148 LPCWSTR wzVersion4 = L"";
149 LPCWSTR wzVersion5 = L"10-2";
150 LPCWSTR wzVersion6 = L"10-4.@";
151
152 try
153 {
154 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
155 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
156
157 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
158 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
159
160 hr = VerParseVersion(wzVersion3, 0, FALSE, &pVersion3);
161 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion3);
162
163 hr = VerParseVersion(wzVersion4, 0, FALSE, &pVersion4);
164 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion4);
165
166 hr = VerParseVersion(wzVersion5, 0, FALSE, &pVersion5);
167 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion5);
168
169 hr = VerParseVersion(wzVersion6, 0, FALSE, &pVersion6);
170 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion6);
171
172 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
173 Assert::Equal<DWORD>(10, pVersion1->dwMajor);
174 Assert::Equal<DWORD>(0, pVersion1->dwMinor);
175 Assert::Equal<DWORD>(0, pVersion1->dwPatch);
176 Assert::Equal<DWORD>(0, pVersion1->dwRevision);
177 Assert::Equal<DWORD>(0, pVersion1->cReleaseLabels);
178 Assert::Equal<DWORD>(3, pVersion1->cchMetadataOffset);
179 Assert::Equal<BOOL>(TRUE, pVersion1->fInvalid);
180
181 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
182 Assert::Equal<DWORD>(10, pVersion2->dwMajor);
183 Assert::Equal<DWORD>(0, pVersion2->dwMinor);
184 Assert::Equal<DWORD>(0, pVersion2->dwPatch);
185 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
186 Assert::Equal<DWORD>(0, pVersion2->cReleaseLabels);
187 Assert::Equal<DWORD>(3, pVersion2->cchMetadataOffset);
188 Assert::Equal<BOOL>(TRUE, pVersion2->fInvalid);
189
190 NativeAssert::StringEqual(wzVersion3, pVersion3->sczVersion);
191 Assert::Equal<DWORD>(0, pVersion3->dwMajor);
192 Assert::Equal<DWORD>(0, pVersion3->dwMinor);
193 Assert::Equal<DWORD>(0, pVersion3->dwPatch);
194 Assert::Equal<DWORD>(0, pVersion3->dwRevision);
195 Assert::Equal<DWORD>(0, pVersion3->cReleaseLabels);
196 Assert::Equal<DWORD>(1, pVersion3->cchMetadataOffset);
197 Assert::Equal<BOOL>(FALSE, pVersion3->fInvalid);
198
199 NativeAssert::StringEqual(wzVersion4, pVersion4->sczVersion);
200 Assert::Equal<DWORD>(0, pVersion4->dwMajor);
201 Assert::Equal<DWORD>(0, pVersion4->dwMinor);
202 Assert::Equal<DWORD>(0, pVersion4->dwPatch);
203 Assert::Equal<DWORD>(0, pVersion4->dwRevision);
204 Assert::Equal<DWORD>(0, pVersion4->cReleaseLabels);
205 Assert::Equal<DWORD>(0, pVersion4->cchMetadataOffset);
206 Assert::Equal<BOOL>(TRUE, pVersion4->fInvalid);
207
208 NativeAssert::StringEqual(wzVersion5, pVersion5->sczVersion);
209 Assert::Equal<DWORD>(10, pVersion5->dwMajor);
210 Assert::Equal<DWORD>(0, pVersion5->dwMinor);
211 Assert::Equal<DWORD>(0, pVersion5->dwPatch);
212 Assert::Equal<DWORD>(0, pVersion5->dwRevision);
213 Assert::Equal<DWORD>(1, pVersion5->cReleaseLabels);
214
215 Assert::Equal<BOOL>(TRUE, pVersion5->rgReleaseLabels[0].fNumeric);
216 Assert::Equal<DWORD>(2, pVersion5->rgReleaseLabels[0].dwValue);
217 Assert::Equal<DWORD>(1, pVersion5->rgReleaseLabels[0].cchLabel);
218 Assert::Equal<DWORD>(3, pVersion5->rgReleaseLabels[0].cchLabelOffset);
219
220 Assert::Equal<DWORD>(4, pVersion5->cchMetadataOffset);
221 Assert::Equal<BOOL>(FALSE, pVersion5->fInvalid);
222
223 NativeAssert::StringEqual(wzVersion6, pVersion6->sczVersion);
224 Assert::Equal<DWORD>(10, pVersion6->dwMajor);
225 Assert::Equal<DWORD>(0, pVersion6->dwMinor);
226 Assert::Equal<DWORD>(0, pVersion6->dwPatch);
227 Assert::Equal<DWORD>(0, pVersion6->dwRevision);
228 Assert::Equal<DWORD>(1, pVersion6->cReleaseLabels);
229
230 Assert::Equal<BOOL>(TRUE, pVersion6->rgReleaseLabels[0].fNumeric);
231 Assert::Equal<DWORD>(4, pVersion6->rgReleaseLabels[0].dwValue);
232 Assert::Equal<DWORD>(1, pVersion6->rgReleaseLabels[0].cchLabel);
233 Assert::Equal<DWORD>(3, pVersion6->rgReleaseLabels[0].cchLabelOffset);
234
235 Assert::Equal<DWORD>(5, pVersion6->cchMetadataOffset);
236 Assert::Equal<BOOL>(TRUE, pVersion6->fInvalid);
237
238 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1);
239 TestVerutilCompareParsedVersions(pVersion3, pVersion4, 1);
240 TestVerutilCompareParsedVersions(pVersion5, pVersion6, 1);
241 }
242 finally
243 {
244 ReleaseVerutilVersion(pVersion1);
245 ReleaseVerutilVersion(pVersion2);
246 ReleaseVerutilVersion(pVersion3);
247 ReleaseVerutilVersion(pVersion4);
248 ReleaseVerutilVersion(pVersion5);
249 ReleaseVerutilVersion(pVersion6);
250 }
251 }
252
253 [Fact]
254 void VerCompareVersionsTreatsHyphenAsVersionSeparator()
255 {
256 HRESULT hr = S_OK;
257 VERUTIL_VERSION* pVersion1 = NULL;
258 VERUTIL_VERSION* pVersion2 = NULL;
259 VERUTIL_VERSION* pVersion3 = NULL;
260 LPCWSTR wzVersion1 = L"0.0.1-a";
261 LPCWSTR wzVersion2 = L"0-2";
262 LPCWSTR wzVersion3 = L"1-2";
263
264 try
265 {
266 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
267 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
268
269 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
270 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
271
272 hr = VerParseVersion(wzVersion3, 0, FALSE, &pVersion3);
273 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion3);
274
275 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
276 Assert::Equal<DWORD>(0, pVersion1->dwMajor);
277 Assert::Equal<DWORD>(0, pVersion1->dwMinor);
278 Assert::Equal<DWORD>(1, pVersion1->dwPatch);
279 Assert::Equal<DWORD>(0, pVersion1->dwRevision);
280 Assert::Equal<DWORD>(1, pVersion1->cReleaseLabels);
281
282 Assert::Equal<BOOL>(FALSE, pVersion1->rgReleaseLabels[0].fNumeric);
283 Assert::Equal<DWORD>(1, pVersion1->rgReleaseLabels[0].cchLabel);
284 Assert::Equal<DWORD>(6, pVersion1->rgReleaseLabels[0].cchLabelOffset);
285
286 Assert::Equal<DWORD>(7, pVersion1->cchMetadataOffset);
287 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
288
289 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
290 Assert::Equal<DWORD>(0, pVersion2->dwMajor);
291 Assert::Equal<DWORD>(0, pVersion2->dwMinor);
292 Assert::Equal<DWORD>(0, pVersion2->dwPatch);
293 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
294 Assert::Equal<DWORD>(1, pVersion2->cReleaseLabels);
295
296 Assert::Equal<BOOL>(TRUE, pVersion2->rgReleaseLabels[0].fNumeric);
297 Assert::Equal<DWORD>(2, pVersion2->rgReleaseLabels[0].dwValue);
298 Assert::Equal<DWORD>(1, pVersion2->rgReleaseLabels[0].cchLabel);
299 Assert::Equal<DWORD>(2, pVersion2->rgReleaseLabels[0].cchLabelOffset);
300
301 Assert::Equal<DWORD>(3, pVersion2->cchMetadataOffset);
302 Assert::Equal<BOOL>(FALSE, pVersion2->fInvalid);
303
304 NativeAssert::StringEqual(wzVersion3, pVersion3->sczVersion);
305 Assert::Equal<DWORD>(1, pVersion3->dwMajor);
306 Assert::Equal<DWORD>(0, pVersion3->dwMinor);
307 Assert::Equal<DWORD>(0, pVersion3->dwPatch);
308 Assert::Equal<DWORD>(0, pVersion3->dwRevision);
309 Assert::Equal<DWORD>(1, pVersion3->cReleaseLabels);
310
311 Assert::Equal<BOOL>(TRUE, pVersion3->rgReleaseLabels[0].fNumeric);
312 Assert::Equal<DWORD>(2, pVersion3->rgReleaseLabels[0].dwValue);
313 Assert::Equal<DWORD>(1, pVersion3->rgReleaseLabels[0].cchLabel);
314 Assert::Equal<DWORD>(2, pVersion3->rgReleaseLabels[0].cchLabelOffset);
315
316 Assert::Equal<DWORD>(3, pVersion3->cchMetadataOffset);
317 Assert::Equal<BOOL>(FALSE, pVersion3->fInvalid);
318
319 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1);
320 TestVerutilCompareParsedVersions(pVersion1, pVersion3, -1);
321 }
322 finally
323 {
324 ReleaseVerutilVersion(pVersion1);
325 ReleaseVerutilVersion(pVersion2);
326 ReleaseVerutilVersion(pVersion3);
327 }
328 }
329
330 [Fact]
331 void VerCompareVersionsIgnoresLeadingZeroes()
332 {
333 HRESULT hr = S_OK;
334 VERUTIL_VERSION* pVersion1 = NULL;
335 VERUTIL_VERSION* pVersion2 = NULL;
336 VERUTIL_VERSION* pVersion3 = NULL;
337 VERUTIL_VERSION* pVersion4 = NULL;
338 LPCWSTR wzVersion1 = L"0.01-a.1";
339 LPCWSTR wzVersion2 = L"0.1.0-a.1";
340 LPCWSTR wzVersion3 = L"0.1-a.b.0";
341 LPCWSTR wzVersion4 = L"0.1.0-a.b.000";
342
343 try
344 {
345 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
346 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
347
348 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
349 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
350
351 hr = VerParseVersion(wzVersion3, 0, FALSE, &pVersion3);
352 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion3);
353
354 hr = VerParseVersion(wzVersion4, 0, FALSE, &pVersion4);
355 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion4);
356
357 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
358 Assert::Equal<DWORD>(0, pVersion1->dwMajor);
359 Assert::Equal<DWORD>(1, pVersion1->dwMinor);
360 Assert::Equal<DWORD>(0, pVersion1->dwPatch);
361 Assert::Equal<DWORD>(0, pVersion1->dwRevision);
362 Assert::Equal<DWORD>(2, pVersion1->cReleaseLabels);
363
364 Assert::Equal<BOOL>(FALSE, pVersion1->rgReleaseLabels[0].fNumeric);
365 Assert::Equal<DWORD>(1, pVersion1->rgReleaseLabels[0].cchLabel);
366 Assert::Equal<DWORD>(5, pVersion1->rgReleaseLabels[0].cchLabelOffset);
367
368 Assert::Equal<BOOL>(TRUE, pVersion1->rgReleaseLabels[1].fNumeric);
369 Assert::Equal<DWORD>(1, pVersion1->rgReleaseLabels[1].dwValue);
370 Assert::Equal<DWORD>(1, pVersion1->rgReleaseLabels[1].cchLabel);
371 Assert::Equal<DWORD>(7, pVersion1->rgReleaseLabels[1].cchLabelOffset);
372
373 Assert::Equal<DWORD>(8, pVersion1->cchMetadataOffset);
374 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
375
376 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
377 Assert::Equal<DWORD>(0, pVersion2->dwMajor);
378 Assert::Equal<DWORD>(1, pVersion2->dwMinor);
379 Assert::Equal<DWORD>(0, pVersion2->dwPatch);
380 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
381 Assert::Equal<DWORD>(2, pVersion2->cReleaseLabels);
382
383 Assert::Equal<BOOL>(FALSE, pVersion2->rgReleaseLabels[0].fNumeric);
384 Assert::Equal<DWORD>(1, pVersion2->rgReleaseLabels[0].cchLabel);
385 Assert::Equal<DWORD>(6, pVersion2->rgReleaseLabels[0].cchLabelOffset);
386
387 Assert::Equal<BOOL>(TRUE, pVersion2->rgReleaseLabels[1].fNumeric);
388 Assert::Equal<DWORD>(1, pVersion2->rgReleaseLabels[1].dwValue);
389 Assert::Equal<DWORD>(1, pVersion2->rgReleaseLabels[1].cchLabel);
390 Assert::Equal<DWORD>(8, pVersion2->rgReleaseLabels[1].cchLabelOffset);
391
392 Assert::Equal<DWORD>(9, pVersion2->cchMetadataOffset);
393 Assert::Equal<BOOL>(FALSE, pVersion2->fInvalid);
394
395 NativeAssert::StringEqual(wzVersion3, pVersion3->sczVersion);
396 Assert::Equal<DWORD>(0, pVersion3->dwMajor);
397 Assert::Equal<DWORD>(1, pVersion3->dwMinor);
398 Assert::Equal<DWORD>(0, pVersion3->dwPatch);
399 Assert::Equal<DWORD>(0, pVersion3->dwRevision);
400 Assert::Equal<DWORD>(3, pVersion3->cReleaseLabels);
401
402 Assert::Equal<BOOL>(FALSE, pVersion3->rgReleaseLabels[0].fNumeric);
403 Assert::Equal<DWORD>(1, pVersion3->rgReleaseLabels[0].cchLabel);
404 Assert::Equal<DWORD>(4, pVersion3->rgReleaseLabels[0].cchLabelOffset);
405
406 Assert::Equal<BOOL>(FALSE, pVersion3->rgReleaseLabels[1].fNumeric);
407 Assert::Equal<DWORD>(1, pVersion3->rgReleaseLabels[1].cchLabel);
408 Assert::Equal<DWORD>(6, pVersion3->rgReleaseLabels[1].cchLabelOffset);
409
410 Assert::Equal<BOOL>(TRUE, pVersion3->rgReleaseLabels[2].fNumeric);
411 Assert::Equal<DWORD>(0, pVersion3->rgReleaseLabels[2].dwValue);
412 Assert::Equal<DWORD>(1, pVersion3->rgReleaseLabels[2].cchLabel);
413 Assert::Equal<DWORD>(8, pVersion3->rgReleaseLabels[2].cchLabelOffset);
414
415 Assert::Equal<DWORD>(9, pVersion3->cchMetadataOffset);
416 Assert::Equal<BOOL>(FALSE, pVersion3->fInvalid);
417
418 NativeAssert::StringEqual(wzVersion4, pVersion4->sczVersion);
419 Assert::Equal<DWORD>(0, pVersion4->dwMajor);
420 Assert::Equal<DWORD>(1, pVersion4->dwMinor);
421 Assert::Equal<DWORD>(0, pVersion4->dwPatch);
422 Assert::Equal<DWORD>(0, pVersion4->dwRevision);
423 Assert::Equal<DWORD>(3, pVersion4->cReleaseLabels);
424
425 Assert::Equal<BOOL>(FALSE, pVersion4->rgReleaseLabels[0].fNumeric);
426 Assert::Equal<DWORD>(1, pVersion4->rgReleaseLabels[0].cchLabel);
427 Assert::Equal<DWORD>(6, pVersion4->rgReleaseLabels[0].cchLabelOffset);
428
429 Assert::Equal<BOOL>(FALSE, pVersion4->rgReleaseLabels[1].fNumeric);
430 Assert::Equal<DWORD>(1, pVersion4->rgReleaseLabels[1].cchLabel);
431 Assert::Equal<DWORD>(8, pVersion4->rgReleaseLabels[1].cchLabelOffset);
432
433 Assert::Equal<BOOL>(TRUE, pVersion4->rgReleaseLabels[2].fNumeric);
434 Assert::Equal<DWORD>(0, pVersion4->rgReleaseLabels[2].dwValue);
435 Assert::Equal<DWORD>(3, pVersion4->rgReleaseLabels[2].cchLabel);
436 Assert::Equal<DWORD>(10, pVersion4->rgReleaseLabels[2].cchLabelOffset);
437
438 Assert::Equal<DWORD>(13, pVersion4->cchMetadataOffset);
439 Assert::Equal<BOOL>(FALSE, pVersion4->fInvalid);
440
441 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 0);
442 TestVerutilCompareParsedVersions(pVersion3, pVersion4, 0);
443 }
444 finally
445 {
446 ReleaseVerutilVersion(pVersion1);
447 ReleaseVerutilVersion(pVersion2);
448 ReleaseVerutilVersion(pVersion3);
449 ReleaseVerutilVersion(pVersion4);
450 }
451 }
452
453 [Fact]
454 void VerCompareVersionsTreatsUnexpectedContentAsMetadata()
455 {
456 HRESULT hr = S_OK;
457 VERUTIL_VERSION* pVersion1 = NULL;
458 VERUTIL_VERSION* pVersion2 = NULL;
459 VERUTIL_VERSION* pVersion3 = NULL;
460 LPCWSTR wzVersion1 = L"1.2.3+abcd";
461 LPCWSTR wzVersion2 = L"1.2.3.abcd";
462 LPCWSTR wzVersion3 = L"1.2.3.-abcd";
463
464 try
465 {
466 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
467 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
468
469 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
470 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
471
472 hr = VerParseVersion(wzVersion3, 0, FALSE, &pVersion3);
473 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion3);
474
475 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
476 Assert::Equal<DWORD>(1, pVersion1->dwMajor);
477 Assert::Equal<DWORD>(2, pVersion1->dwMinor);
478 Assert::Equal<DWORD>(3, pVersion1->dwPatch);
479 Assert::Equal<DWORD>(0, pVersion1->dwRevision);
480 Assert::Equal<DWORD>(0, pVersion1->cReleaseLabels);
481 Assert::Equal<DWORD>(6, pVersion1->cchMetadataOffset);
482 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
483
484 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
485 Assert::Equal<DWORD>(1, pVersion2->dwMajor);
486 Assert::Equal<DWORD>(2, pVersion2->dwMinor);
487 Assert::Equal<DWORD>(3, pVersion2->dwPatch);
488 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
489 Assert::Equal<DWORD>(0, pVersion2->cReleaseLabels);
490 Assert::Equal<DWORD>(6, pVersion2->cchMetadataOffset);
491 Assert::Equal<BOOL>(TRUE, pVersion2->fInvalid);
492
493 NativeAssert::StringEqual(wzVersion3, pVersion3->sczVersion);
494 Assert::Equal<DWORD>(1, pVersion3->dwMajor);
495 Assert::Equal<DWORD>(2, pVersion3->dwMinor);
496 Assert::Equal<DWORD>(3, pVersion3->dwPatch);
497 Assert::Equal<DWORD>(0, pVersion3->dwRevision);
498 Assert::Equal<DWORD>(0, pVersion3->cReleaseLabels);
499 Assert::Equal<DWORD>(6, pVersion3->cchMetadataOffset);
500 Assert::Equal<BOOL>(TRUE, pVersion3->fInvalid);
501
502 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1);
503 TestVerutilCompareParsedVersions(pVersion1, pVersion3, 1);
504 TestVerutilCompareParsedVersions(pVersion2, pVersion3, -1);
505 }
506 finally
507 {
508 ReleaseVerutilVersion(pVersion1);
509 ReleaseVerutilVersion(pVersion2);
510 ReleaseVerutilVersion(pVersion3);
511 }
512 }
513
514 [Fact]
515 void VerCompareVersionsIgnoresLeadingV()
516 {
517 HRESULT hr = S_OK;
518 VERUTIL_VERSION* pVersion1 = NULL;
519 VERUTIL_VERSION* pVersion2 = NULL;
520 VERUTIL_VERSION* pVersion3 = NULL;
521 LPCWSTR wzVersion1 = L"10.20.30.40";
522 LPCWSTR wzVersion2 = L"v10.20.30.40";
523 LPCWSTR wzVersion3 = L"V10.20.30.40";
524
525 try
526 {
527 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
528 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
529
530 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
531 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
532
533 hr = VerParseVersion(wzVersion3, 0, FALSE, &pVersion3);
534 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion3);
535
536 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
537 Assert::Equal<DWORD>(10, pVersion1->dwMajor);
538 Assert::Equal<DWORD>(20, pVersion1->dwMinor);
539 Assert::Equal<DWORD>(30, pVersion1->dwPatch);
540 Assert::Equal<DWORD>(40, pVersion1->dwRevision);
541 Assert::Equal<DWORD>(0, pVersion1->cReleaseLabels);
542 Assert::Equal<DWORD>(11, pVersion1->cchMetadataOffset);
543 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
544
545 NativeAssert::StringEqual(wzVersion1, pVersion2->sczVersion);
546 Assert::Equal<DWORD>(10, pVersion2->dwMajor);
547 Assert::Equal<DWORD>(20, pVersion2->dwMinor);
548 Assert::Equal<DWORD>(30, pVersion2->dwPatch);
549 Assert::Equal<DWORD>(40, pVersion2->dwRevision);
550 Assert::Equal<DWORD>(0, pVersion2->cReleaseLabels);
551 Assert::Equal<DWORD>(11, pVersion2->cchMetadataOffset);
552 Assert::Equal<BOOL>(FALSE, pVersion2->fInvalid);
553
554 NativeAssert::StringEqual(wzVersion1, pVersion3->sczVersion);
555 Assert::Equal<DWORD>(10, pVersion3->dwMajor);
556 Assert::Equal<DWORD>(20, pVersion3->dwMinor);
557 Assert::Equal<DWORD>(30, pVersion3->dwPatch);
558 Assert::Equal<DWORD>(40, pVersion3->dwRevision);
559 Assert::Equal<DWORD>(0, pVersion3->cReleaseLabels);
560 Assert::Equal<DWORD>(11, pVersion3->cchMetadataOffset);
561 Assert::Equal<BOOL>(FALSE, pVersion3->fInvalid);
562
563 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 0);
564 TestVerutilCompareParsedVersions(pVersion1, pVersion3, 0);
565 }
566 finally
567 {
568 ReleaseVerutilVersion(pVersion1);
569 ReleaseVerutilVersion(pVersion2);
570 ReleaseVerutilVersion(pVersion3);
571 }
572 }
573
574 [Fact]
575 void VerCompareVersionsHandlesTooLargeNumbers()
576 {
577 HRESULT hr = S_OK;
578 VERUTIL_VERSION* pVersion1 = NULL;
579 VERUTIL_VERSION* pVersion2 = NULL;
580 LPCWSTR wzVersion1 = L"4294967295.4294967295.4294967295.4294967295";
581 LPCWSTR wzVersion2 = L"4294967296.4294967296.4294967296.4294967296";
582
583 try
584 {
585 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
586 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
587
588 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
589 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
590
591 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
592 Assert::Equal<DWORD>(4294967295, pVersion1->dwMajor);
593 Assert::Equal<DWORD>(4294967295, pVersion1->dwMinor);
594 Assert::Equal<DWORD>(4294967295, pVersion1->dwPatch);
595 Assert::Equal<DWORD>(4294967295, pVersion1->dwRevision);
596 Assert::Equal<DWORD>(0, pVersion1->cReleaseLabels);
597 Assert::Equal<DWORD>(43, pVersion1->cchMetadataOffset);
598 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
599
600 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
601 Assert::Equal<DWORD>(0, pVersion2->dwMajor);
602 Assert::Equal<DWORD>(0, pVersion2->dwMinor);
603 Assert::Equal<DWORD>(0, pVersion2->dwPatch);
604 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
605 Assert::Equal<DWORD>(0, pVersion2->cReleaseLabels);
606 Assert::Equal<DWORD>(0, pVersion2->cchMetadataOffset);
607 Assert::Equal<BOOL>(TRUE, pVersion2->fInvalid);
608
609 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1);
610 }
611 finally
612 {
613 ReleaseVerutilVersion(pVersion1);
614 ReleaseVerutilVersion(pVersion2);
615 }
616 }
617
618 [Fact]
619 void VerCompareVersionsIgnoresMetadataForValidVersions()
620 {
621 HRESULT hr = S_OK;
622 VERUTIL_VERSION* pVersion1 = NULL;
623 VERUTIL_VERSION* pVersion2 = NULL;
624 LPCWSTR wzVersion1 = L"1.2.3+abc";
625 LPCWSTR wzVersion2 = L"1.2.3+xyz";
626
627 try
628 {
629 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
630 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
631
632 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
633 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
634
635 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
636 Assert::Equal<DWORD>(1, pVersion1->dwMajor);
637 Assert::Equal<DWORD>(2, pVersion1->dwMinor);
638 Assert::Equal<DWORD>(3, pVersion1->dwPatch);
639 Assert::Equal<DWORD>(0, pVersion1->dwRevision);
640 Assert::Equal<DWORD>(0, pVersion1->cReleaseLabels);
641 Assert::Equal<DWORD>(6, pVersion1->cchMetadataOffset);
642 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
643
644 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
645 Assert::Equal<DWORD>(1, pVersion2->dwMajor);
646 Assert::Equal<DWORD>(2, pVersion2->dwMinor);
647 Assert::Equal<DWORD>(3, pVersion2->dwPatch);
648 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
649 Assert::Equal<DWORD>(0, pVersion2->cReleaseLabels);
650 Assert::Equal<DWORD>(6, pVersion2->cchMetadataOffset);
651 Assert::Equal<BOOL>(FALSE, pVersion2->fInvalid);
652
653 TestVerutilCompareParsedVersions(pVersion1, pVersion2, 0);
654 }
655 finally
656 {
657 ReleaseVerutilVersion(pVersion1);
658 ReleaseVerutilVersion(pVersion2);
659 }
660 }
661
662 [Fact]
663 void VerCopyVersionCopiesVersion()
664 {
665 HRESULT hr = S_OK;
666 LPCWSTR wzVersion = L"1.2.3.4-a.b.c.d.5.+abc123";
667 VERUTIL_VERSION* pSource = NULL;
668 VERUTIL_VERSION* pCopy = NULL;
669 int nResult = 0;
670
671 try
672 {
673 hr = VerParseVersion(wzVersion, 0, FALSE, &pSource);
674 NativeAssert::Succeeded(hr, "VerParseVersion failed");
675
676 NativeAssert::StringEqual(wzVersion, pSource->sczVersion);
677 Assert::Equal<DWORD>(1, pSource->dwMajor);
678 Assert::Equal<DWORD>(2, pSource->dwMinor);
679 Assert::Equal<DWORD>(3, pSource->dwPatch);
680 Assert::Equal<DWORD>(4, pSource->dwRevision);
681 Assert::Equal<DWORD>(5, pSource->cReleaseLabels);
682
683 Assert::Equal<BOOL>(FALSE, pSource->rgReleaseLabels[0].fNumeric);
684 Assert::Equal<DWORD>(1, pSource->rgReleaseLabels[0].cchLabel);
685 Assert::Equal<DWORD>(8, pSource->rgReleaseLabels[0].cchLabelOffset);
686
687 Assert::Equal<BOOL>(FALSE, pSource->rgReleaseLabels[1].fNumeric);
688 Assert::Equal<DWORD>(1, pSource->rgReleaseLabels[1].cchLabel);
689 Assert::Equal<DWORD>(10, pSource->rgReleaseLabels[1].cchLabelOffset);
690
691 Assert::Equal<BOOL>(FALSE, pSource->rgReleaseLabels[2].fNumeric);
692 Assert::Equal<DWORD>(1, pSource->rgReleaseLabels[2].cchLabel);
693 Assert::Equal<DWORD>(12, pSource->rgReleaseLabels[2].cchLabelOffset);
694
695 Assert::Equal<BOOL>(FALSE, pSource->rgReleaseLabels[3].fNumeric);
696 Assert::Equal<DWORD>(1, pSource->rgReleaseLabels[3].cchLabel);
697 Assert::Equal<DWORD>(14, pSource->rgReleaseLabels[3].cchLabelOffset);
698
699 Assert::Equal<BOOL>(TRUE, pSource->rgReleaseLabels[4].fNumeric);
700 Assert::Equal<DWORD>(5, pSource->rgReleaseLabels[4].dwValue);
701 Assert::Equal<DWORD>(1, pSource->rgReleaseLabels[4].cchLabel);
702 Assert::Equal<DWORD>(16, pSource->rgReleaseLabels[4].cchLabelOffset);
703
704 Assert::Equal<DWORD>(18, pSource->cchMetadataOffset);
705 Assert::Equal<BOOL>(TRUE, pSource->fInvalid);
706
707 hr = VerCopyVersion(pSource, &pCopy);
708 NativeAssert::Succeeded(hr, "VerCopyVersion failed");
709
710 Assert::False(pSource == pCopy);
711 Assert::False(pSource->sczVersion == pCopy->sczVersion);
712 Assert::False(pSource->rgReleaseLabels == pCopy->rgReleaseLabels);
713
714 hr = VerCompareParsedVersions(pSource, pCopy, &nResult);
715 NativeAssert::Succeeded(hr, "VerCompareParsedVersions failed");
716
717 Assert::Equal<int>(nResult, 0);
718 }
719 finally
720 {
721 ReleaseVerutilVersion(pCopy);
722 ReleaseVerutilVersion(pSource);
723 }
724 }
725
726 [Fact]
727 void VerParseVersionTreatsTrailingDotsAsInvalid()
728 {
729 HRESULT hr = S_OK;
730 VERUTIL_VERSION* pVersion1 = NULL;
731 VERUTIL_VERSION* pVersion2 = NULL;
732 VERUTIL_VERSION* pVersion3 = NULL;
733 VERUTIL_VERSION* pVersion4 = NULL;
734 VERUTIL_VERSION* pVersion5 = NULL;
735 VERUTIL_VERSION* pVersion6 = NULL;
736 VERUTIL_VERSION* pVersion7 = NULL;
737 LPCWSTR wzVersion1 = L".";
738 LPCWSTR wzVersion2 = L"1.";
739 LPCWSTR wzVersion3 = L"2.1.";
740 LPCWSTR wzVersion4 = L"3.2.1.";
741 LPCWSTR wzVersion5 = L"4.3.2.1.";
742 LPCWSTR wzVersion6 = L"5-.";
743 LPCWSTR wzVersion7 = L"6-a.";
744
745 try
746 {
747 hr = VerParseVersion(wzVersion1, 0, FALSE, &pVersion1);
748 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion1);
749
750 hr = VerParseVersion(wzVersion2, 0, FALSE, &pVersion2);
751 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion2);
752
753 hr = VerParseVersion(wzVersion3, 0, FALSE, &pVersion3);
754 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion3);
755
756 hr = VerParseVersion(wzVersion4, 0, FALSE, &pVersion4);
757 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion4);
758
759 hr = VerParseVersion(wzVersion5, 0, FALSE, &pVersion5);
760 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion5);
761
762 hr = VerParseVersion(wzVersion6, 0, FALSE, &pVersion6);
763 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion6);
764
765 hr = VerParseVersion(wzVersion7, 0, FALSE, &pVersion7);
766 NativeAssert::Succeeded(hr, "Failed to parse version '{0}'", wzVersion7);
767
768 NativeAssert::StringEqual(wzVersion1, pVersion1->sczVersion);
769 Assert::Equal<DWORD>(0, pVersion1->dwMajor);
770 Assert::Equal<DWORD>(0, pVersion1->dwMinor);
771 Assert::Equal<DWORD>(0, pVersion1->dwPatch);
772 Assert::Equal<DWORD>(0, pVersion1->dwRevision);
773 Assert::Equal<DWORD>(0, pVersion1->cReleaseLabels);
774 Assert::Equal<DWORD>(0, pVersion1->cchMetadataOffset);
775 Assert::Equal<BOOL>(TRUE, pVersion1->fInvalid);
776
777 NativeAssert::StringEqual(wzVersion2, pVersion2->sczVersion);
778 Assert::Equal<DWORD>(1, pVersion2->dwMajor);
779 Assert::Equal<DWORD>(0, pVersion2->dwMinor);
780 Assert::Equal<DWORD>(0, pVersion2->dwPatch);
781 Assert::Equal<DWORD>(0, pVersion2->dwRevision);
782 Assert::Equal<DWORD>(0, pVersion2->cReleaseLabels);
783 Assert::Equal<DWORD>(2, pVersion2->cchMetadataOffset);
784 Assert::Equal<BOOL>(TRUE, pVersion2->fInvalid);
785
786 NativeAssert::StringEqual(wzVersion3, pVersion3->sczVersion);
787 Assert::Equal<DWORD>(2, pVersion3->dwMajor);
788 Assert::Equal<DWORD>(1, pVersion3->dwMinor);
789 Assert::Equal<DWORD>(0, pVersion3->dwPatch);
790 Assert::Equal<DWORD>(0, pVersion3->dwRevision);
791 Assert::Equal<DWORD>(0, pVersion3->cReleaseLabels);
792 Assert::Equal<DWORD>(4, pVersion3->cchMetadataOffset);
793 Assert::Equal<BOOL>(TRUE, pVersion3->fInvalid);
794
795 NativeAssert::StringEqual(wzVersion4, pVersion4->sczVersion);
796 Assert::Equal<DWORD>(3, pVersion4->dwMajor);
797 Assert::Equal<DWORD>(2, pVersion4->dwMinor);
798 Assert::Equal<DWORD>(1, pVersion4->dwPatch);
799 Assert::Equal<DWORD>(0, pVersion4->dwRevision);
800 Assert::Equal<DWORD>(0, pVersion4->cReleaseLabels);
801 Assert::Equal<DWORD>(6, pVersion4->cchMetadataOffset);
802 Assert::Equal<BOOL>(TRUE, pVersion4->fInvalid);
803
804 NativeAssert::StringEqual(wzVersion5, pVersion5->sczVersion);
805 Assert::Equal<DWORD>(4, pVersion5->dwMajor);
806 Assert::Equal<DWORD>(3, pVersion5->dwMinor);
807 Assert::Equal<DWORD>(2, pVersion5->dwPatch);
808 Assert::Equal<DWORD>(1, pVersion5->dwRevision);
809 Assert::Equal<DWORD>(0, pVersion5->cReleaseLabels);
810 Assert::Equal<DWORD>(8, pVersion5->cchMetadataOffset);
811 Assert::Equal<BOOL>(TRUE, pVersion5->fInvalid);
812
813 NativeAssert::StringEqual(wzVersion6, pVersion6->sczVersion);
814 Assert::Equal<DWORD>(5, pVersion6->dwMajor);
815 Assert::Equal<DWORD>(0, pVersion6->dwMinor);
816 Assert::Equal<DWORD>(0, pVersion6->dwPatch);
817 Assert::Equal<DWORD>(0, pVersion6->dwRevision);
818 Assert::Equal<DWORD>(0, pVersion6->cReleaseLabels);
819 Assert::Equal<DWORD>(2, pVersion6->cchMetadataOffset);
820 Assert::Equal<BOOL>(TRUE, pVersion6->fInvalid);
821
822 NativeAssert::StringEqual(wzVersion7, pVersion7->sczVersion);
823 Assert::Equal<DWORD>(6, pVersion7->dwMajor);
824 Assert::Equal<DWORD>(0, pVersion7->dwMinor);
825 Assert::Equal<DWORD>(0, pVersion7->dwPatch);
826 Assert::Equal<DWORD>(0, pVersion7->dwRevision);
827 Assert::Equal<DWORD>(1, pVersion7->cReleaseLabels);
828
829 Assert::Equal<BOOL>(FALSE, pVersion7->rgReleaseLabels[0].fNumeric);
830 Assert::Equal<DWORD>(1, pVersion7->rgReleaseLabels[0].cchLabel);
831 Assert::Equal<DWORD>(2, pVersion7->rgReleaseLabels[0].cchLabelOffset);
832
833 Assert::Equal<DWORD>(4, pVersion7->cchMetadataOffset);
834 Assert::Equal<BOOL>(TRUE, pVersion7->fInvalid);
835 }
836 finally
837 {
838 ReleaseVerutilVersion(pVersion1);
839 ReleaseVerutilVersion(pVersion2);
840 ReleaseVerutilVersion(pVersion3);
841 ReleaseVerutilVersion(pVersion4);
842 ReleaseVerutilVersion(pVersion5);
843 ReleaseVerutilVersion(pVersion6);
844 ReleaseVerutilVersion(pVersion7);
845 }
846 }
847
848 [Fact]
849 void VerVersionFromQwordCreatesVersion()
850 {
851 HRESULT hr = S_OK;
852 VERUTIL_VERSION* pVersion1 = NULL;
853
854 try
855 {
856 hr = VerVersionFromQword(MAKEQWORDVERSION(1, 2, 3, 4), &pVersion1);
857 NativeAssert::Succeeded(hr, "VerVersionFromQword failed");
858
859 NativeAssert::StringEqual(L"1.2.3.4", pVersion1->sczVersion);
860 Assert::Equal<DWORD>(1, pVersion1->dwMajor);
861 Assert::Equal<DWORD>(2, pVersion1->dwMinor);
862 Assert::Equal<DWORD>(3, pVersion1->dwPatch);
863 Assert::Equal<DWORD>(4, pVersion1->dwRevision);
864 Assert::Equal<DWORD>(0, pVersion1->cReleaseLabels);
865 Assert::Equal<DWORD>(7, pVersion1->cchMetadataOffset);
866 Assert::Equal<BOOL>(FALSE, pVersion1->fInvalid);
867 }
868 finally
869 {
870 ReleaseVerutilVersion(pVersion1);
871 }
872 }
873
874 private:
875 void TestVerutilCompareParsedVersions(VERUTIL_VERSION* pVersion1, VERUTIL_VERSION* pVersion2, int nExpectedResult)
876 {
877 HRESULT hr = S_OK;
878 int nResult = 0;
879
880 hr = VerCompareParsedVersions(pVersion1, pVersion2, &nResult);
881 NativeAssert::Succeeded(hr, "Failed to compare versions '{0}' and '{1}'", pVersion1->sczVersion, pVersion2->sczVersion);
882
883 Assert::Equal(nExpectedResult, nResult);
884
885 hr = VerCompareParsedVersions(pVersion2, pVersion1, &nResult);
886 NativeAssert::Succeeded(hr, "Failed to compare versions '{0}' and '{1}'", pVersion1->sczVersion, pVersion2->sczVersion);
887
888 Assert::Equal(nExpectedResult, -nResult);
889 }
890 };
891}
diff --git a/src/test/DUtilUnitTest/precomp.h b/src/test/DUtilUnitTest/precomp.h
index b3a1a9cb..f665fed1 100644
--- a/src/test/DUtilUnitTest/precomp.h
+++ b/src/test/DUtilUnitTest/precomp.h
@@ -22,6 +22,7 @@
22#include <monutil.h> 22#include <monutil.h>
23#include <regutil.h> 23#include <regutil.h>
24#include <uriutil.h> 24#include <uriutil.h>
25#include <verutil.h>
25 26
26#pragma managed 27#pragma managed
27#include <vcclr.h> 28#include <vcclr.h>