diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/auto.pro | 7 | ||||
-rw-r--r-- | tests/auto/tst_analytics/tst_analytics.cpp | 118 | ||||
-rw-r--r-- | tests/auto/tst_analytics/tst_analytics.pro | 10 | ||||
-rw-r--r-- | tests/auto/tst_config/analytics.json | 3 | ||||
-rw-r--r-- | tests/auto/tst_config/tst_config.cpp | 85 | ||||
-rw-r--r-- | tests/auto/tst_config/tst_config.pro | 13 | ||||
-rw-r--r-- | tests/auto/tst_config/tst_config.qrc | 5 | ||||
-rw-r--r-- | tests/auto/tst_google/tst_google.cpp | 111 | ||||
-rw-r--r-- | tests/auto/tst_google/tst_google.pro | 10 | ||||
-rw-r--r-- | tests/auto/tst_matomo/tst_matomo.cpp | 102 | ||||
-rw-r--r-- | tests/auto/tst_matomo/tst_matomo.pro | 10 | ||||
-rw-r--r-- | tests/auto/tst_urlbuilder/tst_urlbuilder.cpp | 96 | ||||
-rw-r--r-- | tests/auto/tst_urlbuilder/tst_urlbuilder.pro | 10 | ||||
-rw-r--r-- | tests/tests.pro | 6 |
14 files changed, 586 insertions, 0 deletions
diff --git a/tests/auto/auto.pro b/tests/auto/auto.pro new file mode 100644 index 0000000..9797882 --- /dev/null +++ b/tests/auto/auto.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + tst_google \ + tst_config \ + tst_analytics \ + tst_matomo diff --git a/tests/auto/tst_analytics/tst_analytics.cpp b/tests/auto/tst_analytics/tst_analytics.cpp new file mode 100644 index 0000000..6b1f7f9 --- /dev/null +++ b/tests/auto/tst_analytics/tst_analytics.cpp @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtTest> + +#include "analytics.h" +#include "hitbuilder.h" +#include "googlebuilder.h" +#include "matomobuilder.h" +#include "context.h" + +class AnalyticsTestCase: public QObject { + Q_OBJECT +private slots: + void testEmptyTracker(); + void testGoogleTracker(); + void testMatomoTracker(); + void testWrongTracker(); + void testServerConfig(); +}; + +void AnalyticsTestCase::testEmptyTracker() +{ + QScopedPointer<Analytics> a(new Analytics()); + HitBuilder * builder = a->getBuilder(); + QCOMPARE(nullptr, builder); +} + +void AnalyticsTestCase::testGoogleTracker() +{ + QScopedPointer<Analytics> a(new Analytics()); + QVariantMap o{ + {"tracker", "google"}, + }; + a->context()->updateConfig(o); + HitBuilder * builder = a->getBuilder(); + QVERIFY(qobject_cast<GoogleBuilder*>(builder)); +} + +void AnalyticsTestCase::testMatomoTracker() +{ + QScopedPointer<Analytics> a(new Analytics()); + QVariantMap o{ + {"tracker", "matomo"}, + }; + a->context()->updateConfig(o); + HitBuilder * builder = a->getBuilder(); + QVERIFY(qobject_cast<MatomoBuilder*>(builder)); + +} + +void AnalyticsTestCase::testWrongTracker() +{ + QScopedPointer<Analytics> a(new Analytics()); + QVariantMap o{ + {"tracker", "unknown"}, + }; + a->context()->updateConfig(o); + HitBuilder * builder = a->getBuilder(); + QCOMPARE(nullptr, builder); + +} + +void AnalyticsTestCase::testServerConfig() +{ + QScopedPointer<Analytics> a(new Analytics()); + QVariantMap o{ + {"tracker", "matomo"}, + {"server", "http://localhost:8000/"}, + }; + a->context()->updateConfig(o); + HitBuilder *builder = a->getBuilder(); + QVERIFY(qobject_cast<MatomoBuilder*>(builder)); + qDebug() << "003"; + QCOMPARE(builder->context()->configString("server"), "http://localhost:8000/"); +} + + +QTEST_MAIN(AnalyticsTestCase) + +#include "tst_analytics.moc" diff --git a/tests/auto/tst_analytics/tst_analytics.pro b/tests/auto/tst_analytics/tst_analytics.pro new file mode 100644 index 0000000..fd3a7eb --- /dev/null +++ b/tests/auto/tst_analytics/tst_analytics.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = tst_analytics + +QT += testlib +CONFIG += testcase + +include( ../../../src/plugin/plugin.pri ) + +SOURCES += \ + tst_analytics.cpp diff --git a/tests/auto/tst_config/analytics.json b/tests/auto/tst_config/analytics.json new file mode 100644 index 0000000..90a9804 --- /dev/null +++ b/tests/auto/tst_config/analytics.json @@ -0,0 +1,3 @@ +{ + "service": "matomo" +} diff --git a/tests/auto/tst_config/tst_config.cpp b/tests/auto/tst_config/tst_config.cpp new file mode 100644 index 0000000..09c5c93 --- /dev/null +++ b/tests/auto/tst_config/tst_config.cpp @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtTest> + +#include "configutil.h" + +class ConfigTestCase: public QObject { + Q_OBJECT +private Q_SLOTS: + void testResolveConfig(); + void testReadConfig(); + void testParseConfig(); + void testLoadConfig(); +}; + +void ConfigTestCase::testResolveConfig() +{ + + QString path = ConfigUtil::resolvePath("analytics"); + QCOMPARE(path, ":/analytics.json"); +} + +void ConfigTestCase::testReadConfig() +{ + QByteArray data = ConfigUtil::readJSON(":/analytics.json"); + QJsonDocument doc = QJsonDocument::fromJson(data); + QVERIFY(doc.isObject()); + QCOMPARE(doc.object().value("service"), "matomo"); +} + +void ConfigTestCase::testParseConfig() +{ + QString path = ConfigUtil::resolvePath("analytics"); + QByteArray data = ConfigUtil::readJSON(path); + QJsonObject o = ConfigUtil::parseJSON(data); + QCOMPARE(o.value("service"), "matomo"); +} + +void ConfigTestCase::testLoadConfig() +{ + QJsonObject o = ConfigUtil::loadJSON("analytics"); + QCOMPARE(o.value("service"), "matomo"); +} + +QTEST_MAIN(ConfigTestCase) + +#include "tst_config.moc" diff --git a/tests/auto/tst_config/tst_config.pro b/tests/auto/tst_config/tst_config.pro new file mode 100644 index 0000000..464a79b --- /dev/null +++ b/tests/auto/tst_config/tst_config.pro @@ -0,0 +1,13 @@ +TEMPLATE = app +TARGET = tst_config + +QT += testlib +CONFIG += testcase + +include( ../../../src/plugin/plugin.pri ) + +SOURCES += \ + tst_config.cpp + +RESOURCES += \ + tst_config.qrc diff --git a/tests/auto/tst_config/tst_config.qrc b/tests/auto/tst_config/tst_config.qrc new file mode 100644 index 0000000..9a59655 --- /dev/null +++ b/tests/auto/tst_config/tst_config.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>analytics.json</file> + </qresource> +</RCC> diff --git a/tests/auto/tst_google/tst_google.cpp b/tests/auto/tst_google/tst_google.cpp new file mode 100644 index 0000000..63414e2 --- /dev/null +++ b/tests/auto/tst_google/tst_google.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtTest> + +#include "googlebuilder.h" +#include "context.h" + +class GoogleTestCase: public QObject { + Q_OBJECT +private slots: + void testEmpty(); + void testTrackPage(); + void testTrackEvent(); +}; + + +void GoogleTestCase::testEmpty() +{ + QVariantMap o{ + {"tid", "12345"}, + }; + QScopedPointer<Context> ctx(new Context(this)); + ctx->setConfig(o); + QScopedPointer<GoogleBuilder> b(new GoogleBuilder(ctx.data())); + b->initQuery(); + QUrlQuery query = b->query(); + QCOMPARE("1", query.queryItemValue(GoogleBuilder::VERSION)); + QCOMPARE("12345", query.queryItemValue(GoogleBuilder::TRACKER_ID)); + ctx->deleteLater(); +} + +void GoogleTestCase::testTrackPage() +{ + QScopedPointer<Context> ctx(new Context(this)); + QScopedPointer<GoogleBuilder> b(new GoogleBuilder(ctx.data())); + QVariantMap o{ + {"tid", "12345"}, + {"cid", "44144"}, + }; + ctx->updateConfig(o); + b->initQuery(); + b->trackPage("/home", "click"); + QUrlQuery query = b->query(); + QCOMPARE("12345", query.queryItemValue("tid")); + QCOMPARE("44144", query.queryItemValue("cid")); + QCOMPARE("1", query.queryItemValue("v")); + QCOMPARE("pageview", query.queryItemValue("t")); + QCOMPARE("/home", query.queryItemValue("dp")); + QCOMPARE(b->url().toString(), "https://www.google-analytics.com/collect"); +} + +void GoogleTestCase::testTrackEvent() +{ + QScopedPointer<Context> ctx(new Context(this)); + QVariantMap o{ + {"tid", "12345"}, + {"cid", "44144"}, + }; + ctx->updateConfig(o); + QScopedPointer<GoogleBuilder> b(new GoogleBuilder(ctx.data())); + b->trackEvent("cat", "click", QString(), QString()); + b->initQuery(); + QUrlQuery query = b->query(); + QCOMPARE("12345", query.queryItemValue("tid")); + QCOMPARE("44144", query.queryItemValue("cid")); + QCOMPARE("cat", query.queryItemValue("ec")); + QCOMPARE("click", query.queryItemValue("ea")); + QCOMPARE(b->url().toString(), "https://www.google-analytics.com/collect"); +} + +QTEST_MAIN(GoogleTestCase) + +#include "tst_google.moc" diff --git a/tests/auto/tst_google/tst_google.pro b/tests/auto/tst_google/tst_google.pro new file mode 100644 index 0000000..96608b0 --- /dev/null +++ b/tests/auto/tst_google/tst_google.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = tst_google + +QT += testlib +CONFIG += testcase + +include( ../../../src/plugin/plugin.pri ) + +SOURCES += \ + tst_google.cpp diff --git a/tests/auto/tst_matomo/tst_matomo.cpp b/tests/auto/tst_matomo/tst_matomo.cpp new file mode 100644 index 0000000..caf5613 --- /dev/null +++ b/tests/auto/tst_matomo/tst_matomo.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtTest> + +#include "matomobuilder.h" +#include "context.h" + +class MatomoTestCase: public QObject { + Q_OBJECT +private slots: + void init(); + void testRequired(); + void testTrackPage(); + void testTrackEvent(); + +}; + +void MatomoTestCase::init() +{ + qDebug() << "init"; +} + +void MatomoTestCase::testRequired() +{ + QVariantMap o{ + {"idsite", "123"}, + {"rec", "1"}, + }; + QScopedPointer<Context> ctx(new Context(this)); + ctx->setConfig(o); + QScopedPointer<MatomoBuilder> b(new MatomoBuilder(ctx.data())); + b->initQuery(); + QUrlQuery query = b->query(); + QCOMPARE("123", query.queryItemValue(MatomoBuilder::SITE_ID)); + QCOMPARE("1", query.queryItemValue(MatomoBuilder::RECORDING)); +} + +void MatomoTestCase::testTrackPage() +{ + QScopedPointer<Context> ctx(new Context(this)); + QScopedPointer<MatomoBuilder> b(new MatomoBuilder(ctx.data())); + b->initQuery(); + b->trackPage("/home", "click"); + QUrlQuery query = b->query(); + qDebug() << query.toString(); + QCOMPARE("/home", query.queryItemValue(MatomoBuilder::ACTION_URL)); + QCOMPARE("click", query.queryItemValue(MatomoBuilder::ACTION_NAME)); +} + +void MatomoTestCase::testTrackEvent() +{ + QScopedPointer<Context> ctx(new Context(this)); + QScopedPointer<MatomoBuilder> b(new MatomoBuilder(ctx.data())); + b->initQuery(); + b->trackEvent("category", "action", QString(), QString()); + QUrlQuery query = b->query(); + qDebug() << query.toString(); + QCOMPARE("category", query.queryItemValue(MatomoBuilder::EVENT_CATEGORY)); + QCOMPARE("action", query.queryItemValue(MatomoBuilder::EVENT_ACTION)); +} + +QTEST_MAIN(MatomoTestCase) + +#include "tst_matomo.moc" diff --git a/tests/auto/tst_matomo/tst_matomo.pro b/tests/auto/tst_matomo/tst_matomo.pro new file mode 100644 index 0000000..de20ff0 --- /dev/null +++ b/tests/auto/tst_matomo/tst_matomo.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = tst_matomo + +QT += testlib +CONFIG += testcase + +include( ../../../src/plugin/plugin.pri ) + +SOURCES += \ + tst_matomo.cpp diff --git a/tests/auto/tst_urlbuilder/tst_urlbuilder.cpp b/tests/auto/tst_urlbuilder/tst_urlbuilder.cpp new file mode 100644 index 0000000..72f12ed --- /dev/null +++ b/tests/auto/tst_urlbuilder/tst_urlbuilder.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Luxoft Sweden AB. All rights reserved. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the analytics module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 3 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL3 included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 3 requirements +** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 2.0 or (at your option) the GNU General +** Public license version 3 or any later version approved by the KDE Free +** Qt Foundation. The licenses are as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-2.0.html and +** https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore> +#include <QtTest> + +#include "matomotracker.h" + +/* + * The tracking API is documented at: + * https://developer.matomo.org/api-reference/tracking-api + */ + +class UrlBuilderTestCase: public QObject { + Q_OBJECT +public: + explicit UrlBuilderTestCase(); +private Q_SLOTS: + void init(); + void cleanup(); + void testDefault(); + void testPing(); + void testVisit(); + void testEvent(); +private: +}; + + +UrlBuilderTestCase::UrlBuilderTestCase() + : QObject () +{ +} + +void UrlBuilderTestCase::init() +{ +} + +void UrlBuilderTestCase::cleanup() +{ +} + + +void UrlBuilderTestCase::testDefault() +{ +} +void UrlBuilderTestCase::testPing() +{ +} + +void UrlBuilderTestCase::testVisit() +{ +} + +void UrlBuilderTestCase::testEvent() +{ +} + +QTEST_MAIN(UrlBuilderTestCase) + +#include "tst_urlbuilder.moc" diff --git a/tests/auto/tst_urlbuilder/tst_urlbuilder.pro b/tests/auto/tst_urlbuilder/tst_urlbuilder.pro new file mode 100644 index 0000000..dab5008 --- /dev/null +++ b/tests/auto/tst_urlbuilder/tst_urlbuilder.pro @@ -0,0 +1,10 @@ +TEMPLATE = app +TARGET = tst_urlbuilder + +QT += testlib +CONFIG += testcase + +include( ../../../src/plugin/plugin.pri ) + +SOURCES += \ + tst_urlbuilder.cpp diff --git a/tests/tests.pro b/tests/tests.pro new file mode 100644 index 0000000..2d7fc24 --- /dev/null +++ b/tests/tests.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs + +include ( ../qtanalytics.pri ) +include ( ../doc/doc.pri ) + +SUBDIRS = auto |