aboutsummaryrefslogtreecommitdiff
path: root/plugins/HostlistFilter/test
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/HostlistFilter/test')
-rw-r--r--plugins/HostlistFilter/test/filterlist.cpp16
-rw-r--r--plugins/HostlistFilter/test/plugin.cpp2
-rw-r--r--plugins/HostlistFilter/test/rule.cpp58
3 files changed, 43 insertions, 33 deletions
diff --git a/plugins/HostlistFilter/test/filterlist.cpp b/plugins/HostlistFilter/test/filterlist.cpp
index 4aa532b..b9b3812 100644
--- a/plugins/HostlistFilter/test/filterlist.cpp
+++ b/plugins/HostlistFilter/test/filterlist.cpp
@@ -3,6 +3,8 @@
#include <QFile>
#include <catch2/catch.hpp>
+// clazy:skip
+
using namespace Hostlist;
TEST_CASE("Hostlist")
@@ -20,10 +22,16 @@ TEST_CASE("Hostlist")
REQUIRE(list.count() == 4);
- REQUIRE(list.findMatch("blockeddomain.first"));
- REQUIRE(list.findMatch("blockeddomain.second"));
+ QUrl first("http://blockeddomain.first");
+ REQUIRE(list.findMatch(first) == Filterlist::Block);
+
+ QUrl second("http://blockeddomain.second/path/to/something");
+ REQUIRE(list.findMatch(second) == Filterlist::Block);
- REQUIRE(list.findMatch("localhost.localdomain"));
+ QUrl localhost("http://localhost.localdomain");
+ REQUIRE(list.findMatch(localhost) == Filterlist::Redirect);
+ REQUIRE(localhost.toString() == "http://127.0.0.1");
- REQUIRE(!list.findMatch("other.domain"));
+ QUrl other("http://other.domain");
+ REQUIRE(list.findMatch(other) == Filterlist::NotFound);
}
diff --git a/plugins/HostlistFilter/test/plugin.cpp b/plugins/HostlistFilter/test/plugin.cpp
index fad34f2..026f579 100644
--- a/plugins/HostlistFilter/test/plugin.cpp
+++ b/plugins/HostlistFilter/test/plugin.cpp
@@ -3,6 +3,8 @@
#include <QFile>
#include <catch2/catch.hpp>
+// clazy:skip
+
TEST_CASE("Hostlist")
{
HostlistFilterPlugin plugin;
diff --git a/plugins/HostlistFilter/test/rule.cpp b/plugins/HostlistFilter/test/rule.cpp
index b5ba6e0..5ee9881 100644
--- a/plugins/HostlistFilter/test/rule.cpp
+++ b/plugins/HostlistFilter/test/rule.cpp
@@ -2,56 +2,56 @@
#include "filterlist.h"
#include <catch2/catch.hpp>
+// clazy:skip
+
using namespace Hostlist;
SCENARIO("Hostlist::Rule")
{
GIVEN("an invalid rule")
{
- const auto rule = Filterlist::parseRule("0.0.0.0 ");
- REQUIRE(rule.empty());
+ QStringList b;
+ QHash<QString, QString> r;
+ parseRule("0.0.0.0 ", b, r);
+
+ REQUIRE(b.empty());
+ REQUIRE(r.empty());
}
GIVEN("127.0.0.1 localhost.localdomain")
{
- auto rule = Filterlist::parseRule("127.0.0.1 localhost.localdomain");
+ QStringList b;
+ QHash<QString, QString> r;
+ parseRule("127.0.0.1 localhost.localdomain", b, r);
- REQUIRE(!rule.empty());
- REQUIRE(rule.size() == 1);
+ REQUIRE(b.empty());
+ REQUIRE(r.size() == 1);
- // note: you need to force it to hash a string, rather than the address itself
- const auto index = qHash(QString("localhost.localdomain"), 0);
- REQUIRE(rule[index].domain == "localhost.localdomain");
- REQUIRE(rule[index].redirect == "127.0.0.1");
+ REQUIRE(r.value("localhost.localdomain") == "127.0.0.1");
}
GIVEN("0.0.0.0 blockeddomain.com")
{
- auto rule = Filterlist::parseRule("0.0.0.0 blockeddomain.com");
+ QStringList b;
+ QHash<QString, QString> r;
+ parseRule("0.0.0.0 blockeddomain.com", b, r);
- REQUIRE(!rule.empty());
- REQUIRE(rule.size() == 1);
+ REQUIRE(b.size() == 1);
+ REQUIRE(r.empty());
- const auto index = qHash(QString("blockeddomain.com"), 0);
- REQUIRE(rule[index].domain == "blockeddomain.com");
- REQUIRE(rule[index].redirect.isEmpty());
+ REQUIRE(b.contains("blockeddomain.com"));
;
}
GIVEN("0.0.0.0 blockeddomain.first blockeddomain.second")
{
- auto rule = Filterlist::parseRule("0.0.0.0 blockeddomain.first blockeddomain.second");
-
- REQUIRE(!rule.empty());
- REQUIRE(rule.size() == 2);
- {
- const auto index = qHash(QString("blockeddomain.first"), 0);
- REQUIRE(rule[index].domain == "blockeddomain.first");
- REQUIRE(rule[index].redirect.isEmpty());
- }
- {
- const auto index = qHash(QString("blockeddomain.second"), 0);
- REQUIRE(rule[index].domain == "blockeddomain.second");
- REQUIRE(rule[index].redirect.isEmpty());
- }
+ QStringList b;
+ QHash<QString, QString> r;
+ parseRule("0.0.0.0 blockeddomain.first blockeddomain.second", b, r);
+
+ REQUIRE(b.size() == 2);
+ REQUIRE(r.empty());
+
+ REQUIRE(b.contains("blockeddomain.first"));
+ REQUIRE(b.contains("blockeddomain.second"));
}
}