diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-01-09 19:38:58 +0100 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2019-01-09 19:38:58 +0100 |
commit | 3d2ae07c455c0e423c64f19e445518427a5684fa (patch) | |
tree | 58f6b47c3db33658a6f2e605fd021f08d1fa9964 /test/hostlist | |
parent | Add assorted unfished doc files to repo (diff) | |
download | smolbote-3d2ae07c455c0e423c64f19e445518427a5684fa.tar.xz |
Rewrite lib/urlfilter
- Make HostList and AdBlockList implementations independent from each
other
- Move urlfilter tests to lib/urlfilter
Diffstat (limited to 'test/hostlist')
-rw-r--r-- | test/hostlist/hostlisttest.cpp | 61 | ||||
-rw-r--r-- | test/hostlist/hostlisttest.h | 23 |
2 files changed, 0 insertions, 84 deletions
diff --git a/test/hostlist/hostlisttest.cpp b/test/hostlist/hostlisttest.cpp deleted file mode 100644 index 7f5c954..0000000 --- a/test/hostlist/hostlisttest.cpp +++ /dev/null @@ -1,61 +0,0 @@ -#include "hostlisttest.h" -#include <QtTest/QtTest> - -void HostlistTest::parseList() -{ - // load filters - QFile hostlist("hostlist.txt"); - QCOMPARE(hostlist.open(QIODevice::ReadOnly | QIODevice::Text), true); - QCOMPARE(loadHostlist(hostlist, &tree), true); - - // hostlist filters are applied to all domains, so there should only be one branch - QCOMPARE(tree.branches().length(), 1); -} - -void HostlistTest::checkRules_data() -{ - QTest::addColumn<QUrl>("domain"); - QTest::addColumn<QUrl>("request"); - QTest::addColumn<int>("matches"); - QTest::addColumn<FilterLeaf::Action>("action"); - - const QVector<QUrl> domains{ QUrl(), QUrl::fromUserInput("testdomain.host") }; - for(const QUrl &domain : domains) { - QTest::newRow("block (1 domain per line)") << domain << QUrl::fromUserInput("blockeddomain.com") << 1 << FilterLeaf::Block; - QTest::newRow("block (2 domains per line #1)") << domain << QUrl::fromUserInput("blockeddomain.first") << 1 << FilterLeaf::Block; - QTest::newRow("block (2 domains per line #2)") << domain << QUrl::fromUserInput("blockeddomain.second") << 1 << FilterLeaf::Block; - QTest::newRow("redirect") << domain << QUrl::fromUserInput("localhost.localdomain") << 1 << FilterLeaf::Redirect; - QTest::newRow("domain not in hostlist") << domain << QUrl::fromUserInput("other.domain") << 0 << FilterLeaf::NotMatched; - } -} - -void HostlistTest::checkRules() -{ - QFETCH(QUrl, domain); - QFETCH(QUrl, request); - QFETCH(int, matches); - QFETCH(FilterLeaf::Action, action); - - auto result = tree.match(domain, request); - QCOMPARE(result.length(), matches); - if(matches > 0) - QCOMPARE(result.constFirst()->action().first, action); - if(action == FilterLeaf::Redirect) - QCOMPARE(result.constFirst()->action().second, QLatin1Literal("127.0.0.1")); -} - -void HostlistTest::benchmark_parse() -{ - QFile hostlist("hostlist-benchmark.txt"); - if(hostlist.open(QIODevice::ReadOnly | QIODevice::Text)) { - FilterTree benchmarkTree; - bool loaded; - QBENCHMARK { - loaded = loadHostlist(hostlist, &benchmarkTree); - } - QCOMPARE(loaded, true); - hostlist.close(); - } -} - -QTEST_GUILESS_MAIN(HostlistTest) diff --git a/test/hostlist/hostlisttest.h b/test/hostlist/hostlisttest.h deleted file mode 100644 index 96051a9..0000000 --- a/test/hostlist/hostlisttest.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef HOSTLIST_TEST -#define HOSTLIST_TEST - -#include "filtertree.h" -#include <QObject> - -class HostlistTest : public QObject -{ - Q_OBJECT - -private slots: - void parseList(); - - void checkRules_data(); - void checkRules(); - - void benchmark_parse(); - -private: - FilterTree tree; -}; - -#endif |