diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-07-09 20:19:30 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2018-07-09 20:19:30 +0200 |
commit | 9808d18fa6cd19400f08897014a9948f168927df (patch) | |
tree | b4224f737ec01391e7d443ad142c94ec4c0bb17f /test | |
parent | Remove PageMenu (diff) | |
download | smolbote-9808d18fa6cd19400f08897014a9948f168927df.tar.xz |
AdBlock rule testing
Diffstat (limited to 'test')
-rw-r--r-- | test/CMakeLists.txt | 9 | ||||
-rw-r--r-- | test/urlfilter/adblocktest.cpp | 40 | ||||
-rw-r--r-- | test/urlfilter/adblocktest.h | 15 |
3 files changed, 64 insertions, 0 deletions
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index a44da07..414d616 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,3 +12,12 @@ target_include_directories(UrlFilterTest ) target_link_libraries(UrlFilterTest Qt5::Test web) + +add_executable(AdBlockTest + urlfilter/adblocktest.cpp + urlfilter/adblocktest.h +) + +target_include_directories(AdBlockTest PRIVATE ../lib/web) + +target_link_libraries(AdBlockTest Qt5::Test web) 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) diff --git a/test/urlfilter/adblocktest.h b/test/urlfilter/adblocktest.h new file mode 100644 index 0000000..a7b9f12 --- /dev/null +++ b/test/urlfilter/adblocktest.h @@ -0,0 +1,15 @@ +#ifndef ADBLOCKTEST_H +#define ADBLOCKTEST_H + +#include <QObject> +class AdBlockTest : public QObject +{ + Q_OBJECT + +private slots: + void blockByAddressPart(); + void blockByDomain(); + void blockExactAddress(); +}; + +#endif // ADBLOCKTEST_H |