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

Unit test reactivation #780

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
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
897 changes: 897 additions & 0 deletions apmplanner_core.pro

Large diffs are not rendered by default.

603 changes: 7 additions & 596 deletions qgcunittest.pro

Large diffs are not rendered by default.

904 changes: 11 additions & 893 deletions qgroundcontrol.pro

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions src/qgcunittest/TestFrameworkTest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <QtTest/QtTest>

#include "TestFrameworkTest.h"

//This function is called before every test
void TestFrameworkTest::init()
{
}

//this function is called after every test
void TestFrameworkTest::cleanup()
{
}

void TestFrameworkTest::testStringComparison()
{
QString test("test");
QVERIFY(test == "test");
}

void TestFrameworkTest::testIntComparison()
{
int x = 5;
QVERIFY(x == 5);
}
23 changes: 23 additions & 0 deletions src/qgcunittest/TestFrameworkTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef TESTFRAMEWORKTEST_H
#define TESTFRAMEWORKTEST_H

#include <QObject>

#include "AutoTest.h"

class TestFrameworkTest : public QObject
{
Q_OBJECT

private slots:
void init();
void cleanup();

private slots:
void testStringComparison();

void testIntComparison();
};

DECLARE_TEST(TestFrameworkTest)
#endif // TESTFRAMEWORKTEST_H
116 changes: 116 additions & 0 deletions src/qgcunittest/versioncomparatortest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#include "versioncomparatortest.h"

#include <QtTest/QtTest>

#include "versioncomparator.h"


VersionComparatorTest::VersionComparatorTest()
{
}

void VersionComparatorTest::testHigherMajorNumberIsNewer()
{
const QString newVersion("v2.3.2-rc1");
const QString currentVersion("v1.2.4");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), true);
QCOMPARE(VersionComparator::isVersionNewer(currentVersion, newVersion), false);
}

void VersionComparatorTest::testHigherMajorNumberWithoutBuildNumberIsNewer()
{
const QString newVersion("v2.1");
const QString currentVersion("v1.2");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), true);
QCOMPARE(VersionComparator::isVersionNewer(currentVersion, newVersion), false);
}

void VersionComparatorTest::testEqualMajorNumberIsNotNewer()
{
const QString newVersion("v1.0.0");
const QString currentVersion("1.0.0");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), false);
}

void VersionComparatorTest::testHigherMinorNumberIsNewer()
{
const QString newVersion("v1.32.24-rc1");
const QString currentVersion("1.31.4");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), true);
QCOMPARE(VersionComparator::isVersionNewer(currentVersion, newVersion), false);
}

void VersionComparatorTest::testHigherMinorNumberWithoutBuildNumberIsHigher()
{
const QString newVersion("1.1");
const QString currentVersion("1.0");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), true);
QCOMPARE(VersionComparator::isVersionNewer(currentVersion, newVersion), false);
}

void VersionComparatorTest::testEqualMinorNumberIsNotNewer()
{
const QString newVersion("v1.3.0");
const QString currentVersion("1.3.0");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), false);
}


void VersionComparatorTest::testHigherBuildNumberIsNewer()
{
const QString newVersion("v2.3.24");
const QString currentVersion("v2.3.20-rc1");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), true);
QCOMPARE(VersionComparator::isVersionNewer(currentVersion, newVersion), false);
}

void VersionComparatorTest::testEqualBuildNumberIsNotNewer()
{
const QString newVersion("2.3.3");
const QString currentVersion("v2.3.3");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), false);
}

void VersionComparatorTest::testExistingBuildNumberIsNewerThanNoBuildNumber()
{
const QString newVersion("2.3.2");
const QString currentVersion("v2.3");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), true);
QCOMPARE(VersionComparator::isVersionNewer(currentVersion, newVersion), false);
}

void VersionComparatorTest::testNoReleaseCandidateIsNewerThanExistingReleaseCandidate()
{
const QString newVersion("2.3.2");
const QString currentVersion("2.3.2-rc1");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), true);
QCOMPARE(VersionComparator::isVersionNewer(currentVersion, newVersion), false);
}

void VersionComparatorTest::testHigherReleaseCandidateIsNewer()
{
const QString newVersion("2.3.2-rc3");
const QString currentVersion("2.3.2-rc1");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), true);
QCOMPARE(VersionComparator::isVersionNewer(currentVersion, newVersion), false);
}

void VersionComparatorTest::testInvalidNewVersionReturnsFalse()
{
const QString newVersion("abcdef");
const QString currentVersion("2.3.2-rc1");

QCOMPARE(VersionComparator::isVersionNewer(newVersion, currentVersion), false);
}

41 changes: 41 additions & 0 deletions src/qgcunittest/versioncomparatortest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#ifndef VERSIONCOMPARATORTEST_H
#define VERSIONCOMPARATORTEST_H

#include <QObject>

#include "AutoTest.h"

