author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 12 Mar 2010 15:46:37 +0200 | |
branch | RCL_3 |
changeset 5 | d3bac044e0f0 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
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 |
||
45 |
#include <qsqlfield.h> |
|
46 |
#include <qvariant.h> |
|
47 |
#include <qsqlfield.h> |
|
48 |
||
49 |
||
50 |
//TESTED_CLASS= |
|
51 |
//TESTED_FILES= |
|
52 |
||
53 |
class tst_QSqlField : public QObject |
|
54 |
{ |
|
55 |
Q_OBJECT |
|
56 |
||
57 |
public: |
|
58 |
tst_QSqlField(); |
|
59 |
virtual ~tst_QSqlField(); |
|
60 |
||
61 |
||
62 |
public slots: |
|
63 |
void init(); |
|
64 |
void cleanup(); |
|
65 |
private slots: |
|
66 |
void getSetCheck(); |
|
67 |
void value(); |
|
68 |
void type(); |
|
69 |
void setValue_data(); |
|
70 |
void setValue(); |
|
71 |
void setReadOnly(); |
|
72 |
void setNull(); |
|
73 |
void setName_data(); |
|
74 |
void setName(); |
|
75 |
void operator_Equal(); |
|
76 |
void operator_Assign(); |
|
77 |
void name_data(); |
|
78 |
void name(); |
|
79 |
void isReadOnly(); |
|
80 |
void isNull(); |
|
81 |
void clear_data(); |
|
82 |
void clear(); |
|
83 |
}; |
|
84 |
||
85 |
// Testing get/set functions |
|
86 |
void tst_QSqlField::getSetCheck() |
|
87 |
{ |
|
88 |
QSqlField obj1; |
|
89 |
// RequiredStatus QSqlField::requiredStatus() |
|
90 |
// void QSqlField::setRequiredStatus(RequiredStatus) |
|
91 |
obj1.setRequiredStatus(QSqlField::RequiredStatus(QSqlField::Unknown)); |
|
92 |
QCOMPARE(QSqlField::RequiredStatus(QSqlField::Unknown), obj1.requiredStatus()); |
|
93 |
obj1.setRequiredStatus(QSqlField::RequiredStatus(QSqlField::Optional)); |
|
94 |
QCOMPARE(QSqlField::RequiredStatus(QSqlField::Optional), obj1.requiredStatus()); |
|
95 |
obj1.setRequiredStatus(QSqlField::RequiredStatus(QSqlField::Required)); |
|
96 |
QCOMPARE(QSqlField::RequiredStatus(QSqlField::Required), obj1.requiredStatus()); |
|
97 |
||
98 |
// int QSqlField::length() |
|
99 |
// void QSqlField::setLength(int) |
|
100 |
obj1.setLength(0); |
|
101 |
QCOMPARE(0, obj1.length()); |
|
102 |
obj1.setLength(INT_MIN); |
|
103 |
QCOMPARE(INT_MIN, obj1.length()); |
|
104 |
obj1.setLength(INT_MAX); |
|
105 |
QCOMPARE(INT_MAX, obj1.length()); |
|
106 |
||
107 |
// int QSqlField::precision() |
|
108 |
// void QSqlField::setPrecision(int) |
|
109 |
obj1.setPrecision(0); |
|
110 |
QCOMPARE(0, obj1.precision()); |
|
111 |
obj1.setPrecision(INT_MIN); |
|
112 |
QCOMPARE(INT_MIN, obj1.precision()); |
|
113 |
obj1.setPrecision(INT_MAX); |
|
114 |
QCOMPARE(INT_MAX, obj1.precision()); |
|
115 |
} |
|
116 |
||
117 |
tst_QSqlField::tst_QSqlField() |
|
118 |
{ |
|
119 |
} |
|
120 |
||
121 |
tst_QSqlField::~tst_QSqlField() |
|
122 |
{ |
|
123 |
||
124 |
} |
|
125 |
||
126 |
void tst_QSqlField::init() |
|
127 |
{ |
|
128 |
// TODO: Add initialization code here. |
|
129 |
// This will be executed immediately before each test is run. |
|
130 |
} |
|
131 |
||
132 |
void tst_QSqlField::cleanup() |
|
133 |
{ |
|
134 |
// TODO: Add cleanup code here. |
|
135 |
// This will be executed immediately after each test is run. |
|
136 |
} |
|
137 |
||
138 |
void tst_QSqlField::clear_data() |
|
139 |
{ |
|
140 |
QTest::addColumn<int>("val"); |
|
141 |
QTest::addColumn<bool>("bval"); |
|
142 |
QTest::addColumn<QString>("strVal"); |
|
143 |
QTest::addColumn<double>("fval"); |
|
144 |
||
145 |
//next we fill it with data |
|
146 |
QTest::newRow( "data0" ) << (int)5 << true << QString("Hallo") << (double)0; |
|
147 |
QTest::newRow( "data1" ) << -5 << false << QString("NULL") << (double)-4; |
|
148 |
QTest::newRow( "data2" ) << 0 << false << QString("0") << (double)0; |
|
149 |
} |
|
150 |
||
151 |
void tst_QSqlField::clear() |
|
152 |
{ |
|
153 |
QSqlField field( "Testfield", QVariant::Int ); |
|
154 |
QFETCH( int, val ); |
|
155 |
field.setValue( val ); |
|
156 |
field.setReadOnly(true); |
|
157 |
field.clear(); |
|
158 |
QVERIFY( field.value() == val ); |
|
159 |
QVERIFY( !field.isNull() ); |
|
160 |
||
161 |
QSqlField bfield( "Testfield", QVariant::Bool ); |
|
162 |
QFETCH( bool, bval ); |
|
163 |
bfield.setValue( QVariant(bval) ); |
|
164 |
bfield.setReadOnly(true); |
|
165 |
bfield.clear(); |
|
166 |
||
167 |
QVERIFY( bfield.value() == QVariant(bval) ); |
|
168 |
QVERIFY( !bfield.isNull() ); |
|
169 |
||
170 |
QSqlField ffield( "Testfield", QVariant::Double ); |
|
171 |
QFETCH( double, fval ); |
|
172 |
ffield.setValue( fval ); |
|
173 |
ffield.setReadOnly(true); |
|
174 |
ffield.clear(); |
|
175 |
QVERIFY( ffield.value() == fval ); |
|
176 |
QVERIFY( !ffield.isNull() ); |
|
177 |
||
178 |
QSqlField sfield( "Testfield", QVariant::String ); |
|
179 |
QFETCH( QString, strVal ); |
|
180 |
sfield.setValue( strVal ); |
|
181 |
sfield.setReadOnly(true); |
|
182 |
sfield.clear(); |
|
183 |
QVERIFY( sfield.value() == strVal ); |
|
184 |
QVERIFY( !sfield.isNull() ); |
|
185 |
} |
|
186 |
||
187 |
void tst_QSqlField::isNull() |
|
188 |
{ |
|
189 |
QSqlField field( "test", QVariant::String ); |
|
190 |
QVERIFY( field.isNull() ); |
|
191 |
} |
|
192 |
||
193 |
void tst_QSqlField::isReadOnly() |
|
194 |
{ |
|
195 |
QSqlField field( "test", QVariant::String ); |
|
196 |
QVERIFY( !field.isReadOnly() ); |
|
197 |
field.setReadOnly( true ); |
|
198 |
QVERIFY( field.isReadOnly() ); |
|
199 |
field.setReadOnly( false ); |
|
200 |
QVERIFY( !field.isReadOnly() ); |
|
201 |
} |
|
202 |
||
203 |
void tst_QSqlField::name_data() |
|
204 |
{ |
|
205 |
QTest::addColumn<QString>("val"); |
|
206 |
||
207 |
//next we fill it with data |
|
208 |
QTest::newRow( "data0" ) << QString("test"); |
|
209 |
QTest::newRow( "data1" ) << QString("Harry"); |
|
210 |
QTest::newRow( "data2" ) << QString(""); |
|
211 |
} |
|
212 |
||
213 |
void tst_QSqlField::name() |
|
214 |
{ |
|
215 |
QSqlField field( "test", QVariant::String ); |
|
216 |
QFETCH( QString, val ); |
|
217 |
QVERIFY( field.name() == "test" ); |
|
218 |
field.setName( val ); |
|
219 |
QVERIFY( field.name() == val ); |
|
220 |
} |
|
221 |
||
222 |
void tst_QSqlField::operator_Assign() |
|
223 |
{ |
|
224 |
QSqlField field1( "test", QVariant::String ); |
|
225 |
field1.setValue( "Harry" ); |
|
226 |
field1.setReadOnly( true ); |
|
227 |
QSqlField field2 = field1; |
|
228 |
QVERIFY( field1 == field2 ); |
|
229 |
QSqlField field3( "test", QVariant::Double ); |
|
230 |
field3.clear(); |
|
231 |
field1 = field3; |
|
232 |
QVERIFY( field1 == field3 ); |
|
233 |
} |
|
234 |
||
235 |
void tst_QSqlField::operator_Equal() |
|
236 |
{ |
|
237 |
QSqlField field1( "test", QVariant::String ); |
|
238 |
QSqlField field2( "test2", QVariant::String ); |
|
239 |
QSqlField field3( "test", QVariant::Int ); |
|
240 |
QVERIFY( !(field1 == field2) ); |
|
241 |
QVERIFY( !(field1 == field3) ); |
|
242 |
field2.setName( "test" ); |
|
243 |
QVERIFY( field1 == field2 ); |
|
244 |
QVERIFY( field1 == field2 ); |
|
245 |
field1.setValue( "Harry" ); |
|
246 |
QVERIFY( !(field1 == field2) ); |
|
247 |
field2.setValue( "Harry" ); |
|
248 |
QVERIFY( field1 == field2 ); |
|
249 |
field1.setReadOnly( true ); |
|
250 |
QVERIFY( !(field1 == field2) ); |
|
251 |
field2.setReadOnly( true ); |
|
252 |
QVERIFY( field1 == field2 ); |
|
253 |
} |
|
254 |
||
255 |
void tst_QSqlField::setName_data() |
|
256 |
{ |
|
257 |
QTest::addColumn<QString>("val"); |
|
258 |
||
259 |
//next we fill it with data |
|
260 |
QTest::newRow( "data0" ) << QString("test"); |
|
261 |
QTest::newRow( "data1" ) << QString("Harry"); |
|
262 |
QTest::newRow( "data2" ) << QString(""); |
|
263 |
} |
|
264 |
||
265 |
void tst_QSqlField::setName() |
|
266 |
{ |
|
267 |
QSqlField field( "test", QVariant::String ); |
|
268 |
QFETCH( QString, val ); |
|
269 |
QVERIFY( field.name() == "test" ); |
|
270 |
field.setName( val ); |
|
271 |
QVERIFY( field.name() == val ); |
|
272 |
} |
|
273 |
||
274 |
void tst_QSqlField::setNull() |
|
275 |
{ |
|
276 |
QSqlField field( "test", QVariant::String ); |
|
277 |
field.setValue( "test" ); |
|
278 |
field.clear(); |
|
279 |
QVERIFY( field.value() == QVariant().toString() ); |
|
280 |
QVERIFY( field.isNull() ); |
|
281 |
} |
|
282 |
||
283 |
void tst_QSqlField::setReadOnly() |
|
284 |
{ |
|
285 |
QSqlField field( "test", QVariant::String ); |
|
286 |
field.setValue( "test" ); |
|
287 |
field.setReadOnly( true ); |
|
288 |
field.setValue( "Harry" ); |
|
289 |
QVERIFY( field.value() == "test" ); |
|
290 |
field.clear(); |
|
291 |
QVERIFY( field.value() == "test" ); |
|
292 |
QVERIFY( !field.isNull() ); |
|
293 |
field.clear(); |
|
294 |
QVERIFY( field.value() == "test" ); |
|
295 |
QVERIFY( !field.isNull() ); |
|
296 |
field.setReadOnly( false ); |
|
297 |
field.setValue( "Harry" ); |
|
298 |
QVERIFY( field.value() == "Harry" ); |
|
299 |
field.clear(); |
|
300 |
QVERIFY( field.value() == QVariant().toString() ); |
|
301 |
QVERIFY( field.isNull() ); |
|
302 |
} |
|
303 |
||
304 |
void tst_QSqlField::setValue_data() |
|
305 |
{ |
|
306 |
QTest::addColumn<int>("ival"); |
|
307 |
QTest::addColumn<bool>("bval"); |
|
308 |
QTest::addColumn<double>("dval"); |
|
309 |
QTest::addColumn<QString>("sval"); |
|
310 |
||
311 |
//next we fill it with data |
|
312 |
QTest::newRow( "data0" ) << 0 << false << (double)223.232 << QString(""); |
|
313 |
QTest::newRow( "data1" ) << 123 << true << (double)-232.232 << QString("Harry"); |
|
314 |
QTest::newRow( "data2" ) << -123 << false << (double)232222.323223233338 << QString("Woipertinger"); |
|
315 |
} |
|
316 |
||
317 |
void tst_QSqlField::setValue() |
|
318 |
{ |
|
319 |
QSqlField field1 ( "test", QVariant::Int ); |
|
320 |
QSqlField field2 ( "test", QVariant::String ); |
|
321 |
QSqlField field3 ( "test", QVariant::Bool ); |
|
322 |
QSqlField field4 ( "test", QVariant::Double ); |
|
323 |
field1.clear(); |
|
324 |
QFETCH( int, ival ); |
|
325 |
QFETCH( QString, sval ); |
|
326 |
QFETCH( double, dval ); |
|
327 |
QFETCH( bool, bval ); |
|
328 |
field1.setValue( ival ); |
|
329 |
QCOMPARE( field1.value().toInt(), ival ); |
|
330 |
// setValue should also reset the NULL flag |
|
331 |
QVERIFY( !field1.isNull() ); |
|
332 |
||
333 |
field2.setValue( sval ); |
|
334 |
QCOMPARE( field2.value().toString(), sval ); |
|
335 |
field3.setValue( QVariant( bval) ); |
|
336 |
QVERIFY( field3.value().toBool() == bval ); |
|
337 |
field4.setValue( dval ); |
|
338 |
QCOMPARE( field4.value().toDouble(), dval ); |
|
339 |
field4.setReadOnly( true ); |
|
340 |
field4.setValue( "Something_that's_not_a_double" ); |
|
341 |
QCOMPARE( field4.value().toDouble(), dval ); |
|
342 |
} |
|
343 |
||
344 |
void tst_QSqlField::type() |
|
345 |
{ |
|
346 |
QSqlField field1( "string", QVariant::String ); |
|
347 |
QSqlField field2( "string", QVariant::Bool ); |
|
348 |
QSqlField field3( "string", QVariant::Double ); |
|
349 |
QVERIFY( field1.type() == QVariant::String ); |
|
350 |
QVERIFY( field2.type() == QVariant::Bool ); |
|
351 |
QVERIFY( field3.type() == QVariant::Double ); |
|
352 |
} |
|
353 |
||
354 |
void tst_QSqlField::value() |
|
355 |
{ |
|
356 |
DEPENDS_ON( "setValue" ); |
|
357 |
} |
|
358 |
||
359 |
QTEST_MAIN(tst_QSqlField) |
|
360 |
#include "tst_qsqlfield.moc" |