#define CATCH_CONFIG_MAIN #include "filterlist.h" #include #include using namespace AdblockPlus; QByteArray sampleList = R"(! comment on line ! Last modified: 1 Jan 2000 00:00 UTC ! Expires: 4 days (update frequency) )"; TEST_CASE("placeholder") { QBuffer buffer(&sampleList); buffer.open(QIODevice::ReadOnly | QIODevice::Text); AdblockPlus::FilterList list(buffer); REQUIRE(!list.isUpToDate()); } TEST_CASE("domain match") { const QString block1 = "http://ads.example.com/foo.gif"; const QString block2 = "http://server1.ads.example.com/foo.gif"; const QString block3 = "https://ads.example.com:8000/"; const QString block4 = "https://ads.example.com"; const QString allow1 = "http://ads.example.com.ua/foo.gif"; const QString allow2 = "http://example.com/redirect/http://ads.example.com/"; auto *rule = FilterList::parseRule("||ads.example.com^"); REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); REQUIRE(rule->hasMatch(&block1)); REQUIRE(rule->hasMatch(&block2)); REQUIRE(rule->hasMatch(&block3)); REQUIRE(rule->hasMatch(&block4)); REQUIRE(!rule->hasMatch(&allow1)); REQUIRE(!rule->hasMatch(&allow2)); delete rule; } TEST_CASE("string equals") { const QString block = "http://example.com/"; const QString allow1 = "http://example.com/foo.gif"; const QString allow2 = "http://example.info/redirect/http://example.com/"; auto *rule = FilterList::parseRule("|http://example.com/|"); REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); REQUIRE(rule->hasMatch(&block)); REQUIRE(!rule->hasMatch(&allow1)); REQUIRE(!rule->hasMatch(&allow2)); delete rule; } TEST_CASE("string starts with") { auto *rule = FilterList::parseRule("|http://baddomain.example/"); REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); const QString blocks = "http://baddomain.example/banner.gif"; const QString allows = "http://gooddomain.example/analyze?http://baddomain.example"; REQUIRE(rule->hasMatch(&blocks)); REQUIRE(!rule->hasMatch(&allows)); delete rule; } TEST_CASE("string ends with") { auto *rule = FilterList::parseRule("swf|"); REQUIRE(rule->shouldBlock()); REQUIRE(!rule->shouldRedirect()); const QString blocks = "http://example.com/annoyingflash.swf"; const QString allows = "http://example.com/swf/index.html"; REQUIRE(rule->hasMatch(&blocks)); REQUIRE(!rule->hasMatch(&allows)); delete rule; }