mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-04-24 15:37:23 +00:00
add test for telemetryhandler class
This commit is contained in:
parent
3403d1de50
commit
6449465be2
@ -111,7 +111,7 @@ bool AWTelemetryHandler::put(const QString group, const QString value) const
|
||||
settings.endGroup();
|
||||
settings.sync();
|
||||
// return status
|
||||
return (settings.status() != QSettings::NoError);
|
||||
return (settings.status() == QSettings::NoError);
|
||||
}
|
||||
|
||||
|
||||
@ -168,8 +168,10 @@ void AWTelemetryHandler::telemetryReplyRecieved(QNetworkReply *reply)
|
||||
|
||||
// convert to map
|
||||
QVariantMap response = jsonDoc.toVariant().toMap();
|
||||
qCInfo(LOG_AW) << "Server reply on telemetry"
|
||||
<< response[QString("message")].toString();
|
||||
QString message = response[QString("message")].toString();
|
||||
qCInfo(LOG_AW) << "Server reply on telemetry" << message;
|
||||
|
||||
return emit(replyReceived(message));
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,9 +22,6 @@
|
||||
#include <QObject>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
#define REMOTE_TELEMETRY_URL "http://arcanis.me/telemetry"
|
||||
#define REMOTE_TELEMETRY_PORT 8080
|
||||
|
||||
|
||||
class QAbstractButton;
|
||||
class QNetworkReply;
|
||||
@ -34,6 +31,9 @@ class AWTelemetryHandler : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
const char *REMOTE_TELEMETRY_URL = "http://arcanis.me/telemetry";
|
||||
const int REMOTE_TELEMETRY_PORT = 8080;
|
||||
|
||||
explicit AWTelemetryHandler(QObject *parent = nullptr,
|
||||
const QString clientId = QString());
|
||||
virtual ~AWTelemetryHandler();
|
||||
@ -42,6 +42,9 @@ public:
|
||||
Q_INVOKABLE bool put(const QString group, const QString value) const;
|
||||
Q_INVOKABLE void uploadTelemetry(const QString group, const QString value);
|
||||
|
||||
signals:
|
||||
void replyReceived(QString message);
|
||||
|
||||
private slots:
|
||||
void telemetryReplyRecieved(QNetworkReply *reply);
|
||||
|
||||
|
@ -30,7 +30,7 @@ set(TEST_MODULES
|
||||
abstractformatter datetimeformatter floatformatter listformatter noformatter scriptformatter stringformatter
|
||||
extitemaggregator
|
||||
batterysource desktopsource gpuloadsource gputempsource hddtempsource networksource playersource processessource
|
||||
awbugreporter awconfighelper awkeycache awkeys awpatternfunctions awupdatehelper
|
||||
awbugreporter awconfighelper awkeycache awkeys awpatternfunctions awtelemetryhandler awupdatehelper
|
||||
dpplugin)
|
||||
foreach (TEST_MODULE ${TEST_MODULES})
|
||||
set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h)
|
||||
@ -57,6 +57,8 @@ foreach (TEST_MODULE ${TEST_MODULES})
|
||||
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awformatterhelper.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awkeysaggregator.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awpatternfunctions.cpp)
|
||||
elseif (TEST_MODULE MATCHES "awtelemetryhandler")
|
||||
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awtelemetryhandler.cpp)
|
||||
elseif (TEST_MODULE MATCHES "awupdatehelper")
|
||||
set(${TEST_MODULE}_SOURCES ${${TEST_MODULE}_SOURCES} ${CMAKE_CURRENT_SOURCE_DIR}/../awesome-widget/plugin/awupdatehelper.cpp)
|
||||
elseif (TEST_MODULE MATCHES "dpplugin")
|
||||
|
75
sources/test/testawtelemetryhandler.cpp
Normal file
75
sources/test/testawtelemetryhandler.cpp
Normal file
@ -0,0 +1,75 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "testawtelemetryhandler.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "awtelemetryhandler.h"
|
||||
#include "awtestlibrary.h"
|
||||
|
||||
|
||||
void TestAWTelemetryHandler::initTestCase()
|
||||
{
|
||||
plugin = new AWTelemetryHandler(this, telemetryId);
|
||||
telemetryData = AWTestLibrary::randomString();
|
||||
telemetryGroup = AWTestLibrary::randomString();
|
||||
}
|
||||
|
||||
|
||||
void TestAWTelemetryHandler::cleanupTestCase()
|
||||
{
|
||||
delete plugin;
|
||||
}
|
||||
|
||||
|
||||
void TestAWTelemetryHandler::test_put()
|
||||
{
|
||||
QVERIFY(plugin->put(telemetryGroup, telemetryData));
|
||||
}
|
||||
|
||||
|
||||
void TestAWTelemetryHandler::test_get()
|
||||
{
|
||||
QStringList output = plugin->get(telemetryGroup);
|
||||
|
||||
QVERIFY(!output.isEmpty());
|
||||
QCOMPARE(QSet<QString>::fromList(output).count(), output.count());
|
||||
QVERIFY(output.contains(telemetryData));
|
||||
}
|
||||
|
||||
|
||||
void TestAWTelemetryHandler::test_getLast()
|
||||
{
|
||||
QCOMPARE(telemetryData, plugin->getLast(telemetryGroup));
|
||||
}
|
||||
|
||||
|
||||
void TestAWTelemetryHandler::test_uploadTelemetry()
|
||||
{
|
||||
QSignalSpy spy(plugin, SIGNAL(replyReceived(QString)));
|
||||
plugin->uploadTelemetry(telemetryValidGroup, telemetryData);
|
||||
|
||||
QVERIFY(spy.wait(5000));
|
||||
QVariantList arguments = spy.takeFirst();
|
||||
|
||||
QCOMPARE(arguments.at(0).toString(), QString("saved"));
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestAWTelemetryHandler);
|
50
sources/test/testawtelemetryhandler.h
Normal file
50
sources/test/testawtelemetryhandler.h
Normal file
@ -0,0 +1,50 @@
|
||||
/***************************************************************************
|
||||
* This file is part of awesome-widgets *
|
||||
* *
|
||||
* awesome-widgets is free software: you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation, either version 3 of the *
|
||||
* License, or (at your option) any later version. *
|
||||
* *
|
||||
* awesome-widgets is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with awesome-widgets. If not, see http://www.gnu.org/licenses/ *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef TESTAWTELEMETRYHANDLER_H
|
||||
#define TESTAWTELEMETRYHANDLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class AWTelemetryHandler;
|
||||
|
||||
class TestAWTelemetryHandler : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// initialization
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
// test
|
||||
void test_put();
|
||||
void test_get();
|
||||
void test_getLast();
|
||||
void test_uploadTelemetry();
|
||||
|
||||
private:
|
||||
AWTelemetryHandler *plugin = nullptr;
|
||||
QString telemetryData;
|
||||
QString telemetryGroup;
|
||||
QString telemetryId = QString("autotest");
|
||||
QString telemetryValidGroup = QString("awwidgetconfig");
|
||||
};
|
||||
|
||||
|
||||
#endif /* TESTAWTELEMETRYHANDLER_H */
|
Loading…
Reference in New Issue
Block a user