mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-18 06:29:44 +08:00
Version helper compare operator fix (#1824)
* Version helper compare operator fix * Simplyfy compare code
This commit is contained in:
parent
a6b7ba41ee
commit
90a228619e
@ -50,45 +50,51 @@ namespace UnitTestsVersionHelper
|
||||
}
|
||||
TEST_METHOD (whenMajorVersionIsGreaterComparationOperatorShouldReturnProperValue)
|
||||
{
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper lhs(MAJOR_VERSION_0 + 1, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
|
||||
Assert::IsTrue(lhs > rhs);
|
||||
}
|
||||
TEST_METHOD (whenMajorVersionIsLesserComparationOperatorShouldReturnProperValue)
|
||||
{
|
||||
VersionHelper rhs(MAJOR_VERSION_0 + 1, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper rhs(MAJOR_VERSION_0 + 1, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
|
||||
Assert::IsFalse(lhs > rhs);
|
||||
}
|
||||
TEST_METHOD (whenMajorVersionIsEqualComparationOperatorShouldCompareMinorVersionValue)
|
||||
{
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12 - 1, REVISION_VERSION_0);
|
||||
|
||||
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12 - 1, REVISION_VERSION_0);
|
||||
|
||||
Assert::IsTrue(lhs > rhs);
|
||||
}
|
||||
TEST_METHOD (whenMajorVersionIsEqualComparationOperatorShouldCompareMinorVersionValue2)
|
||||
{
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12 - 1, REVISION_VERSION_0);
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
|
||||
Assert::IsFalse(lhs > rhs);
|
||||
}
|
||||
|
||||
TEST_METHOD (whenMajorAndMinorVersionIsEqualComparationOperatorShouldCompareRevisionValue)
|
||||
{
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0 + 1);
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
|
||||
Assert::IsTrue(lhs > rhs);
|
||||
}
|
||||
TEST_METHOD (whenMajorAndMinorVersionIsEqualComparationOperatorShouldCompareRevisionValue2)
|
||||
{
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0 + 1);
|
||||
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0 + 1);
|
||||
|
||||
Assert::IsFalse(lhs > rhs);
|
||||
}
|
||||
TEST_METHOD (whenMajorMinorAndRevisionIsEqualGreaterThanOperatorShouldReturnFalse)
|
||||
{
|
||||
VersionHelper lhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
VersionHelper rhs(MAJOR_VERSION_0, MINOR_VERSION_12, REVISION_VERSION_0);
|
||||
|
||||
Assert::IsFalse(lhs > rhs);
|
||||
}
|
||||
|
@ -30,34 +30,5 @@ VersionHelper::VersionHelper(int major, int minor, int revision) :
|
||||
|
||||
bool VersionHelper::operator>(const VersionHelper& rhs)
|
||||
{
|
||||
if (major < rhs.major)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (major > rhs.major)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (minor < rhs.minor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (minor > rhs.minor)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (revision < rhs.revision)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return std::tie(major, minor, revision) > std::tie(rhs.major, rhs.minor, rhs.revision);
|
||||
}
|
||||
|
@ -110,16 +110,15 @@ std::future<std::optional<new_version_download_info>> check_for_new_github_relea
|
||||
winrt::Windows::Foundation::Uri release_page_uri{ json_body.GetNamedString(L"html_url") };
|
||||
|
||||
VersionHelper github_version(winrt::to_string(new_version));
|
||||
|
||||
VersionHelper current_version(VERSION_MAJOR, VERSION_MINOR, VERSION_REVISION);
|
||||
|
||||
if (current_version > github_version)
|
||||
if (github_version > current_version)
|
||||
{
|
||||
co_return std::nullopt;
|
||||
co_return new_version_download_info{ std::move(release_page_uri), new_version.c_str() };
|
||||
}
|
||||
else
|
||||
{
|
||||
co_return new_version_download_info{ std::move(release_page_uri), new_version.c_str() };
|
||||
co_return std::nullopt;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
|
Loading…
Reference in New Issue
Block a user