pwmfantest.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright 2015 <copyright holder> <email>
  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. #include "pwmfantest.h"
  22. #include <QtTest/QtTest>
  23. #include <QtTest/QSignalSpy>
  24. void PwmFanTest::initTestCase()
  25. {
  26. m_pwmString = QStringLiteral("0");
  27. m_modeString = QStringLiteral("0");
  28. m_fan = new TestPwmFan(&m_pwmString, &m_modeString, Q_NULLPTR);
  29. }
  30. void PwmFanTest::cleanupTestCase()
  31. {
  32. delete m_fan;
  33. }
  34. void PwmFanTest::init()
  35. {
  36. // Called before each testfunction is executed
  37. }
  38. void PwmFanTest::cleanup()
  39. {
  40. // Called after every testfunction
  41. }
  42. void PwmFanTest::nameTest_data()
  43. {
  44. QTest::addColumn<QString>("name");
  45. QTest::newRow("SmallFan") << "SmallFan";
  46. QTest::newRow("fan4") << "fan4";
  47. }
  48. void PwmFanTest::nameTest()
  49. {
  50. QFETCH(QString, name);
  51. m_fan->setName(name);
  52. QCOMPARE(m_fan->name(), name);
  53. }
  54. void PwmFanTest::pwmTest_data()
  55. {
  56. QTest::addColumn<int>("value");
  57. QTest::addColumn<QString>("error");
  58. QTest::newRow("0") << 0 << "";
  59. QTest::newRow("100") << 100 << "";
  60. QTest::newRow("255") << 255 << "";
  61. QTest::newRow("-1") << -1 << "Pwm cannot exceed 0-255!";
  62. QTest::newRow("256") << 256 << "Pwm cannot exceed 0-255!";
  63. }
  64. void PwmFanTest::pwmTest()
  65. {
  66. QFETCH(int, value);
  67. QFETCH(QString, error);
  68. QSignalSpy spy(m_fan, SIGNAL(error(QString,bool)));
  69. m_fan->setPwm(value);
  70. if (error.isEmpty())
  71. QCOMPARE(m_fan->pwm(), value);
  72. else
  73. {
  74. QCOMPARE(spy.at(0).at(0).toString(), error);
  75. QCOMPARE(spy.at(0).at(1).toBool(), true);
  76. }
  77. }
  78. void PwmFanTest::enableTest_data()
  79. {
  80. QTest::addColumn<TestPwmFan::PwmEnable>("value");
  81. QTest::addColumn<QString>("error");
  82. QTest::newRow("0") << TestPwmFan::FullSpeed << "";
  83. QTest::newRow("1") << TestPwmFan::ManualControl << "";
  84. QTest::newRow("2") << TestPwmFan::BiosControl << "";
  85. }
  86. void PwmFanTest::enableTest()
  87. {
  88. QFETCH(TestPwmFan::PwmEnable, value);
  89. QFETCH(QString, error);
  90. QSignalSpy spy(m_fan, SIGNAL(error(QString,bool)));
  91. m_fan->setPwmEnable(value);
  92. if (error.isEmpty())
  93. QCOMPARE(m_fan->pwmEnable(), value);
  94. else
  95. {
  96. QCOMPARE(spy.at(0).at(0).toString(), error);
  97. QCOMPARE(spy.at(0).at(1).toBool(), true);
  98. }
  99. }
  100. void PwmFanTest::activeTest()
  101. {
  102. m_fan->setActive(false);
  103. QCOMPARE(m_fan->active(), false);
  104. m_fan->setActive(true);
  105. QCOMPARE(m_fan->active(), true);
  106. }
  107. QTEST_MAIN(PwmFanTest)