From a35b365504c51d4c8e605e5586438deb93ad6d63 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sat, 18 Apr 2020 15:06:35 +0300 Subject: Add staging/hostlist --- staging/hostlist/test/rule.cpp | 57 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 staging/hostlist/test/rule.cpp (limited to 'staging/hostlist/test/rule.cpp') diff --git a/staging/hostlist/test/rule.cpp b/staging/hostlist/test/rule.cpp new file mode 100644 index 0000000..6a16f86 --- /dev/null +++ b/staging/hostlist/test/rule.cpp @@ -0,0 +1,57 @@ +#define CATCH_CONFIG_MAIN +#include "filterlist.hpp" +#include + +using namespace Hostlist; + +SCENARIO("MatcherRule") +{ + GIVEN("an invalid rule") + { + const auto rule = Filterlist::parseRule("0.0.0.0 "); + REQUIRE(rule.empty()); + } + GIVEN("127.0.0.1 localhost.localdomain") + { + auto rule = Filterlist::parseRule("127.0.0.1 localhost.localdomain"); + + REQUIRE(!rule.empty()); + REQUIRE(rule.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"); + } + + GIVEN("0.0.0.0 blockeddomain.com") + { + auto rule = Filterlist::parseRule("0.0.0.0 blockeddomain.com"); + + REQUIRE(!rule.empty()); + REQUIRE(rule.size() == 1); + + const auto index = qHash(QString("blockeddomain.com"), 0); + REQUIRE(rule[index].domain == "blockeddomain.com"); + REQUIRE(rule[index].redirect.isEmpty()); + ; + } + + 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()); + } + } +} -- cgit v1.2.1