File indexing completed on 2024-04-21 04:55:39

0001 /* ============================================================
0002 * Falkon - Qt web browser
0003 * Copyright (C) 2013-2014  David Rosca <nowrep@gmail.com>
0004 *
0005 * This program is free software: you can redistribute it and/or modify
0006 * it under the terms of the GNU General Public License as published by
0007 * the Free Software Foundation, either version 3 of the License, or
0008 * (at your option) any later version.
0009 *
0010 * This program is distributed in the hope that it will be useful,
0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 * GNU General Public License for more details.
0014 *
0015 * You should have received a copy of the GNU General Public License
0016 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017 * ============================================================ */
0018 #include "updatertest.h"
0019 #include "updater.h"
0020 
0021 #include <QtTest/QtTest>
0022 
0023 void UpdaterTest::parseVersionsTest_data()
0024 {
0025     QTest::addColumn<QString>("versionString");
0026     QTest::addColumn<bool>("valid");
0027     QTest::addColumn<int>("major");
0028     QTest::addColumn<int>("minor");
0029     QTest::addColumn<int>("revision");
0030 
0031     QTest::newRow("zeros") << "0.0.0" << true << 0 << 0 << 0;
0032     QTest::newRow("zero-1") << "0.0.1" << true << 0 << 0 << 1;
0033     QTest::newRow("current") << "1.4.1" << true << 1 << 4 << 1;
0034     QTest::newRow("next-bugfix") << "1.4.2" << true << 1 << 4 << 2;
0035     QTest::newRow("2digits") << "2.5.15" << true << 2 << 5 << 15;
0036     QTest::newRow("3digits") << "123.123.333" << true << 123 << 123 << 333;
0037     QTest::newRow("negative") << "-1.4.1" << false << 0 << 0 << 0;
0038     QTest::newRow("invalid") << "0.0.0-1" << false << 0 << 0 << 0;
0039     QTest::newRow("invalid2") << "invalid1text" << false << 0 << 0 << 0;
0040 }
0041 
0042 void UpdaterTest::parseVersionsTest()
0043 {
0044     QFETCH(QString, versionString);
0045     QFETCH(bool, valid);
0046     QFETCH(int, major);
0047     QFETCH(int, minor);
0048     QFETCH(int, revision);
0049 
0050     Updater::Version v(versionString);
0051 
0052     QCOMPARE(v.isValid, valid);
0053 
0054     if (valid) {
0055         QCOMPARE(v.majorVersion, major);
0056         QCOMPARE(v.minorVersion, minor);
0057         QCOMPARE(v.revisionNumber, revision);
0058     }
0059 }
0060 
0061 void UpdaterTest::compareVersionsTest_data()
0062 {
0063     QTest::addColumn<QString>("version1");
0064     QTest::addColumn<QString>("version2");
0065     QTest::addColumn<bool>("less");
0066     QTest::addColumn<bool>("more");
0067     QTest::addColumn<bool>("equal");
0068 
0069     QTest::newRow("test1") << "0.0.1" << "0.0.2" << true << false << false;
0070     QTest::newRow("test2") << "0.1.2" << "0.0.2" << false << true << false;
0071     QTest::newRow("test3") << "1.0.1" << "0.0.2" << false << true << false;
0072     QTest::newRow("test4") << "1.4.1" << "1.4.2" << true << false << false;
0073     QTest::newRow("test5") << "1.5.0" << "1.4.2" << false << true << false;
0074     QTest::newRow("test6") << "1.5.0" << "1.5.0" << false << false << true;
0075     QTest::newRow("test7") << "1.5.1" << "1.4.2" << false << true << false;
0076     QTest::newRow("test8") << "1.4.1" << "1.4.2" << true << false << false;
0077 }
0078 
0079 void UpdaterTest::compareVersionsTest()
0080 {
0081     QFETCH(QString, version1);
0082     QFETCH(QString, version2);
0083     QFETCH(bool, less);
0084     QFETCH(bool, more);
0085     QFETCH(bool, equal);
0086 
0087     Updater::Version v1(version1);
0088     Updater::Version v2(version2);
0089 
0090     QCOMPARE(v1 < v2, less);
0091     QCOMPARE(v1 > v2, more);
0092     QCOMPARE(v1 == v2, equal);
0093 }
0094 
0095 QTEST_GUILESS_MAIN(UpdaterTest)