summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/test/test-compareversion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/rbutilqt/test/test-compareversion.cpp')
-rw-r--r--rbutil/rbutilqt/test/test-compareversion.cpp59
1 files changed, 40 insertions, 19 deletions
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