diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-16 17:25:40 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-10-16 17:25:40 +0200 |
commit | c74367d82c1c7bec393548d2e5014c794333822f (patch) | |
tree | 909bcde935c84e566db528b1ab25d81778e13036 /test/hostlist | |
parent | Add workaround for QTBUG-62511 (diff) | |
download | smolbote-c74367d82c1c7bec393548d2e5014c794333822f.tar.xz |
urlfilter: Add FilterTree class
FilterTree is a class that holds filter rules, sorted by the domain they
are to be applied on. The rules are to follow FilterLeaf as interface.
- Add a hostlist rule format to FilterTree.
- Add a test for hostlist format.
Diffstat (limited to 'test/hostlist')
-rw-r--r-- | test/hostlist/hostlisttest.cpp | 42 | ||||
-rw-r--r-- | test/hostlist/hostlisttest.h | 19 |
2 files changed, 61 insertions, 0 deletions
diff --git a/test/hostlist/hostlisttest.cpp b/test/hostlist/hostlisttest.cpp new file mode 100644 index 0000000..46f6a85 --- /dev/null +++ b/test/hostlist/hostlisttest.cpp @@ -0,0 +1,42 @@ +#include "hostlisttest.h" +#include <QtTest/QtTest> + +void HostlistTest::parseList() +{ + //FilterTree tree; + + // load filters + QFile hostlist("hostlist.txt"); + QCOMPARE(hostlist.open(QIODevice::ReadOnly | QIODevice::Text), true); + QCOMPARE(loadHostlist(hostlist, &tree), true); + + QCOMPARE(tree.branches().length(), 1); +} + +void HostlistTest::checkRules() +{ + // test block + QVector<const FilterLeaf *> block = tree.match(QString(), "blockeddomain.com"); + QCOMPARE(block.length(), 1); + QCOMPARE(block.constFirst()->action(), FilterLeaf::Block); + + // test redirect + QVector<const FilterLeaf *> redirectResult = tree.match(QString(), "localhost.localdomain"); + QCOMPARE(redirectResult.length(), 1); + QCOMPARE(redirectResult.at(0)->action(), FilterLeaf::Redirect); + QCOMPARE(redirectResult.at(0)->redirect(), "127.0.0.1"); + + // two domains on one line + QVector<const FilterLeaf *> blockFirst = tree.match(QString(), "blockeddomain.first"); + QCOMPARE(blockFirst.length(), 1); + QCOMPARE(blockFirst.constFirst()->action(), FilterLeaf::Block); + QVector<const FilterLeaf *> blockSecond = tree.match(QString(), "blockeddomain.second"); + QCOMPARE(blockSecond.length(), 1); + QCOMPARE(blockSecond.constFirst()->action(), FilterLeaf::Block); + + // domain not on list + QVector<const FilterLeaf *> missing = tree.match(QString(), "other.domain"); + QCOMPARE(missing.length(), 0); +} + +QTEST_GUILESS_MAIN(HostlistTest) diff --git a/test/hostlist/hostlisttest.h b/test/hostlist/hostlisttest.h new file mode 100644 index 0000000..9a87e0d --- /dev/null +++ b/test/hostlist/hostlisttest.h @@ -0,0 +1,19 @@ +#ifndef HOSTLIST_TEST +#define HOSTLIST_TEST + +#include <QObject> +#include "filtertree.h" + +class HostlistTest : public QObject +{ + Q_OBJECT + +private slots: + void parseList(); + void checkRules(); + +private: + FilterTree tree; +}; + +#endif |