blob: 76e607b5cfe9cafc96d545e659cc479a7bf163f8 (
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
/*
* This file is part of smolbote. It's copyrighted by the contributors recorded
* in the version control history of the file, available from its original
* location: git://neueland.iserlohn-fortress.net/smolbote.git
*
* SPDX-License-Identifier: GPL-3.0
*/
#include "filtertest.h"
#include <QtTest/QtTest>
#include "../filterrule.h"
#include <QUrl>
FilterTest::FilterTest(QObject *parent) : QObject(parent)
{
}
void FilterTest::initTestCase()
{
addressRule = new FilterRule("/banner/*/img^");
QVERIFY(addressRule->isValid() == true);
QVERIFY(addressRule->isException() == false);
domainRule = new FilterRule("||ads.example.com^");
QVERIFY(domainRule->isValid() == true);
QVERIFY(domainRule->isException() == false);
exactAddressRule = new FilterRule("|http://example.com/|");
QVERIFY(exactAddressRule->isValid() == true);
QVERIFY(exactAddressRule->isException() == false);
}
void FilterTest::testAddressBlock()
{
// This rule blocks:
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/foo/img")) == true);
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/foo/bar/img?param")) == true);
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner//img/foo")) == true);
// This rule doesn't block:
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/img")) == false);
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/foo/imgraph")) == false);
QVERIFY(addressRule->shouldBlock(QUrl("http://example.com/banner/foo/img.gif")) == false);
}
void FilterTest::testDomainBlock()
{
// This rule blocks:
QVERIFY(domainRule->shouldBlock(QUrl("http://ads.example.com/foo.gif")) == true);
QVERIFY(domainRule->shouldBlock(QUrl("http://server1.ads.example.com/foo.gif")) == true);
QVERIFY(domainRule->shouldBlock(QUrl("https://ads.example.com:8000/")) == true);
// This rule doesn't block:
QVERIFY(domainRule->shouldBlock(QUrl("http://ads.example.com.ua/foo.gif")) == false);
QVERIFY(domainRule->shouldBlock(QUrl("http://example.com/redirect/http://ads.example.com/")) == false);
}
void FilterTest::testExactAddressBlock()
{
// This rule blocks:
QVERIFY(exactAddressRule->shouldBlock(QUrl("http://example.com/")) == true);
// This rule doesn't block:
QVERIFY(exactAddressRule->shouldBlock(QUrl("http://example.com/foo.gif")) == false);
QVERIFY(exactAddressRule->shouldBlock(QUrl("http://example.info/redirect/http://example.com/")) == false);
}
void FilterTest::cleanupTestCase()
{
delete addressRule;
}
|