~loic.molinari/+junk/qtdeclarative-shadereffectsource-changes

« back to all changes in this revision

Viewing changes to tests/auto/quick/qquicksystempalette/tst_qquicksystempalette.cpp

  • Committer: Loïc Molinari
  • Date: 2012-04-21 17:59:51 UTC
  • Revision ID: loic.molinari@canonical.com-20120421175951-bqx68caaf5zrp76l
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
 
4
** Contact: http://www.qt-project.org/
 
5
**
 
6
** This file is part of the test suite of the Qt Toolkit.
 
7
**
 
8
** $QT_BEGIN_LICENSE:LGPL$
 
9
** GNU Lesser General Public License Usage
 
10
** This file may be used under the terms of the GNU Lesser General Public
 
11
** License version 2.1 as published by the Free Software Foundation and
 
12
** appearing in the file LICENSE.LGPL included in the packaging of this
 
13
** file. Please review the following information to ensure the GNU Lesser
 
14
** General Public License version 2.1 requirements will be met:
 
15
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
 
16
**
 
17
** In addition, as a special exception, Nokia gives you certain additional
 
18
** rights. These rights are described in the Nokia Qt LGPL Exception
 
19
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
 
20
**
 
21
** GNU General Public License Usage
 
22
** Alternatively, this file may be used under the terms of the GNU General
 
23
** Public License version 3.0 as published by the Free Software Foundation
 
24
** and appearing in the file LICENSE.GPL included in the packaging of this
 
25
** file. Please review the following information to ensure the GNU General
 
26
** Public License version 3.0 requirements will be met:
 
27
** http://www.gnu.org/copyleft/gpl.html.
 
28
**
 
29
** Other Usage
 
30
** Alternatively, this file may be used in accordance with the terms and
 
31
** conditions contained in a signed written agreement between you and Nokia.
 
32
**
 
33
**
 
34
**
 
35
**
 
36
**
 
37
**
 
38
** $QT_END_LICENSE$
 
39
**
 
40
****************************************************************************/
 
41
 
 
42
#include <qtest.h>
 
43
#include <QDebug>
 
44
#include <QtQml/qqmlengine.h>
 
45
#include <QtQml/qqmlcomponent.h>
 
46
#include <QtQuick/private/qquicksystempalette_p.h>
 
47
#include <qpalette.h>
 
48
 
 
49
class tst_qquicksystempalette : public QObject
 
50
{
 
51
    Q_OBJECT
 
52
public:
 
53
    tst_qquicksystempalette();
 
54
 
 
55
private slots:
 
56
    void activePalette();
 
57
    void inactivePalette();
 
58
    void disabledPalette();
 
59
    void paletteChanged();
 
60
 
 
61
private:
 
62
    QQmlEngine engine;
 
63
};
 
64
 
 
65
tst_qquicksystempalette::tst_qquicksystempalette()
 
66
{
 
67
}
 
68
 
 
69
void tst_qquicksystempalette::activePalette()
 
70
{
 
71
    QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
 
72
    QQmlComponent component(&engine);
 
73
    component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
 
74
    QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(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_qquicksystempalette::inactivePalette()
 
99
{
 
100
    QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Inactive }";
 
101
    QQmlComponent component(&engine);
 
102
    component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
 
103
    QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create());
 
104
 
 
105
    QVERIFY(object != 0);
 
106
    QVERIFY(object->colorGroup() == QQuickSystemPalette::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_qquicksystempalette::disabledPalette()
 
129
{
 
130
    QString componentStr = "import QtQuick 2.0\nSystemPalette { colorGroup: SystemPalette.Disabled }";
 
131
    QQmlComponent component(&engine);
 
132
    component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
 
133
    QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(component.create());
 
134
 
 
135
    QVERIFY(object != 0);
 
136
    QVERIFY(object->colorGroup() == QQuickSystemPalette::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_qquicksystempalette::paletteChanged()
 
159
{
 
160
    QString componentStr = "import QtQuick 2.0\nSystemPalette { }";
 
161
    QQmlComponent component(&engine);
 
162
    component.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
 
163
    QQuickSystemPalette *object = qobject_cast<QQuickSystemPalette*>(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(QQuickSystemPalette::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_qquicksystempalette)
 
184
 
 
185
#include "tst_qquicksystempalette.moc"