summaryrefslogtreecommitdiff
path: root/rbutil
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil')
-rw-r--r--rbutil/rbutilqt/test/stubs/stubs-compareversion.cpp31
-rw-r--r--rbutil/rbutilqt/test/test-compareversion.cpp59
-rw-r--r--rbutil/rbutilqt/test/test-compareversion.pro9
3 files changed, 75 insertions, 24 deletions
diff --git a/rbutil/rbutilqt/test/stubs/stubs-compareversion.cpp b/rbutil/rbutilqt/test/stubs/stubs-compareversion.cpp
new file mode 100644
index 0000000000..07e2d18f19
--- /dev/null
+++ b/rbutil/rbutilqt/test/stubs/stubs-compareversion.cpp
@@ -0,0 +1,31 @@
+
+#include "playerbuildinfo.h"
+#include "rbsettings.h"
+#include "rockboxinfo.h"
+
+// not used by the test, just to make things compile.
+QVariant RbSettings::value(RbSettings::UserSettings setting)
+{
+ (void)setting;
+ return QVariant();
+}
+
+
+// not used in the test. If used the test will crash!
+PlayerBuildInfo* PlayerBuildInfo::instance()
+{
+ return nullptr;
+}
+
+QVariant PlayerBuildInfo::value(PlayerBuildInfo::DeviceInfo item, QString target)
+{
+ (void)item;
+ (void)target;
+ return QVariant();
+}
+
+RockboxInfo::RockboxInfo(QString, QString)
+{
+}
+
+
diff --git a/rbutil/rbutilqt/test/test-compareversion.cpp b/rbutil/rbutilqt/test/test-compareversion.cpp
index a7c5aef13e..94d7697646 100644
--- a/rbutil/rbutilqt/test/test-compareversion.cpp
+++ b/rbutil/rbutilqt/test/test-compareversion.cpp
@@ -28,17 +28,17 @@ class TestVersionCompare : public QObject
Q_OBJECT
private slots:
void testCompare();
+ void testCompare_data();
void testTrim();
+ void testTrim_data();
};
-struct compvector {
+struct {
const char* first;
const char* second;
const int expected;
-};
-
-const struct compvector compdata[] =
+} const compdata[] =
{
{ "1.2.3", "1.2.3 ", 0 },
{ "1.2.3", " 1.2.3", 0 },
@@ -74,12 +74,10 @@ const struct compvector compdata[] =
{ "prog-1.2a-64bit.tar.bz2","prog-1.2.3-64bit.tar.bz2", 1 },
};
-struct trimvector {
+struct {
const char* input;
const QString expected;
-};
-
-const struct trimvector trimdata[] =
+} const trimdata[] =
{
{ "prog-1.2-64bit.tar.bz2", "1.2" },
{ "prog-1.2.tar.bz2", "1.2" },
@@ -95,27 +93,50 @@ const struct trimvector trimdata[] =
{ "prog-1.2a-64bit.tar.bz2","1.2a" },
};
+
+void TestVersionCompare::testCompare_data()
+{
+ QTest::addColumn<QString>("first");
+ QTest::addColumn<QString>("second");
+ QTest::addColumn<int>("expected");
+ for(size_t i = 0; i < sizeof(compdata) / sizeof(compdata[0]); i++) {
+ QTest::newRow("") << compdata[i].first << compdata[i].second << compdata[i].expected;
+ }
+}
+
+
void TestVersionCompare::testCompare()
{
- unsigned int i;
- for(i = 0; i < sizeof(compdata) / sizeof(struct compvector); i++) {
- QCOMPARE(Utils::compareVersionStrings(compdata[i].first,
- compdata[i].second), compdata[i].expected);
- // inverse test possible because function return values are symmetrical.
- if(compdata[i].expected != 0)
- QCOMPARE(Utils::compareVersionStrings(compdata[i].second,
- compdata[i].first), -compdata[i].expected);
+ QFETCH(QString, first);
+ QFETCH(QString, second);
+ QFETCH(int, expected);
+
+ QCOMPARE(Utils::compareVersionStrings(first, second), expected);
+ if(expected != 0) {
+ QCOMPARE(Utils::compareVersionStrings(second, first), -expected);
}
}
-void TestVersionCompare::testTrim()
+
+void TestVersionCompare::testTrim_data()
{
- for(size_t i = 0; i < sizeof(trimdata) / sizeof(struct trimvector); i++) {
- QCOMPARE(Utils::trimVersionString(trimdata[i].input), trimdata[i].expected);
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<QString>("expected");
+ for(size_t i = 0; i < sizeof(trimdata) / sizeof(trimdata[0]); i++) {
+ QTest::newRow("") << trimdata[i].input << trimdata[i].expected;
}
}
+void TestVersionCompare::testTrim()
+{
+ QFETCH(QString, input);
+ QFETCH(QString, expected);
+
+ QCOMPARE(Utils::trimVersionString(input), expected);
+}
+
+
QTEST_MAIN(TestVersionCompare)
// this include is needed because we don't use a separate header file for the
diff --git a/rbutil/rbutilqt/test/test-compareversion.pro b/rbutil/rbutilqt/test/test-compareversion.pro
index 8fbd7e1c07..c8e5a899ac 100644
--- a/rbutil/rbutilqt/test/test-compareversion.pro
+++ b/rbutil/rbutilqt/test/test-compareversion.pro
@@ -16,7 +16,8 @@
# Test: Utils::compareVersionStrings().
#
-include(tests.pri)
+
+QT += testlib
TEMPLATE = app
TARGET = test-compareversion
@@ -25,14 +26,12 @@ INCLUDEPATH += . ../base stubs
# Input
SOURCES += \
test-compareversion.cpp \
- ../base/rbsettings.cpp \
- ../base/rockboxinfo.cpp \
- ../base/systeminfo.cpp \
+ stubs/stubs-compareversion.cpp \
../base/utils.cpp
HEADERS += \
../base/rbsettings.h \
+ ../base/playerbuildinfo.h \
../base/rockboxinfo.h \
- ../base/systeminfo.h \
../base/utils.h