Prefix compareversion test files.
[maemo-rb.git] / rbutil / rbutilqt / test / test-compareversion.cpp
blobfa1b8892548e15d2643ca01058314b0def886bcd
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2010 Dominik Riebeling
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 #include <QtTest/QtTest>
22 #include <QObject>
23 #include "utils.h"
26 class TestVersionCompare : public QObject
28 Q_OBJECT
29 private slots:
30 void testMain();
34 struct testvector {
35 const char* first;
36 const char* second;
37 const int expected;
40 const struct testvector testdata[] =
42 { "1.2.3", "1.2.3 ", 0 },
43 { "1.2.3", " 1.2.3", 0 },
44 { "1.2.3", "1.2.4", 1 },
45 { "1.2.3", "1.3.0", 1 },
46 { "1.2.3", "2.0.0", 1 },
47 { "10.22.33", "10.22.33", 0 },
48 { "10.22.33", "10.23.0", 1 },
49 { "10.22.33", "11.0.0", 1 },
50 { "1.2.3", "1.2.3.1", 1 },
51 { "1.2.3", "1.2.3-1", 1 },
52 { "1.2.3-1", "1.2.3.1", 1 },
53 { "1.2.3-10", "1.2.3.0", 1 },
54 { "1.2.3-1", "1.2.3.10", 1 },
55 { "1.2.3-1", "1.2.3a", 1 },
56 { "1.2.3", "1.2.3a", 1 },
57 { "1.2.3a", "1.2.3b", 1 },
58 { "1.2.3", "1.2.3b", 1 },
59 { "1.2.3.0", "2.0.0", 1 },
60 { "1.2.3b", "2.0.0", 1 },
61 { "1.2.3", "2.0.0.1", 1 },
62 { "test-1.2.3", "test-1.2.3.tar.gz", 0 },
63 { "1.2.3", "test-1.2.3.tar.bz2", 0 },
64 { "test-1.2.3.tar.gz", "test-1.2.3.tar.bz2", 0 },
65 { "test-1.2.3.tar.gz", "program-1.2.3.1.tar.bz2", 1 },
66 { "program-1.2.3.zip", "program-1.2.3a.zip", 1 },
67 { "program-1.2.3.tar.bz2", "2.0.0", 1 },
68 { "prog-1.2-64bit.tar.bz2", "prog-1.2.3.tar.bz2", 1 },
69 { "prog-1.2-64bit.tar.bz2", "prog-1.2-64bit.tar.bz2", 0 },
70 { "prog-1.2-64bit.tar.bz2", "prog-1.2.3-64bit.tar.bz2", 1 },
71 { "prog-1.2a-64bit.tar.bz2","prog-1.2b-64bit.tar.bz2", 1 },
72 { "prog-1.2-64bit.tar.bz2", "prog-1.2.3a-64bit.tar.bz2", 1 },
73 { "prog-1.2a-64bit.tar.bz2","prog-1.2.3-64bit.tar.bz2", 1 },
77 void TestVersionCompare::testMain()
79 unsigned int i;
80 for(i = 0; i < sizeof(testdata) / sizeof(struct testvector); i++) {
81 QCOMPARE(Utils::compareVersionStrings(testdata[i].first,
82 testdata[i].second), testdata[i].expected);
83 // inverse test possible because function return values are symmetrical.
84 if(testdata[i].expected != 0)
85 QCOMPARE(Utils::compareVersionStrings(testdata[i].second,
86 testdata[i].first), -testdata[i].expected);
91 QTEST_MAIN(TestVersionCompare)
93 // this include is needed because we don't use a separate header file for the
94 // test class. It also needs to be at the end.
95 #include "test-compareversion.moc"