File indexing completed on 2024-05-12 05:40:52

0001 /***************************************************************************
0002  *   Copyright (C) 2015 by Benoit Lagarde                                  *
0003  *   http://renaudguezennec.homelinux.org/accueil,3.html                   *
0004  *                                                                         *
0005  *   Rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #include <QtTest/QtTest>
0021 
0022 #include <QAbstractItemModelTester>
0023 #include <model/palettemodel.h>
0024 
0025 class PaletteModelTest : public QObject
0026 {
0027     Q_OBJECT
0028 
0029 public:
0030     PaletteModelTest();
0031 
0032 private slots:
0033     void initTestCase();
0034     void cleanupTestCase();
0035     void getAndSetTest();
0036     void paletteColorChangedTest();
0037     void paletteColorChangedTest2();
0038     void paletteColorChangedTest3();
0039     void paletteColorChangedTest4();
0040     void getAndSetColorTest();
0041     void getAndSetColorNameTest();
0042     void paletteColorConstructor();
0043 
0044 private:
0045     PaletteModel* m_paletteModel;
0046     PaletteColor* m_paletteColor;
0047 };
0048 PaletteModelTest::PaletteModelTest() {}
0049 void PaletteModelTest::initTestCase()
0050 {
0051     m_paletteModel= new PaletteModel(this);
0052     m_paletteColor= new PaletteColor(QColor(), "WindowText", QPalette::Active, QPalette::WindowText);
0053     new QAbstractItemModelTester(m_paletteModel);
0054 }
0055 
0056 void PaletteModelTest::getAndSetTest()
0057 {
0058     QPalette test_palette;
0059     m_paletteModel->setPalette(test_palette);
0060     QPalette result= m_paletteModel->getPalette();
0061 
0062     bool equal= true;
0063     for(int grp= 0; grp < QPalette::NColorGroups; grp++)
0064     {
0065         for(int role= 0; role < QPalette::NColorRoles; role++)
0066         {
0067             if((result.color(static_cast<QPalette::ColorGroup>(grp), static_cast<QPalette::ColorRole>(role))
0068                 != test_palette.color(static_cast<QPalette::ColorGroup>(grp), static_cast<QPalette::ColorRole>(role))))
0069             {
0070                 equal= false;
0071             }
0072         }
0073     }
0074     QVERIFY(equal);
0075 }
0076 void PaletteModelTest::paletteColorChangedTest()
0077 {
0078     QPalette test_palette;
0079     m_paletteModel->setPalette(test_palette);
0080     QColor test_color(1, 87, 42);
0081     QModelIndex firstIndex= m_paletteModel->index(0, 0);
0082     m_paletteModel->setColor(firstIndex.row(), test_color);
0083     QColor result_color= m_paletteModel->data(firstIndex, Qt::DecorationRole).value<QColor>();
0084     QVERIFY(result_color == test_color);
0085 }
0086 void PaletteModelTest::paletteColorChangedTest2()
0087 {
0088     QPalette test_palette;
0089     m_paletteModel->setPalette(test_palette);
0090     QColor test_color(1, 87, 42);
0091     QModelIndex firstIndex= m_paletteModel->index(10, 0);
0092     m_paletteModel->setColor(firstIndex.row(), test_color);
0093     QColor result_color= m_paletteModel->data(firstIndex, Qt::DecorationRole).value<QColor>();
0094     QVERIFY(result_color == test_color);
0095 }
0096 void PaletteModelTest::paletteColorChangedTest3()
0097 {
0098     QPalette test_palette;
0099     m_paletteModel->setPalette(test_palette);
0100     QColor test_color(201, 7, 252);
0101     QModelIndex firstIndex= m_paletteModel->index(20, 0);
0102     m_paletteModel->setColor(firstIndex.row(), test_color);
0103     QColor result_color= m_paletteModel->data(firstIndex, Qt::DecorationRole).value<QColor>();
0104     QVERIFY(result_color == test_color);
0105 }
0106 void PaletteModelTest::paletteColorChangedTest4()
0107 {
0108     QPalette test_palette;
0109     m_paletteModel->setPalette(test_palette);
0110     QColor test_color(102, 87, 42);
0111     QModelIndex firstIndex= m_paletteModel->index(30, 0);
0112     m_paletteModel->setColor(firstIndex.row(), test_color);
0113     QColor result_color= m_paletteModel->data(firstIndex, Qt::DecorationRole).value<QColor>();
0114     QVERIFY(result_color == test_color);
0115 }
0116 void PaletteModelTest::getAndSetColorTest()
0117 {
0118     QColor test_color(1, 2, 3);
0119     m_paletteColor->setColor(test_color);
0120     QColor result= m_paletteColor->getColor();
0121     QVERIFY(result == test_color);
0122 }
0123 void PaletteModelTest::getAndSetColorNameTest()
0124 {
0125     QString test_colorName("rouge");
0126     m_paletteColor->setName(test_colorName);
0127     QString result= m_paletteColor->getName();
0128     QVERIFY(result == test_colorName);
0129 }
0130 void PaletteModelTest::paletteColorConstructor()
0131 {
0132     PaletteColor test_paletteColor(QColor(1, 2, 4), "texte", QPalette::Active, QPalette::Highlight);
0133     QVERIFY2(test_paletteColor.getColor() == QColor(1, 2, 4), "color is not equal");
0134 }
0135 
0136 void PaletteModelTest::cleanupTestCase()
0137 {
0138     delete m_paletteModel;
0139     delete m_paletteColor;
0140 }
0141 
0142 QTEST_MAIN(PaletteModelTest);
0143 
0144 #include "tst_paletteModel.moc"