Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed version comparison used for project migration #1230

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ set(VERSION_MINOR 0)
# Add the spdlog directory to the include path
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/third_party/spdlog/include ${CMAKE_CURRENT_SOURCE_DIR}/third_party/exprtk)

set(VERSION_PATCH 227)
set(VERSION_PATCH 228)

option(
WITH_LIBCXX
"Building with clang++ and libc++(in Linux). To enable with: -DWITH_LIBCXX=On"
Expand Down
13 changes: 10 additions & 3 deletions src/Main/ProjectFile/ProjectFileComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,17 @@ bool operator!=(const Version &v1, const Version &v2) {
return (v1.maj != v2.maj) || (v1.min != v2.min) || (v1.patch != v2.patch);
}

bool operator==(const Version &v1, const Version &v2) { return !(v1 != v2); }

bool operator<(const Version &v1, const Version &v2) {
if (v1.maj < v2.maj) return true;
if (v1.min < v2.min) return true;
if (v1.patch < v2.patch) return true;
if (v1.maj < v2.maj)
return true;
else if (v1.maj == v2.maj) {
if (v1.min < v2.min)
return true;
else if (v1.min == v2.min)
return (v1.patch < v2.patch);
}
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/Main/ProjectFile/ProjectFileComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct Version {
};

bool operator!=(const Version &v1, const Version &v2);
bool operator==(const Version &v1, const Version &v2);
bool operator<(const Version &v1, const Version &v2);

QString toString(Version version);
Expand Down
167 changes: 167 additions & 0 deletions tests/unittest/MainWindow/ProjectFileComponent_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,170 @@ TEST(ErrorCode, operatorBool) {
ErrorCode erc{true, errorStr};
EXPECT_EQ((bool)erc, true);
}

TEST(Version, Equal) {
Version v1{0, 0, 0};
Version v2{0, 0, 0};
bool notEqual = (v1 != v2);
EXPECT_EQ(notEqual, false);
}

TEST(Version, NotEqualMaj) {
Version v1{0, 0, 0};
Version v2{1, 0, 0};
bool notEqual = (v1 != v2);
EXPECT_EQ(notEqual, true);
}

TEST(Version, NotEqualMin) {
Version v1{0, 0, 0};
Version v2{0, 1, 0};
bool notEqual = (v1 != v2);
EXPECT_EQ(notEqual, true);
}

TEST(Version, NotEqualPatch) {
Version v1{0, 0, 0};
Version v2{0, 0, 1};
bool notEqual = (v1 != v2);
EXPECT_EQ(notEqual, true);
}

TEST(Version, OperatorLess) {
Version v1{0, 0, 0};
Version v2{0, 0, 0};
bool less = (v1 < v2);
EXPECT_EQ(less, false);
}

TEST(Version, OperatorLessCase0) {
Version v1{1, 0, 0};
Version v2{0, 0, 0};
bool less = (v1 < v2);
EXPECT_EQ(less, false);
}

TEST(Version, OperatorLessCase1) {
Version v1{0, 0, 0};
Version v2{1, 0, 0};
bool less = (v1 < v2);
EXPECT_EQ(less, true);
}

TEST(Version, OperatorLessCase2) {
Version v1{0, 1, 0};
Version v2{0, 0, 0};
bool less = (v1 < v2);
EXPECT_EQ(less, false);
}

TEST(Version, OperatorLessCase3) {
Version v1{0, 0, 0};
Version v2{0, 1, 0};
bool less = (v1 < v2);
EXPECT_EQ(less, true);
}

TEST(Version, OperatorLessCase4) {
Version v1{0, 0, 1};
Version v2{0, 0, 0};
bool less = (v1 < v2);
EXPECT_EQ(less, false);
}

TEST(Version, OperatorLessCase5) {
Version v1{0, 0, 0};
Version v2{0, 0, 1};
bool less = (v1 < v2);
EXPECT_EQ(less, true);
}

TEST(Version, OperatorLessCase6) {
Version v1{0, 1, 0};
Version v2{0, 0, 1};
bool less = (v1 < v2);
EXPECT_EQ(less, false);
}

TEST(Version, OperatorLessCase7) {
Version v1{1, 0, 0};
Version v2{0, 1, 0};
bool less = (v1 < v2);
EXPECT_EQ(less, false);
}

TEST(Version, OperatorLessCase8) {
Version v1{1, 0, 0};
Version v2{0, 0, 1};
bool less = (v1 < v2);
EXPECT_EQ(less, false);
}

TEST(Version, toString) {
Version v{1, 2, 3};
QString str = toString(v);
EXPECT_EQ(str, "1.2.3");
}

TEST(Version, toVersionFailedString) {
QString str{"some string"};
bool ok{};
Version v = toVersion(str, &ok);
EXPECT_EQ(ok, false);
EXPECT_EQ(v, Version{});
}

TEST(Version, toVersion2Nums) {
QString str{"2.9"};
bool ok{};
Version v = toVersion(str, &ok);
EXPECT_EQ(ok, false);
EXPECT_EQ(v, Version{});
}

TEST(Version, toVersionNotNumber0) {
QString str{"notnumber.9.0"};
bool ok{};
Version v = toVersion(str, &ok);
EXPECT_EQ(ok, false);
EXPECT_EQ(v, Version{});
}

TEST(Version, toVersionNotNumber1) {
QString str{"2.notnumber.0"};
bool ok{};
Version v = toVersion(str, &ok);
EXPECT_EQ(ok, false);
EXPECT_EQ(v, Version{});
}

TEST(Version, toVersionNotNumber2) {
QString str{"2.9.notnumber"};
bool ok{};
Version v = toVersion(str, &ok);
EXPECT_EQ(ok, false);
EXPECT_EQ(v, Version{});
}

TEST(Version, toVersion) {
QString str{"2.9.0"};
bool ok{};
Version v = toVersion(str, &ok);
Version expected{2, 9, 0};
EXPECT_EQ(ok, true);
EXPECT_EQ(v, expected);
}

TEST(Version, toVersionNoVerification) {
QString str{"2.9.0"};
Version v = toVersion(str);
Version expected{2, 9, 0};
EXPECT_EQ(v, expected);
}

TEST(Version, toVersionNoVerificationFailed) {
QString str{"some str"};
Version v = toVersion(str);
Version expected{};
EXPECT_EQ(v, expected);
}