#include "hostlisttest.h" #include void HostlistTest::parseList() { //FilterTree tree; // load filters QFile hostlist("hostlist.txt"); QCOMPARE(hostlist.open(QIODevice::ReadOnly | QIODevice::Text), true); QCOMPARE(loadHostlist(hostlist, &tree), true); QCOMPARE(tree.branches().length(), 1); } void HostlistTest::checkRules() { // test block QVector block = tree.match(QString(), "blockeddomain.com"); QCOMPARE(block.length(), 1); QCOMPARE(block.constFirst()->action(), FilterLeaf::Block); // test redirect QVector redirectResult = tree.match(QString(), "localhost.localdomain"); QCOMPARE(redirectResult.length(), 1); QCOMPARE(redirectResult.at(0)->action(), FilterLeaf::Redirect); QCOMPARE(redirectResult.at(0)->redirect(), "127.0.0.1"); // two domains on one line QVector blockFirst = tree.match(QString(), "blockeddomain.first"); QCOMPARE(blockFirst.length(), 1); QCOMPARE(blockFirst.constFirst()->action(), FilterLeaf::Block); QVector blockSecond = tree.match(QString(), "blockeddomain.second"); QCOMPARE(blockSecond.length(), 1); QCOMPARE(blockSecond.constFirst()->action(), FilterLeaf::Block); // domain not on list QVector missing = tree.match(QString(), "other.domain"); QCOMPARE(missing.length(), 0); } QTEST_GUILESS_MAIN(HostlistTest)