15251ecf1585107d153e6cf189c44ebdcd71e2ff
[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 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 **
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 **
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
29 **
30 ** Other Usage
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
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 <QtDeclarative/private/qdeclarativesystempalette_p.h>
47 #include <qpalette.h>
48 #include "../../../shared/util.h"
49
50 class tst_qdeclarativesystempalette : public QObject
51 {
52     Q_OBJECT
53 public:
54     tst_qdeclarativesystempalette();
55
56 private slots:
57     void activePalette();
58     void inactivePalette();
59     void disabledPalette();
60     void paletteChanged();
61
62 private:
63     QDeclarativeEngine engine;
64 };
65
66 tst_qdeclarativesystempalette::tst_qdeclarativesystempalette()
67 {
68 }
69
70 void tst_qdeclarativesystempalette::activePalette()
71 {
72     QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
73     QDeclarativeComponent component(&engine);
74     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
75     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
76
77     QVERIFY(object != 0);
78
79     QPalette palette;
80     palette.setCurrentColorGroup(QPalette::Active);
81     QCOMPARE(palette.window().color(), object->window());
82     QCOMPARE(palette.windowText().color(), object->windowText());
83     QCOMPARE(palette.base().color(), object->base());
84     QCOMPARE(palette.text().color(), object->text());
85     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
86     QCOMPARE(palette.button().color(), object->button());
87     QCOMPARE(palette.buttonText().color(), object->buttonText());
88     QCOMPARE(palette.light().color(), object->light());
89     QCOMPARE(palette.midlight().color(), object->midlight());
90     QCOMPARE(palette.dark().color(), object->dark());
91     QCOMPARE(palette.mid().color(), object->mid());
92     QCOMPARE(palette.shadow().color(), object->shadow());
93     QCOMPARE(palette.highlight().color(), object->highlight());
94     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
95
96     delete object;
97 }
98
99 void tst_qdeclarativesystempalette::inactivePalette()
100 {
101     QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Inactive }";
102     QDeclarativeComponent component(&engine);
103     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
104     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
105
106     QVERIFY(object != 0);
107     QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Inactive);
108
109     QPalette palette;
110     palette.setCurrentColorGroup(QPalette::Inactive);
111     QCOMPARE(palette.window().color(), object->window());
112     QCOMPARE(palette.windowText().color(), object->windowText());
113     QCOMPARE(palette.base().color(), object->base());
114     QCOMPARE(palette.text().color(), object->text());
115     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
116     QCOMPARE(palette.button().color(), object->button());
117     QCOMPARE(palette.buttonText().color(), object->buttonText());
118     QCOMPARE(palette.light().color(), object->light());
119     QCOMPARE(palette.midlight().color(), object->midlight());
120     QCOMPARE(palette.dark().color(), object->dark());
121     QCOMPARE(palette.mid().color(), object->mid());
122     QCOMPARE(palette.shadow().color(), object->shadow());
123     QCOMPARE(palette.highlight().color(), object->highlight());
124     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
125
126     delete object;
127 }
128
129 void tst_qdeclarativesystempalette::disabledPalette()
130 {
131     QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Disabled }";
132     QDeclarativeComponent component(&engine);
133     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
134     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
135
136     QVERIFY(object != 0);
137     QVERIFY(object->colorGroup() == QDeclarativeSystemPalette::Disabled);
138
139     QPalette palette;
140     palette.setCurrentColorGroup(QPalette::Disabled);
141     QCOMPARE(palette.window().color(), object->window());
142     QCOMPARE(palette.windowText().color(), object->windowText());
143     QCOMPARE(palette.base().color(), object->base());
144     QCOMPARE(palette.text().color(), object->text());
145     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
146     QCOMPARE(palette.button().color(), object->button());
147     QCOMPARE(palette.buttonText().color(), object->buttonText());
148     QCOMPARE(palette.light().color(), object->light());
149     QCOMPARE(palette.midlight().color(), object->midlight());
150     QCOMPARE(palette.dark().color(), object->dark());
151     QCOMPARE(palette.mid().color(), object->mid());
152     QCOMPARE(palette.shadow().color(), object->shadow());
153     QCOMPARE(palette.highlight().color(), object->highlight());
154     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
155
156     delete object;
157 }
158
159 void tst_qdeclarativesystempalette::paletteChanged()
160 {
161     QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
162     QDeclarativeComponent component(&engine);
163     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
164     QDeclarativeSystemPalette *object = qobject_cast<QDeclarativeSystemPalette*>(component.create());
165
166     QVERIFY(object != 0);
167
168     QPalette p;
169     p.setCurrentColorGroup(QPalette::Active);
170     p.setColor(QPalette::Active, QPalette::Text, QColor("red"));
171     p.setColor(QPalette::Active, QPalette::ButtonText, QColor("green"));
172     p.setColor(QPalette::Active, QPalette::WindowText, QColor("blue"));
173
174     qApp->setPalette(p);
175
176     object->setColorGroup(QDeclarativeSystemPalette::Active);
177     QTRY_COMPARE(QColor("red"), object->text());
178     QTRY_COMPARE(QColor("green"), object->buttonText());
179     QTRY_COMPARE(QColor("blue"), object->windowText());
180
181     delete object;
182 }
183
184 QTEST_MAIN(tst_qdeclarativesystempalette)
185
186 #include "tst_qdeclarativesystempalette.moc"