Initial import from the monolithic Qt.
[profile/ivi/qtdeclarative.git] / tests / auto / declarative / qdeclarativesystempalette / tst_qdeclarativesystempalette.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
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
14 ** this package.
15 **
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.
23 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include <qtest.h>
43 #include <QDebug>
44 #include <QtDeclarative/qdeclarativeengine.h>
45 #include <QtDeclarative/qdeclarativecomponent.h>
46 #include <private/qdeclarativesystempalette_p.h>
47 #include <qpalette.h>
48 #include "../../../shared/util.h"
49
50 #ifdef Q_OS_SYMBIAN
51 // In Symbian OS test data is located in applications private dir
52 #define SRCDIR "."
53 #endif
54
55 class tst_qdeclarativesystempalette : public QObject
56
57 {
58     Q_OBJECT
59 public:
60     tst_qdeclarativesystempalette();
61
62 private slots:
63     void activePalette();
64     void inactivePalette();
65     void disabledPalette();
66     void paletteChanged();
67
68 private:
69     QDeclarativeEngine engine;
70 };
71
72 tst_qdeclarativesystempalette::tst_qdeclarativesystempalette()
73 {
74 }
75
76 void tst_qdeclarativesystempalette::activePalette()
77 {
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());
82
83     QVERIFY(object != 0);
84
85     QPalette palette;
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());
101
102     delete object;
103 }
104
105 void tst_qdeclarativesystempalette::inactivePalette()
106 {
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());
111
112     QVERIFY(object != 0);
113     QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Inactive);
114
115     QPalette palette;
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());
131
132     delete object;
133 }
134
135 void tst_qdeclarativesystempalette::disabledPalette()
136 {
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());
141
142     QVERIFY(object != 0);
143     QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Disabled);
144
145     QPalette palette;
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());
161
162     delete object;
163 }
164
165 void tst_qdeclarativesystempalette::paletteChanged()
166 {
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());
171
172     QVERIFY(object != 0);
173
174     QPalette p;
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"));
179
180     qApp->setPalette(p);
181
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());
186
187     delete object;
188 }
189
190 QTEST_MAIN(tst_qdeclarativesystempalette)
191
192 #include "tst_qdeclarativesystempalette.moc"