Skip to content

Commit

Permalink
make the tests works with the existing adblock code
Browse files Browse the repository at this point in the history
  • Loading branch information
icefox authored and gzsombor committed Sep 12, 2009
1 parent 066ecfc commit a8b3961
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 132 deletions.
30 changes: 26 additions & 4 deletions autotests/adblockfilter/tst_adblockfilter.cpp
Expand Up @@ -18,7 +18,11 @@
*/

#include <QtTest/QtTest>
#include <adblockfilter.h>

#include <qbuffer.h>

#include <urlaccessrule.h>
#include <networkaccesspolicy.h>

class tst_AdBlockFilter : public QObject
{
Expand All @@ -36,13 +40,31 @@ private slots:
};

// Subclass that exposes the protected functions.
class SubAdBlockFilter : public AdBlockFilter
class SubAdBlockFilter
{
public:
SubAdBlockFilter(const QString &filter)
: AdBlockFilter(filter) {}
SubAdBlockFilter(const QString &filter);
bool match(const QUrl &url);
UrlAccessRule *rule;
};

SubAdBlockFilter::SubAdBlockFilter(const QString &filter)
: rule(0)
{
QList<UrlAccessRule*> rules;
QString dummy = "dummy";
QBuffer buffer(&filter.toUtf8());
bool ok = NetworkAccessPolicy::importAdBlockRules(buffer, rules, dummy);
rule = rules.value(0);
}

bool SubAdBlockFilter::match(const QUrl &url)
{
if (!rule)
return false;
return rule->match(url.toString());
}

// This will be called before the first test function is executed.
// It is only called once.
void tst_AdBlockFilter::initTestCase()
Expand Down
2 changes: 0 additions & 2 deletions src/adblock/adblock.pri
Expand Up @@ -3,7 +3,6 @@ DEPENDPATH += $$PWD

HEADERS += \
adblocksubscription.h \
adblockfilter.h \
blockednetworkreply.h \
networkaccesspolicy.h \
urlaccessrule.h \
Expand All @@ -16,7 +15,6 @@ HEADERS += \

SOURCES += \
adblocksubscription.cpp \
# adblockfilter.cpp \
blockednetworkreply.cpp \
networkaccesspolicy.cpp \
urlaccessrule.cpp \
Expand Down
62 changes: 0 additions & 62 deletions src/adblock/adblockfilter.cpp

This file was deleted.

63 changes: 0 additions & 63 deletions src/adblock/adblockfilter.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/adblock/networkaccesspolicy.cpp
Expand Up @@ -148,7 +148,7 @@ bool NetworkAccessPolicy::importAdBlockRules(QTextStream &txt, QList<UrlAccessR
QString line;
rules.clear();
do {
line = txt.readLine(1024);
line = txt.readLine();
if (!line.startsWith(QLatin1String("!")) && !line.contains(QLatin1Char('#'))) {
bool exception = false;

Expand Down

0 comments on commit a8b3961

Please sign in to comment.