diff --git a/sources/extsysmonsources/gputempsource.cpp b/sources/extsysmonsources/gputempsource.cpp
index e69ff7c..437c143 100644
--- a/sources/extsysmonsources/gputempsource.cpp
+++ b/sources/extsysmonsources/gputempsource.cpp
@@ -55,19 +55,19 @@ GPUTemperatureSource::~GPUTemperatureSource()
QString GPUTemperatureSource::autoGpu()
{
- QString gpu = QString("disable");
- QFile moduleFile(QString("/proc/modules"));
- if (!moduleFile.open(QIODevice::ReadOnly))
- return gpu;
-
- QString output = moduleFile.readAll();
- if (output.contains(QString("fglrx")))
- gpu = QString("ati");
- else if (output.contains(QString("nvidia")))
- gpu = QString("nvidia");
-
- qCInfo(LOG_ESM) << "Device" << gpu;
+ QString gpu = QString("disable");
+ QFile moduleFile(QString("/proc/modules"));
+ if (!moduleFile.open(QIODevice::ReadOnly))
return gpu;
+
+ QString output = moduleFile.readAll();
+ if (output.contains(QString("fglrx")))
+ gpu = QString("ati");
+ else if (output.contains(QString("nvidia")))
+ gpu = QString("nvidia");
+
+ qCInfo(LOG_ESM) << "Device" << gpu;
+ return gpu;
}
@@ -78,7 +78,7 @@ QVariant GPUTemperatureSource::data(QString source)
if (source == QString("gpu/temperature"))
run();
- return m_value;
+ return m_values[source];
}
@@ -140,7 +140,7 @@ void GPUTemperatureSource::updateValue()
continue;
QString temp = str.remove(QString(""))
.remove(QString("C"));
- m_value = temp.toFloat();
+ m_values[QString("gpu/temperature")] = temp.toFloat();
break;
}
} else if (m_device == QString("ati")) {
@@ -148,8 +148,10 @@ void GPUTemperatureSource::updateValue()
if (!str.contains(QString("Temperature")))
continue;
QString temp = str.split(QChar(' '), QString::SkipEmptyParts).at(4);
- m_value = temp.toFloat();
+ m_values[QString("gpu/temperature")] = temp.toFloat();
break;
}
}
+
+ emit(dataReceived(m_values));
}
diff --git a/sources/extsysmonsources/gputempsource.h b/sources/extsysmonsources/gputempsource.h
index 62332c2..0ebfc62 100644
--- a/sources/extsysmonsources/gputempsource.h
+++ b/sources/extsysmonsources/gputempsource.h
@@ -43,7 +43,7 @@ private:
// configuration and values
QString m_device;
QProcess *m_process = nullptr;
- QVariant m_value;
+ QVariantHash m_values;
};
diff --git a/sources/test/testgputempsource.cpp b/sources/test/testgputempsource.cpp
new file mode 100644
index 0000000..29a8f36
--- /dev/null
+++ b/sources/test/testgputempsource.cpp
@@ -0,0 +1,64 @@
+/***************************************************************************
+ * 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 "testgputempsource.h"
+
+#include
+
+#include "awtestlibrary.h"
+#include "gputempsource.h"
+
+
+void TestGPUTemperatureSource::initTestCase()
+{
+ device = GPUTemperatureSource::autoGpu();
+ QVERIFY(!device.isEmpty());
+
+ gputempSource = new GPUTemperatureSource(this, QStringList() << device);
+}
+
+
+void TestGPUTemperatureSource::cleanupTestCase()
+{
+ delete gputempSource;
+}
+
+
+void TestGPUTemperatureSource::test_sources()
+{
+ QCOMPARE(gputempSource->sources(), QStringList() << source);
+}
+
+
+void TestGPUTemperatureSource::test_gputemp()
+{
+ if (device == QString("disable"))
+ QSKIP("Not supported device, test will be skipped");
+
+ QSignalSpy spy(gputempSource, SIGNAL(dataReceived(const QVariantHash &)));
+ float firstValue = gputempSource->data(source).toFloat();
+ QCOMPARE(firstValue, 0.0f);
+
+ QVERIFY(spy.wait(5000));
+ QVariantHash arguments = spy.takeFirst().at(0).toHash();
+ float secondValue = arguments[source].toFloat();
+ QVERIFY((secondValue >= temp.first) && (secondValue <= temp.second));
+}
+
+
+QTEST_MAIN(TestGPUTemperatureSource);
diff --git a/sources/test/testgputempsource.h b/sources/test/testgputempsource.h
new file mode 100644
index 0000000..f095066
--- /dev/null
+++ b/sources/test/testgputempsource.h
@@ -0,0 +1,47 @@
+/***************************************************************************
+ * 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 TESTGPUTEMPSOURCE_H
+#define TESTGPUTEMPSOURCE_H
+
+#include
+
+
+class GPUTemperatureSource;
+
+class TestGPUTemperatureSource : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ // initialization
+ void initTestCase();
+ void cleanupTestCase();
+ // test
+ void test_sources();
+ void test_gputemp();
+
+private:
+ GPUTemperatureSource *gputempSource = nullptr;
+ QString device;
+ QString source = QString("gpu/temperature");
+ QPair temp = QPair(0.0f, 40.0f);
+};
+
+
+#endif /* TESTGPUTEMPSOURCE_H */