aboutsummaryrefslogtreecommitdiff
path: root/plugins/HostlistFilter/test/filterlist.cpp
blob: b9b381260119c5e7b7e609e34f9312fbc8340db5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#define CATCH_CONFIG_MAIN
#include "filterlist.h"
#include <QFile>
#include <catch2/catch.hpp>

// clazy:skip

using namespace Hostlist;

TEST_CASE("Hostlist")
{
    Filterlist list;

    const QString filename(qgetenv("HOSTLIST_TXT"));
    REQUIRE(!filename.isEmpty());

    QFile f(filename);
    REQUIRE(f.open(QIODevice::ReadOnly | QIODevice::Text));

    REQUIRE(list.load(f));
    f.close();

    REQUIRE(list.count() == 4);

    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);

    QUrl localhost("http://localhost.localdomain");
    REQUIRE(list.findMatch(localhost) == Filterlist::Redirect);
    REQUIRE(localhost.toString() == "http://127.0.0.1");

    QUrl other("http://other.domain");
    REQUIRE(list.findMatch(other) == Filterlist::NotFound);
}