1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the test suite of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file. Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42
43 #include <QtTest/QtTest>
44 #include "qdatetime.h"
45
46 //TESTED_CLASS=
47 //TESTED_FILES=corelib/thread/qthreadstorage.h corelib/thread/qthreadstorage.cpp
48
49 class tst_QTime : public QObject
50 {
51 Q_OBJECT
52
53 public:
54 tst_QTime();
55 virtual ~tst_QTime();
56
57
58 public slots:
59 void initTestCase();
60 void cleanupTestCase();
61 void init();
62 void cleanup();
63 private slots:
64 void toStringLocale();
65 void toString();
66 void msecsTo_data();
67 void msecsTo();
68 void secsTo_data();
69 void secsTo();
70 void setHMS_data();
71 void setHMS();
72 void msec();
73 void second();
74 void minute();
75 void hour_data();
76 void hour();
77 void isValid();
78 void isNull();
79 void addMSecs_data();
80 void addMSecs();
81 void addSecs_data();
82 void addSecs();
83 void operator_eq_eq();
84 void operator_not_eq();
85 void operator_lt();
86 void operator_gt();
87 void operator_lt_eq();
88 void operator_gt_eq();
89 void fromString_data();
90 void fromString();
91 void fromStringFormat_data();
92 void fromStringFormat();
93 void toString_data();
94 void toString_format_data();
95 void toString_format();
96 };
97
Q_DECLARE_METATYPE(QTime)98 Q_DECLARE_METATYPE(QTime)
99
100 tst_QTime::tst_QTime()
101 {
102 }
103
~tst_QTime()104 tst_QTime::~tst_QTime()
105 {
106
107 }
108
109 // initTestCase will be executed once before the first testfunction is executed.
initTestCase()110 void tst_QTime::initTestCase()
111 {
112 }
113
114 // cleanupTestCase will be executed once after the last testfunction is executed.
cleanupTestCase()115 void tst_QTime::cleanupTestCase()
116 {
117 }
118
119 // init() will be executed immediately before each testfunction is run.
init()120 void tst_QTime::init()
121 {
122 // TODO: Add testfunction specific initialization code here.
123 }
124
125 // cleanup() will be executed immediately after each testfunction is run.
cleanup()126 void tst_QTime::cleanup()
127 {
128 // TODO: Add testfunction specific cleanup code here.
129 }
130
addSecs_data()131 void tst_QTime::addSecs_data()
132 {
133 QTest::addColumn<QTime>("t1");
134 QTest::addColumn<int>("i");
135 QTest::addColumn<QTime>("exp");
136
137 QTest::newRow("Data0") << QTime(0,0,0) << 200 << QTime(0,3,20);
138 QTest::newRow("Data1") << QTime(0,0,0) << 20 << QTime(0,0,20);
139 }
140
addSecs()141 void tst_QTime::addSecs()
142 {
143 QFETCH( QTime, t1 );
144 QFETCH( int, i );
145 QTime t2;
146 t2 = t1.addSecs( i );
147 QFETCH( QTime, exp );
148 QCOMPARE( t2, exp );
149 }
150
addMSecs_data()151 void tst_QTime::addMSecs_data()
152 {
153 QTest::addColumn<QTime>("t1");
154 QTest::addColumn<int>("i");
155 QTest::addColumn<QTime>("exp");
156
157 // start with testing positive values
158 QTest::newRow( "Data1_0") << QTime(0,0,0,0) << 2000 << QTime(0,0,2,0);
159 QTest::newRow( "Data1_1") << QTime(0,0,0,0) << 200 << QTime(0,0,0,200);
160 QTest::newRow( "Data1_2") << QTime(0,0,0,0) << 20 << QTime(0,0,0,20);
161 QTest::newRow( "Data1_3") << QTime(0,0,0,1) << 1 << QTime(0,0,0,2);
162 QTest::newRow( "Data1_4") << QTime(0,0,0,0) << 0 << QTime(0,0,0,0);
163
164 QTest::newRow( "Data2_0") << QTime(0,0,0,98) << 0 << QTime(0,0,0,98);
165 QTest::newRow( "Data2_1") << QTime(0,0,0,98) << 1 << QTime(0,0,0,99);
166 QTest::newRow( "Data2_2") << QTime(0,0,0,98) << 2 << QTime(0,0,0,100);
167 QTest::newRow( "Data2_3") << QTime(0,0,0,98) << 3 << QTime(0,0,0,101);
168
169 QTest::newRow( "Data3_0") << QTime(0,0,0,998) << 0 << QTime(0,0,0,998);
170 QTest::newRow( "Data3_1") << QTime(0,0,0,998) << 1 << QTime(0,0,0,999);
171 QTest::newRow( "Data3_2") << QTime(0,0,0,998) << 2 << QTime(0,0,1,0);
172 QTest::newRow( "Data3_3") << QTime(0,0,0,998) << 3 << QTime(0,0,1,1);
173
174 QTest::newRow( "Data4_0") << QTime(0,0,1,995) << 4 << QTime(0,0,1,999);
175 QTest::newRow( "Data4_1") << QTime(0,0,1,995) << 5 << QTime(0,0,2,0);
176 QTest::newRow( "Data4_2") << QTime(0,0,1,995) << 6 << QTime(0,0,2,1);
177 QTest::newRow( "Data4_3") << QTime(0,0,1,995) << 100 << QTime(0,0,2,95);
178 QTest::newRow( "Data4_4") << QTime(0,0,1,995) << 105 << QTime(0,0,2,100);
179
180 QTest::newRow( "Data5_0") << QTime(0,0,59,995) << 4 << QTime(0,0,59,999);
181 QTest::newRow( "Data5_1") << QTime(0,0,59,995) << 5 << QTime(0,1,0,0);
182 QTest::newRow( "Data5_2") << QTime(0,0,59,995) << 6 << QTime(0,1,0,1);
183 QTest::newRow( "Data5_3") << QTime(0,0,59,995) << 1006 << QTime(0,1,1,1);
184
185 QTest::newRow( "Data6_0") << QTime(0,59,59,995) << 4 << QTime(0,59,59,999);
186 QTest::newRow( "Data6_1") << QTime(0,59,59,995) << 5 << QTime(1,0,0,0);
187 QTest::newRow( "Data6_2") << QTime(0,59,59,995) << 6 << QTime(1,0,0,1);
188 QTest::newRow( "Data6_3") << QTime(0,59,59,995) << 106 << QTime(1,0,0,101);
189 QTest::newRow( "Data6_4") << QTime(0,59,59,995) << 1004 << QTime(1,0,0,999);
190 QTest::newRow( "Data6_5") << QTime(0,59,59,995) << 1005 << QTime(1,0,1,0);
191 QTest::newRow( "Data6_6") << QTime(0,59,59,995) << 61006 << QTime(1,1,1,1);
192
193 QTest::newRow( "Data7_0") << QTime(23,59,59,995) << 0 << QTime(23,59,59,995);
194 QTest::newRow( "Data7_1") << QTime(23,59,59,995) << 4 << QTime(23,59,59,999);
195 QTest::newRow( "Data7_2") << QTime(23,59,59,995) << 5 << QTime(0,0,0,0);
196 QTest::newRow( "Data7_3") << QTime(23,59,59,995) << 6 << QTime(0,0,0,1);
197 QTest::newRow( "Data7_4") << QTime(23,59,59,995) << 7 << QTime(0,0,0,2);
198
199 // must test negative values too...
200 QTest::newRow( "Data11_0") << QTime(0,0,2,0) << -2000 << QTime(0,0,0,0);
201 QTest::newRow( "Data11_1") << QTime(0,0,0,200) << -200 << QTime(0,0,0,0);
202 QTest::newRow( "Data11_2") << QTime(0,0,0,20) << -20 << QTime(0,0,0,0);
203 QTest::newRow( "Data11_3") << QTime(0,0,0,2) << -1 << QTime(0,0,0,1);
204 QTest::newRow( "Data11_4") << QTime(0,0,0,0) << -0 << QTime(0,0,0,0);
205
206 QTest::newRow( "Data12_0") << QTime(0,0,0,98) << -0 << QTime(0,0,0,98);
207 QTest::newRow( "Data12_1") << QTime(0,0,0,99) << -1 << QTime(0,0,0,98);
208 QTest::newRow( "Data12_2") << QTime(0,0,0,100) << -2 << QTime(0,0,0,98);
209 QTest::newRow( "Data12_3") << QTime(0,0,0,101) << -3 << QTime(0,0,0,98);
210
211 QTest::newRow( "Data13_0") << QTime(0,0,0,998) << -0 << QTime(0,0,0,998);
212 QTest::newRow( "Data13_1") << QTime(0,0,0,999) << -1 << QTime(0,0,0,998);
213 QTest::newRow( "Data13_2") << QTime(0,0,1,0) << -2 << QTime(0,0,0,998);
214 QTest::newRow( "Data13_3") << QTime(0,0,1,1) << -3 << QTime(0,0,0,998);
215
216 QTest::newRow( "Data14_0") << QTime(0,0,1,999) << -4 << QTime(0,0,1,995);
217 QTest::newRow( "Data14_1") << QTime(0,0,2,0) << -5 << QTime(0,0,1,995);
218 QTest::newRow( "Data14_2") << QTime(0,0,2,1) << -6 << QTime(0,0,1,995);
219 QTest::newRow( "Data14_3") << QTime(0,0,2,95) << -100 << QTime(0,0,1,995);
220 QTest::newRow( "Data14_4") << QTime(0,0,2,100) << -105 << QTime(0,0,1,995);
221
222 QTest::newRow( "Data15_0") << QTime(0,0,59,999) << -4 << QTime(0,0,59,995);
223 QTest::newRow( "Data15_1") << QTime(0,1,0,0) << -5 << QTime(0,0,59,995);
224 QTest::newRow( "Data15_2") << QTime(0,1,0,1) << -6 << QTime(0,0,59,995);
225 QTest::newRow( "Data15_3") << QTime(0,1,1,1) << -1006 << QTime(0,0,59,995);
226
227 QTest::newRow( "Data16_0") << QTime(0,59,59,999) << -4 << QTime(0,59,59,995);
228 QTest::newRow( "Data16_1") << QTime(1,0,0,0) << -5 << QTime(0,59,59,995);
229 QTest::newRow( "Data16_2") << QTime(1,0,0,1) << -6 << QTime(0,59,59,995);
230 QTest::newRow( "Data16_3") << QTime(1,0,0,101) << -106 << QTime(0,59,59,995);
231 QTest::newRow( "Data16_4") << QTime(1,0,0,999) << -1004 << QTime(0,59,59,995);
232 QTest::newRow( "Data16_5") << QTime(1,0,1,0) << -1005 << QTime(0,59,59,995);
233 QTest::newRow( "Data16_6") << QTime(1,1,1,1) << -61006 << QTime(0,59,59,995);
234
235 QTest::newRow( "Data17_0") << QTime(23,59,59,995) << -0 << QTime(23,59,59,995);
236 QTest::newRow( "Data17_1") << QTime(23,59,59,999) << -4 << QTime(23,59,59,995);
237 QTest::newRow( "Data17_2") << QTime(0,0,0,0) << -5 << QTime(23,59,59,995);
238 QTest::newRow( "Data17_3") << QTime(0,0,0,1) << -6 << QTime(23,59,59,995);
239 QTest::newRow( "Data17_4") << QTime(0,0,0,2) << -7 << QTime(23,59,59,995);
240 }
241
addMSecs()242 void tst_QTime::addMSecs()
243 {
244 QFETCH( QTime, t1 );
245 QFETCH( int, i );
246 QTime t2;
247 t2 = t1.addMSecs( i );
248 QFETCH( QTime, exp );
249 QCOMPARE( t2, exp );
250 }
251
isNull()252 void tst_QTime::isNull()
253 {
254 QTime t1;
255 QVERIFY( t1.isNull() );
256 QTime t2(0,0,0);
257 QVERIFY( !t2.isNull() );
258 QTime t3(0,0,1);
259 QVERIFY( !t3.isNull() );
260 QTime t4(0,0,0,1);
261 QVERIFY( !t4.isNull() );
262 QTime t5(23,59,59);
263 QVERIFY( !t5.isNull() );
264 }
265
isValid()266 void tst_QTime::isValid()
267 {
268 QTime t1;
269 QVERIFY( !t1.isValid() );
270 QTime t2(24,0,0,0);
271 QVERIFY( !t2.isValid() );
272 QTime t3(23,60,0,0);
273 QVERIFY( !t3.isValid() );
274 QTime t4(23,0,-1,0);
275 QVERIFY( !t4.isValid() );
276 QTime t5(23,0,60,0);
277 QVERIFY( !t5.isValid() );
278 QTime t6(23,0,0,1000);
279 QVERIFY( !t6.isValid() );
280 }
281
hour_data()282 void tst_QTime::hour_data()
283 {
284 QTest::addColumn<int>("hour");
285 QTest::addColumn<int>("minute");
286 QTest::addColumn<int>("sec");
287 QTest::addColumn<int>("msec");
288
289 QTest::newRow( "data0" ) << 0 << 0 << 0 << 0;
290 QTest::newRow( "data1" ) << 0 << 0 << 0 << 1;
291 QTest::newRow( "data2" ) << 1 << 2 << 3 << 4;
292 QTest::newRow( "data3" ) << 2 << 12 << 13 << 65;
293 QTest::newRow( "data4" ) << 23 << 59 << 59 << 999;
294 }
295
hour()296 void tst_QTime::hour()
297 {
298 QFETCH( int, hour );
299 QFETCH( int, minute );
300 QFETCH( int, sec );
301 QFETCH( int, msec );
302
303 QTime t1( hour, minute, sec, msec );
304 QCOMPARE( t1.hour(), hour );
305 QCOMPARE( t1.minute(), minute );
306 QCOMPARE( t1.second(), sec );
307 QCOMPARE( t1.msec(), msec );
308 }
309
minute()310 void tst_QTime::minute()
311 {
312 DEPENDS_ON( "hour" );
313 }
314
second()315 void tst_QTime::second()
316 {
317 DEPENDS_ON( "hour" );
318 }
319
msec()320 void tst_QTime::msec()
321 {
322 DEPENDS_ON( "hour" );
323 }
324
setHMS_data()325 void tst_QTime::setHMS_data()
326 {
327 QTest::addColumn<int>("hour");
328 QTest::addColumn<int>("minute");
329 QTest::addColumn<int>("sec");
330
331 QTest::newRow( "data0" ) << 0 << 0 << 0;
332 QTest::newRow( "data1" ) << 1 << 2 << 3;
333 QTest::newRow( "data2" ) << 0 << 59 << 0;
334 QTest::newRow( "data3" ) << 0 << 59 << 59;
335 QTest::newRow( "data4" ) << 23 << 0 << 0;
336 QTest::newRow( "data5" ) << 23 << 59 << 0;
337 QTest::newRow( "data6" ) << 23 << 59 << 59;
338 }
339
setHMS()340 void tst_QTime::setHMS()
341 {
342 QFETCH( int, hour );
343 QFETCH( int, minute );
344 QFETCH( int, sec );
345
346 QTime t(3,4,5);
347 t.setHMS( hour, minute, sec );
348 QCOMPARE( t.hour(), hour );
349 QCOMPARE( t.minute(), minute );
350 QCOMPARE( t.second(), sec );
351 }
352
secsTo_data()353 void tst_QTime::secsTo_data()
354 {
355 QTest::addColumn<QTime>("t1");
356 QTest::addColumn<QTime>("t2");
357 QTest::addColumn<int>("delta");
358
359 QTest::newRow( "data0" ) << QTime(0,0,0) << QTime(0,0,59) << 59;
360 QTest::newRow( "data1" ) << QTime(0,0,0) << QTime(0,1,0) << 60;
361 QTest::newRow( "data2" ) << QTime(0,0,0) << QTime(0,10,0) << 600;
362 QTest::newRow( "data3" ) << QTime(0,0,0) << QTime(23,59,59) << 86399;
363 }
364
secsTo()365 void tst_QTime::secsTo()
366 {
367 QFETCH( QTime, t1 );
368 QFETCH( QTime, t2 );
369 QFETCH( int, delta );
370
371 QCOMPARE( t1.secsTo( t2 ), delta );
372 }
373
msecsTo_data()374 void tst_QTime::msecsTo_data()
375 {
376 QTest::addColumn<QTime>("t1");
377 QTest::addColumn<QTime>("t2");
378 QTest::addColumn<int>("delta");
379
380 QTest::newRow( "data0" ) << QTime(0,0,0,0) << QTime(0,0,0,0) << 0;
381 QTest::newRow( "data1" ) << QTime(0,0,0,0) << QTime(0,0,1,0) << 1000;
382 QTest::newRow( "data2" ) << QTime(0,0,0,0) << QTime(0,0,10,0) << 10000;
383 QTest::newRow( "data3" ) << QTime(0,0,0,0) << QTime(23,59,59,0) << 86399000;
384 }
385
msecsTo()386 void tst_QTime::msecsTo()
387 {
388 QFETCH( QTime, t1 );
389 QFETCH( QTime, t2 );
390 QFETCH( int, delta );
391
392 QCOMPARE( t1.msecsTo( t2 ), delta );
393 }
394
operator_eq_eq()395 void tst_QTime::operator_eq_eq()
396 {
397 QTime t1(0,0,0,0);
398 QTime t2(0,0,0,0);
399 QVERIFY( t1 == t2 );
400
401 t1 = QTime(12,34,56,20);
402 t2 = QTime(12,34,56,20);
403 QVERIFY( t1 == t2 );
404
405 t1 = QTime(01,34,56,20);
406 t2 = QTime(13,34,56,20);
407 QVERIFY( !(t1 == t2) );
408 }
409
operator_not_eq()410 void tst_QTime::operator_not_eq()
411 {
412 QTime t1(0,0,0,0);
413 QTime t2(0,0,0,0);
414 QVERIFY( !(t1 != t2) );
415
416 t1 = QTime(12,34,56,20);
417 t2 = QTime(12,34,56,20);
418 QVERIFY( !(t1 != t2) );
419
420 t1 = QTime(01,34,56,20);
421 t2 = QTime(13,34,56,20);
422 QVERIFY( t1 != t2 );
423 }
424
operator_lt()425 void tst_QTime::operator_lt()
426 {
427 QTime t1(0,0,0,0);
428 QTime t2(0,0,0,0);
429 QVERIFY( !(t1 < t2) );
430
431 t1 = QTime(12,34,56,20);
432 t2 = QTime(12,34,56,30);
433 QVERIFY( t1 < t2 );
434
435 t1 = QTime(13,34,46,20);
436 t2 = QTime(13,34,56,20);
437 QVERIFY( t1 < t2 );
438
439 t1 = QTime(13,24,56,20);
440 t2 = QTime(13,34,56,20);
441 QVERIFY( t1 < t2 );
442
443 t1 = QTime(12,34,56,20);
444 t2 = QTime(13,34,56,20);
445 QVERIFY( t1 < t2 );
446
447 t1 = QTime(14,34,56,20);
448 t2 = QTime(13,34,56,20);
449 QVERIFY( !(t1 < t2) );
450
451 t1 = QTime(13,44,56,20);
452 t2 = QTime(13,34,56,20);
453 QVERIFY( !(t1 < t2) );
454
455 t1 = QTime(13,34,56,20);
456 t2 = QTime(13,34,46,20);
457 QVERIFY( !(t1 < t2) );
458
459 t1 = QTime(13,44,56,30);
460 t2 = QTime(13,44,56,20);
461 QVERIFY( !(t1 < t2) );
462 }
463
operator_gt()464 void tst_QTime::operator_gt()
465 {
466 QTime t1(0,0,0,0);
467 QTime t2(0,0,0,0);
468 QVERIFY( !(t1 > t2) );
469
470 t1 = QTime(12,34,56,20);
471 t2 = QTime(12,34,56,30);
472 QVERIFY( !(t1 > t2) );
473
474 t1 = QTime(13,34,46,20);
475 t2 = QTime(13,34,56,20);
476 QVERIFY( !(t1 > t2) );
477
478 t1 = QTime(13,24,56,20);
479 t2 = QTime(13,34,56,20);
480 QVERIFY( !(t1 > t2) );
481
482 t1 = QTime(12,34,56,20);
483 t2 = QTime(13,34,56,20);
484 QVERIFY( !(t1 > t2) );
485
486 t1 = QTime(14,34,56,20);
487 t2 = QTime(13,34,56,20);
488 QVERIFY( t1 > t2 );
489
490 t1 = QTime(13,44,56,20);
491 t2 = QTime(13,34,56,20);
492 QVERIFY( t1 > t2 );
493
494 t1 = QTime(13,34,56,20);
495 t2 = QTime(13,34,46,20);
496 QVERIFY( t1 > t2 );
497
498 t1 = QTime(13,44,56,30);
499 t2 = QTime(13,44,56,20);
500 QVERIFY( t1 > t2 );
501 }
502
operator_lt_eq()503 void tst_QTime::operator_lt_eq()
504 {
505 QTime t1(0,0,0,0);
506 QTime t2(0,0,0,0);
507 QVERIFY( t1 <= t2 );
508
509 t1 = QTime(12,34,56,20);
510 t2 = QTime(12,34,56,30);
511 QVERIFY( t1 <= t2 );
512
513 t1 = QTime(13,34,46,20);
514 t2 = QTime(13,34,56,20);
515 QVERIFY( t1 <= t2 );
516
517 t1 = QTime(13,24,56,20);
518 t2 = QTime(13,34,56,20);
519 QVERIFY( t1 <= t2 );
520
521 t1 = QTime(12,34,56,20);
522 t2 = QTime(13,34,56,20);
523 QVERIFY( t1 <= t2 );
524
525 t1 = QTime(14,34,56,20);
526 t2 = QTime(13,34,56,20);
527 QVERIFY( !(t1 <= t2) );
528
529 t1 = QTime(13,44,56,20);
530 t2 = QTime(13,34,56,20);
531 QVERIFY( !(t1 <= t2) );
532
533 t1 = QTime(13,34,56,20);
534 t2 = QTime(13,34,46,20);
535 QVERIFY( !(t1 <= t2) );
536
537 t1 = QTime(13,44,56,30);
538 t2 = QTime(13,44,56,20);
539 QVERIFY( !(t1 <= t2) );
540 }
541
operator_gt_eq()542 void tst_QTime::operator_gt_eq()
543 {
544 QTime t1(0,0,0,0);
545 QTime t2(0,0,0,0);
546 QVERIFY( t1 >= t2 );
547
548 t1 = QTime(12,34,56,20);
549 t2 = QTime(12,34,56,30);
550 QVERIFY( !(t1 >= t2) );
551
552 t1 = QTime(13,34,46,20);
553 t2 = QTime(13,34,56,20);
554 QVERIFY( !(t1 >= t2) );
555
556 t1 = QTime(13,24,56,20);
557 t2 = QTime(13,34,56,20);
558 QVERIFY( !(t1 >= t2) );
559
560 t1 = QTime(12,34,56,20);
561 t2 = QTime(13,34,56,20);
562 QVERIFY( !(t1 >= t2) );
563
564 t1 = QTime(14,34,56,20);
565 t2 = QTime(13,34,56,20);
566 QVERIFY( t1 >= t2 );
567
568 t1 = QTime(13,44,56,20);
569 t2 = QTime(13,34,56,20);
570 QVERIFY( t1 >= t2 );
571
572 t1 = QTime(13,34,56,20);
573 t2 = QTime(13,34,46,20);
574 QVERIFY( t1 >= t2 );
575
576 t1 = QTime(13,44,56,30);
577 t2 = QTime(13,44,56,20);
578 QVERIFY( t1 >= t2 );
579 }
580
fromString_data()581 void tst_QTime::fromString_data()
582 {
583 // Since we can't define an element of Qt::DateFormat, t1 will be the time
584 // expected when we have a TextDate, and t2 will be the time expected when
585 // we have an ISODate.
586
587 QTest::addColumn<QString>("str");
588 QTest::addColumn<QTime>("t1");
589 QTest::addColumn<QTime>("t2");
590
591 QTest::newRow( "data0" ) << QString("00:00:00") << QTime(0,0,0,0) << QTime(0,0,0,0);
592 QTest::newRow( "data1" ) << QString("10:12:34") << QTime(10,12,34,0) << QTime(10,12,34,0);
593 QTest::newRow( "data2" ) << QString("19:03:54.998601") << QTime(19, 3, 54, 999) << QTime(19, 3, 54, 999);
594 QTest::newRow( "data3" ) << QString("19:03:54.999601") << QTime(19, 3, 54, 999) << QTime(19, 3, 54, 999);
595 }
596
fromString()597 void tst_QTime::fromString()
598 {
599 QFETCH( QString, str );
600 QFETCH( QTime, t1 );
601 QFETCH( QTime, t2 );
602
603 QCOMPARE( t1, QTime::fromString( str, Qt::TextDate ) );
604 QCOMPARE( t2, QTime::fromString( str, Qt::ISODate ) );
605 }
606
607
fromStringFormat_data()608 void tst_QTime::fromStringFormat_data()
609 {
610 QTest::addColumn<QString>("str");
611 QTest::addColumn<QString>("format");
612 QTest::addColumn<QTime>("t");
613
614 QTest::newRow( "data0" ) << QString("02:23PM") << QString("hh:mmAP") << QTime(14,23,0,0);
615 QTest::newRow( "data1" ) << QString("02:23pm") << QString("hh:mmap") << QTime(14,23,0,0);
616 }
617
fromStringFormat()618 void tst_QTime::fromStringFormat()
619 {
620 QFETCH(QString, str);
621 QFETCH(QString, format);
622 QFETCH(QTime, t);
623
624 QCOMPARE(t, QTime::fromString( str, format));
625
626 }
627
toString_data()628 void tst_QTime::toString_data()
629 {
630 // Since we can't define an element of Qt::DateFormat, str1 will be the string
631 // in TextDate format, and str2 will be the time in ISODate format.
632
633 QTest::addColumn<QTime>("t");
634 QTest::addColumn<QString>("str1");
635 QTest::addColumn<QString>("str2");
636
637 QTest::newRow( "data0" ) << QTime(0,0,0,0) << QString("00:00:00") << QString("00:00:00");
638 QTest::newRow( "data1" ) << QTime(10,12,34,0) << QString("10:12:34") << QString("10:12:34");
639 }
640
toString()641 void tst_QTime::toString()
642 {
643 QFETCH( QTime, t );
644 QFETCH( QString, str1 );
645 QFETCH( QString, str2 );
646
647 QCOMPARE( str1, t.toString( Qt::TextDate ) );
648 QCOMPARE( str2, t.toString( Qt::ISODate ) );
649 }
650
toString_format_data()651 void tst_QTime::toString_format_data()
652 {
653 QTest::addColumn<QTime>("t");
654 QTest::addColumn<QString>("format");
655 QTest::addColumn<QString>("str");
656
657 QTest::newRow( "data0" ) << QTime(0,0,0,0) << QString("h:m:s:z") << QString("0:0:0:0");
658 QTest::newRow( "data1" ) << QTime(10,12,34,53) << QString("hh:mm:ss:zzz") << QString("10:12:34:053");
659 QTest::newRow( "data2" ) << QTime(10,12,34,45) << QString("hh:m:ss:z") << QString("10:12:34:45");
660 QTest::newRow( "data3" ) << QTime(10,12,34,45) << QString("hh:ss ap") << QString("10:34 am");
661 QTest::newRow( "data4" ) << QTime(22,12,34,45) << QString("hh:zzz AP") << QString("10:045 PM");
662 QTest::newRow( "data5" ) << QTime(230,230,230,230) << QString("hh:mm:ss") << QString();
663 }
664
toString_format()665 void tst_QTime::toString_format()
666 {
667 QFETCH( QTime, t );
668 QFETCH( QString, format );
669 QFETCH( QString, str );
670
671 QCOMPARE( t.toString( format ), str );
672 }
673
toStringLocale()674 void tst_QTime::toStringLocale()
675 {
676 QTime time(18, 30);
677 QCOMPARE(time.toString(Qt::SystemLocaleDate),
678 QLocale::system().toString(time, QLocale::ShortFormat));
679 QCOMPARE(time.toString(Qt::LocaleDate),
680 QLocale().toString(time, QLocale::ShortFormat));
681 QLocale::setDefault(QLocale::German);
682 QCOMPARE(time.toString(Qt::SystemLocaleDate),
683 QLocale::system().toString(time, QLocale::ShortFormat));
684 QCOMPARE(time.toString(Qt::LocaleDate),
685 QLocale().toString(time, QLocale::ShortFormat));
686 }
687
688 QTEST_APPLESS_MAIN(tst_QTime)
689 #include "tst_qtime.moc"
690