aboutsummaryrefslogtreecommitdiff
path: root/test/urlfilter
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-16 17:25:40 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-16 17:25:40 +0200
commitc74367d82c1c7bec393548d2e5014c794333822f (patch)
tree909bcde935c84e566db528b1ab25d81778e13036 /test/urlfilter
parentAdd workaround for QTBUG-62511 (diff)
downloadsmolbote-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/urlfilter')
-rw-r--r--test/urlfilter/adblocktest.cpp65
-rw-r--r--test/urlfilter/adblocktest.h13
2 files changed, 0 insertions, 78 deletions
diff --git a/test/urlfilter/adblocktest.cpp b/test/urlfilter/adblocktest.cpp
deleted file mode 100644
index b31d965..0000000
--- a/test/urlfilter/adblocktest.cpp
+++ /dev/null
@@ -1,65 +0,0 @@
-#include "adblocktest.h"
-#include <QtTest/QtTest>
-#include "filterrule.h"
-#include "formats/adblockrule.h"
-
-inline bool check(const std::vector<AdBlockRule> rules, const QUrl &url)
-{
- for(const AdBlockRule &rule : rules) {
- if(rule.matchesDomain(qHash(url.host())) && rule.matchesUrl(url))
- return true;
- }
- return false;
-}
-
-void AdBlockTest::parseList()
-{
- std::vector<AdBlockRule> rules;
-
- QFile list("adblock.txt");
- int ruleCount = 0;
- QCOMPARE(list.open(QIODevice::ReadOnly | QIODevice::Text), true);
- {
- QTextStream l(&list);
- QString line;
- while(l.readLineInto(&line)) {
- AdBlockRule rule(line);
- if(rule.isEnabled()) {
- rules.emplace_back(std::move(rule));
- ruleCount++;
- qDebug("added rule: %s", qUtf8Printable(line));
- }
- }
- }
- list.close();
-
- // there should be 3 rules
- QCOMPARE(rules.size(), ruleCount);
-
- // block by address part
- QCOMPARE(check(rules, QUrl("http://example.com/banner/foo/img")), true);
- QCOMPARE(check(rules, QUrl("http://example.com/banner/foo/bar/img?param")), true);
- QCOMPARE(check(rules, QUrl("http://example.com/banner//img/foo")), true);
- QCOMPARE(check(rules, QUrl("http://example.com/banner/img")), false);
- QCOMPARE(check(rules, QUrl("http://example.com/banner/foo/imgraph")), false);
- QCOMPARE(check(rules, QUrl("http://example.com/banner/foo/img.gif")), false);
-
- // block by domain
- QCOMPARE(check(rules, QUrl("http://ads.example.com/foo.gif")), true);
- QCOMPARE(check(rules, QUrl("http://server1.ads.example.com/foo.gif")), true);
- QCOMPARE(check(rules, QUrl("https://ads.example.com:8000/")), true);
- QCOMPARE(check(rules, QUrl("http://ads.example.com.ua/foo.gif")), false);
- QCOMPARE(check(rules, QUrl("http://example.com/redirect/http://ads.example.com/")), false);
-
- // block exact address
- QCOMPARE(check(rules, QUrl("http://example.com/")), true);
- QCOMPARE(check(rules, QUrl("http://example.com/foo.gif")), false);
- QCOMPARE(check(rules, QUrl("http://example.info/redirect/http://example.com/")), false);
-
- // regular expression
- QCOMPARE(check(rules, QUrl("http://another.com/banner123")), true);
- QCOMPARE(check(rules, QUrl("http://another.com/banner321")), true);
- QCOMPARE(check(rules, QUrl("http://another.com/banners")), false);
-}
-
-QTEST_GUILESS_MAIN(AdBlockTest)
diff --git a/test/urlfilter/adblocktest.h b/test/urlfilter/adblocktest.h
deleted file mode 100644
index 95cb7e2..0000000
--- a/test/urlfilter/adblocktest.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#ifndef ADBLOCKTEST_H
-#define ADBLOCKTEST_H
-
-#include <QObject>
-class AdBlockTest : public QObject
-{
- Q_OBJECT
-
-private slots:
- void parseList();
-};
-
-#endif // ADBLOCKTEST_H