diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 15 | ||||
-rw-r--r-- | test/adblock/adblocktest.cpp (renamed from test/urlfilter/adblocktest.cpp) | 0 | ||||
-rw-r--r-- | test/adblock/adblocktest.h (renamed from test/urlfilter/adblocktest.h) | 0 | ||||
-rw-r--r-- | test/hostlist.txt | 6 | ||||
-rw-r--r-- | test/hostlist/hostlisttest.cpp | 42 | ||||
-rw-r--r-- | test/hostlist/hostlisttest.h | 19 |
6 files changed, 79 insertions, 3 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 4302ab2..6b740d7 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -3,10 +3,19 @@ set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) add_executable(AdBlockTest - urlfilter/adblocktest.cpp - urlfilter/adblocktest.h + adblock/adblocktest.cpp + adblock/adblocktest.h ) target_include_directories(AdBlockTest PRIVATE ../lib/urlfilter) - target_link_libraries(AdBlockTest Qt5::Test urlfilter) + +add_executable(HostlistTest + hostlist/hostlisttest.cpp + hostlist/hostlisttest.h +) +target_include_directories(HostlistTest PRIVATE ../lib/urlfilter/) +target_link_libraries(HostlistTest Qt5::Test urlfilter) + +add_test(NAME urlfilter-adblock COMMAND AdBlockTest WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) +add_test(NAME urlfilter-hostlist COMMAND HostlistTest WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}) diff --git a/test/urlfilter/adblocktest.cpp b/test/adblock/adblocktest.cpp index b31d965..b31d965 100644 --- a/test/urlfilter/adblocktest.cpp +++ b/test/adblock/adblocktest.cpp diff --git a/test/urlfilter/adblocktest.h b/test/adblock/adblocktest.h index 95cb7e2..95cb7e2 100644 --- a/test/urlfilter/adblocktest.h +++ b/test/adblock/adblocktest.h diff --git a/test/hostlist.txt b/test/hostlist.txt new file mode 100644 index 0000000..a0b4e5c --- /dev/null +++ b/test/hostlist.txt @@ -0,0 +1,6 @@ +# This is a comment, and after it comes a blank line + +127.0.0.1 localhost.localdomain + +0.0.0.0 blockeddomain.com +0.0.0.0 blockeddomain.first blockeddomain.second 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 |