aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
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)