From a8b39613341484a1e88d87c45cefaa9a4ead720b Mon Sep 17 00:00:00 2001 From: Benjamin C Meyer Date: Mon, 17 Aug 2009 01:15:48 -0400 Subject: [PATCH] make the tests works with the existing adblock code --- autotests/adblockfilter/tst_adblockfilter.cpp | 30 +++++++-- src/adblock/adblock.pri | 2 - src/adblock/adblockfilter.cpp | 62 ------------------ src/adblock/adblockfilter.h | 63 ------------------- src/adblock/networkaccesspolicy.cpp | 2 +- 5 files changed, 27 insertions(+), 132 deletions(-) delete mode 100644 src/adblock/adblockfilter.cpp delete mode 100644 src/adblock/adblockfilter.h diff --git a/autotests/adblockfilter/tst_adblockfilter.cpp b/autotests/adblockfilter/tst_adblockfilter.cpp index 92e4db2b..9ab0ab28 100644 --- a/autotests/adblockfilter/tst_adblockfilter.cpp +++ b/autotests/adblockfilter/tst_adblockfilter.cpp @@ -18,7 +18,11 @@ */ #include -#include + +#include + +#include +#include class tst_AdBlockFilter : public QObject { @@ -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 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() diff --git a/src/adblock/adblock.pri b/src/adblock/adblock.pri index 11e164a5..999c99e4 100644 --- a/src/adblock/adblock.pri +++ b/src/adblock/adblock.pri @@ -3,7 +3,6 @@ DEPENDPATH += $$PWD HEADERS += \ adblocksubscription.h \ - adblockfilter.h \ blockednetworkreply.h \ networkaccesspolicy.h \ urlaccessrule.h \ @@ -16,7 +15,6 @@ HEADERS += \ SOURCES += \ adblocksubscription.cpp \ -# adblockfilter.cpp \ blockednetworkreply.cpp \ networkaccesspolicy.cpp \ urlaccessrule.cpp \ diff --git a/src/adblock/adblockfilter.cpp b/src/adblock/adblockfilter.cpp deleted file mode 100644 index 2318e791..00000000 --- a/src/adblock/adblockfilter.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2009, Benjamin C. Meyer - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Benjamin Meyer nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -AdBlockFilter::AdBlockFilter(const QString &filter) - : m_filter(filter); -{ -} - -bool AdBlockFilter::isException() const -{ - return false; -} - -bool AdBlockFilter::isComment() const -{ - return m_filter.value(0) == QLatin1Char('!'); -} - -bool AdBlockFilter::appliesToHtml() const -{ - return m_filter.contains(QLatin1String("##")); -} - -bool AdBlockFilter::match(const QUrl &url) -{ - return false; -} - -void AdBlockFilter::load(QDataStream &in, AdBlockFilter &filter) -{ -} - -void AdBlockFilter::save(QDataStream &out, const AdBlockFilter &filter) -{ -} - - diff --git a/src/adblock/adblockfilter.h b/src/adblock/adblockfilter.h deleted file mode 100644 index 2aeb4cc7..00000000 --- a/src/adblock/adblockfilter.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2009, Benjamin C. Meyer - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the Benjamin Meyer nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef ADBLOCKFILTER_H -#define ADBLOCKFILTER_H - -class AdBlockFilter -{ - -public: - AdBlockFilter(const QString &filter) {}; - - bool isException() const; - bool isComment() const; - bool appliesToHtml() const; - - bool match(const QUrl &url) { return false; } ; - - static void load(QDataStream &in, AdBlockFilter &filter); - static void save(QDataStream &out, const AdBlockFilter &filter); - -private: - QString m_filter; - //bool m_enabled; - //uint m_hitCount; - //QDateTime m_lastHit; - -}; - -/* -QDataStream &operator<<(QDataStream &, const AdBlockFilter &filter); -QDataStream &operator>>(QDataStream &, AdBlockFilter &filter); - -Q_DECLARE_METATYPE(AdBlockFilter) -Q_DECLARE_METATYPE(QList) -*/ -#endif // ADBLOCKFILTER_H - diff --git a/src/adblock/networkaccesspolicy.cpp b/src/adblock/networkaccesspolicy.cpp index 94ee02a3..797255ce 100644 --- a/src/adblock/networkaccesspolicy.cpp +++ b/src/adblock/networkaccesspolicy.cpp @@ -148,7 +148,7 @@ bool NetworkAccessPolicy::importAdBlockRules(QTextStream &txt, QList