pwmfantest.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * <one line to give the library's name and an idea of what it does.>
  3. * Copyright 2015 <copyright holder> <email>
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License as
  7. * published by the Free Software Foundation; either version 2 of
  8. * the License or (at your option) version 3 or any later version
  9. * accepted by the membership of KDE e.V. (or its successor approved
  10. * by the membership of KDE e.V.), which shall act as a proxy
  11. * defined in Section 14 of version 3 of the license.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "pwmfantest.h"
  23. #include <QtTest/QtTest>
  24. #include <QtTest/QSignalSpy>
  25. void PwmFanTest::initTestCase()
  26. {
  27. m_pwmString = QStringLiteral("0");
  28. m_modeString = QStringLiteral("0");
  29. m_fan = new TestPwmFan(&m_pwmString, &m_modeString, Q_NULLPTR);
  30. }
  31. void PwmFanTest::cleanupTestCase()
  32. {
  33. delete m_fan;
  34. }
  35. void PwmFanTest::init()
  36. {
  37. // Called before each testfunction is executed
  38. }
  39. void PwmFanTest::cleanup()
  40. {
  41. // Called after every testfunction
  42. }
  43. void PwmFanTest::nameTest_data()
  44. {
  45. QTest::addColumn<QString>("name");
  46. QTest::newRow("SmallFan") << "SmallFan";
  47. QTest::newRow("fan4") << "fan4";
  48. }
  49. void PwmFanTest::nameTest()
  50. {
  51. QFETCH(QString, name);
  52. m_fan->setName(name);
  53. QCOMPARE(m_fan->name(), name);
  54. }
  55. void PwmFanTest::pwmTest_data()
  56. {
  57. QTest::addColumn<int>("value");
  58. QTest::addColumn<QString>("error");
  59. QTest::newRow("0") << 0 << "";
  60. QTest::newRow("100") << 100 << "";
  61. QTest::newRow("255") << 255 << "";
  62. QTest::newRow("-1") << -1 << "Pwm cannot exceed 0-255!";
  63. QTest::newRow("256") << 256 << "Pwm cannot exceed 0-255!";
  64. }
  65. void PwmFanTest::pwmTest()
  66. {
  67. QFETCH(int, value);
  68. QFETCH(QString, error);
  69. QSignalSpy spy(m_fan, SIGNAL(error(QString,bool)));
  70. m_fan->setPwm(value);
  71. if (error.isEmpty())
  72. QCOMPARE(m_fan->pwm(), value);
  73. else
  74. {
  75. QCOMPARE(spy.at(0).at(0).toString(), error);
  76. QCOMPARE(spy.at(0).at(1).toBool(), true);
  77. }
  78. }
  79. void PwmFanTest::enableTest_data()
  80. {
  81. QTest::addColumn<int>("value");
  82. QTest::addColumn<QString>("error");
  83. QTest::newRow("0") << 0 << "";
  84. QTest::newRow("1") << 1 << "";
  85. QTest::newRow("2") << 2 << "";
  86. QTest::newRow("3") << 3 << "PwmEnable cannot exceed 0-2!";
  87. QTest::newRow("-1") << -1 << "PwmEnable cannot exceed 0-2!";
  88. }
  89. void PwmFanTest::enableTest()
  90. {
  91. QFETCH(int, value);
  92. QFETCH(QString, error);
  93. QSignalSpy spy(m_fan, SIGNAL(error(QString,bool)));
  94. m_fan->setPwmEnable(value);
  95. if (error.isEmpty())
  96. QCOMPARE(m_fan->pwmEnable(), value);
  97. else
  98. {
  99. QCOMPARE(spy.at(0).at(0).toString(), error);
  100. QCOMPARE(spy.at(0).at(1).toBool(), true);
  101. }
  102. }
  103. void PwmFanTest::activeTest()
  104. {
  105. m_fan->setActive(false);
  106. QCOMPARE(m_fan->active(), false);
  107. m_fan->setActive(true);
  108. QCOMPARE(m_fan->active(), true);
  109. }
  110. QTEST_MAIN(PwmFanTest)