From ed0ef472c76ac0d2a3d7a138e4f3b7ad950a56bc Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Tue, 30 Mar 2021 17:15:25 -0500 Subject: Add test for apuputil and fix descending sorting. --- src/dutil/apuputil.cpp | 27 +++++---- src/dutil/inc/verutil.h | 4 +- src/dutil/verutil.cpp | 16 +++-- src/test/DUtilUnitTest/ApupUtilTests.cpp | 46 +++++++++++++++ src/test/DUtilUnitTest/DUtilUnitTest.vcxproj | 4 ++ .../DUtilUnitTest/DUtilUnitTest.vcxproj.filters | 3 + .../TestData/ApupUtilTests/FeedBv2.0.xml | 68 ++++++++++++++++++++++ src/test/DUtilUnitTest/precomp.h | 6 +- 8 files changed, 155 insertions(+), 19 deletions(-) create mode 100644 src/test/DUtilUnitTest/ApupUtilTests.cpp create mode 100644 src/test/DUtilUnitTest/TestData/ApupUtilTests/FeedBv2.0.xml (limited to 'src') 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( ) { HRESULT hr = S_OK; - BOOL fVersionFound = FALSE; int nCompareResult = 0; // First search the ATOM entry's custom elements to try and find the application update information. @@ -255,25 +254,26 @@ static HRESULT ProcessEntry( { hr = VerParseVersion(pElement->wzValue, 0, FALSE, &pApupEntry->pVersion); ApupExitOnFailure(hr, "Failed to parse version string '%ls' from ATOM entry.", pElement->wzValue); - - fVersionFound = TRUE; } } } // If there is no application identity or no version, skip the whole thing. - if ((!pApupEntry->wzApplicationId && !wzDefaultAppId) || !fVersionFound) + if ((!pApupEntry->wzApplicationId && !wzDefaultAppId) || !pApupEntry->pVersion) { ExitFunction1(hr = S_FALSE); // skip this update since it has no application id or version. } - hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult); - ApupExitOnFailure(hr, "Failed to compare version to upgrade version."); - - if (nCompareResult >= 0) + if (pApupEntry->pUpgradeVersion) { - hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); - ApupExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version."); + hr = VerCompareParsedVersions(pApupEntry->pUpgradeVersion, pApupEntry->pVersion, &nCompareResult); + ApupExitOnFailure(hr, "Failed to compare version to upgrade version."); + + if (nCompareResult >= 0) + { + hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); + ApupExitOnRootFailure(hr, "Upgrade version is greater than or equal to application version."); + } } if (pAtomEntry->wzTitle) @@ -443,11 +443,14 @@ static __callback int __cdecl CompareEntries( VerCompareParsedVersions(pEntryLeft->pUpgradeVersion, pEntryRight->pUpgradeVersion, &ret); if (0 == ret) { - ret = (pEntryRight->dw64TotalSize < pEntryLeft->dw64TotalSize) ? -1 : - (pEntryRight->dw64TotalSize > pEntryLeft->dw64TotalSize) ? 1 : 0; + ret = (pEntryLeft->dw64TotalSize < pEntryRight->dw64TotalSize) ? -1 : + (pEntryLeft->dw64TotalSize > pEntryRight->dw64TotalSize) ? 1 : 0; } } + // Sort descending. + ret = -ret; + return ret; } 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 *******************************************************************/ HRESULT DAPI VerCompareParsedVersions( - __in VERUTIL_VERSION* pVersion1, - __in VERUTIL_VERSION* pVersion2, + __in_opt VERUTIL_VERSION* pVersion1, + __in_opt VERUTIL_VERSION* pVersion2, __out int* pnResult ); 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( DAPI_(HRESULT) VerCompareParsedVersions( - __in VERUTIL_VERSION* pVersion1, - __in VERUTIL_VERSION* pVersion2, + __in_opt VERUTIL_VERSION* pVersion1, + __in_opt VERUTIL_VERSION* pVersion2, __out int* pnResult ) { @@ -50,8 +50,8 @@ DAPI_(HRESULT) VerCompareParsedVersions( DWORD cMaxReleaseLabels = 0; BOOL fCompareMetadata = FALSE; - if (!pVersion1 || !pVersion1->sczVersion || - !pVersion2 || !pVersion2->sczVersion) + if (pVersion1 && !pVersion1->sczVersion || + pVersion2 && !pVersion2->sczVersion) { ExitFunction1(hr = E_INVALIDARG); } @@ -60,6 +60,14 @@ DAPI_(HRESULT) VerCompareParsedVersions( { ExitFunction1(nResult = 0); } + else if (pVersion1 && !pVersion2) + { + ExitFunction1(nResult = 1); + } + else if (!pVersion1 && pVersion2) + { + ExitFunction1(nResult = -1); + } nResult = CompareDword(pVersion1->dwMajor, pVersion2->dwMajor); 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 @@ +// 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 WixBuildTools::TestSupport; + +namespace DutilTests +{ + public ref class ApupUtil + { + public: + [Fact] + void AllocChainFromAtomSortsDescending() + { + HRESULT hr = S_OK; + ATOM_FEED* pFeed = NULL; + APPLICATION_UPDATE_CHAIN* pChain = NULL; + + DutilInitialize(&DutilTestTraceError); + + try + { + XmlInitialize(); + NativeAssert::Succeeded(hr, "Failed to initialize Xml."); + + pin_ptr feedFilePath = PtrToStringChars(TestData::Get("TestData", "ApupUtilTests", "FeedBv2.0.xml")); + hr = AtomParseFromFile(feedFilePath, &pFeed); + NativeAssert::Succeeded(hr, "Failed to parse feed: {0}", feedFilePath); + + hr = ApupAllocChainFromAtom(pFeed, &pChain); + NativeAssert::Succeeded(hr, "Failed to get chain from feed."); + + Assert::Equal(3ul, pChain->cEntries); + NativeAssert::StringEqual(L"Bundle v2.0", pChain->rgEntries[0].wzTitle); + NativeAssert::StringEqual(L"Bundle v1.0", pChain->rgEntries[1].wzTitle); + NativeAssert::StringEqual(L"Bundle v1.0-preview", pChain->rgEntries[2].wzTitle); + } + finally + { + DutilUninitialize(); + } + } + }; +} 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 @@ rpcrt4.lib;Mpr.lib;Ws2_32.lib;urlmon.lib;wininet.lib + @@ -59,6 +60,9 @@ + + + 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 @@ + + Source Files + Source Files 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 @@ + + + + + + BundleB v2.0 + Bundle Subtitle. + 1116353B-7C6E-4C29-BFA1-D4A972CD421D + 2014-07-14T12:39:00.000Z + http://localhost:9999/wix4/BundleB/feed + + manual build + + Bundle v2.0 + v2.0 + + Bundle_Author + http://mycompany.com/software + Bundle_Author@mycompany.com + + + + + <p>Change list:</p><ul> + <li>Updated release.</li> + </ul> + + 2.0.0.0 + 2014-11-10T12:39:00.000Z + + + Bundle v1.0 + v1.0 + + Bundle_Author + http://mycompany.com/software + Bundle_Author@mycompany.com + + + + + <p>Change list:</p><ul> + <li>Initial release.</li> + </ul> + + + 1.0.0.0 + 2014-11-09T12:39:00.000Z + + + Bundle v1.0-preview + v1.0-preview + + Bundle_Author + http://mycompany.com/software + Bundle_Author@mycompany.com + + + + + <p>Change list:</p><ul> + <li>Initial release.</li> + </ul> + + 1.0.0.0 + 2014-11-09T12:39:00.000Z + + 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 @@ #include "error.h" #include +#include +#include #include #include #include @@ -21,8 +23,10 @@ #include #include #include +#include +#include // NOTE: this must come after atomutil.h and rssutil.h since it uses them. #include -#include +#include #pragma managed #include -- cgit v1.2.3-55-g6feb