d005b90d7d22e9400bce7415afa05edc2f0073e4
[profile/ivi/qtdeclarative.git] / tests / auto / qtquick1 / qdeclarativesystempalette / tst_qdeclarativesystempalette.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: http://www.qt-project.org/
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 <QtQuick1/private/qdeclarativesystempalette_p.h>
47 #include <qpalette.h>
48
49 class tst_qdeclarativesystempalette : public QObject
50 {
51     Q_OBJECT
52 public:
53     tst_qdeclarativesystempalette();
54
55 private slots:
56     void activePalette();
57     void inactivePalette();
58     void disabledPalette();
59     void paletteChanged();
60
61 private:
62     QDeclarativeEngine engine;
63 };
64
65 tst_qdeclarativesystempalette::tst_qdeclarativesystempalette()
66 {
67 }
68
69 void tst_qdeclarativesystempalette::activePalette()
70 {
71     QString componentStr = "import QtQuick 1.0\nSystemPalette { }";
72     QDeclarativeComponent component(&engine);
73     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
74     QDeclarative1SystemPalette *object = qobject_cast<QDeclarative1SystemPalette*>(component.create());
75
76     QVERIFY(object != 0);
77
78     QPalette palette;
79     palette.setCurrentColorGroup(QPalette::Active);
80     QCOMPARE(palette.window().color(), object->window());
81     QCOMPARE(palette.windowText().color(), object->windowText());
82     QCOMPARE(palette.base().color(), object->base());
83     QCOMPARE(palette.text().color(), object->text());
84     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
85     QCOMPARE(palette.button().color(), object->button());
86     QCOMPARE(palette.buttonText().color(), object->buttonText());
87     QCOMPARE(palette.light().color(), object->light());
88     QCOMPARE(palette.midlight().color(), object->midlight());
89     QCOMPARE(palette.dark().color(), object->dark());
90     QCOMPARE(palette.mid().color(), object->mid());
91     QCOMPARE(palette.shadow().color(), object->shadow());
92     QCOMPARE(palette.highlight().color(), object->highlight());
93     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
94
95     delete object;
96 }
97
98 void tst_qdeclarativesystempalette::inactivePalette()
99 {
100     QString componentStr = "import QtQuick 1.0\nSystemPalette { colorGroup: SystemPalette.Inactive }";
101     QDeclarativeComponent component(&engine);
102     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
103     QDeclarative1SystemPalette *object = qobject_cast<QDeclarative1SystemPalette*>(component.create());
104
105     QVERIFY(object != 0);
106     QVERIFY(object->colorGroup() == QDeclarative1SystemPalette::Inactive);
107
108     QPalette palette;
109     palette.setCurrentColorGroup(QPalette::Inactive);
110     QCOMPARE(palette.window().color(), object->window());
111     QCOMPARE(palette.windowText().color(), object->windowText());
112     QCOMPARE(palette.base().color(), object->base());
113     QCOMPARE(palette.text().color(), object->text());
114     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
115     QCOMPARE(palette.button().color(), object->button());
116     QCOMPARE(palette.buttonText().color(), object->buttonText());
117     QCOMPARE(palette.light().color(), object->light());
118     QCOMPARE(palette.midlight().color(), object->midlight());
119     QCOMPARE(palette.dark().color(), object->dark());
120     QCOMPARE(palette.mid().color(), object->mid());
121     QCOMPARE(palette.shadow().color(), object->shadow());
122     QCOMPARE(palette.highlight().color(), object->highlight());
123     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
124
125     delete object;
126 }
127
128 void tst_qdeclarativesystempalette::disabledPalette()
129 {
130     QString componentStr = "import QtQuick 1.0\nSystemPalette { colorGroup: SystemPalette.Disabled }";
131     QDeclarativeComponent component(&engine);
132     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
133     QDeclarative1SystemPalette *object = qobject_cast<QDeclarative1SystemPalette*>(component.create());
134
135     QVERIFY(object != 0);
136     QVERIFY(object->colorGroup() == QDeclarative1SystemPalette::Disabled);
137
138     QPalette palette;
139     palette.setCurrentColorGroup(QPalette::Disabled);
140     QCOMPARE(palette.window().color(), object->window());
141     QCOMPARE(palette.windowText().color(), object->windowText());
142     QCOMPARE(palette.base().color(), object->base());
143     QCOMPARE(palette.text().color(), object->text());
144     QCOMPARE(palette.alternateBase().color(), object->alternateBase());
145     QCOMPARE(palette.button().color(), object->button());
146     QCOMPARE(palette.buttonText().color(), object->buttonText());
147     QCOMPARE(palette.light().color(), object->light());
148     QCOMPARE(palette.midlight().color(), object->midlight());
149     QCOMPARE(palette.dark().color(), object->dark());
150     QCOMPARE(palette.mid().color(), object->mid());
151     QCOMPARE(palette.shadow().color(), object->shadow());
152     QCOMPARE(palette.highlight().color(), object->highlight());
153     QCOMPARE(palette.highlightedText().color(), object->highlightedText());
154
155     delete object;
156 }
157
158 void tst_qdeclarativesystempalette::paletteChanged()
159 {
160     QString componentStr = "import QtQuick 1.0\nSystemPalette { }";
161     QDeclarativeComponent component(&engine);
162     component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
163     QDeclarative1SystemPalette *object = qobject_cast<QDeclarative1SystemPalette*>(component.create());
164
165     QVERIFY(object != 0);
166
167     QPalette p;
168     p.setCurrentColorGroup(QPalette::Active);
169     p.setColor(QPalette::Active, QPalette::Text, QColor("red"));
170     p.setColor(QPalette::Active, QPalette::ButtonText, QColor("green"));
171     p.setColor(QPalette::Active, QPalette::WindowText, QColor("blue"));
172
173     qApp->setPalette(p);
174
175     object->setColorGroup(QDeclarative1SystemPalette::Active);
176     QTRY_COMPARE(QColor("red"), object->text());
177     QTRY_COMPARE(QColor("green"), object->buttonText());
178     QTRY_COMPARE(QColor("blue"), object->windowText());
179
180     delete object;
181 }
182
183 QTEST_MAIN(tst_qdeclarativesystempalette)
184
185 #include "tst_qdeclarativesystempalette.moc"