~gabriel1984sibiu/minitube/qt5.6

« back to all changes in this revision

Viewing changes to tests/auto/widgets/widgets/qframe/tst_qframe.cpp

  • Committer: Grevutiu Gabriel
  • Date: 2017-06-13 08:43:17 UTC
  • Revision ID: gabriel1984sibiu@gmail.com-20170613084317-ek0zqe0u9g3ocvi8
Original upstream code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 2016 The Qt Company Ltd.
 
4
** Copyright (C) 2014 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
 
5
** Contact: https://www.qt.io/licensing/
 
6
**
 
7
** This file is part of the test suite of the Qt Toolkit.
 
8
**
 
9
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
 
10
** Commercial License Usage
 
11
** Licensees holding valid commercial Qt licenses may use this file in
 
12
** accordance with the commercial license agreement provided with the
 
13
** Software or, alternatively, in accordance with the terms contained in
 
14
** a written agreement between you and The Qt Company. For licensing terms
 
15
** and conditions see https://www.qt.io/terms-conditions. For further
 
16
** information use the contact form at https://www.qt.io/contact-us.
 
17
**
 
18
** GNU General Public License Usage
 
19
** Alternatively, this file may be used under the terms of the GNU
 
20
** General Public License version 3 as published by the Free Software
 
21
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
 
22
** included in the packaging of this file. Please review the following
 
23
** information to ensure the GNU General Public License requirements will
 
24
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
 
25
**
 
26
** $QT_END_LICENSE$
 
27
**
 
28
****************************************************************************/
 
29
 
 
30
#include <QTest>
 
31
#include <QFrame>
 
32
#include <QStyleOptionFrame>
 
33
#include <QPixmap>
 
34
#include <QStyle>
 
35
#include <QStyleFactory>
 
36
 
 
37
class tst_QFrame : public QObject
 
38
{
 
39
    Q_OBJECT
 
40
private slots:
 
41
    void testDefaults();
 
42
    void testInitStyleOption_data();
 
43
    void testInitStyleOption();
 
44
    void testPainting_data();
 
45
    void testPainting();
 
46
};
 
47
 
 
48
Q_DECLARE_METATYPE(QFrame::Shape)
 
49
Q_DECLARE_METATYPE(QFrame::Shadow)
 
50
 
 
51
void tst_QFrame::testDefaults()
 
52
{
 
53
    QFrame frame;
 
54
    QCOMPARE(frame.frameStyle(), int(QFrame::NoFrame | QFrame::Plain));
 
55
    frame.setFrameShape(QFrame::Box);
 
56
    QCOMPARE(frame.frameStyle(), int(QFrame::Box | QFrame::Plain));
 
57
    frame.setFrameStyle(QFrame::Box); // no shadow specified!
 
58
    QCOMPARE(frame.frameStyle(), int(QFrame::Box));
 
59
}
 
60
 
 
61
static void provideFrameData()
 
62
{
 
63
    QTest::addColumn<QString>("basename");
 
64
    QTest::addColumn<int>("lineWidth");
 
65
    QTest::addColumn<int>("midLineWidth");
 
66
    QTest::addColumn<QFrame::Shape>("shape");
 
67
    QTest::addColumn<QFrame::Shadow>("shadow");
 
68
 
 
69
    for (int lineWidth = 0; lineWidth < 3; ++lineWidth) {
 
70
        for (int midLineWidth = 0; midLineWidth < 3; ++midLineWidth) {
 
71
            const QByteArray postFix = '_' + QByteArray::number(lineWidth) + '_'
 
72
                + QByteArray::number(midLineWidth);
 
73
            QTest::newRow(("box_noshadow" + postFix).constData())
 
74
                     << "box_noshadow" << lineWidth << midLineWidth << QFrame::Box << (QFrame::Shadow)0;
 
75
            QTest::newRow(("box_plain" + postFix).constData())
 
76
                    << "box_plain" << lineWidth << midLineWidth << QFrame::Box << QFrame::Plain;
 
77
            QTest::newRow(("box_raised" + postFix).constData())
 
78
                    << "box_raised" << lineWidth << midLineWidth << QFrame::Box << QFrame::Raised;
 
79
            QTest::newRow(("box_sunken" + postFix).constData())
 
80
                    << "box_sunken" << lineWidth << midLineWidth << QFrame::Box << QFrame::Sunken;
 
81
 
 
82
            QTest::newRow(("winpanel_noshadow" + postFix).constData())
 
83
                    << "winpanel_noshadow" << lineWidth << midLineWidth << QFrame::WinPanel << (QFrame::Shadow)0;
 
84
            QTest::newRow(("winpanel_plain" + postFix).constData())
 
85
                    << "winpanel_plain" << lineWidth << midLineWidth << QFrame::WinPanel << QFrame::Plain;
 
86
            QTest::newRow(("winpanel_raised" + postFix).constData())
 
87
                    << "winpanel_raised" << lineWidth << midLineWidth << QFrame::WinPanel << QFrame::Raised;
 
88
            QTest::newRow(("winpanel_sunken" + postFix).constData())
 
89
                    << "winpanel_sunken" << lineWidth << midLineWidth << QFrame::WinPanel << QFrame::Sunken;
 
90
        }
 
91
    }
 
92
}
 
