1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
44 #include <QtDeclarative/qdeclarativeengine.h>
45 #include <QtDeclarative/qdeclarativecomponent.h>
46 #include <private/qdeclarativesystempalette_p.h>
48 #include "../../../shared/util.h"
51 // In Symbian OS test data is located in applications private dir
55 class tst_qdeclarativesystempalette : public QObject
60 tst_qdeclarativesystempalette();
64 void inactivePalette();
65 void disabledPalette();
66 void paletteChanged();
69 QDeclarativeEngine engine;
72 tst_qdeclarativesystempalette::tst_qdeclarativesystempalette()
76 void tst_qdeclarativesystempalette::activePalette()
78 QString componentStr = "import QtQuick 1.0\nSystemPalette { }";
79 QDeclarativeComponent component(&engine);
80 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
81 QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
86 palette.setCurrentColorGroup(QPalette::Active);
87 QCOMPARE(palette.window().color(), object->window());
88 QCOMPARE(palette.windowText().color(), object->windowText());
89 QCOMPARE(palette.base().color(), object->base());
90 QCOMPARE(palette.text().color(), object->text());
91 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
92 QCOMPARE(palette.button().color(), object->button());
93 QCOMPARE(palette.buttonText().color(), object->buttonText());
94 QCOMPARE(palette.light().color(), object->light());
95 QCOMPARE(palette.midlight().color(), object->midlight());
96 QCOMPARE(palette.dark().color(), object->dark());
97 QCOMPARE(palette.mid().color(), object->mid());
98 QCOMPARE(palette.shadow().color(), object->shadow());
99 QCOMPARE(palette.highlight().color(), object->highlight());
100 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
105 void tst_qdeclarativesystempalette::inactivePalette()
107 QString componentStr = "import QtQuick 1.0\nSystemPalette { colorGroup: SystemPalette.Inactive }";
108 QDeclarativeComponent component(&engine);
109 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
110 QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
112 QVERIFY(object != 0);
113 QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Inactive);
116 palette.setCurrentColorGroup(QPalette::Inactive);
117 QCOMPARE(palette.window().color(), object->window());
118 QCOMPARE(palette.windowText().color(), object->windowText());
119 QCOMPARE(palette.base().color(), object->base());
120 QCOMPARE(palette.text().color(), object->text());
121 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
122 QCOMPARE(palette.button().color(), object->button());
123 QCOMPARE(palette.buttonText().color(), object->buttonText());
124 QCOMPARE(palette.light().color(), object->light());
125 QCOMPARE(palette.midlight().color(), object->midlight());
126 QCOMPARE(palette.dark().color(), object->dark());
127 QCOMPARE(palette.mid().color(), object->mid());
128 QCOMPARE(palette.shadow().color(), object->shadow());
129 QCOMPARE(palette.highlight().color(), object->highlight());
130 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
135 void tst_qdeclarativesystempalette::disabledPalette()
137 QString componentStr = "import QtQuick 1.0\nSystemPalette { colorGroup: SystemPalette.Disabled }";
138 QDeclarativeComponent component(&engine);
139 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
140 QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
142 QVERIFY(object != 0);
143 QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Disabled);
146 palette.setCurrentColorGroup(QPalette::Disabled);
147 QCOMPARE(palette.window().color(), object->window());
148 QCOMPARE(palette.windowText().color(), object->windowText());
149 QCOMPARE(palette.base().color(), object->base());
150 QCOMPARE(palette.text().color(), object->text());
151 QCOMPARE(palette.alternateBase().color(), object->alternateBase());
152 QCOMPARE(palette.button().color(), object->button());
153 QCOMPARE(palette.buttonText().color(), object->buttonText());
154 QCOMPARE(palette.light().color(), object->light());
155 QCOMPARE(palette.midlight().color(), object->midlight());
156 QCOMPARE(palette.dark().color(), object->dark());
157 QCOMPARE(palette.mid().color(), object->mid());
158 QCOMPARE(palette.shadow().color(), object->shadow());
159 QCOMPARE(palette.highlight().color(), object->highlight());
160 QCOMPARE(palette.highlightedText().color(), object->highlightedText());
165 void tst_qdeclarativesystempalette::paletteChanged()
167 QString componentStr = "import QtQuick 1.0\nSystemPalette { }";
168 QDeclarativeComponent component(&engine);
169 component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
170 QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
172 QVERIFY(object != 0);
175 p.setCurrentColorGroup(QPalette::Active);
176 p.setColor(QPalette::Active, QPalette::Text, QColor("red"));
177 p.setColor(QPalette::Active, QPalette::ButtonText, QColor("green"));
178 p.setColor(QPalette::Active, QPalette::WindowText, QColor("blue"));
182 object->setColorGroup(QDeclarativeSystemPalette::Active);
183 QTRY_COMPARE(QColor("red"), object->text());
184 QTRY_COMPARE(QColor("green"), object->buttonText());
185 QTRY_COMPARE(QColor("blue"), object->windowText());
190 QTEST_MAIN(tst_qdeclarativesystempalette)
192 #include "tst_qdeclarativesystempalette.moc"