class VersionComparatorTest : public QObject
{
Q_OBJECT
public:
VersionComparatorTest();

private slots:
void testHigherMajorNumberIsNewer();

void testHigherMajorNumberWithoutBuildNumberIsNewer();

void testEqualMajorNumberIsNotNewer();

void testHigherMinorNumberIsNewer();

void testHigherMinorNumberWithoutBuildNumberIsHigher();

void testEqualMinorNumberIsNotNewer();

void testHigherBuildNumberIsNewer();

void testEqualBuildNumberIsNotNewer();

void testExistingBuildNumberIsNewerThanNoBuildNumber();

void testNoReleaseCandidateIsNewerThanExistingReleaseCandidate();

void testHigherReleaseCandidateIsNewer();

void testInvalidNewVersionReturnsFalse();
};

DECLARE_TEST(VersionComparatorTest)
#endif // VERSIONCOMPARATORTEST_H
98 changes: 2 additions & 96 deletions src/ui/AutoUpdateCheck.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ This file is part of the APM_PLANNER project
#include <QMessageBox>
#include <QSettings>
#include "QGC.h"

static const QString VersionCompareRegEx = "(\\d*\\.\\d+\\.?\\d+)-?(rc\\d)?";
#include "versioncomparator.h"

AutoUpdateCheck::AutoUpdateCheck(QObject *parent) :
QObject(parent),
Expand Down Expand Up @@ -170,100 +169,7 @@ void AutoUpdateCheck::updateDataReadProgress(qint64 bytesRead, qint64 totalBytes

bool AutoUpdateCheck::compareVersionStrings(const QString& newVersion, const QString& currentVersion)
{
// [TODO] DRY this out by creating global function for use in APM Firmware as well
int newMajor = 0,newMinor = 0,newBuild = 0;
int currentMajor = 0, currentMinor = 0,currentBuild = 0;

QString newBuildSubMoniker, oldBuildSubMoniker; // holds if the build is a rc or dev build


QRegExp versionEx(VersionCompareRegEx);
QString versionstr = "";
int pos = versionEx.indexIn(newVersion);
if (pos > -1) {
// Split first sub-element to get numercal major.minor.build version
QLOG_DEBUG() << "Detected newVersion:" << versionEx.capturedTexts()<< " count:"
<< versionEx.captureCount();
versionstr = versionEx.cap(1);
QStringList versionList = versionstr.split(".");
newMajor = versionList[0].toInt();
newMinor = versionList[1].toInt();
if (versionList.size() > 2){
newBuild = versionList[2].toInt();
}
// second subelement is either rcX candidate or developement build
if (versionEx.captureCount() == 2)
newBuildSubMoniker = versionEx.cap(2);
}

QRegExp versionEx2(VersionCompareRegEx);
versionstr = "";
pos = versionEx2.indexIn(currentVersion);
if (pos > -1) {
QLOG_DEBUG() << "Detected currentVersion:" << versionEx2.capturedTexts() << " count:"
<< versionEx2.captureCount();
versionstr = versionEx2.cap(1);
QStringList versionList = versionstr.split(".");
currentMajor = versionList[0].toInt();
currentMinor = versionList[1].toInt();
if (versionList.size() > 2){
currentBuild = versionList[2].toInt();
}
// second subelement is either rcX candidate or developement build
if (versionEx2.captureCount() == 2)
oldBuildSubMoniker = versionEx2.cap(2);
}

QLOG_DEBUG() << "Verison Compare:" <<QString().sprintf(" New Version %d.%d.%d compared to Old Version %d.%d.%d",
newMajor,newMinor,newBuild, currentMajor, currentMinor,currentBuild);
if (newMajor>currentMajor){
// A Major release
return true;
} else if (newMajor == currentMajor){
if (newMinor > currentMinor){
// A minor release
return true;
} else if (newMinor == currentMinor){
if (newBuild > currentBuild)
// new build (or tiny release)
return true;
else if (newBuild == currentBuild) {
// Check if RC is newer
// If the version isn't newer, it might be a new release candidate
int newRc = 0, oldRc = 0;

if (newBuildSubMoniker.startsWith("RC", Qt::CaseInsensitive)
&& oldBuildSubMoniker.startsWith("RC", Qt::CaseInsensitive)) {
QRegExp releaseNumber("\\d+");
pos = releaseNumber.indexIn(newBuildSubMoniker);
if (pos > -1) {
QLOG_DEBUG() << "Detected newRc:" << versionEx.capturedTexts();
newRc = releaseNumber.cap(0).toInt();
}

QRegExp releaseNumber2("\\d+");
pos = releaseNumber2.indexIn(oldBuildSubMoniker);
if (pos > -1) {
QLOG_DEBUG() << "Detected oldRc:" << versionEx2.capturedTexts();
oldRc = releaseNumber2.cap(0).toInt();
}

if (newRc > oldRc)
return true;
}

if (newBuildSubMoniker.length() == 0
&& oldBuildSubMoniker.startsWith("RC", Qt::CaseInsensitive)) {
QLOG_DEBUG() << "Stable build newer that last unstable release candidate ";
return true; // this means a new stable build of the unstable rc is available
}
}
}
}



return false;
return VersionComparator::isVersionNewer(newVersion, currentVersion);
}

void AutoUpdateCheck::setSkipVersion(const QString& version)
Expand Down
Loading