aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2018-10-01 16:43:18 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2018-10-02 11:47:49 +0200
commit7d8cbdb9941532cd5bf560b21395f6ed371d1ab5 (patch)
tree9c5a2d72a3882050f2c3c95ec2d15ad21ff98a93 /test
parentupdater: windows fixes (diff)
downloadsmolbote-7d8cbdb9941532cd5bf560b21395f6ed371d1ab5.tar.xz
Split off UrlFilter into library
- add more adblock filter options
Diffstat (limited to 'test')
-rw-r--r--test/CMakeLists.txt4
-rw-r--r--test/adblock.txt2
-rw-r--r--test/urlfilter/adblocktest.cpp21
3 files changed, 17 insertions, 10 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index a026ad6..4302ab2 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -7,6 +7,6 @@ add_executable(AdBlockTest
urlfilter/adblocktest.h
)
-target_include_directories(AdBlockTest PRIVATE ../lib/web)
+target_include_directories(AdBlockTest PRIVATE ../lib/urlfilter)
-target_link_libraries(AdBlockTest Qt5::Test web)
+target_link_libraries(AdBlockTest Qt5::Test urlfilter)
diff --git a/test/adblock.txt b/test/adblock.txt
index 38d4688..cd284e8 100644
--- a/test/adblock.txt
+++ b/test/adblock.txt
@@ -1,4 +1,4 @@
/banner/*/img^
||ads.example.com^
|http://example.com/|
-
+/banner\d+/
diff --git a/test/urlfilter/adblocktest.cpp b/test/urlfilter/adblocktest.cpp
index 416bc20..b31d965 100644
--- a/test/urlfilter/adblocktest.cpp
+++ b/test/urlfilter/adblocktest.cpp
@@ -1,11 +1,12 @@
#include "adblocktest.h"
#include <QtTest/QtTest>
-#include "urlfilter/adblockrule.h"
+#include "filterrule.h"
+#include "formats/adblockrule.h"
-inline bool check(const std::vector<FilterRule> rules, const QUrl &url)
+inline bool check(const std::vector<AdBlockRule> rules, const QUrl &url)
{
- for(const FilterRule &rule : rules) {
- if(rule.matchesDomain(url.host()) && rule.matchesUrl(url))
+ for(const AdBlockRule &rule : rules) {
+ if(rule.matchesDomain(qHash(url.host())) && rule.matchesUrl(url))
return true;
}
return false;
@@ -13,9 +14,10 @@ inline bool check(const std::vector<FilterRule> rules, const QUrl &url)
void AdBlockTest::parseList()
{
- std::vector<FilterRule> rules;
+ std::vector<AdBlockRule> rules;
QFile list("adblock.txt");
+ int ruleCount = 0;
QCOMPARE(list.open(QIODevice::ReadOnly | QIODevice::Text), true);
{
QTextStream l(&list);
@@ -24,6 +26,7 @@ void AdBlockTest::parseList()
AdBlockRule rule(line);
if(rule.isEnabled()) {
rules.emplace_back(std::move(rule));
+ ruleCount++;
qDebug("added rule: %s", qUtf8Printable(line));
}
}
@@ -31,7 +34,7 @@ void AdBlockTest::parseList()
list.close();
// there should be 3 rules
- QCOMPARE(rules.size(), 3);
+ QCOMPARE(rules.size(), ruleCount);
// block by address part
QCOMPARE(check(rules, QUrl("http://example.com/banner/foo/img")), true);
@@ -48,11 +51,15 @@ void AdBlockTest::parseList()
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)