Add cleaned up tests used for Utils::compareVersionStrings().
[kugel-rb.git] / rbutil / rbutilqt / test / compareversion.cpp
blobdb1c62e5d58d2ee59374c0d81e3868c2fb8b56b3
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 Dominik Riebeling
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <QtTest/QtTest>
23 #include <QObject>
24 #include "utils.h"
27 class TestVersionCompare : public QObject
29 Q_OBJECT
30 private slots:
31 void testMain();
35 struct testvector {
36 const char* first;
37 const char* second;
38 const int expected;
41 const struct testvector testdata[] =
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 },
68 void TestVersionCompare::testMain()
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);
81 QTEST_MAIN(TestVersionCompare)
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"