aboutsummaryrefslogtreecommitdiff
path: root/staging/adblock/test
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2020-04-19 18:45:20 +0300
committerAqua-sama <aqua@iserlohn-fortress.net>2020-04-21 20:14:58 +0300
commit29f584fb51738385b4257d35d4041bac6e72071d (patch)
treee3f31c7f1e616396e01d88b93bd691717aa5de9c /staging/adblock/test
parentHostlist: test list parsing (diff)
downloadsmolbote-29f584fb51738385b4257d35d4041bac6e72071d.tar.xz
Fix some clazy warnings
Diffstat (limited to 'staging/adblock/test')
-rw-r--r--staging/adblock/test/filterlist.cpp42
-rw-r--r--staging/adblock/test/rule.cpp32
2 files changed, 44 insertions, 30 deletions
diff --git a/staging/adblock/test/filterlist.cpp b/staging/adblock/test/filterlist.cpp
index 262e84b..ca122ac 100644
--- a/staging/adblock/test/filterlist.cpp
+++ b/staging/adblock/test/filterlist.cpp
@@ -22,6 +22,8 @@ TEST_CASE("placeholder")
TEST_CASE("domain match")
{
+ const QString defaultUrl = "";
+
const QString block1 = "http://ads.example.com/foo.gif";
const QString block2 = "http://server1.ads.example.com/foo.gif";
const QString block3 = "https://ads.example.com:8000/";
@@ -34,19 +36,21 @@ TEST_CASE("domain match")
REQUIRE(rule->shouldBlock());
REQUIRE(!rule->shouldRedirect());
- REQUIRE(rule->hasMatch(&block1));
- REQUIRE(rule->hasMatch(&block2));
- REQUIRE(rule->hasMatch(&block3));
- REQUIRE(rule->hasMatch(&block4));
+ REQUIRE(rule->hasMatch(&block1, &defaultUrl, &defaultUrl));
+ REQUIRE(rule->hasMatch(&block2, &defaultUrl, &defaultUrl));
+ REQUIRE(rule->hasMatch(&block3, &defaultUrl, &defaultUrl));
+ REQUIRE(rule->hasMatch(&block4, &defaultUrl, &defaultUrl));
- REQUIRE(!rule->hasMatch(&allow1));
- REQUIRE(!rule->hasMatch(&allow2));
+ REQUIRE(!rule->hasMatch(&allow1, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule->hasMatch(&allow2, &defaultUrl, &defaultUrl));
delete rule;
}
TEST_CASE("string equals")
{
+ const QString defaultUrl = "";
+
const QString block = "http://example.com/";
const QString allow1 = "http://example.com/foo.gif";
@@ -56,16 +60,18 @@ TEST_CASE("string equals")
REQUIRE(rule->shouldBlock());
REQUIRE(!rule->shouldRedirect());
- REQUIRE(rule->hasMatch(&block));
+ REQUIRE(rule->hasMatch(&block, &defaultUrl, &defaultUrl));
- REQUIRE(!rule->hasMatch(&allow1));
- REQUIRE(!rule->hasMatch(&allow2));
+ REQUIRE(!rule->hasMatch(&allow1, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule->hasMatch(&allow2, &defaultUrl, &defaultUrl));
delete rule;
}
TEST_CASE("string starts with")
{
+ const QString defaultUrl = "";
+
auto *rule = FilterList::parseRule("|http://baddomain.example/");
REQUIRE(rule->shouldBlock());
REQUIRE(!rule->shouldRedirect());
@@ -73,13 +79,15 @@ TEST_CASE("string starts with")
const QString blocks = "http://baddomain.example/banner.gif";
const QString allows = "http://gooddomain.example/analyze?http://baddomain.example";
- REQUIRE(rule->hasMatch(&blocks));
- REQUIRE(!rule->hasMatch(&allows));
+ REQUIRE(rule->hasMatch(&blocks, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule->hasMatch(&allows, &defaultUrl, &defaultUrl));
delete rule;
}
TEST_CASE("string ends with")
{
+ const QString defaultUrl = "";
+
auto *rule = FilterList::parseRule("swf|");
REQUIRE(rule->shouldBlock());
REQUIRE(!rule->shouldRedirect());
@@ -87,22 +95,24 @@ TEST_CASE("string ends with")
const QString blocks = "http://example.com/annoyingflash.swf";
const QString allows = "http://example.com/swf/index.html";
- REQUIRE(rule->hasMatch(&blocks));
- REQUIRE(!rule->hasMatch(&allows));
+ REQUIRE(rule->hasMatch(&blocks, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule->hasMatch(&allows, &defaultUrl, &defaultUrl));
delete rule;
}
TEST_CASE("regular expressions")
{
+ const QString defaultUrl = "";
+
auto *rule = FilterList::parseRule("/banner\\d+/");
const QString matches1 = "banner123";
const QString matches2 = "banner321";
const QString ignores = "banners";
- REQUIRE(rule->hasMatch(&matches1));
- REQUIRE(rule->hasMatch(&matches2));
- REQUIRE(!rule->hasMatch(&ignores));
+ REQUIRE(rule->hasMatch(&matches1, &defaultUrl, &defaultUrl));
+ REQUIRE(rule->hasMatch(&matches2, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule->hasMatch(&ignores, &defaultUrl, &defaultUrl));
delete rule;
}
diff --git a/staging/adblock/test/rule.cpp b/staging/adblock/test/rule.cpp
index 31af7d5..07186b9 100644
--- a/staging/adblock/test/rule.cpp
+++ b/staging/adblock/test/rule.cpp
@@ -8,6 +8,8 @@ SCENARIO("MatcherRule")
{
GIVEN("options with case sensitive pattern")
{
+ const QString defaultUrl = "";
+
const Options opt { .matchcase=true };
const QString patternContains("this string contains the pattern in it");
const QString patternBegins("pattern starts this string");
@@ -21,10 +23,10 @@ SCENARIO("MatcherRule")
THEN("pattern is matched anywhere in the URL")
{
- REQUIRE(rule.hasMatch(&patternContains));
- REQUIRE(rule.hasMatch(&patternBegins));
- REQUIRE(rule.hasMatch(&patternEnds));
- REQUIRE(!rule.hasMatch(&patternMissing));
+ REQUIRE(rule.hasMatch(&patternContains, &defaultUrl, &defaultUrl));
+ REQUIRE(rule.hasMatch(&patternBegins, &defaultUrl, &defaultUrl));
+ REQUIRE(rule.hasMatch(&patternEnds, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule.hasMatch(&patternMissing, &defaultUrl, &defaultUrl));
}
}
@@ -35,10 +37,10 @@ SCENARIO("MatcherRule")
THEN("pattern is matched if at the start of the URL")
{
- REQUIRE(!rule.hasMatch(&patternContains));
- REQUIRE(rule.hasMatch(&patternBegins));
- REQUIRE(!rule.hasMatch(&patternEnds));
- REQUIRE(!rule.hasMatch(&patternMissing));
+ REQUIRE(!rule.hasMatch(&patternContains, &defaultUrl, &defaultUrl));
+ REQUIRE(rule.hasMatch(&patternBegins, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule.hasMatch(&patternEnds, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule.hasMatch(&patternMissing, &defaultUrl, &defaultUrl));
}
}
@@ -49,10 +51,10 @@ SCENARIO("MatcherRule")
THEN("pattern is matched if at the end of the URL")
{
- REQUIRE(!rule.hasMatch(&patternContains));
- REQUIRE(!rule.hasMatch(&patternBegins));
- REQUIRE(rule.hasMatch(&patternEnds));
- REQUIRE(!rule.hasMatch(&patternMissing));
+ REQUIRE(!rule.hasMatch(&patternContains, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule.hasMatch(&patternBegins, &defaultUrl, &defaultUrl));
+ REQUIRE(rule.hasMatch(&patternEnds, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule.hasMatch(&patternMissing, &defaultUrl, &defaultUrl));
}
}
}
@@ -62,6 +64,8 @@ SCENARIO("RegexRule")
{
GIVEN("options with case sensitive pattern")
{
+ const QString defaultUrl;
+
const Options opt { .matchcase=true };
const QString patternContains("this string contains the pattern in it");
const QString patternMissing("and this one does not");
@@ -73,8 +77,8 @@ SCENARIO("RegexRule")
THEN("pattern is matched anywhere in the URL")
{
- REQUIRE(rule.hasMatch(&patternContains));
- REQUIRE(!rule.hasMatch(&patternMissing));
+ REQUIRE(rule.hasMatch(&patternContains, &defaultUrl, &defaultUrl));
+ REQUIRE(!rule.hasMatch(&patternMissing, &defaultUrl, &defaultUrl));
}
}
}