author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 14 May 2010 16:40:13 +0300 | |
changeset 22 | 79de32ba3296 |
parent 18 | 2f34d5167611 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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(QSize) |
|
47 |
||
48 |
//TESTED_CLASS= |
|
49 |
//TESTED_FILES= |
|
50 |
||
51 |
class tst_QSize : public QObject |
|
52 |
{ |
|
53 |
Q_OBJECT |
|
54 |
||
55 |
public: |
|
56 |
tst_QSize(); |
|
57 |
virtual ~tst_QSize(); |
|
58 |
||
59 |
||
60 |
public slots: |
|
61 |
void init(); |
|
62 |
void cleanup(); |
|
63 |
private slots: |
|
64 |
void getSetCheck(); |
|
65 |
void scale(); |
|
66 |
||
67 |
void expandedTo(); |
|
68 |
void expandedTo_data(); |
|
69 |
||
70 |
void boundedTo_data(); |
|
71 |
void boundedTo(); |
|
72 |
||
73 |
void transpose_data(); |
|
74 |
void transpose(); |
|
75 |
}; |
|
76 |
||
77 |
// Testing get/set functions |
|
78 |
void tst_QSize::getSetCheck() |
|
79 |
{ |
|
80 |
QSize obj1; |
|
81 |
// int QSize::width() |
|
82 |
// void QSize::setWidth(int) |
|
83 |
obj1.setWidth(0); |
|
84 |
QCOMPARE(0, obj1.width()); |
|
85 |
obj1.setWidth(INT_MIN); |
|
86 |
QCOMPARE(INT_MIN, obj1.width()); |
|
87 |
obj1.setWidth(INT_MAX); |
|
88 |
QCOMPARE(INT_MAX, obj1.width()); |
|
89 |
||
90 |
// int QSize::height() |
|
91 |
// void QSize::setHeight(int) |
|
92 |
obj1.setHeight(0); |
|
93 |
QCOMPARE(0, obj1.height()); |
|
94 |
obj1.setHeight(INT_MIN); |
|
95 |
QCOMPARE(INT_MIN, obj1.height()); |
|
96 |
obj1.setHeight(INT_MAX); |
|
97 |
QCOMPARE(INT_MAX, obj1.height()); |
|
98 |
||
99 |
QSizeF obj2; |
|
100 |
// qreal QSizeF::width() |
|
101 |
// void QSizeF::setWidth(qreal) |
|
102 |
obj2.setWidth(0.0); |
|
103 |
QCOMPARE(0.0, obj2.width()); |
|
104 |
obj2.setWidth(1.1); |
|
105 |
QCOMPARE(1.1, obj2.width()); |
|
106 |
||
107 |
// qreal QSizeF::height() |
|
108 |
// void QSizeF::setHeight(qreal) |
|
109 |
obj2.setHeight(0.0); |
|
110 |
QCOMPARE(0.0, obj2.height()); |
|
111 |
obj2.setHeight(1.1); |
|
112 |
QCOMPARE(1.1, obj2.height()); |
|
113 |
} |
|
114 |
||
115 |
||
116 |
tst_QSize::tst_QSize() |
|
117 |
{ |
|
118 |
} |
|
119 |
||
120 |
tst_QSize::~tst_QSize() |
|
121 |
{ |
|
122 |
} |
|
123 |
||
124 |
void tst_QSize::init() |
|
125 |
{ |
|
126 |
} |
|
127 |
||
128 |
void tst_QSize::cleanup() |
|
129 |
{ |
|
130 |
} |
|
131 |
||
132 |
void tst_QSize::scale() |
|
133 |
{ |
|
134 |
QSize t1( 10, 12 ); |
|
135 |
t1.scale( 60, 60, Qt::IgnoreAspectRatio ); |
|
136 |
QCOMPARE( t1, QSize(60, 60) ); |
|
137 |
||
138 |
QSize t2( 10, 12 ); |
|
139 |
t2.scale( 60, 60, Qt::KeepAspectRatio ); |
|
140 |
QCOMPARE( t2, QSize(50, 60) ); |
|
141 |
||
142 |
QSize t3( 10, 12 ); |
|
143 |
t3.scale( 60, 60, Qt::KeepAspectRatioByExpanding ); |
|
144 |
QCOMPARE( t3, QSize(60, 72) ); |
|
145 |
||
146 |
QSize t4( 12, 10 ); |
|
147 |
t4.scale( 60, 60, Qt::KeepAspectRatio ); |
|
148 |
QCOMPARE( t4, QSize(60, 50) ); |
|
149 |
||
150 |
QSize t5( 12, 10 ); |
|
151 |
t5.scale( 60, 60, Qt::KeepAspectRatioByExpanding ); |
|
152 |
QCOMPARE( t5, QSize(72, 60) ); |
|
153 |
||
154 |
// test potential int overflow |
|
155 |
QSize t6(88473, 88473); |
|
156 |
t6.scale(141817, 141817, Qt::KeepAspectRatio); |
|
157 |
QCOMPARE(t6, QSize(141817, 141817)); |
|
158 |
||
159 |
QSize t7(800, 600); |
|
160 |
t7.scale(400, INT_MAX, Qt::KeepAspectRatio); |
|
161 |
QCOMPARE(t7, QSize(400, 300)); |
|
162 |
||
163 |
QSize t8(800, 600); |
|
164 |
t8.scale(INT_MAX, 150, Qt::KeepAspectRatio); |
|
165 |
QCOMPARE(t8, QSize(200, 150)); |
|
166 |
||
167 |
QSize t9(600, 800); |
|
168 |
t9.scale(300, INT_MAX, Qt::KeepAspectRatio); |
|
169 |
QCOMPARE(t9, QSize(300, 400)); |
|
170 |
||
171 |
QSize t10(600, 800); |
|
172 |
t10.scale(INT_MAX, 200, Qt::KeepAspectRatio); |
|
173 |
QCOMPARE(t10, QSize(150, 200)); |
|
174 |
||
175 |
QSize t11(0, 0); |
|
176 |
t11.scale(240, 200, Qt::IgnoreAspectRatio); |
|
177 |
QCOMPARE(t11, QSize(240, 200)); |
|
178 |
||
179 |
QSize t12(0, 0); |
|
180 |
t12.scale(240, 200, Qt::KeepAspectRatio); |
|
181 |
QCOMPARE(t12, QSize(240, 200)); |
|
182 |
||
183 |
QSize t13(0, 0); |
|
184 |
t13.scale(240, 200, Qt::KeepAspectRatioByExpanding); |
|
185 |
QCOMPARE(t13, QSize(240, 200)); |
|
186 |
} |
|
187 |
||
188 |
||
189 |
void tst_QSize::expandedTo_data() |
|
190 |
{ |
|
191 |
QTest::addColumn<QSize>("input1"); |
|
192 |
QTest::addColumn<QSize>("input2"); |
|
193 |
QTest::addColumn<QSize>("expected"); |
|
194 |
||
195 |
QTest::newRow("data0") << QSize(10,12) << QSize(6,4) << QSize(10,12); |
|
196 |
QTest::newRow("data1") << QSize(0,0) << QSize(6,4) << QSize(6,4); |
|
197 |
// This should pick the highest of w,h components independently of each other, |
|
198 |
// thus the result dont have to be equal to neither input1 nor input2. |
|
199 |
QTest::newRow("data3") << QSize(6,4) << QSize(4,6) << QSize(6,6); |
|
200 |
} |
|
201 |
||
202 |
void tst_QSize::expandedTo() |
|
203 |
{ |
|
204 |
QFETCH( QSize, input1); |
|
205 |
QFETCH( QSize, input2); |
|
206 |
QFETCH( QSize, expected); |
|
207 |
||
208 |
QCOMPARE( input1.expandedTo(input2), expected); |
|
209 |
} |
|
210 |
||
211 |
void tst_QSize::boundedTo_data() |
|
212 |
{ |
|
213 |
QTest::addColumn<QSize>("input1"); |
|
214 |
QTest::addColumn<QSize>("input2"); |
|
215 |
QTest::addColumn<QSize>("expected"); |
|
216 |
||
217 |
QTest::newRow("data0") << QSize(10,12) << QSize(6,4) << QSize(6,4); |
|
218 |
QTest::newRow("data1") << QSize(0,0) << QSize(6,4) << QSize(0,0); |
|
219 |
// This should pick the lowest of w,h components independently of each other, |
|
220 |
// thus the result dont have to be equal to neither input1 nor input2. |
|
221 |
QTest::newRow("data3") << QSize(6,4) << QSize(4,6) << QSize(4,4); |
|
222 |
} |
|
223 |
||
224 |
void tst_QSize::boundedTo() |
|
225 |
{ |
|
226 |
QFETCH( QSize, input1); |
|
227 |
QFETCH( QSize, input2); |
|
228 |
QFETCH( QSize, expected); |
|
229 |
||
230 |
QCOMPARE( input1.boundedTo(input2), expected); |
|
231 |
} |
|
232 |
||
233 |
void tst_QSize::transpose_data() |
|
234 |
{ |
|
235 |
QTest::addColumn<QSize>("input1"); |
|
236 |
QTest::addColumn<QSize>("expected"); |
|
237 |
||
238 |
QTest::newRow("data0") << QSize(10,12) << QSize(12,10); |
|
239 |
QTest::newRow("data1") << QSize(0,0) << QSize(0,0); |
|
240 |
QTest::newRow("data3") << QSize(6,4) << QSize(4,6); |
|
241 |
} |
|
242 |
||
243 |
void tst_QSize::transpose() |
|
244 |
{ |
|
245 |
QFETCH( QSize, input1); |
|
246 |
QFETCH( QSize, expected); |
|
247 |
||
248 |
// transpose() works only inplace and does not return anything, so we must do the operation itself before the compare. |
|
249 |
input1.transpose(); |
|
250 |
QCOMPARE(input1 , expected); |
|
251 |
} |
|
252 |
||
253 |
QTEST_APPLESS_MAIN(tst_QSize) |
|
254 |
#include "tst_qsize.moc" |