diff options
Diffstat (limited to 'test/urlfilter/adblocktest.cpp')
-rw-r--r-- | test/urlfilter/adblocktest.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/urlfilter/adblocktest.cpp b/test/urlfilter/adblocktest.cpp new file mode 100644 index 0000000..d1060f1 --- /dev/null +++ b/test/urlfilter/adblocktest.cpp @@ -0,0 +1,40 @@ +#include "adblocktest.h" +#include <QtTest/QtTest> +#include "urlfilter/adblockrule.h" + +void AdBlockTest::blockByAddressPart() +{ + AdBlockRule rule("/banner/*/img^"); + + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/foo/img")), true); + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/foo/bar/img?param")), true); + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner//img/foo")), true); + + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/img")), false); + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/foo/imgraph")), false); + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/banner/foo/img.gif")), false); +} + +void AdBlockTest::blockByDomain() +{ + AdBlockRule rule("||ads.example.com^"); + + QCOMPARE(rule.shouldBlock(QUrl("http://ads.example.com/foo.gif")), true); + QCOMPARE(rule.shouldBlock(QUrl("http://server1.ads.example.com/foo.gif")), true); + QCOMPARE(rule.shouldBlock(QUrl("https://ads.example.com:8000/")), true); + + QCOMPARE(rule.shouldBlock(QUrl("http://ads.example.com.ua/foo.gif")), false); + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/redirect/http://ads.example.com/")), false); +} + +void AdBlockTest::blockExactAddress() +{ + AdBlockRule rule("|http://example.com/|"); + + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/")), true); + + QCOMPARE(rule.shouldBlock(QUrl("http://example.com/foo.gif")), false); + QCOMPARE(rule.shouldBlock(QUrl("http://example.info/redirect/http://example.com/")), false); +} + +QTEST_GUILESS_MAIN(AdBlockTest) |