File indexing completed on 2024-05-12 05:40:47
0001 /*************************************************************************** 0002 * Copyright (C) 2015 by Renaud Guezennec * 0003 * Copyright (C) 2015 by Benoit Lagarde * 0004 * http://renaudguezennec.homelinux.org/accueil,3.html * 0005 * * 0006 * Rolisteam is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 * This program is distributed in the hope that it will be useful, * 0012 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0014 * GNU General Public License for more details. * 0015 * * 0016 * You should have received a copy of the GNU General Public License * 0017 * along with this program; if not, write to the * 0018 * Free Software Foundation, Inc., * 0019 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0020 ***************************************************************************/ 0021 #include <QtTest/QtTest> 0022 0023 #include <common_widgets/colorbutton.h> 0024 0025 class ColorButtonTest : public QObject 0026 { 0027 Q_OBJECT 0028 0029 public: 0030 ColorButtonTest(); 0031 0032 private slots: 0033 void initTestCase(); 0034 void cleanupTestCase(); 0035 void getAndSetTest(); 0036 void colorChangedTest(); 0037 void colorChangedTwiceTest(); 0038 void colorChangedTwiceDifferentTest(); 0039 0040 private: 0041 ColorButton* m_colorButton; 0042 }; 0043 ColorButtonTest::ColorButtonTest() {} 0044 void ColorButtonTest::initTestCase() 0045 { 0046 m_colorButton= new ColorButton(nullptr, false); 0047 } 0048 0049 void ColorButtonTest::getAndSetTest() 0050 { 0051 QColor test_color(12, 74, 181); 0052 m_colorButton->setColor(test_color); 0053 QColor result= m_colorButton->color(); 0054 QVERIFY(result == test_color); 0055 } 0056 void ColorButtonTest::colorChangedTest() 0057 { 0058 QColor test_color(12, 74, 182); 0059 QSignalSpy spy(m_colorButton, SIGNAL(colorChanged(QColor))); 0060 m_colorButton->setColor(test_color); 0061 QCOMPARE(spy.count(), 1); 0062 } 0063 void ColorButtonTest::colorChangedTwiceTest() 0064 { 0065 QColor test_color(12, 74, 183); 0066 QSignalSpy spy(m_colorButton, SIGNAL(colorChanged(QColor))); 0067 m_colorButton->setColor(test_color); 0068 m_colorButton->setColor(test_color); 0069 QCOMPARE(spy.count(), 1); 0070 } 0071 void ColorButtonTest::colorChangedTwiceDifferentTest() 0072 { 0073 QColor test_color(12, 74, 184); 0074 QColor test_color2(74, 180, 12); 0075 QSignalSpy spy(m_colorButton, SIGNAL(colorChanged(QColor))); 0076 m_colorButton->setColor(test_color); 0077 m_colorButton->setColor(test_color2); 0078 QCOMPARE(spy.count(), 2); 0079 } 0080 void ColorButtonTest::cleanupTestCase() 0081 { 0082 delete m_colorButton; 0083 } 0084 0085 QTEST_MAIN(ColorButtonTest); 0086 0087 #include "tst_colorButton.moc"