diff options
author | Sean Hall <r.sean.hall@gmail.com> | 2021-03-30 17:15:25 -0500 |
---|---|---|
committer | Sean Hall <r.sean.hall@gmail.com> | 2021-03-30 17:19:19 -0500 |
commit | ed0ef472c76ac0d2a3d7a138e4f3b7ad950a56bc (patch) | |
tree | 0b409592d759b43f583b44d2d854d8c44199bcee | |
parent | 10ebf674da5df9224e4eddd3545518434c5b455b (diff) | |
download | wix-ed0ef472c76ac0d2a3d7a138e4f3b7ad950a56bc.tar.gz wix-ed0ef472c76ac0d2a3d7a138e4f3b7ad950a56bc.tar.bz2 wix-ed0ef472c76ac0d2a3d7a138e4f3b7ad950a56bc.zip |
Add test for apuputil and fix descending sorting.
-rw-r--r-- | src/dutil/apuputil.cpp | 27 | ||||
-rw-r--r-- | src/dutil/inc/verutil.h | 4 | ||||
-rw-r--r-- | src/dutil/verutil.cpp | 16 | ||||
-rw-r--r-- | src/test/DUtilUnitTest/ApupUtilTests.cpp | 46 | ||||
-rw-r--r-- | src/test/DUtilUnitTest/DUtilUnitTest.vcxproj | 4 | ||||
-rw-r--r-- | src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters | 3 | ||||
-rw-r--r-- | src/test/DUtilUnitTest/TestData/ApupUtilTests/FeedBv2.0.xml | 68 | ||||
-rw-r--r-- | src/test/DUtilUnitTest/precomp.h | 6 |
8 files changed, 155 insertions, 19 deletions
diff --git a/src/dutil/apuputil.cpp b/src/dutil/apuputil.cpp index 07d591a7..6f5825bb 100644 --- a/src/dutil/apuputil.cpp +++ b/src/dutil/apuputil.cpp | |||
@@ -208,7 +208,6 @@ static HRESULT ProcessEntry( | |||
208 | ) | 208 | ) |
209 | { | 209 | { |
210 | HRESULT hr = S_OK; | 210 | HRESULT hr = S_OK; |
211 | BOOL fVersionFound = FALSE; | ||
212 | int nCompareResult = 0; | 211 | int nCompareResult = 0; |
213 | 212 | ||
214 | // First search the ATOM entry's custom elements to try and find the application update information. | 213 | // First search the ATOM entry's custom elements to try and find the application update information. |
@@ -255,25 +254,26 @@ static HRESULT ProcessEntry( | |||
255 | { | 254 | { |
256 | hr = VerParseVersion(pElement->wzValue, 0, FALSE, &pApupEntry->pVersion); | 255 | hr = VerParseVersion(pElement->wzValue, 0, FALSE, &pApupEntry->pVersion); |
257 | ApupExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue); | 256 | ApupExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue); |
258 | |||
259 | fVersionFound = TRUE; | ||
260 | } | 257 | } |
261 | } | 258 | } |
262 | } | 259 | } |
263 | 260 | ||
264 | // If there is no application identity or no version, skip the whole thing. | 261 | // If there is no application identity or no version, skip the whole thing. |
265 | if ((!pApupEntry->wzApplicationId && !wzDefaultAppId) || !fVersionFound) | 262 | if ((!pApupEntry->wzApplicationId && !wzDefaultAppId) || !pApupEntry->pVersion) |
266 | { | 263 | { |
267 | ExitFunction1(hr = S_FALSE); // skip this update since it has no application id or version. | 264 | ExitFunction1(hr = S_FALSE); // skip this update since it has no application id or version. |
268 | } | 265 | } |
269 | 266 | ||
270 | hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult); | 267 | if (pApupEntry->pUpgradeVersion) |
271 | ApupExitOnFailure(hr, "Failed to compare version to upgrade version."); | ||
272 | |||
273 | if (nCompareResult >= 0) | ||
274 | { | 268 | { |
275 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | 269 | hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult); |
276 | ApupExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version."); | 270 | ApupExitOnFailure(hr, "Failed to compare version to upgrade version."); |
271 | |||
272 | if (nCompareResult >= 0) | ||
273 | { | ||
274 | hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); | ||
275 | ApupExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version."); | ||
276 | } | ||
277 | } | 277 | } |
278 | 278 | ||
279 | if (pAtomEntry->wzTitle) | 279 | if (pAtomEntry->wzTitle) |
@@ -443,11 +443,14 @@ static __callback int __cdecl CompareEntries( | |||
443 | VerCompareParsedVersions(pEntryLeft->pUpgradeVersion, pEntryRight->pUpgradeVersion, &ret); | 443 | VerCompareParsedVersions(pEntryLeft->pUpgradeVersion, pEntryRight->pUpgradeVersion, &ret); |
444 | if (0 == ret) | 444 | if (0 == ret) |
445 | { | 445 | { |
446 | ret = (pEntryRight->dw64TotalSize < pEntryLeft->dw64TotalSize) ? -1 : | 446 | ret = (pEntryLeft->dw64TotalSize < pEntryRight->dw64TotalSize) ? -1 : |
447 | (pEntryRight->dw64TotalSize > pEntryLeft->dw64TotalSize) ? 1 : 0; | 447 | (pEntryLeft->dw64TotalSize > pEntryRight->dw64TotalSize) ? 1 : 0; |
448 | } | 448 | } |
449 | } | 449 | } |
450 | 450 | ||
451 | // Sort descending. | ||
452 | ret = -ret; | ||
453 | |||
451 | return ret; | 454 | return ret; |
452 | } | 455 | } |
453 | 456 | ||
diff --git a/src/dutil/inc/verutil.h b/src/dutil/inc/verutil.h index 30869aef..3caa17e1 100644 --- a/src/dutil/inc/verutil.h +++ b/src/dutil/inc/verutil.h | |||
@@ -34,8 +34,8 @@ typedef struct _VERUTIL_VERSION | |||
34 | 34 | ||
35 | *******************************************************************/ | 35 | *******************************************************************/ |
36 | HRESULT DAPI VerCompareParsedVersions( | 36 | HRESULT DAPI VerCompareParsedVersions( |
37 | __in VERUTIL_VERSION* pVersion1, | 37 | __in_opt VERUTIL_VERSION* pVersion1, |
38 | __in VERUTIL_VERSION* pVersion2, | 38 | __in_opt VERUTIL_VERSION* pVersion2, |
39 | __out int* pnResult | 39 | __out int* pnResult |
40 | ); | 40 | ); |
41 | 41 | ||
diff --git a/src/dutil/verutil.cpp b/src/dutil/verutil.cpp index 835dde81..fdb5a10a 100644 --- a/src/dutil/verutil.cpp +++ b/src/dutil/verutil.cpp | |||
@@ -40,8 +40,8 @@ static HRESULT CompareVersionSubstring( | |||
40 | 40 | ||
41 | 41 | ||
42 | DAPI_(HRESULT) VerCompareParsedVersions( | 42 | DAPI_(HRESULT) VerCompareParsedVersions( |
43 | __in VERUTIL_VERSION* pVersion1, | 43 | __in_opt VERUTIL_VERSION* pVersion1, |
44 | __in VERUTIL_VERSION* pVersion2, | 44 | __in_opt VERUTIL_VERSION* pVersion2, |
45 | __out int* pnResult | 45 | __out int* pnResult |
46 | ) | 46 | ) |
47 | { | 47 | { |
@@ -50,8 +50,8 @@ DAPI_(HRESULT) VerCompareParsedVersions( | |||
50 | DWORD cMaxReleaseLabels = 0; | 50 | DWORD cMaxReleaseLabels = 0; |
51 | BOOL fCompareMetadata = FALSE; | 51 | BOOL fCompareMetadata = FALSE; |
52 | 52 | ||
53 | if (!pVersion1 || !pVersion1->sczVersion || | 53 | if (pVersion1 && !pVersion1->sczVersion || |
54 | !pVersion2 || !pVersion2->sczVersion) | 54 | pVersion2 && !pVersion2->sczVersion) |
55 | { | 55 | { |
56 | ExitFunction1(hr = E_INVALIDARG); | 56 | ExitFunction1(hr = E_INVALIDARG); |
57 | } | 57 | } |
@@ -60,6 +60,14 @@ DAPI_(HRESULT) VerCompareParsedVersions( | |||
60 | { | 60 | { |
61 | ExitFunction1(nResult = 0); | 61 | ExitFunction1(nResult = 0); |
62 | } | 62 | } |
63 | else if (pVersion1 && !pVersion2) | ||
64 | { | ||
65 | ExitFunction1(nResult = 1); | ||
66 | } | ||
67 | else if (!pVersion1 && pVersion2) | ||
68 | { | ||
69 | ExitFunction1(nResult = -1); | ||
70 | } | ||
63 | 71 | ||
64 | nResult = CompareDword(pVersion1->dwMajor, pVersion2->dwMajor); | 72 | nResult = CompareDword(pVersion1->dwMajor, pVersion2->dwMajor); |
65 | if (0 != nResult) | 73 | if (0 != nResult) |
diff --git a/src/test/DUtilUnitTest/ApupUtilTests.cpp b/src/test/DUtilUnitTest/ApupUtilTests.cpp new file mode 100644 index 00000000..30a45f5a --- /dev/null +++ b/src/test/DUtilUnitTest/ApupUtilTests.cpp | |||
@@ -0,0 +1,46 @@ | |||
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 ApupUtil | ||
12 | { | ||
13 | public: | ||
14 | [Fact] | ||
15 | void AllocChainFromAtomSortsDescending() | ||
16 | { | ||
17 | HRESULT hr = S_OK; | ||
18 | ATOM_FEED* pFeed = NULL; | ||
19 | APPLICATION_UPDATE_CHAIN* pChain = NULL; | ||
20 | |||
21 | DutilInitialize(&DutilTestTraceError); | ||
22 | |||
23 | try | ||
24 | { | ||
25 | XmlInitialize(); | ||
26 | NativeAssert::Succeeded(hr, "Failed to initialize Xml."); | ||
27 | |||
28 | pin_ptr<const wchar_t> feedFilePath = PtrToStringChars(TestData::Get("TestData", "ApupUtilTests", "FeedBv2.0.xml")); | ||
29 | hr = AtomParseFromFile(feedFilePath, &pFeed); | ||
30 | NativeAssert::Succeeded(hr, "Failed to parse feed: {0}", feedFilePath); | ||
31 | |||
32 | hr = ApupAllocChainFromAtom(pFeed, &pChain); | ||
33 | NativeAssert::Succeeded(hr, "Failed to get chain from feed."); | ||
34 | |||
35 | Assert::Equal(3ul, pChain->cEntries); | ||
36 | NativeAssert::StringEqual(L"Bundle v2.0", pChain->rgEntries[0].wzTitle); | ||
37 | NativeAssert::StringEqual(L"Bundle v1.0", pChain->rgEntries[1].wzTitle); | ||
38 | NativeAssert::StringEqual(L"Bundle v1.0-preview", pChain->rgEntries[2].wzTitle); | ||
39 | } | ||
40 | finally | ||
41 | { | ||
42 | DutilUninitialize(); | ||
43 | } | ||
44 | } | ||
45 | }; | ||
46 | } | ||
diff --git a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj index 942c39f0..32463262 100644 --- a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj +++ b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj | |||
@@ -30,6 +30,7 @@ | |||
30 | <ProjectAdditionalLinkLibraries>rpcrt4.lib;Mpr.lib;Ws2_32.lib;urlmon.lib;wininet.lib</ProjectAdditionalLinkLibraries> | 30 | <ProjectAdditionalLinkLibraries>rpcrt4.lib;Mpr.lib;Ws2_32.lib;urlmon.lib;wininet.lib</ProjectAdditionalLinkLibraries> |
31 | </PropertyGroup> | 31 | </PropertyGroup> |
32 | <ItemGroup> | 32 | <ItemGroup> |
33 | <ClCompile Include="ApupUtilTests.cpp" /> | ||
33 | <ClCompile Include="AssemblyInfo.cpp" /> | 34 | <ClCompile Include="AssemblyInfo.cpp" /> |
34 | <ClCompile Include="DictUtilTest.cpp" /> | 35 | <ClCompile Include="DictUtilTest.cpp" /> |
35 | <ClCompile Include="DirUtilTests.cpp" /> | 36 | <ClCompile Include="DirUtilTests.cpp" /> |
@@ -60,6 +61,9 @@ | |||
60 | <ResourceCompile Include="UnitTest.rc" /> | 61 | <ResourceCompile Include="UnitTest.rc" /> |
61 | </ItemGroup> | 62 | </ItemGroup> |
62 | <ItemGroup> | 63 | <ItemGroup> |
64 | <None Include="TestData\ApupUtilTests\FeedBv2.0.xml" CopyToOutputDirectory="PreserveNewest" /> | ||
65 | </ItemGroup> | ||
66 | <ItemGroup> | ||
63 | <Reference Include="System" /> | 67 | <Reference Include="System" /> |
64 | <Reference Include="System.Core" /> | 68 | <Reference Include="System.Core" /> |
65 | <Reference Include="WixBuildTools.TestSupport"> | 69 | <Reference Include="WixBuildTools.TestSupport"> |
diff --git a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters index fdc6d278..4df7af89 100644 --- a/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters +++ b/src/test/DUtilUnitTest/DUtilUnitTest.vcxproj.filters | |||
@@ -15,6 +15,9 @@ | |||
15 | </Filter> | 15 | </Filter> |
16 | </ItemGroup> | 16 | </ItemGroup> |
17 | <ItemGroup> | 17 | <ItemGroup> |
18 | <ClCompile Include="ApupUtilTests.cpp"> | ||
19 | <Filter>Source Files</Filter> | ||
20 | </ClCompile> | ||
18 | <ClCompile Include="AssemblyInfo.cpp"> | 21 | <ClCompile Include="AssemblyInfo.cpp"> |
19 | <Filter>Source Files</Filter> | 22 | <Filter>Source Files</Filter> |
20 | </ClCompile> | 23 | </ClCompile> |
diff --git a/src/test/DUtilUnitTest/TestData/ApupUtilTests/FeedBv2.0.xml b/src/test/DUtilUnitTest/TestData/ApupUtilTests/FeedBv2.0.xml new file mode 100644 index 00000000..d9f961fe --- /dev/null +++ b/src/test/DUtilUnitTest/TestData/ApupUtilTests/FeedBv2.0.xml | |||
@@ -0,0 +1,68 @@ | |||
1 | <?xml version='1.0' ?> | ||
2 | <!-- 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. --> | ||
3 | |||
4 | |||
5 | <feed xmlns="http://www.w3.org/2005/Atom" xmlns:as="http://appsyndication.org/2006/appsyn"> | ||
6 | <title type="text">BundleB v2.0</title> | ||
7 | <subtitle type="text">Bundle Subtitle.</subtitle> | ||
8 | <as:application type="application/exe">1116353B-7C6E-4C29-BFA1-D4A972CD421D</as:application> | ||
9 | <updated>2014-07-14T12:39:00.000Z</updated> | ||
10 | <id>http://localhost:9999/wix4/BundleB/feed</id> | ||
11 | <link rel="self" type="application/atom+xml" href="http://localhost:9999/wix4/BundleB/feed"/> | ||
12 | <generator version="0.1">manual build</generator> | ||
13 | <entry> | ||
14 | <title>Bundle v2.0</title> | ||
15 | <id>v2.0</id> | ||
16 | <author> | ||
17 | <name>Bundle_Author</name> | ||
18 | <uri>http://mycompany.com/software</uri> | ||
19 | <email>Bundle_Author@mycompany.com</email> | ||
20 | </author> | ||
21 | <link rel="alternate" href="http://www.mycompany.com/content/view/software"/> | ||
22 | <link rel="enclosure" href="http://localhost:9999/wix4/BundleB/2.0/BundleB.exe" length="0" type="application/octet-stream"/> | ||
23 | <content type="html"> | ||
24 | <p>Change list:</p><ul> | ||
25 | <li>Updated release.</li> | ||
26 | </ul> | ||
27 | </content> | ||
28 | <as:version>2.0.0.0</as:version> | ||
29 | <updated>2014-11-10T12:39:00.000Z</updated> | ||
30 | </entry> | ||
31 | <entry> | ||
32 | <title>Bundle v1.0</title> | ||
33 | <id>v1.0</id> | ||
34 | <author> | ||
35 | <name>Bundle_Author</name> | ||
36 | <uri>http://mycompany.com/software</uri> | ||
37 | <email>Bundle_Author@mycompany.com</email> | ||
38 | </author> | ||
39 | <link rel="alternate" href="http://www.mycompany.com/content/view/software"/> | ||
40 | <link rel="enclosure" href="http://localhost:9999/wix4/BundleB/1.0/BundleB.exe" length="0" type="application/octet-stream"/> | ||
41 | <content type="html"> | ||
42 | <p>Change list:</p><ul> | ||
43 | <li>Initial release.</li> | ||
44 | </ul> | ||
45 | </content> | ||
46 | <as:upgrade version="1.0.0.0-preview" /> | ||
47 | <as:version>1.0.0.0</as:version> | ||
48 | <updated>2014-11-09T12:39:00.000Z</updated> | ||
49 | </entry> | ||
50 | <entry> | ||
51 | <title>Bundle v1.0-preview</title> | ||
52 | <id>v1.0-preview</id> | ||
53 | <author> | ||
54 | <name>Bundle_Author</name> | ||
55 | <uri>http://mycompany.com/software</uri> | ||
56 | <email>Bundle_Author@mycompany.com</email> | ||
57 | </author> | ||
58 | <link rel="alternate" href="http://www.mycompany.com/content/view/software"/> | ||
59 | <link rel="enclosure" href="http://localhost:9999/wix4/BundleB/1.0-preview/BundleB.exe" length="10000" type="application/octet-stream"/> | ||
60 | <content type="html"> | ||
61 | <p>Change list:</p><ul> | ||
62 | <li>Initial release.</li> | ||
63 | </ul> | ||
64 | </content> | ||
65 | <as:version>1.0.0.0</as:version> | ||
66 | <updated>2014-11-09T12:39:00.000Z</updated> | ||
67 | </entry> | ||
68 | </feed> | ||
diff --git a/src/test/DUtilUnitTest/precomp.h b/src/test/DUtilUnitTest/precomp.h index f665fed1..e9f8770b 100644 --- a/src/test/DUtilUnitTest/precomp.h +++ b/src/test/DUtilUnitTest/precomp.h | |||
@@ -11,6 +11,8 @@ | |||
11 | #include "error.h" | 11 | #include "error.h" |
12 | #include <dutil.h> | 12 | #include <dutil.h> |
13 | 13 | ||
14 | #include <verutil.h> | ||
15 | #include <atomutil.h> | ||
14 | #include <dictutil.h> | 16 | #include <dictutil.h> |
15 | #include <dirutil.h> | 17 | #include <dirutil.h> |
16 | #include <fileutil.h> | 18 | #include <fileutil.h> |
@@ -21,8 +23,10 @@ | |||
21 | #include <strutil.h> | 23 | #include <strutil.h> |
22 | #include <monutil.h> | 24 | #include <monutil.h> |
23 | #include <regutil.h> | 25 | #include <regutil.h> |
26 | #include <rssutil.h> | ||
27 | #include <apuputil.h> // NOTE: this must come after atomutil.h and rssutil.h since it uses them. | ||
24 | #include <uriutil.h> | 28 | #include <uriutil.h> |
25 | #include <verutil.h> | 29 | #include <xmlutil.h> |
26 | 30 | ||
27 | #pragma managed | 31 | #pragma managed |
28 | #include <vcclr.h> | 32 | #include <vcclr.h> |