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

0001 /***************************************************************************
0002  *   Copyright (C) 2015 by Renaud Guezennec                                *
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 <QObject>
0021 #include <QtTest/QtTest>
0022 #include <data/rolisteamtheme.h>
0023 #include <helper.h>
0024 #include <QStyle>
0025 #include <QStyleFactory>
0026 
0027 class RolisteamThemeTest : public QObject
0028 {
0029     Q_OBJECT
0030 
0031 public:
0032     RolisteamThemeTest();
0033 
0034 private slots:
0035     void initTestCase();
0036     void setAndGetTest();
0037     void cleanupTestCase();
0038 
0039 private:
0040     RolisteamTheme* m_theme;
0041 };
0042 RolisteamThemeTest::RolisteamThemeTest() {}
0043 
0044 void RolisteamThemeTest::initTestCase()
0045 {
0046     m_theme = new RolisteamTheme();
0047 }
0048 
0049 void RolisteamThemeTest::setAndGetTest()
0050 {
0051     QPalette pal(Qt::blue);
0052 
0053     {
0054         QList<QPalette::ColorGroup> group{QPalette::ColorGroup::Disabled,QPalette::ColorGroup::Active,QPalette::ColorGroup::Inactive};
0055         QList<QPalette::ColorRole> role{QPalette::Highlight, QPalette::HighlightedText,
0056                                         QPalette::Link, QPalette::LinkVisited,
0057                                         QPalette::NoRole};
0058         for(auto g : group)
0059         {
0060             for(auto r : role)
0061             {
0062                 pal.setColor(g, r, pal.color(g, r));
0063             }
0064         }
0065     }
0066     m_theme->setPalette(pal);
0067 
0068     QList<QPalette::ColorGroup> group{QPalette::ColorGroup::Disabled,QPalette::ColorGroup::Active,QPalette::ColorGroup::Inactive};
0069     QList<QPalette::ColorRole> role{QPalette::WindowText, QPalette::Button, QPalette::Light, QPalette::Midlight, QPalette::Dark, QPalette::Mid,
0070         QPalette::Text, QPalette::BrightText, QPalette::ButtonText, QPalette::Base, QPalette::Window, QPalette::Shadow,
0071         QPalette::Highlight, QPalette::HighlightedText,
0072         QPalette::Link, QPalette::LinkVisited,
0073         QPalette::AlternateBase,
0074         QPalette::NoRole,
0075         QPalette::ToolTipBase, QPalette::ToolTipText,
0076         QPalette::PlaceholderText};
0077     for(auto g : group)
0078     {
0079         for(auto r : role)
0080         {
0081             QCOMPARE(m_theme->getPalette().color(g, r), pal.color(g, r));
0082         }
0083     }
0084     QCOMPARE(m_theme->getPalette(), pal);
0085 
0086     auto name = Helper::randomString();
0087     m_theme->setName(name);
0088     QCOMPARE(m_theme->getName(), name);
0089 
0090     auto css  = Helper::randomString();
0091     m_theme->setCss(css);
0092     QCOMPARE(m_theme->getCss(), css);
0093 
0094 
0095     m_theme->setRemovable(true);
0096     QVERIFY(m_theme->isRemovable());
0097     m_theme->setRemovable(false);
0098     QVERIFY(!m_theme->isRemovable());
0099 
0100     auto style = QStyleFactory::create("fusion");
0101     m_theme->setStyle(style);
0102     QCOMPARE(m_theme->getStyle()->objectName(), style->objectName());
0103     QCOMPARE(m_theme->getStyleName(), "fusion");
0104 
0105     auto imgPath = Helper::randomString();
0106     m_theme->setBackgroundImage(imgPath);
0107     QCOMPARE(m_theme->getBackgroundImage(), imgPath);
0108 
0109     auto bgColor = Helper::randomColor();
0110     m_theme->setBackgroundColor(bgColor);
0111     QCOMPARE(m_theme->getBackgroundColor(), bgColor);
0112 
0113     auto position = Helper::generate<int>(0,10);
0114     m_theme->setBackgroundPosition(position);
0115     QCOMPARE(m_theme->getBackgroundPosition(), position);
0116 
0117     auto diceColor = Helper::randomColor();
0118     m_theme->setDiceHighlightColor(diceColor);
0119     QCOMPARE(m_theme->getDiceHighlightColor(), diceColor);
0120 
0121 }
0122 void RolisteamThemeTest::cleanupTestCase()
0123 {
0124     delete m_theme;
0125 }
0126 
0127 QTEST_MAIN(RolisteamThemeTest);
0128 
0129 #include "tst_rolisteamtheme.moc"