summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-15 19:49:43 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-15 19:49:43 +0000
commit738d83c59b2adc480751e0e70ccd75adc3d5903d (patch)
tree2f493c46911f9cfab79a6019ed73b94174c21b48
parenta8c35f4d5608d173b77f172d66d1aac9289cb65c (diff)
downloadrockbox-738d83c59b2adc480751e0e70ccd75adc3d5903d.tar.gz
rockbox-738d83c59b2adc480751e0e70ccd75adc3d5903d.zip
Add cleaned up tests used for Utils::compareVersionStrings().
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26861 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--rbutil/rbutilqt/test/compareversion.cpp86
-rw-r--r--rbutil/rbutilqt/test/compareversion.pro38
-rw-r--r--rbutil/rbutilqt/test/tests.pri25
3 files changed, 149 insertions, 0 deletions
diff --git a/rbutil/rbutilqt/test/compareversion.cpp b/rbutil/rbutilqt/test/compareversion.cpp
new file mode 100644
index 0000000000..db1c62e5d5
--- /dev/null
+++ b/rbutil/rbutilqt/test/compareversion.cpp
@@ -0,0 +1,86 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Dominik Riebeling
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <QtTest/QtTest>
23#include <QObject>
24#include "utils.h"
25
26
27class TestVersionCompare : public QObject
28{
29 Q_OBJECT
30 private slots:
31 void testMain();
32};
33
34
35struct testvector {
36 const char* first;
37 const char* second;
38 const int expected;
39};
40
41const struct testvector testdata[] =
42{
43 { "1.2.3", "1.2.3 ", 0 },
44 { "1.2.3", " 1.2.3", 0 },
45 { "1.2.3", "1.2.4", 1 },
46 { "1.2.3", "1.3.0", 1 },
47 { "1.2.3", "2.0.0", 1 },
48 { "10.22.33", "10.22.33", 0 },
49 { "10.22.33", "10.23.0", 1 },
50 { "10.22.33", "11.0.0", 1 },
51 { "1.2.3", "1.2.3.1", 1 },
52 { "1.2.3", "1.2.3-1", 1 },
53 { "1.2.3", "1.2.3a", 1 },
54 { "1.2.3a", "1.2.3b", 1 },
55 { "1.2.3", "1.2.3b", 1 },
56 { "1.2.3.0", "2.0.0", 1 },
57 { "1.2.3b", "2.0.0", 1 },
58 { "1.2.3", "2.0.0.1", 1 },
59 { "test-1.2.3", "test-1.2.3.tar.gz", 0 },
60 { "1.2.3", "test-1.2.3.tar.bz2", 0 },
61 { "test-1.2.3.tar.gz", "test-1.2.3.tar.bz2", 0 },
62 { "test-1.2.3.tar.gz", "program-1.2.3.1.tar.bz2", 1 },
63 { "program-1.2.3.zip", "program-1.2.3a.zip", 1 },
64 { "program-1.2.3.tar.bz2", "2.0.0", 1 },
65};
66
67
68void TestVersionCompare::testMain()
69{
70 unsigned int i;
71 for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) {
72 QCOMPARE(Utils::compareVersionStrings(testdata[i].first,
73 testdata[i].second), testdata[i].expected);
74 // inverse test possible because function return values are symmetrical.
75 QCOMPARE(Utils::compareVersionStrings(testdata[i].second,
76 testdata[i].first), -testdata[i].expected);
77 }
78}
79
80
81QTEST_MAIN(TestVersionCompare)
82
83// this include is needed because we don't use a separate header file for the
84// test class. It also needs to be at the end.
85#include "compareversion.moc"
86
diff --git a/rbutil/rbutilqt/test/compareversion.pro b/rbutil/rbutilqt/test/compareversion.pro
new file mode 100644
index 0000000000..84344438ec
--- /dev/null
+++ b/rbutil/rbutilqt/test/compareversion.pro
@@ -0,0 +1,38 @@
1#
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
10# All files in this archive are subject to the GNU General Public License.
11# See the file COPYING in the source tree root for full license agreement.
12#
13# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
14# KIND, either express or implied.
15#
16
17# Test: Utils::compareVersionStrings().
18#
19include(tests.pri)
20
21TEMPLATE = app
22TARGET = compareversion
23INCLUDEPATH += . ../base
24
25# Input
26SOURCES += \
27 compareversion.cpp \
28 ../base/rbsettings.cpp \
29 ../base/rockboxinfo.cpp \
30 ../base/systeminfo.cpp \
31 ../base/utils.cpp
32
33HEADERS += \
34 ../base/rbsettings.h \
35 ../base/rockboxinfo.h \
36 ../base/systeminfo.h \
37 ../base/utils.h
38
diff --git a/rbutil/rbutilqt/test/tests.pri b/rbutil/rbutilqt/test/tests.pri
new file mode 100644
index 0000000000..072edd2c98
--- /dev/null
+++ b/rbutil/rbutilqt/test/tests.pri
@@ -0,0 +1,25 @@
1#
2# __________ __ ___.
3# Open \______ \ ____ ____ | | _\_ |__ _______ ___
4# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7# \/ \/ \/ \/ \/
8# $Id$
9#
10# All files in this archive are subject to the GNU General Public License.
11# See the file COPYING in the source tree root for full license agreement.
12#
13# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
14# KIND, either express or implied.
15#
16
17# common settings for tests.
18
19CONFIG += qtestlib
20DEPENDPATH += .
21OBJECTS_DIR = build
22UI_DIR = build
23MOC_DIR = build
24RCC_DIR = build
25