mirror of
https://github.com/arcan1s/awesome-widgets.git
synced 2025-07-16 07:09:58 +00:00
Add test for hddsource, move sources to own library
This commit is contained in:
@ -7,6 +7,7 @@ include_directories(
|
||||
${CMAKE_SOURCE_DIR}
|
||||
${CMAKE_BINARY_DIR}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_LIBRARY}/
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../${PROJECT_MONITORSOURCES}/
|
||||
${PROJECT_TRDPARTY_DIR}
|
||||
${Qt_INCLUDE}
|
||||
${Qt5Test_INCLUDE_DIRS}
|
||||
@ -18,13 +19,14 @@ set(AWTESTLIBRARY_HEADERS awtestlibrary.h)
|
||||
set(AWTESTLIBRARY_SOURCES awtestlibrary.cpp)
|
||||
add_library(${SUBPROJECT}-awtest STATIC ${AWTESTLIBRARY_SOURCES} ${AWTESTLIBRARY_HEADERS})
|
||||
target_link_libraries(${SUBPROJECT}-awtest ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
|
||||
set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
|
||||
set(LIBRARY_TEST_SET ${SUBPROJECT}-awtest ${PROJECT_LIBRARY} ${PROJECT_MONITORSOURCES} ${Qt_LIBRARIES} ${Qt5Test_LIBRARIES})
|
||||
|
||||
## modules
|
||||
set(TEST_MODULES
|
||||
abstractextitem extquotes extscript extupgrade extweather
|
||||
abstractformatter datetimeformatter floatformatter noformatter scriptformatter
|
||||
extitemaggregator)
|
||||
extitemaggregator
|
||||
hddtempsource)
|
||||
foreach (TEST_MODULE ${TEST_MODULES})
|
||||
set(${TEST_MODULE}_HEADERS test${TEST_MODULE}.h)
|
||||
set(${TEST_MODULE}_SOURCES test${TEST_MODULE}.cpp)
|
||||
|
@ -21,8 +21,9 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class AWNoFormatter;
|
||||
template<class T> class ExtItemAggregator;
|
||||
template <class T> class ExtItemAggregator;
|
||||
|
||||
class TestExtItemAggregator : public QObject
|
||||
{
|
||||
|
@ -123,13 +123,13 @@ void TestExtWeather::run()
|
||||
QWARN("May fail here for Yahoo! Weather, see "
|
||||
"https://yahoo.uservoice.com/forums/207813-us-weather/suggestions/"
|
||||
"14209233-invalid-pressure-calculation");
|
||||
QVERIFY((arguments[extWeather->tag(QString("pressure"))].toFloat()
|
||||
QVERIFY((arguments[extWeather->tag(QString("pressure"))].toInt()
|
||||
> pressure.first)
|
||||
&& (arguments[extWeather->tag(QString("pressure"))].toInt()
|
||||
< pressure.second));
|
||||
QVERIFY((arguments[extWeather->tag(QString("temperature"))].toFloat()
|
||||
> temp.first)
|
||||
&& (arguments[extWeather->tag(QString("temperature"))].toInt()
|
||||
&& (arguments[extWeather->tag(QString("temperature"))].toFloat()
|
||||
< temp.second));
|
||||
// image should be only one symbol here
|
||||
QCOMPARE(arguments[extWeather->tag(QString("weather"))].toString().count(),
|
||||
|
91
sources/test/testhddtempsource.cpp
Normal file
91
sources/test/testhddtempsource.cpp
Normal file
@ -0,0 +1,91 @@
|
||||
/***************************************************************************
|
||||
* 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 "testhddtempsource.h"
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
#include "awtestlibrary.h"
|
||||
#include "hddtempsource.h"
|
||||
|
||||
|
||||
void TestHDDTemperatureSource::initTestCase()
|
||||
{
|
||||
devices = HDDTemperatureSource::allHdd();
|
||||
QVERIFY(devices.count() > 0);
|
||||
|
||||
hddtempSource = new HDDTemperatureSource(
|
||||
this, QStringList() << devices.join(QChar(',')) << hddtempCmd);
|
||||
smartctlSource = new HDDTemperatureSource(
|
||||
this, QStringList() << devices.join(QChar(',')) << smartctlCmd);
|
||||
}
|
||||
|
||||
|
||||
void TestHDDTemperatureSource::cleanupTestCase()
|
||||
{
|
||||
delete hddtempSource;
|
||||
delete smartctlSource;
|
||||
}
|
||||
|
||||
|
||||
void TestHDDTemperatureSource::test_sources()
|
||||
{
|
||||
std::for_each(devices.begin(), devices.end(), [](QString &device) {
|
||||
device.prepend(QString("hdd/temperature"));
|
||||
});
|
||||
|
||||
QCOMPARE(hddtempSource->sources(), devices);
|
||||
QCOMPARE(smartctlSource->sources(), devices);
|
||||
}
|
||||
|
||||
|
||||
void TestHDDTemperatureSource::test_hddtemp()
|
||||
{
|
||||
std::for_each(devices.begin(), devices.end(), [this](QString device) {
|
||||
QSignalSpy spy(hddtempSource,
|
||||
SIGNAL(dataReceived(const QVariantHash &)));
|
||||
float firstValue = hddtempSource->data(device).toFloat();
|
||||
QCOMPARE(firstValue, 0.0f);
|
||||
|
||||
QVERIFY(spy.wait(5000));
|
||||
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
||||
device.remove(QString("hdd/temperature"));
|
||||
float secondValue = arguments[device].toFloat();
|
||||
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void TestHDDTemperatureSource::test_smartctl()
|
||||
{
|
||||
std::for_each(devices.begin(), devices.end(), [this](QString &device) {
|
||||
QSignalSpy spy(smartctlSource,
|
||||
SIGNAL(dataReceived(const QVariantHash &)));
|
||||
float firstValue = smartctlSource->data(device).toFloat();
|
||||
QCOMPARE(firstValue, 0.0f);
|
||||
|
||||
QVERIFY(spy.wait(5000));
|
||||
QVariantHash arguments = spy.takeFirst().at(0).toHash();
|
||||
device.remove(QString("hdd/temperature"));
|
||||
float secondValue = arguments[device].toFloat();
|
||||
QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
QTEST_MAIN(TestHDDTemperatureSource);
|
50
sources/test/testhddtempsource.h
Normal file
50
sources/test/testhddtempsource.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 TESTHDDTEMPSOURCE_H
|
||||
#define TESTHDDTEMPSOURCE_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
|
||||
class HDDTemperatureSource;
|
||||
|
||||
class TestHDDTemperatureSource : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
// initialization
|
||||
void initTestCase();
|
||||
void cleanupTestCase();
|
||||
// test
|
||||
void test_sources();
|
||||
void test_hddtemp();
|
||||
void test_smartctl();
|
||||
|
||||
private:
|
||||
HDDTemperatureSource *hddtempSource = nullptr;
|
||||
HDDTemperatureSource *smartctlSource = nullptr;
|
||||
QStringList devices;
|
||||
QString hddtempCmd = QString("sudo hddtemp");
|
||||
QString smartctlCmd = QString("sudo smartctl -a");
|
||||
QPair<float, float> temp = QPair<float, float>(0.0f, 40.0f);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TESTHDDTEMPSOURCE_H */
|
Reference in New Issue
Block a user