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

0001 /***************************************************************************
0002  *   Copyright (C) 2011 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 <QtTest>
0021 
0022 #include <memory.h>
0023 #include "common_qml/theme.h"
0024 #include "test_root_path.h"
0025 #include <helper.h>
0026 
0027 class ThemeTest : public QObject
0028 {
0029     Q_OBJECT
0030 public:
0031     ThemeTest();
0032 
0033 
0034 private slots:
0035     void init();
0036     void getAndSet();
0037 
0038 private:
0039     std::unique_ptr<customization::Theme> m_theme;
0040 };
0041 
0042 
0043 
0044 ThemeTest::ThemeTest()
0045 {
0046 
0047 }
0048 
0049 void ThemeTest::init()
0050 {
0051     customization::Theme::setPath(QString("%1/../../resources/stylesheet/qml/theme.ini").arg(tests::root_path));
0052     m_theme.reset(new customization::Theme);
0053 }
0054 void ThemeTest::getAndSet()
0055 {
0056     auto styleSheet = m_theme->styleSheet("InstantMessaging");
0057 
0058     auto key = Helper::randomString();
0059     auto value = Helper::randomString();
0060     styleSheet->insertOrUpdate(key, QVariant::fromValue(value));
0061 
0062     QCOMPARE(styleSheet->value(key), value);
0063 
0064     QSignalSpy spy(m_theme.get(), &customization::Theme::nightModeChanged);
0065 
0066     m_theme->setNightMode(true);
0067     m_theme->setNightMode(true);
0068     m_theme->setNightMode(false);
0069 
0070     spy.wait();
0071     QCOMPARE(spy.count(), 2);
0072 }
0073 
0074 QTEST_MAIN(ThemeTest)
0075 
0076 #include "tst_theme.moc"