diff --git a/autotests/adblocktest.cpp b/autotests/adblocktest.cpp index f4c3a434..24158ae6 100644 --- a/autotests/adblocktest.cpp +++ b/autotests/adblocktest.cpp @@ -1,111 +1,111 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #include "adblocktest.h" #include "adblockrule.h" #include class AdBlockRule_Test : public AdBlockRule { public: QStringList parseRegExpFilter(const QString &parsedFilter) { return AdBlockRule::parseRegExpFilter(parsedFilter); } bool isMatchingDomain(const QString &domain, const QString &filter) const { return AdBlockRule::isMatchingDomain(domain, filter); } }; void AdBlockTest::isMatchingCookieTest_data() { // Test copied from CookiesTest QTest::addColumn("filterDomain"); QTest::addColumn("siteDomain"); QTest::addColumn("result"); QTest::newRow("test1") << "example.com" << "www.example.com" << true; QTest::newRow("test2") << "example.com" << "example.com" << true; QTest::newRow("test3") << "example.com" << "anotherexample.com" << false; QTest::newRow("test4") << "test.example.com" << "example.com" << false; QTest::newRow("test5") << "www.example.com" << "example.com" << false; QTest::newRow("test_empty") << "www.example.com" << "" << false; QTest::newRow("test_empty2") << "" << "example.com" << false; } void AdBlockTest::isMatchingCookieTest() { AdBlockRule_Test rule_test; QFETCH(QString, filterDomain); QFETCH(QString, siteDomain); QFETCH(bool, result); QCOMPARE(rule_test.isMatchingDomain(siteDomain, filterDomain), result); } void AdBlockTest::parseRegExpFilterTest_data() { QTest::addColumn("parsedFilter"); QTest::addColumn("result"); QTest::newRow("test1") << "||doubleclick.net/pfadx/tmg.telegraph." << (QStringList() << "doubleclick.net/pfadx/tmg.telegraph."); QTest::newRow("test2") << "||doubleclick.net/pfadx/*.mtvi" << (QStringList() << "doubleclick.net/pfadx/" << ".mtvi"); QTest::newRow("test3") << "&prvtof=*&poru=" << (QStringList() << "&prvtof=" << "&poru="); QTest::newRow("test4") << "/addyn|*;adtech;" << (QStringList() << "/addyn" << ";adtech;"); QTest::newRow("test5") << "/eas_fif.html^" << (QStringList() << "/eas_fif.html"); QTest::newRow("test6") << "://findnsave.^.*/api/groupon.json?" << (QStringList() << "://findnsave." << "/api/groupon.json?"); QTest::newRow("test7") << "^fp=*&prvtof=" << (QStringList() << "fp=" << "&prvtof="); QTest::newRow("test8") << "|http://ax-d.*/jstag^" << (QStringList() << "http://ax-d." << "/jstag"); QTest::newRow("test9") << "||reuters.com^*/rcom-wt-mlt.js" << (QStringList() << "reuters.com" <<"/rcom-wt-mlt.js"); QTest::newRow("test10") << "||chip.de^*/tracking.js" << (QStringList() << "chip.de" << "/tracking.js"); QTest::newRow("ignore1char") << "/search.php?uid=*.*&src=" << (QStringList() << "/search.php?uid=" << "&src="); QTest::newRow("ignoreDuplicates") << "/search.*.dup.*.dup.*&src=" << (QStringList() << "/search." << ".dup." << "&src="); QTest::newRow("empty") << QString() << (QStringList()); QTest::newRow("justspaces") << QString(" ") << (QStringList() << " "); QTest::newRow("spacesWithMetachars") << QString(" * ?") << (QStringList() << " " << " ?"); } void AdBlockTest::parseRegExpFilterTest() { AdBlockRule_Test rule_test; QFETCH(QString, parsedFilter); QFETCH(QStringList, result); QCOMPARE(rule_test.parseRegExpFilter(parsedFilter), result); } -QTEST_MAIN(AdBlockTest) +QTEST_GUILESS_MAIN(AdBlockTest) diff --git a/autotests/databaseencryptedpasswordbackendtest.cpp b/autotests/databaseencryptedpasswordbackendtest.cpp index b93a42f0..32cfa284 100644 --- a/autotests/databaseencryptedpasswordbackendtest.cpp +++ b/autotests/databaseencryptedpasswordbackendtest.cpp @@ -1,57 +1,57 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2013-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #include "databaseencryptedpasswordbackendtest.h" #include "aesinterface.h" #include #include #include void DatabaseEncryptedPasswordBackendTest::reloadBackend() { delete m_backend; DatabaseEncryptedPasswordBackend* backend = new DatabaseEncryptedPasswordBackend; if (m_testMasterPassword.isEmpty()) { m_testMasterPassword = AesInterface::passwordToHash(QString::fromUtf8(AesInterface::createRandomData(8))); backend->updateSampleData(m_testMasterPassword); } // a trick for setting masterPassword without gui interactions backend->isPasswordVerified(m_testMasterPassword); backend->setAskMasterPasswordState(false); m_backend = backend; } void DatabaseEncryptedPasswordBackendTest::init() { QSqlDatabase db = QSqlDatabase::database(); if (!db.isValid()) { db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":memory:"); } db.open(); } void DatabaseEncryptedPasswordBackendTest::cleanup() { QSqlDatabase::removeDatabase(QSqlDatabase::database().databaseName()); } -QTEST_MAIN(DatabaseEncryptedPasswordBackendTest) +QTEST_GUILESS_MAIN(DatabaseEncryptedPasswordBackendTest) diff --git a/autotests/databasepasswordbackendtest.cpp b/autotests/databasepasswordbackendtest.cpp index 89e3fa4d..c6c7ccdf 100644 --- a/autotests/databasepasswordbackendtest.cpp +++ b/autotests/databasepasswordbackendtest.cpp @@ -1,45 +1,45 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2013-2018 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #include "databasepasswordbackendtest.h" #include #include #include void DatabasePasswordBackendTest::reloadBackend() { delete m_backend; m_backend = new DatabasePasswordBackend; } void DatabasePasswordBackendTest::init() { QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(":memory:"); db.open(); db.exec("CREATE TABLE autofill (data TEXT, id INTEGER PRIMARY KEY, password TEXT," "server TEXT, username TEXT, last_used NUMERIC)"); } void DatabasePasswordBackendTest::cleanup() { QSqlDatabase::removeDatabase(QSqlDatabase::database().databaseName()); } -QTEST_MAIN(DatabasePasswordBackendTest) +QTEST_GUILESS_MAIN(DatabasePasswordBackendTest) diff --git a/autotests/qztoolstest.cpp b/autotests/qztoolstest.cpp index 05c39792..3a433b38 100644 --- a/autotests/qztoolstest.cpp +++ b/autotests/qztoolstest.cpp @@ -1,279 +1,279 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2013-2014 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #include "qztoolstest.h" #include "qztools.h" #include #include void QzToolsTest::initTestCase() { m_tmpPath = QDir::tempPath() + QL1S("/falkon-test/qztoolstest"); QDir().mkpath(m_tmpPath); QVERIFY(QDir(m_tmpPath).exists()); } void QzToolsTest::cleanupTestCase() { QDir().rmpath(m_tmpPath); QVERIFY(!QDir(m_tmpPath).exists()); } void QzToolsTest::samePartOfStrings_data() { QTest::addColumn("string1"); QTest::addColumn("string2"); QTest::addColumn("result"); // Lorem ipsum dolor sit amet, consectetur adipiscing elit. QTest::newRow("General") << "Lorem ipsum dolor" << "Lorem ipsum dolor Test_1" << "Lorem ipsum dolor"; QTest::newRow("OneChar") << "L" << "LTest_1" << "L"; QTest::newRow("EmptyReturn") << "Lorem ipsum dolor" << "orem ipsum dolor Test_1" << ""; QTest::newRow("EmptyString1") << "" << "orem ipsum dolor Test_1" << ""; QTest::newRow("EmptyString2") << "Lorem ipsum dolor" << "" << ""; QTest::newRow("EmptyBoth") << "" << "" << ""; } void QzToolsTest::samePartOfStrings() { QFETCH(QString, string1); QFETCH(QString, string2); QFETCH(QString, result); QCOMPARE(QzTools::samePartOfStrings(string1, string2), result); } void QzToolsTest::getFileNameFromUrl_data() { QTest::addColumn("url"); QTest::addColumn("result"); QTest::newRow("Basic") << QUrl("http://www.google.com/filename.html") << "filename.html"; QTest::newRow("OnlyHost") << QUrl("http://www.google.com/") << "www.google.com"; QTest::newRow("OnlyHostWithoutSlash") << QUrl("http://www.google.com") << "www.google.com"; QTest::newRow("EndingDirectory") << QUrl("http://www.google.com/filename/") << "filename"; QTest::newRow("EmptyUrl") << QUrl("") << ""; QTest::newRow("OnlyScheme") << QUrl("http:") << ""; QTest::newRow("FileSchemeUrl") << QUrl("file:///usr/share/test/file.tx") << "file.tx"; QTest::newRow("FileSchemeUrlDirectory") << QUrl("file:///usr/share/test/") << "test"; QTest::newRow("FileSchemeUrlRoot") << QUrl("file:///") << ""; } void QzToolsTest::getFileNameFromUrl() { QFETCH(QUrl, url); QFETCH(QString, result); QCOMPARE(QzTools::getFileNameFromUrl(url), result); } void QzToolsTest::splitCommandArguments_data() { QTest::addColumn("command"); QTest::addColumn("result"); QTest::newRow("Basic") << "/usr/bin/foo -o foo.out" << (QStringList() << "/usr/bin/foo" << "-o" << "foo.out"); QTest::newRow("Empty") << QString() << QStringList(); QTest::newRow("OnlySpaces") << QString(" ") << QStringList(); QTest::newRow("OnlyQuotes") << QString("\"\" \"\"") << QStringList(); QTest::newRow("EmptyQuotesAndSpace") << QString("\"\" \"\" \" \"") << QStringList(" "); QTest::newRow("MultipleSpaces") << " /usr/foo -o foo.out " << (QStringList() << "/usr/foo" << "-o" << "foo.out"); QTest::newRow("Quotes") << "\"/usr/foo\" \"-o\" \"foo.out\"" << (QStringList() << "/usr/foo" << "-o" << "foo.out"); QTest::newRow("SingleQuotes") << "'/usr/foo' '-o' 'foo.out'" << (QStringList() << "/usr/foo" << "-o" << "foo.out"); QTest::newRow("SingleAndDoubleQuotes") << " '/usr/foo' \"-o\" 'foo.out' " << (QStringList() << "/usr/foo" << "-o" << "foo.out"); QTest::newRow("SingleInDoubleQuotes") << "/usr/foo \"-o 'ds' \" 'foo.out' " << (QStringList() << "/usr/foo" << "-o 'ds' " << "foo.out"); QTest::newRow("DoubleInSingleQuotes") << "/usr/foo -o 'foo\" d \".out' " << (QStringList() << "/usr/foo" << "-o" << "foo\" d \".out"); QTest::newRow("SpacesWithQuotes") << QString(" \" \" \" \" ") << (QStringList() << " " << " "); QTest::newRow("QuotesAndSpaces") << "/usr/foo -o \"foo - out\"" << (QStringList() << "/usr/foo" << "-o" << "foo - out"); QTest::newRow("EqualAndQuotes") << "/usr/foo -o=\"foo - out\"" << (QStringList() << "/usr/foo" << "-o=foo - out"); QTest::newRow("EqualWithSpaces") << "/usr/foo -o = \"foo - out\"" << (QStringList() << "/usr/foo" << "-o" << "=" << "foo - out"); QTest::newRow("MultipleSpacesAndQuotes") << " /usr/foo -o=\" foo.out \" " << (QStringList() << "/usr/foo" << "-o= foo.out "); // Unmatched quotes should be treated as an error QTest::newRow("UnmatchedQuote") << "/usr/bin/foo -o \"bar" << QStringList(); } void QzToolsTest::splitCommandArguments() { QFETCH(QString, command); QFETCH(QStringList, result); QCOMPARE(QzTools::splitCommandArguments(command), result); } void QzToolsTest::escapeSqlGlobString_data() { QTest::addColumn("input"); QTest::addColumn("result"); QTest::newRow("NothingToEscape") << "http://test" << "http://test"; QTest::newRow("Escape *") << "http://test*/heh" << "http://test[*]/heh"; QTest::newRow("Escape **") << "http://test**/he*h" << "http://test[*][*]/he[*]h"; QTest::newRow("Escape ?") << "http://test?/heh" << "http://test[?]/heh"; QTest::newRow("Escape ??") << "http://t??est?/heh" << "http://t[?][?]est[?]/heh"; QTest::newRow("Escape [") << "http://[test/heh" << "http://[[]test/heh"; QTest::newRow("Escape [[") << "http://[[te[st/heh" << "http://[[][[]te[[]st/heh"; QTest::newRow("Escape ]") << "http://]test/heh" << "http://[]]test/heh"; QTest::newRow("Escape ]]") << "http://]]te]st/heh" << "http://[]][]]te[]]st/heh"; QTest::newRow("Escape []") << "http://[]test/heh" << "http://[[][]]test/heh"; QTest::newRow("Escape [][[]][]") << "http://t[][[]][]est/heh" << "http://t[[][]][[][[][]][]][[][]]est/heh"; QTest::newRow("Escape [?]][[*]") << "http://t[?]][[*]est/heh" << "http://t[[][?][]][]][[][[][*][]]est/heh"; } void QzToolsTest::escapeSqlGlobString() { QFETCH(QString, input); QFETCH(QString, result); QCOMPARE(QzTools::escapeSqlGlobString(input), result); } class TempFile { QString name; public: explicit TempFile(const QString &name) : name(name) { QFile file(name); file.open(QFile::WriteOnly); file.write(QByteArrayLiteral("falkon-test")); file.close(); } ~TempFile() { QFile::remove(name); } }; void QzToolsTest::ensureUniqueFilename() { QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out")), createPath("test.out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test")); // default appendFormat = (%1) { TempFile f1(createPath("test.out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out")), createPath("test(1).out")); TempFile f2(createPath("test(1).out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out")), createPath("test(2).out")); TempFile f3(createPath("test(2).out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out")), createPath("test(3).out")); } { TempFile f1(createPath("test")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test(1)")); TempFile f2(createPath("test(1)")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test(2)")); TempFile f3(createPath("test(2)")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test(3)")); } { TempFile f1(createPath("test(1)")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test")); TempFile f2(createPath("test")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test")), createPath("test(2)")); } // appendFormat = %1 { QString appendFormat = QSL("%1"); TempFile f1(createPath("test.out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test1.out")); TempFile f2(createPath("test1.out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test2.out")); TempFile f3(createPath("test2.out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test3.out")); } { QString appendFormat = QSL("%1"); TempFile f1(createPath("test")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test1")); TempFile f2(createPath("test1")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test2")); TempFile f3(createPath("test2")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test3")); } { QString appendFormat = QSL("%1"); TempFile f1(createPath("test1")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test")); TempFile f2(createPath("test")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test2")); } // appendFormat = .%1 { QString appendFormat = QSL(".%1"); TempFile f1(createPath("test.out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test.1.out")); TempFile f2(createPath("test.1.out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test.2.out")); TempFile f3(createPath("test.2.out")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test.out"), appendFormat), createPath("test.3.out")); } { QString appendFormat = QSL(".%1"); TempFile f1(createPath("test")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test.1")); TempFile f2(createPath("test.1")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test.2")); TempFile f3(createPath("test.2")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test.3")); } { QString appendFormat = QSL(".%1"); TempFile f1(createPath("test.1")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test")); TempFile f2(createPath("test")); QCOMPARE(QzTools::ensureUniqueFilename(createPath("test"), appendFormat), createPath("test.2")); } } QString QzToolsTest::createPath(const char *file) const { return m_tmpPath + QL1S("/") + file; } -QTEST_MAIN(QzToolsTest) +QTEST_GUILESS_MAIN(QzToolsTest) diff --git a/autotests/updatertest.cpp b/autotests/updatertest.cpp index 24861a30..8a146e13 100644 --- a/autotests/updatertest.cpp +++ b/autotests/updatertest.cpp @@ -1,95 +1,95 @@ /* ============================================================ * Falkon - Qt web browser * Copyright (C) 2013-2014 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * ============================================================ */ #include "updatertest.h" #include "updater.h" #include void UpdaterTest::parseVersionsTest_data() { QTest::addColumn("versionString"); QTest::addColumn("valid"); QTest::addColumn("major"); QTest::addColumn("minor"); QTest::addColumn("revision"); QTest::newRow("zeros") << "0.0.0" << true << 0 << 0 << 0; QTest::newRow("zero-1") << "0.0.1" << true << 0 << 0 << 1; QTest::newRow("current") << "1.4.1" << true << 1 << 4 << 1; QTest::newRow("next-bugfix") << "1.4.2" << true << 1 << 4 << 2; QTest::newRow("2digits") << "2.5.15" << true << 2 << 5 << 15; QTest::newRow("3digits") << "123.123.333" << true << 123 << 123 << 333; QTest::newRow("negative") << "-1.4.1" << false << 0 << 0 << 0; QTest::newRow("invalid") << "0.0.0-1" << false << 0 << 0 << 0; QTest::newRow("invalid2") << "invalid1text" << false << 0 << 0 << 0; } void UpdaterTest::parseVersionsTest() { QFETCH(QString, versionString); QFETCH(bool, valid); QFETCH(int, major); QFETCH(int, minor); QFETCH(int, revision); Updater::Version v(versionString); QCOMPARE(v.isValid, valid); if (valid) { QCOMPARE(v.majorVersion, major); QCOMPARE(v.minorVersion, minor); QCOMPARE(v.revisionNumber, revision); } } void UpdaterTest::compareVersionsTest_data() { QTest::addColumn("version1"); QTest::addColumn("version2"); QTest::addColumn("less"); QTest::addColumn("more"); QTest::addColumn("equal"); QTest::newRow("test1") << "0.0.1" << "0.0.2" << true << false << false; QTest::newRow("test2") << "0.1.2" << "0.0.2" << false << true << false; QTest::newRow("test3") << "1.0.1" << "0.0.2" << false << true << false; QTest::newRow("test4") << "1.4.1" << "1.4.2" << true << false << false; QTest::newRow("test5") << "1.5.0" << "1.4.2" << false << true << false; QTest::newRow("test6") << "1.5.0" << "1.5.0" << false << false << true; QTest::newRow("test7") << "1.5.1" << "1.4.2" << false << true << false; QTest::newRow("test8") << "1.4.1" << "1.4.2" << true << false << false; } void UpdaterTest::compareVersionsTest() { QFETCH(QString, version1); QFETCH(QString, version2); QFETCH(bool, less); QFETCH(bool, more); QFETCH(bool, equal); Updater::Version v1(version1); Updater::Version v2(version2); QCOMPARE(v1 < v2, less); QCOMPARE(v1 > v2, more); QCOMPARE(v1 == v2, equal); } -QTEST_MAIN(UpdaterTest) +QTEST_GUILESS_MAIN(UpdaterTest)