93
 
 
94
class Frame : public QFrame
 
95
{
 
96
public:
 
97
    using QFrame::initStyleOption;
 
98
};
 
99
 
 
100
void tst_QFrame::testInitStyleOption_data()
 
101
{
 
102
    provideFrameData();
 
103
}
 
104
 
 
105
void tst_QFrame::testInitStyleOption()
 
106
{
 
107
    QFETCH(QString, basename);
 
108
    QFETCH(int, lineWidth);
 
109
    QFETCH(int, midLineWidth);
 
110
    QFETCH(QFrame::Shape, shape);
 
111
    QFETCH(QFrame::Shadow, shadow);
 
112
 
 
113
    Frame frame;
 
114
    frame.setFrameStyle(shape | shadow);
 
115
    frame.setLineWidth(lineWidth);
 
116
    frame.setMidLineWidth(midLineWidth);
 
117
    frame.resize(16, 16);
 
118
 
 
119
    QStyleOptionFrame styleOption;
 
120
    frame.initStyleOption(&styleOption);
 
121
 
 
122
    switch (shape) {
 
123
    case QFrame::Box:
 
124
    case QFrame::Panel:
 
125
    case QFrame::StyledPanel:
 
126
    case QFrame::HLine:
 
127
    case QFrame::VLine:
 
128
        QCOMPARE(styleOption.lineWidth, lineWidth);
 
129
        QCOMPARE(styleOption.midLineWidth, midLineWidth);
 
130
        break;
 
131
 
 
132
    case QFrame::NoFrame:
 
133
    case QFrame::WinPanel:
 
134
        QCOMPARE(styleOption.lineWidth, frame.frameWidth());
 
135
        QCOMPARE(styleOption.midLineWidth, 0);
 
136
        break;
 
137
    }
 
138
 
 
139
    QCOMPARE(styleOption.features, QStyleOptionFrame::None);
 
140
    QCOMPARE(styleOption.frameShape, shape);
 
141
    if (shadow == QFrame::Sunken)
 
142
        QVERIFY(styleOption.state & QStyle::State_Sunken);
 
143
    else if (shadow == QFrame::Raised)
 
144
        QVERIFY(styleOption.state & QStyle::State_Raised);
 
145
}
 
146
 
 
147
QT_BEGIN_NAMESPACE
 
148
Q_GUI_EXPORT QPalette qt_fusionPalette();
 
149
QT_END_NAMESPACE
 
150
 
 
151
void tst_QFrame::testPainting_data()
 
152
{
 
153
    provideFrameData();
 
154
}
 
155
 
 
156
void tst_QFrame::testPainting()
 
157
{
 
158
    QFETCH(QString, basename);
 
159
    QFETCH(int, lineWidth);
 
160
    QFETCH(int, midLineWidth);
 
161
    QFETCH(QFrame::Shape, shape);
 
162
    QFETCH(QFrame::Shadow, shadow);
 
163
 
 
164
    QFrame frame;
 
165
    frame.setStyle(QStyleFactory::create(QStringLiteral("fusion")));
 
166
    frame.setPalette(qt_fusionPalette());
 
167
    frame.setFrameStyle(shape | shadow);
 
168
    frame.setLineWidth(lineWidth);
 
169
    frame.setMidLineWidth(midLineWidth);
 
170
    frame.resize(16, 16);
 
171
 
 
172
    const QPixmap pixmap = frame.grab();
 
173
 
 
174
    const QString fileName = QLatin1String("images/") + basename + QLatin1Char('_')
 
175
        + QString::number(lineWidth) + QLatin1Char('_') + QString::number(midLineWidth)
 
176
        + QLatin1String(".png");
 
177
    const QString referenceFilePath = QFINDTESTDATA(fileName);
 
178
    const QPixmap referencePixmap(referenceFilePath);
 
179
    QVERIFY2(!referencePixmap.isNull(), qPrintable(QStringLiteral("Could not load reference pixmap %1").arg(referenceFilePath)));
 
180
    QCOMPARE(pixmap, referencePixmap);
 
181
}
 
182
 
 
183
QTEST_MAIN(tst_QFrame)
 
184
 
 
185
#include "tst_qframe.moc"