0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 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 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include <qsize.h>
|
|
45 |
|
|
46 |
Q_DECLARE_METATYPE(QSizeF)
|
|
47 |
|
|
48 |
//TESTED_CLASS=
|
|
49 |
//TESTED_FILES=corelib/tools/qsize.h corelib/tools/qsize.cpp
|
|
50 |
|
|
51 |
class tst_QSizeF : public QObject {
|
|
52 |
Q_OBJECT
|
|
53 |
|
|
54 |
public:
|
|
55 |
tst_QSizeF();
|
|
56 |
virtual ~tst_QSizeF();
|
|
57 |
|
|
58 |
public slots:
|
|
59 |
void init();
|
|
60 |
void cleanup();
|
|
61 |
|
|
62 |
private slots:
|
|
63 |
void scale();
|
|
64 |
|
|
65 |
void expandedTo();
|
|
66 |
void expandedTo_data();
|
|
67 |
|
|
68 |
void boundedTo_data();
|
|
69 |
void boundedTo();
|
|
70 |
|
|
71 |
void transpose_data();
|
|
72 |
void transpose();
|
|
73 |
};
|
|
74 |
|
|
75 |
tst_QSizeF::tst_QSizeF() {
|
|
76 |
}
|
|
77 |
|
|
78 |
tst_QSizeF::~tst_QSizeF() {
|
|
79 |
}
|
|
80 |
|
|
81 |
void tst_QSizeF::init() {
|
|
82 |
}
|
|
83 |
|
|
84 |
void tst_QSizeF::cleanup() {
|
|
85 |
}
|
|
86 |
|
|
87 |
void tst_QSizeF::scale() {
|
|
88 |
QSizeF t1(10.4, 12.8);
|
|
89 |
t1.scale(60.6, 60.6, Qt::IgnoreAspectRatio);
|
|
90 |
QCOMPARE(t1, QSizeF(60.6, 60.6));
|
|
91 |
|
|
92 |
QSizeF t2(10.4, 12.8);
|
|
93 |
t2.scale(43.52, 43.52, Qt::KeepAspectRatio);
|
|
94 |
QCOMPARE(t2, QSizeF(35.36, 43.52));
|
|
95 |
|
|
96 |
QSizeF t3(9.6, 12.48);
|
|
97 |
t3.scale(31.68, 31.68, Qt::KeepAspectRatioByExpanding);
|
|
98 |
QCOMPARE(t3, QSizeF(31.68, 41.184));
|
|
99 |
|
|
100 |
QSizeF t4(12.8, 10.4);
|
|
101 |
t4.scale(43.52, 43.52, Qt::KeepAspectRatio);
|
|
102 |
QCOMPARE(t4, QSizeF(43.52, 35.36));
|
|
103 |
|
|
104 |
QSizeF t5(12.48, 9.6);
|
|
105 |
t5.scale(31.68, 31.68, Qt::KeepAspectRatioByExpanding);
|
|
106 |
QCOMPARE(t5, QSizeF(41.184, 31.68));
|
|
107 |
|
|
108 |
QSizeF t6(0.0, 0.0);
|
|
109 |
t6.scale(200, 240, Qt::IgnoreAspectRatio);
|
|
110 |
QCOMPARE(t6, QSizeF(200, 240));
|
|
111 |
|
|
112 |
QSizeF t7(0.0, 0.0);
|
|
113 |
t7.scale(200, 240, Qt::KeepAspectRatio);
|
|
114 |
QCOMPARE(t7, QSizeF(200, 240));
|
|
115 |
|
|
116 |
QSizeF t8(0.0, 0.0);
|
|
117 |
t8.scale(200, 240, Qt::KeepAspectRatioByExpanding);
|
|
118 |
QCOMPARE(t8, QSizeF(200, 240));
|
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
void tst_QSizeF::expandedTo_data() {
|
|
123 |
QTest::addColumn<QSizeF>("input1");
|
|
124 |
QTest::addColumn<QSizeF>("input2");
|
|
125 |
QTest::addColumn<QSizeF>("expected");
|
|
126 |
|
|
127 |
QTest::newRow("data0") << QSizeF(10.4, 12.8) << QSizeF(6.6, 4.4) << QSizeF(10.4, 12.8);
|
|
128 |
QTest::newRow("data1") << QSizeF(0.0, 0.0) << QSizeF(6.6, 4.4) << QSizeF(6.6, 4.4);
|
|
129 |
// This should pick the highest of w,h components independently of each other,
|
|
130 |
// thus the result dont have to be equal to neither input1 nor input2.
|
|
131 |
QTest::newRow("data3") << QSizeF(6.6, 4.4) << QSizeF(4.4, 6.6) << QSizeF(6.6, 6.6);
|
|
132 |
}
|
|
133 |
|
|
134 |
void tst_QSizeF::expandedTo() {
|
|
135 |
QFETCH( QSizeF, input1);
|
|
136 |
QFETCH( QSizeF, input2);
|
|
137 |
QFETCH( QSizeF, expected);
|
|
138 |
|
|
139 |
QCOMPARE( input1.expandedTo(input2), expected);
|
|
140 |
}
|
|
141 |
|
|
142 |
void tst_QSizeF::boundedTo_data() {
|
|
143 |
QTest::addColumn<QSizeF>("input1");
|
|
144 |
QTest::addColumn<QSizeF>("input2");
|
|
145 |
QTest::addColumn<QSizeF>("expected");
|
|
146 |
|
|
147 |
QTest::newRow("data0") << QSizeF(10.4, 12.8) << QSizeF(6.6, 4.4) << QSizeF(6.6, 4.4);
|
|
148 |
QTest::newRow("data1") << QSizeF(0.0, 0.0) << QSizeF(6.6, 4.4) << QSizeF(0.0, 0.0);
|
|
149 |
// This should pick the lowest of w,h components independently of each other,
|
|
150 |
// thus the result dont have to be equal to neither input1 nor input2.
|
|
151 |
QTest::newRow("data3") << QSizeF(6.6, 4.4) << QSizeF(4.4, 6.6) << QSizeF(4.4, 4.4);
|
|
152 |
}
|
|
153 |
|
|
154 |
void tst_QSizeF::boundedTo() {
|
|
155 |
QFETCH( QSizeF, input1);
|
|
156 |
QFETCH( QSizeF, input2);
|
|
157 |
QFETCH( QSizeF, expected);
|
|
158 |
|
|
159 |
QCOMPARE( input1.boundedTo(input2), expected);
|
|
160 |
}
|
|
161 |
|
|
162 |
void tst_QSizeF::transpose_data() {
|
|
163 |
QTest::addColumn<QSizeF>("input1");
|
|
164 |
QTest::addColumn<QSizeF>("expected");
|
|
165 |
|
|
166 |
QTest::newRow("data0") << QSizeF(10.4, 12.8) << QSizeF(12.8, 10.4);
|
|
167 |
QTest::newRow("data1") << QSizeF(0.0, 0.0) << QSizeF(0.0, 0.0);
|
|
168 |
QTest::newRow("data3") << QSizeF(6.6, 4.4) << QSizeF(4.4, 6.6);
|
|
169 |
}
|
|
170 |
|
|
171 |
void tst_QSizeF::transpose() {
|
|
172 |
QFETCH( QSizeF, input1);
|
|
173 |
QFETCH( QSizeF, expected);
|
|
174 |
|
|
175 |
// transpose() works only inplace and does not return anything, so we must do the operation itself before the compare.
|
|
176 |
input1.transpose();
|
|
177 |
QCOMPARE(input1 , expected);
|
|
178 |
}
|
|
179 |
|
|
180 |
QTEST_APPLESS_MAIN(tst_QSizeF)
|
|
181 |
#include "tst_qsizef.moc"
|