diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2010-06-15 19:49:43 +0000 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2010-06-15 19:49:43 +0000 |
commit | 738d83c59b2adc480751e0e70ccd75adc3d5903d (patch) | |
tree | 2f493c46911f9cfab79a6019ed73b94174c21b48 /rbutil/rbutilqt/test/compareversion.cpp | |
parent | a8c35f4d5608d173b77f172d66d1aac9289cb65c (diff) | |
download | rockbox-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
Diffstat (limited to 'rbutil/rbutilqt/test/compareversion.cpp')
-rw-r--r-- | rbutil/rbutilqt/test/compareversion.cpp | 86 |
1 files changed, 86 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 | |||
27 | class TestVersionCompare : public QObject | ||
28 | { | ||
29 | Q_OBJECT | ||
30 | private slots: | ||
31 | void testMain(); | ||
32 | }; | ||
33 | |||
34 | |||
35 | struct testvector { | ||
36 | const char* first; | ||
37 | const char* second; | ||
38 | const int expected; | ||
39 | }; | ||
40 | |||
41 | const 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 | |||
68 | void 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 | |||
81 | QTEST_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 | |||