diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dutil/verutil.cpp | 57 | ||||
| -rw-r--r-- | src/test/DUtilUnitTest/VerUtilTests.cpp | 44 |
2 files changed, 73 insertions, 28 deletions
diff --git a/src/dutil/verutil.cpp b/src/dutil/verutil.cpp index f362f413..835dde81 100644 --- a/src/dutil/verutil.cpp +++ b/src/dutil/verutil.cpp | |||
| @@ -85,22 +85,6 @@ DAPI_(HRESULT) VerCompareParsedVersions( | |||
| 85 | ExitFunction(); | 85 | ExitFunction(); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | if (pVersion1->fInvalid) | ||
| 89 | { | ||
| 90 | if (!pVersion2->fInvalid) | ||
| 91 | { | ||
| 92 | ExitFunction1(nResult = -1); | ||
| 93 | } | ||
| 94 | else | ||
| 95 | { | ||
| 96 | fCompareMetadata = TRUE; | ||
| 97 | } | ||
| 98 | } | ||
| 99 | else if (pVersion2->fInvalid) | ||
| 100 | { | ||
| 101 | ExitFunction1(nResult = 1); | ||
| 102 | } | ||
| 103 | |||
| 104 | if (pVersion1->cReleaseLabels) | 88 | if (pVersion1->cReleaseLabels) |
| 105 | { | 89 | { |
| 106 | if (pVersion2->cReleaseLabels) | 90 | if (pVersion2->cReleaseLabels) |
| @@ -132,6 +116,22 @@ DAPI_(HRESULT) VerCompareParsedVersions( | |||
| 132 | } | 116 | } |
| 133 | } | 117 | } |
| 134 | 118 | ||
| 119 | if (pVersion1->fInvalid) | ||
| 120 | { | ||
| 121 | if (!pVersion2->fInvalid) | ||
| 122 | { | ||
| 123 | ExitFunction1(nResult = -1); | ||
| 124 | } | ||
| 125 | else | ||
| 126 | { | ||
| 127 | fCompareMetadata = TRUE; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | else if (pVersion2->fInvalid) | ||
| 131 | { | ||
| 132 | ExitFunction1(nResult = 1); | ||
| 133 | } | ||
| 134 | |||
| 135 | if (fCompareMetadata) | 135 | if (fCompareMetadata) |
| 136 | { | 136 | { |
| 137 | hr = CompareVersionSubstring(pVersion1->sczVersion + pVersion1->cchMetadataOffset, -1, pVersion2->sczVersion + pVersion2->cchMetadataOffset, -1, &nResult); | 137 | hr = CompareVersionSubstring(pVersion1->sczVersion + pVersion1->cchMetadataOffset, -1, pVersion2->sczVersion + pVersion2->cchMetadataOffset, -1, &nResult); |
| @@ -191,20 +191,23 @@ DAPI_(HRESULT) VerCopyVersion( | |||
| 191 | pCopy->dwPatch = pSource->dwPatch; | 191 | pCopy->dwPatch = pSource->dwPatch; |
| 192 | pCopy->dwRevision = pSource->dwRevision; | 192 | pCopy->dwRevision = pSource->dwRevision; |
| 193 | 193 | ||
| 194 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pCopy->rgReleaseLabels), 0, sizeof(VERUTIL_VERSION_RELEASE_LABEL), pSource->cReleaseLabels); | 194 | if (pSource->cReleaseLabels) |
| 195 | VerExitOnFailure(hr, "Failed to allocate memory for Verutil version release labels copies."); | 195 | { |
| 196 | hr = MemEnsureArraySize(reinterpret_cast<LPVOID*>(&pCopy->rgReleaseLabels), 0, sizeof(VERUTIL_VERSION_RELEASE_LABEL), pSource->cReleaseLabels); | ||
| 197 | VerExitOnFailure(hr, "Failed to allocate memory for Verutil version release labels copies."); | ||
| 196 | 198 | ||
| 197 | pCopy->cReleaseLabels = pSource->cReleaseLabels; | 199 | pCopy->cReleaseLabels = pSource->cReleaseLabels; |
| 198 | 200 | ||
| 199 | for (DWORD i = 0; i < pCopy->cReleaseLabels; ++i) | 201 | for (DWORD i = 0; i < pCopy->cReleaseLabels; ++i) |
| 200 | { | 202 | { |
| 201 | VERUTIL_VERSION_RELEASE_LABEL* pSourceLabel = pSource->rgReleaseLabels + i; | 203 | VERUTIL_VERSION_RELEASE_LABEL* pSourceLabel = pSource->rgReleaseLabels + i; |
| 202 | VERUTIL_VERSION_RELEASE_LABEL* pCopyLabel = pCopy->rgReleaseLabels + i; | 204 | VERUTIL_VERSION_RELEASE_LABEL* pCopyLabel = pCopy->rgReleaseLabels + i; |
| 203 | 205 | ||
| 204 | pCopyLabel->cchLabelOffset = pSourceLabel->cchLabelOffset; | 206 | pCopyLabel->cchLabelOffset = pSourceLabel->cchLabelOffset; |
| 205 | pCopyLabel->cchLabel = pSourceLabel->cchLabel; | 207 | pCopyLabel->cchLabel = pSourceLabel->cchLabel; |
| 206 | pCopyLabel->fNumeric = pSourceLabel->fNumeric; | 208 | pCopyLabel->fNumeric = pSourceLabel->fNumeric; |
| 207 | pCopyLabel->dwValue = pSourceLabel->dwValue; | 209 | pCopyLabel->dwValue = pSourceLabel->dwValue; |
| 210 | } | ||
| 208 | } | 211 | } |
| 209 | 212 | ||
| 210 | pCopy->cchMetadataOffset = pSource->cchMetadataOffset; | 213 | pCopy->cchMetadataOffset = pSource->cchMetadataOffset; |
diff --git a/src/test/DUtilUnitTest/VerUtilTests.cpp b/src/test/DUtilUnitTest/VerUtilTests.cpp index 58b561e9..8f24ad1a 100644 --- a/src/test/DUtilUnitTest/VerUtilTests.cpp +++ b/src/test/DUtilUnitTest/VerUtilTests.cpp | |||
| @@ -237,7 +237,7 @@ namespace DutilTests | |||
| 237 | 237 | ||
| 238 | TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1); | 238 | TestVerutilCompareParsedVersions(pVersion1, pVersion2, 1); |
| 239 | TestVerutilCompareParsedVersions(pVersion3, pVersion4, 1); | 239 | TestVerutilCompareParsedVersions(pVersion3, pVersion4, 1); |
| 240 | TestVerutilCompareParsedVersions(pVersion5, pVersion6, 1); | 240 | TestVerutilCompareParsedVersions(pVersion5, pVersion6, -1); |
| 241 | } | 241 | } |
| 242 | finally | 242 | finally |
| 243 | { | 243 | { |
| @@ -663,6 +663,48 @@ namespace DutilTests | |||
| 663 | void VerCopyVersionCopiesVersion() | 663 | void VerCopyVersionCopiesVersion() |
| 664 | { | 664 | { |
| 665 | HRESULT hr = S_OK; | 665 | HRESULT hr = S_OK; |
| 666 | LPCWSTR wzVersion = L"1.2.3.4+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>(0, pSource->cReleaseLabels); | ||
| 682 | |||
| 683 | Assert::Equal<DWORD>(8, pSource->cchMetadataOffset); | ||
| 684 | Assert::Equal<BOOL>(FALSE, pSource->fInvalid); | ||
| 685 | |||
| 686 | hr = VerCopyVersion(pSource, &pCopy); | ||
| 687 | NativeAssert::Succeeded(hr, "VerCopyVersion failed"); | ||
| 688 | |||
| 689 | Assert::False(pSource == pCopy); | ||
| 690 | Assert::False(pSource->sczVersion == pCopy->sczVersion); | ||
| 691 | |||
| 692 | hr = VerCompareParsedVersions(pSource, pCopy, &nResult); | ||
| 693 | NativeAssert::Succeeded(hr, "VerCompareParsedVersions failed"); | ||
| 694 | |||
| 695 | Assert::Equal<int>(nResult, 0); | ||
| 696 | } | ||
| 697 | finally | ||
| 698 | { | ||
| 699 | ReleaseVerutilVersion(pCopy); | ||
| 700 | ReleaseVerutilVersion(pSource); | ||
| 701 | } | ||
| 702 | } | ||
| 703 | |||
| 704 | [Fact] | ||
| 705 | void VerCopyVersionCopiesPrereleaseVersion() | ||
| 706 | { | ||
| 707 | HRESULT hr = S_OK; | ||
| 666 | LPCWSTR wzVersion = L"1.2.3.4-a.b.c.d.5.+abc123"; | 708 | LPCWSTR wzVersion = L"1.2.3.4-a.b.c.d.5.+abc123"; |
| 667 | VERUTIL_VERSION* pSource = NULL; | 709 | VERUTIL_VERSION* pSource = NULL; |
| 668 | VERUTIL_VERSION* pCopy = NULL; | 710 | VERUTIL_VERSION* pCopy = NULL; |
