loadertest.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright 2015 Malte Veerman maldela@halloarsch.de
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation; either version 2 of
  7. * the License or (at your option) version 3 or any later version
  8. * accepted by the membership of KDE e.V. (or its successor approved
  9. * by the membership of KDE e.V.), which shall act as a proxy
  10. * defined in Section 14 of version 3 of the license.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. */
  21. #ifndef LOADERTEST_H
  22. #define LOADERTEST_H
  23. #include <QtCore/QObject>
  24. #include "loader.h"
  25. #include "hwmon.h"
  26. #include "temptest.h"
  27. #include "fantest.h"
  28. #include "pwmfantest.h"
  29. using namespace Fancontrol;
  30. class TestHwmon : public Hwmon
  31. {
  32. Q_OBJECT
  33. public:
  34. explicit TestHwmon(const QString &name, const QList<QString *> &rpms, const QList<QString *> &pwms, const QList<QString *> &pwmmodes, const QList<QString *> &temps, uint index = 0, Loader *parent = Q_NULLPTR) : Hwmon(QString(), parent)
  35. {
  36. m_name = name;
  37. m_index = index;
  38. if (parent)
  39. {
  40. connect(this, &Hwmon::configUpdateNeeded, parent, &Loader::updateConfig);
  41. connect(this, &Hwmon::error, parent, &Loader::error);
  42. }
  43. if (pwms.size() != pwmmodes.size())
  44. return;
  45. if (pwms.size() > rpms.size())
  46. return;
  47. for (auto i=0; i<pwms.size(); i++)
  48. {
  49. const auto newPwmFan = new TestPwmFan(pwms.at(i), pwmmodes.at(i), rpms.at(i), i, this);
  50. connect(this, &Hwmon::sensorsUpdateNeeded, newPwmFan, &PwmFan::update);
  51. if (parent)
  52. connect(newPwmFan, &PwmFan::testStatusChanged, parent, &Loader::handleTestStatusChanged);
  53. m_pwmFans << qobject_cast<PwmFan *>(newPwmFan);
  54. m_fans << qobject_cast<Fan *>(newPwmFan);
  55. }
  56. emit pwmFansChanged();
  57. for (auto i=m_pwmFans.size()-1; i<rpms.size(); i++)
  58. {
  59. const auto newFan = new TestFan(rpms.at(i), i, this);
  60. connect(this, &Hwmon::sensorsUpdateNeeded, newFan, &Fan::update);
  61. m_fans << qobject_cast<Fan *>(newFan);
  62. }
  63. emit fansChanged();
  64. for (auto i=0; i<temps.size(); i++)
  65. {
  66. const auto newTemp = new TestTemp(temps.at(i), i, this);
  67. connect(this, &Hwmon::sensorsUpdateNeeded, newTemp, &Temp::update);
  68. m_temps << qobject_cast<Temp *>(newTemp);
  69. }
  70. emit tempsChanged();
  71. m_valid = true;
  72. }
  73. };
  74. class TestLoader : public Loader
  75. {
  76. Q_OBJECT
  77. public:
  78. explicit TestLoader(GUIBase *parent = Q_NULLPTR) : Loader(parent) {}
  79. void addHwmon(Hwmon *hwmon)
  80. {
  81. connect(this, &Loader::sensorsUpdateNeeded, hwmon, &Hwmon::sensorsUpdateNeeded);
  82. m_hwmons << hwmon;
  83. emit hwmonsChanged();
  84. }
  85. void addHwmon(TestHwmon *hwmon)
  86. {
  87. addHwmon(qobject_cast<Hwmon *>(hwmon));
  88. }
  89. void parse(const QString &string)
  90. {
  91. parseConfig(string);
  92. }
  93. QString createConfig() const
  94. {
  95. return Loader::createConfig();
  96. }
  97. };
  98. class LoaderTest : public QObject
  99. {
  100. Q_OBJECT
  101. private slots:
  102. void initTestCase();
  103. void cleanupTestCase();
  104. void init();
  105. void cleanup();
  106. void parseIntervalTest_data();
  107. void parseIntervalTest();
  108. void parseFctempTest_data();
  109. void parseFctempTest();
  110. void parseDevnameTest_data();
  111. void parseDevnameTest();
  112. void parseMintempTest_data();
  113. void parseMintempTest();
  114. void parseMaxtempTest_data();
  115. void parseMaxtempTest();
  116. void parseMinstartTest_data();
  117. void parseMinstartTest();
  118. void parseMinstopTest_data();
  119. void parseMinstopTest();
  120. void parseMinpwmTest_data();
  121. void parseMinpwmTest();
  122. void parseMaxpwmTest_data();
  123. void parseMaxpwmTest();
  124. void parseUnrecognizableLineTest_data();
  125. void parseUnrecognizableLineTest();
  126. void createConfigTest();
  127. private:
  128. TestLoader *m_loader;
  129. QList<QList<QString *> > m_rpms;
  130. QList<QList<QString *> > m_pwms;
  131. QList<QList<QString *> > m_temps;
  132. QList<QList<QString *> > m_pwmModes;
  133. };
  134. #endif // LOADERTEST_H