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:LGPL21$
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** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34#include <QtTest/QtTest>
35
36#include <QtCore/qset.h>
37
38#include <QtOrganizer/qorganizer.h>
39
40//TESTED_COMPONENT=src/organizer
41
42QTORGANIZER_USE_NAMESPACE
43class tst_QOrganizerItemDetail : public QObject
44{
45Q_OBJECT
46
47public:
48 tst_QOrganizerItemDetail();
49 virtual ~tst_QOrganizerItemDetail();
50
51public slots:
52 void init();
53 void cleanup();
54
55private slots:
56 void classHierarchy();
57 void assignment();
58 void templates();
59 void values();
60 void hash();
61 void datastream();
62 void traits();
63 void keys();
64};
65
66tst_QOrganizerItemDetail::tst_QOrganizerItemDetail()
67{
68}
69
70tst_QOrganizerItemDetail::~tst_QOrganizerItemDetail()
71{
72}
73
74void tst_QOrganizerItemDetail::init()
75{
76}
77
78void tst_QOrganizerItemDetail::cleanup()
79{
80}
81
82/* Test class that doesn't do the right thing */
83class NonMacroCustomDetail : public QOrganizerItemDetail
84{
85public:
86 NonMacroCustomDetail() : QOrganizerItemDetail(QOrganizerItemDetail::TypeUndefined) {}
87 void doAssign(const QOrganizerItemDetail& other) {assign(other, expectedDetailType: QOrganizerItemDetail::TypeUndefined);}
88 NonMacroCustomDetail(const QOrganizerItemDetail& other)
89 : QOrganizerItemDetail(other, QOrganizerItemDetail::TypeUndefined) {}
90};
91
92class NonMacroCustomDetail2 : public QOrganizerItemDetail
93{
94public:
95 NonMacroCustomDetail2() : QOrganizerItemDetail(QOrganizerItemDetail::TypeUndefined) {}
96 void doAssign(const QOrganizerItemDetail& other) {assign(other, expectedDetailType: QOrganizerItemDetail::TypeUndefined);}
97 NonMacroCustomDetail2(const QOrganizerItemDetail& other)
98 : QOrganizerItemDetail(other, QOrganizerItemDetail::TypeUndefined) {}
99};
100
101void tst_QOrganizerItemDetail::classHierarchy()
102{
103 QOrganizerItemDetail f1;
104 QOrganizerItemDetail f2;
105
106 QVERIFY(f1.isEmpty());
107 QVERIFY(f2.isEmpty());
108
109 QOrganizerItemPriority p1;
110 p1.setPriority(QOrganizerItemPriority::VeryHighPriority);
111 QVERIFY(!p1.isEmpty());
112 QVERIFY(p1.type() == QOrganizerItemDetail::TypePriority);
113
114 QOrganizerItemComment m1;
115 m1.setComment("Bob");
116 QVERIFY(!m1.isEmpty());
117 QVERIFY(m1.type() == QOrganizerItemDetail::TypeComment);
118
119 QVERIFY(p1 != m1);
120 QVERIFY(f1 == f2);
121
122 f1 = p1; // f1 is a priority
123 QVERIFY(f1 == p1);
124
125 f1 = f1; // assign to itself
126 QVERIFY(f1 == f1);
127 QVERIFY(f1 == p1);
128 QVERIFY(f1 != f2);
129 QVERIFY(p1 != f2);
130
131 p1 = p1; // assign leaf class to itself
132 QVERIFY(p1 == p1);
133 QVERIFY(f1 == p1);
134 QVERIFY(p1 == f1);
135
136 f2 = f1; // f2 = f1 = priority
137 QVERIFY(f1 == f2);
138 QVERIFY(f2 == f1);
139 QVERIFY(f2 == p1);
140 QVERIFY(f1 == p1);
141
142 f1 = m1; // f1 = name, f2 = priority
143 QVERIFY(f1 == m1);
144 QVERIFY(f1 != f2);
145 QVERIFY(f2 == p1);
146
147 QOrganizerItemPriority p2(f2); // p2 = f2 = priority
148 QVERIFY(p1 == p2);
149 QVERIFY(p1 == f2);
150 QCOMPARE(p2.priority(), p1.priority());
151 QCOMPARE(p2.priority(), QOrganizerItemPriority::VeryHighPriority);
152
153 p2 = p1; // priority to priority
154 QVERIFY(p1 == p2);
155 QVERIFY(p1 == f2);
156 QCOMPARE(p2.priority(), p1.priority());
157 QCOMPARE(p2.priority(), QOrganizerItemPriority::VeryHighPriority);
158
159 p2.setPriority(QOrganizerItemPriority::VeryLowPriority); // NOTE: implicitly shared, this has caused a detach so p1 != 2
160 QVERIFY(p1 != p2);
161 QVERIFY(p1 == f2);
162 QVERIFY(p2 != f2);
163 QCOMPARE(p2.priority(), QOrganizerItemPriority::VeryLowPriority);
164 QCOMPARE(p1.priority(), QOrganizerItemPriority::VeryHighPriority);
165
166 /* Bad assignment */
167 p2 = m1; // assign a comment to a priority
168 QVERIFY(p2 != m1);
169 QVERIFY(p2.type() == QOrganizerItemDetail::TypePriority);
170 QVERIFY(p2.isEmpty());
171
172 /* copy ctor */
173 QOrganizerItemComment m2(m1);
174 QVERIFY(m2 == m1);
175
176 /* another bad assignment */
177 m2 = p2; // priority to a comment
178 QVERIFY(m2 != m1);
179 QVERIFY(m2.type() == QOrganizerItemDetail::TypeComment);
180 QVERIFY(m2.isEmpty());
181
182 /* Copy ctor from valid type */
183 QOrganizerItemDetail f3(p2);
184 QVERIFY(f3 == p2);
185 QVERIFY(f3.type() == QOrganizerItemDetail::TypePriority);
186
187 /* Copy ctor from invalid type */
188 QOrganizerItemPriority p3(m1);
189 QVERIFY(p3 != m1);
190 QVERIFY(p3.type() == QOrganizerItemDetail::TypePriority);
191 QVERIFY(p3.isEmpty());
192
193 /* Copy ctore from invalid type, through base type */
194 f3 = m1;
195 QOrganizerItemPriority p4(f3);
196 QVERIFY(p4 != f3);
197 QVERIFY(p4.type() == QOrganizerItemDetail::TypePriority);
198 QVERIFY(p4.isEmpty());
199
200 /* Try a reference */
201 p1.setPriority(QOrganizerItemPriority::VeryLowPriority);
202 QOrganizerItemDetail& ref = p1;
203 QVERIFY(p1.priority() == QOrganizerItemPriority::VeryLowPriority);
204 QVERIFY(p1.value(QOrganizerItemPriority::FieldPriority).toInt() == static_cast<int>(QOrganizerItemPriority::VeryLowPriority));
205 QVERIFY(ref.value(QOrganizerItemPriority::FieldPriority).toInt() == static_cast<int>(QOrganizerItemPriority::VeryLowPriority));
206 QVERIFY(p1 == ref);
207 QVERIFY(ref == p1);
208
209 /* Try changing the original */
210 p1.setPriority(QOrganizerItemPriority::MediumPriority);
211 QVERIFY(p1.priority() == QOrganizerItemPriority::MediumPriority);
212 QVERIFY(p1.value(QOrganizerItemPriority::FieldPriority).toInt() == static_cast<int>(QOrganizerItemPriority::MediumPriority));
213 QVERIFY(ref.value(QOrganizerItemPriority::FieldPriority).toInt() == static_cast<int>(QOrganizerItemPriority::MediumPriority));
214 QVERIFY(p1 == ref);
215 QVERIFY(ref == p1);
216
217 /* Try changing the reference */
218 ref.setValue(field: QOrganizerItemPriority::FieldPriority, value: QOrganizerItemPriority::LowPriority);
219 QVERIFY(p1.priority() == QOrganizerItemPriority::LowPriority);
220 QVERIFY(p1.value(QOrganizerItemPriority::FieldPriority).toInt() == static_cast<int>(QOrganizerItemPriority::LowPriority));
221 QVERIFY(ref.value(QOrganizerItemPriority::FieldPriority).toInt() == static_cast<int>(QOrganizerItemPriority::LowPriority));
222 QVERIFY(p1 == ref);
223 QVERIFY(ref == p1);
224
225 /* Random other test */
226 NonMacroCustomDetail md;
227 QVERIFY(md.type() == QOrganizerItemDetail::TypeUndefined);
228 QVERIFY(md.setValue(1, "value"));
229 QVERIFY(!md.isEmpty());
230 md.doAssign(other: md); // self assignment
231 QVERIFY(!md.isEmpty());
232 QVERIFY(md.value(1) == "value");
233
234 QOrganizerItemDetail mdv;
235 mdv = md;
236 QVERIFY(mdv.type() == QOrganizerItemDetail::TypeUndefined);
237 QVERIFY(mdv.value(1) == "value");
238
239 md = mdv;
240 QVERIFY(md.type() == QOrganizerItemDetail::TypeUndefined);
241 QVERIFY(md.value(1) == "value");
242
243 NonMacroCustomDetail2 md2;
244 QVERIFY(md2.setValue(1, "value"));
245 QVERIFY(md2.type() == QOrganizerItemDetail::TypeUndefined);
246 QVERIFY(md2.value(1) == "value");
247 md2.doAssign(other: md);
248 QVERIFY(md2 == md);
249 md2 = md;
250 QVERIFY(md.type() == QOrganizerItemDetail::TypeUndefined);
251 QVERIFY(md.value(1) == "value");
252
253 // Self assignment
254 md2.doAssign(other: md2);
255 QVERIFY(md2.type() == QOrganizerItemDetail::TypeUndefined);
256 QVERIFY(md2.value(1) == "value");
257
258 md.doAssign(other: md2);
259 QVERIFY(md == md2);
260
261 // Assigning something else
262 QOrganizerItemPriority pn;
263 pn.setPriority(QOrganizerItemPriority::LowestPriority);
264 md2.doAssign(other: pn);
265 QVERIFY(md2.isEmpty());
266 QVERIFY(md2.type() == QOrganizerItemDetail::TypeUndefined);
267
268 NonMacroCustomDetail mdb(pn);
269 QVERIFY(mdb.isEmpty());
270 QVERIFY(mdb.type() == QOrganizerItemDetail::TypeUndefined);
271
272 NonMacroCustomDetail2 md2b(pn);
273 QVERIFY(md2b.isEmpty());
274 QVERIFY(md2b.type() == QOrganizerItemDetail::TypeUndefined);
275}
276
277void tst_QOrganizerItemDetail::assignment()
278{
279 QOrganizerItemPriority p1, p2;
280 p1.setPriority(QOrganizerItemPriority::LowPriority);
281 p2.setPriority(QOrganizerItemPriority::HighPriority);
282 QVERIFY(p1 != p2);
283
284 p1 = p2;
285 QVERIFY(p1 == p2);
286
287 QOrganizerItemComment c1;
288 c1.setComment("test comment");
289 QVERIFY(c1 != p1);
290 c1 = p1;
291 QVERIFY(c1 != p1); // assignment across types shouldn't work
292 QVERIFY(c1.comment() == QString()); // should reset the detail
293 QCOMPARE(c1, QOrganizerItemComment());
294}
295
296void tst_QOrganizerItemDetail::templates()
297{
298 QOrganizerItem c;
299 QOrganizerItemPriority p1, p2;
300 p1.setPriority(QOrganizerItemPriority::HighPriority);
301 p2.setPriority(QOrganizerItemPriority::HighestPriority);
302 QVERIFY(c.saveDetail(&p1));
303 QVERIFY(c.saveDetail(&p2));
304
305 QList<QOrganizerItemDetail> l = c.details(detailType: QOrganizerItemDetail::TypePriority);
306
307 QCOMPARE(l.count(), 2);
308 QCOMPARE(QOrganizerItemPriority(l.at(0)), p1);
309 QCOMPARE(QOrganizerItemPriority(l.at(1)), p2);
310
311 QList<QOrganizerItemDetail> l2 = c.details(detailType: QOrganizerItemDetail::TypePriority);
312 QCOMPARE(l2.count(), 2);
313 QCOMPARE(static_cast<QOrganizerItemPriority>(l2.at(0)), p1);
314 QCOMPARE(static_cast<QOrganizerItemPriority>(l2.at(1)), p2);
315}
316
317void tst_QOrganizerItemDetail::values()
318{
319 QOrganizerItemDetail p;
320
321 QCOMPARE(p.values(), (QMap<int, QVariant>()));
322
323 QDateTime dt = QDateTime::currentDateTime();
324 QTime t = dt.time();
325 t.setHMS(h: t.hour(), m: t.minute(), s: t.second(), ms: 0); // milliseconds don't round trip through ISODate
326 dt.setTime(t);
327 QDate d = dt.date();
328
329 QDateTime ddt(d); // DateTime version of a Date (QTime())
330
331 p.setValue(field: 101, value: "This is a string");
332 p.setValue(field: 102, value: d);
333 p.setValue(field: 103, value: dt);
334 p.setValue(field: 104, value: (int)6);
335
336 p.setValue(field: 105, value: d.toString(format: Qt::ISODate));
337 p.setValue(field: 106, value: dt.toString(format: Qt::ISODate));
338
339 // Test the setter that takes a QString
340 p.setValue(field: 107, value: "123");
341
342 // and the setter that takes a QL1C
343 p.setValue(field: QOrganizerItemPriority::FieldPriority, value: QVariant::fromValue(value: static_cast<int>(QOrganizerItemPriority::ExtremelyHighPriority)));
344
345 /* Presence test */
346 QVERIFY(p.hasValue(101));
347 QVERIFY(p.hasValue(102));
348 QVERIFY(p.hasValue(103));
349 QVERIFY(p.hasValue(104));
350 QVERIFY(p.hasValue(105));
351 QVERIFY(p.hasValue(106));
352 QVERIFY(p.hasValue(107));
353 QVERIFY(p.hasValue(QOrganizerItemPriority::FieldPriority));
354 QVERIFY(!p.hasValue(666));
355
356 QVERIFY(p.hasValue(QOrganizerItemPriority::FieldPriority));
357
358 /* Variant accessor */
359 QCOMPARE(p.value(101), QVariant(QString("This is a string")));
360 QCOMPARE(p.value(102), QVariant(d));
361 QCOMPARE(p.value(103), QVariant(dt));
362 QCOMPARE(p.value(104), QVariant((int)6));
363 QCOMPARE(p.value(105), QVariant(d.toString(Qt::ISODate)));
364 QCOMPARE(p.value(106), QVariant(dt.toString(Qt::ISODate)));
365 QCOMPARE(p.value(107), QVariant(QString("123")));
366 QCOMPARE(p.value(QOrganizerItemPriority::FieldPriority).toInt(), static_cast<int>(QOrganizerItemPriority::ExtremelyHighPriority));
367
368 /* Typed accessors */
369 QCOMPARE(p.value<QString>(101), QString("This is a string"));
370 QCOMPARE(p.value<QString>(102), d.toString(Qt::ISODate));
371 QCOMPARE(p.value<QString>(103), dt.toString(Qt::ISODate));
372 QCOMPARE(p.value<QString>(104), QString("6"));
373 QCOMPARE(p.value<QString>(105), d.toString(Qt::ISODate));
374 QCOMPARE(p.value<QString>(106), dt.toString(Qt::ISODate));
375 QCOMPARE(p.value<QString>(107), QString("123"));
376 QCOMPARE(p.value<int>(QOrganizerItemPriority::FieldPriority), static_cast<int>(QOrganizerItemPriority::ExtremelyHighPriority));
377
378 /* Now individual original types */
379 QCOMPARE(p.value<QDate>(102), d);
380 QCOMPARE(p.value<QDateTime>(103), dt);
381 QCOMPARE(p.value<int>(104), 6);
382
383 /* Now cross types that should fail */
384 QDate id;
385 QDateTime idt;
386 QCOMPARE(p.value<QDate>(101), id);
387 QCOMPARE(p.value<QDate>(104), id);
388 QCOMPARE(p.value<QDate>(107), id);
389 QCOMPARE(p.value<QDateTime>(101), idt);
390 QCOMPARE(p.value<QDateTime>(104), idt);
391 QCOMPARE(p.value<QDateTime>(107), idt);
392 QCOMPARE(p.value<int>(102), 0);
393 QCOMPARE(p.value<int>(103), 0);
394 QCOMPARE(p.value<int>(101), 0);
395 QCOMPARE(p.value<int>(105), 0);
396 QCOMPARE(p.value<int>(106), 0);
397
398 /* Cross types that should work.. */
399 QCOMPARE(p.value<int>(107), 123);
400 QCOMPARE(p.value<QDate>(105), d);
401 QCOMPARE(p.value<QDateTime>(106), dt);
402 QCOMPARE(p.value<QDate>(103), d);
403 QCOMPARE(p.value<QDate>(106), d);
404 QCOMPARE(p.value<QDateTime>(102), ddt);
405 QCOMPARE(p.value<QDateTime>(105), ddt);
406
407 /* Now set everything again */
408 QMap<int, QVariant> emptyValues;
409 QMap<int, QVariant> values = p.values();
410 QList<int> keys = values.keys();
411 foreach (int key, keys)
412 QVERIFY(p.setValue(key, QVariant()));
413
414 QCOMPARE(p.values(), emptyValues);
415 QVERIFY(p.values().count() == 0);
416 QVERIFY(!p.hasValue(101));
417 QVERIFY(!p.hasValue(102));
418 QVERIFY(!p.hasValue(103));
419 QVERIFY(!p.hasValue(104));
420 QVERIFY(!p.hasValue(105));
421 QVERIFY(!p.hasValue(106));
422 QVERIFY(!p.hasValue(107));
423 QVERIFY(!p.hasValue(666));
424
425 QVERIFY(p.value(101).toString() == QString());
426 QVERIFY(p.value(101) == QVariant());
427
428 values.insert(akey: 101, avalue: "This is a string");
429 values.insert(akey: 102, avalue: d);
430 values.insert(akey: 103, avalue: dt);
431 values.insert(akey: 104, avalue: (int)6);
432
433 values.insert(akey: 105, avalue: d.toString(format: Qt::ISODate));
434 values.insert(akey: 106, avalue: dt.toString(format: Qt::ISODate));
435 values.insert(akey: 107, avalue: "123");
436 values.insert(akey: 101, avalue: QString("This is a string"));
437
438 /* Set values */
439 keys = values.keys();
440 foreach (int key, keys)
441 QVERIFY(p.setValue(key, values.value(key)));
442
443 /* Now repeat the tests with our bulk set map */
444 QVERIFY(p.hasValue(101));
445 QVERIFY(p.hasValue(102));
446 QVERIFY(p.hasValue(103));
447 QVERIFY(p.hasValue(104));
448 QVERIFY(p.hasValue(105));
449 QVERIFY(p.hasValue(106));
450 QVERIFY(p.hasValue(107));
451 QVERIFY(!p.hasValue(666));
452
453 /* String accessors */
454 QCOMPARE(p.value(101).toString(), QString("This is a string"));
455 QCOMPARE(p.value(102).toString(), d.toString(Qt::ISODate));
456 QCOMPARE(p.value(103).toString(), dt.toString(Qt::ISODate));
457 QCOMPARE(p.value(104).toString(), QString("6"));
458 QCOMPARE(p.value(105).toString(), d.toString(Qt::ISODate));
459 QCOMPARE(p.value(106).toString(), dt.toString(Qt::ISODate));
460 QCOMPARE(p.value(107).toString(), QString("123"));
461
462 /* Typed accessors, string first */
463 QCOMPARE(p.value<QString>(101), QString("This is a string"));
464 QCOMPARE(p.value<QString>(102), d.toString(Qt::ISODate));
465 QCOMPARE(p.value<QString>(103), dt.toString(Qt::ISODate));
466 QCOMPARE(p.value<QString>(104), QString("6"));
467 QCOMPARE(p.value<QString>(105), d.toString(Qt::ISODate));
468 QCOMPARE(p.value<QString>(106), dt.toString(Qt::ISODate));
469 QCOMPARE(p.value<QString>(107), QString("123"));
470
471 /* Now individual original types */
472 QCOMPARE(p.value<QDate>(102), d);
473 QCOMPARE(p.value<QDateTime>(103), dt);
474 QCOMPARE(p.value<int>(104), 6);
475
476 /* Now cross types that should fail */
477 QCOMPARE(p.value<QDate>(101), id);
478 QCOMPARE(p.value<QDate>(104), id);
479 QCOMPARE(p.value<QDate>(107), id);
480 QCOMPARE(p.value<QDateTime>(101), idt);
481 QCOMPARE(p.value<QDateTime>(104), idt);
482 QCOMPARE(p.value<QDateTime>(107), idt);
483 QCOMPARE(p.value<int>(101), 0);
484 QCOMPARE(p.value<int>(102), 0);
485 QCOMPARE(p.value<int>(103), 0);
486 QCOMPARE(p.value<int>(105), 0);
487 QCOMPARE(p.value<int>(106), 0);
488
489 /* Cross types that should work.. */
490 QCOMPARE(p.value<int>(107), 123);
491 QCOMPARE(p.value<QDate>(105), d);
492 QCOMPARE(p.value<QDateTime>(106), dt);
493 QCOMPARE(p.value<QDate>(103), d);
494 QCOMPARE(p.value<QDate>(106), d);
495 QCOMPARE(p.value<QDateTime>(102), ddt);
496 QCOMPARE(p.value<QDateTime>(105), ddt);
497
498 /* Reset again */
499 values = p.values();
500 keys = values.keys();
501 foreach (int key, keys)
502 QVERIFY(p.setValue(key, QVariant()));
503 QCOMPARE(p.values(), emptyValues);
504
505 /* Check that we can add a null variant */
506 //QVERIFY(p.setValue("nullvariant", QVariant()));
507 //QVERIFY(p.hasValue("nullvariant"));
508 //QCOMPARE(p.value("nullvariant"), QString());
509 //QCOMPARE(p.value("nullvariant"), QVariant());
510 //QVERIFY(p.removeValue("nullvariant"));
511 //QVERIFY(p.values().count() == 0);
512
513 /* Check that adding a value, then setting it to null updates it */
514 //QVERIFY(p.setValue("string", QString("string value")));
515 //QCOMPARE(p.values().count(), 1);
516 //QCOMPARE(p.value("string"), QString("string value"));
517 //QVERIFY(p.setValue("string", QVariant()));
518 //QCOMPARE(p.values().count(), 1);
519 //QVERIFY(p.hasValue("string"));
520 //QVERIFY(p.removeValue("string"));
521 //QCOMPARE(p.values().count(), 0);
522
523 /* See if adding a null QString triggers the same behaviour */
524 //QVERIFY(p.setValue("string", QString("string value")));
525 //QCOMPARE(p.values().count(), 1);
526 //QCOMPARE(p.value("string"), QString("string value"));
527 //QVERIFY(p.setValue("string", QString()));
528 //QCOMPARE(p.values().count(), 1);
529 //QVERIFY(p.hasValue("string"));
530 //QVERIFY(p.removeValue("string"));
531 //QCOMPARE(p.values().count(), 0);
532
533 /* Check adding a null value removes the field */
534 p.setValue(field: 101, value: "stringvalue");
535 QVERIFY(p.values().contains(101));
536 QVERIFY(p.value(101) == QString("stringvalue"));
537 p.setValue(field: 101, value: QVariant());
538 QVERIFY(!p.values().contains(101));
539
540 /* Check adding a field whose value is an empty string */
541 p.setValue(field: 101, value: "");
542 QVERIFY(p.values().contains(101));
543 QVERIFY(p.value(101) == QString(""));
544
545 /* Check accessing a missing value */
546 QCOMPARE(p.value(666).toString(), QString());
547 QVERIFY(p.setValue(666, "changed my mind"));
548 QCOMPARE(p.value(666).toString(), QString("changed my mind"));
549
550 /* Check removing a missing value */
551 QVERIFY(!p.removeValue(777));
552 QVERIFY(!p.removeValue(QOrganizerItemComment::FieldComment));
553
554 p.setValue(field: 107, value: "555");
555 p.setValue(field: QOrganizerItemPriority::FieldPriority, value: "1234");
556
557 /* Check removing a real value */
558 QVERIFY(p.removeValue(101));
559 QVERIFY(p.removeValue(107));
560 QVERIFY(p.removeValue(QOrganizerItemPriority::FieldPriority));
561}
562
563void tst_QOrganizerItemDetail::hash()
564{
565 QOrganizerItemDetail detail1(QOrganizerItemDetail::TypeComment);
566 detail1.setValue(field: QOrganizerItemComment::FieldComment, value: "value");
567 QOrganizerItemDetail detail2(QOrganizerItemDetail::TypeComment);
568 detail2.setValue(field: QOrganizerItemComment::FieldComment, value: "value");
569 QOrganizerItemDetail detail3(QOrganizerItemDetail::TypeComment);
570 detail3.setValue(field: QOrganizerItemComment::FieldComment, value: "different value");
571 QVERIFY(qHash(detail1) == qHash(detail2));
572 QVERIFY(qHash(detail1) != qHash(detail3));
573 QSet<QOrganizerItemDetail> set;
574 set.insert(value: detail1);
575 set.insert(value: detail2);
576 set.insert(value: detail3);
577 QCOMPARE(set.size(), 2);
578}
579
580void tst_QOrganizerItemDetail::datastream()
581{
582 QByteArray buffer;
583 QDataStream stream1(&buffer, QIODevice::WriteOnly);
584 QOrganizerItemDetail detailIn(QOrganizerItemDetail::TypeComment);
585 detailIn.setValue(field: QOrganizerItemComment::FieldComment, value: "value1");
586 stream1 << detailIn;
587
588 QVERIFY(buffer.size() > 0);
589
590 QDataStream stream2(buffer);
591 QOrganizerItemDetail detailOut;
592 stream2 >> detailOut;
593 QCOMPARE(detailOut, detailIn);
594}
595
596void tst_QOrganizerItemDetail::traits()
597{
598 QCOMPARE(sizeof(QOrganizerItemDetail), sizeof(void *));
599 QTypeInfo<QOrganizerItemDetail> ti;
600 QVERIFY(ti.isComplex);
601 QVERIFY(!ti.isStatic);
602 QVERIFY(!ti.isLarge);
603 QVERIFY(!ti.isPointer);
604 QVERIFY(!ti.isDummy);
605}
606
607void tst_QOrganizerItemDetail::keys()
608{
609 QOrganizerItemDetail d;
610 QOrganizerItemDetail d2;
611 QVERIFY(d.key() != d2.key());
612
613 d = d2;
614 QVERIFY(d.key() == d2.key());
615 d.resetKey();
616 QVERIFY(d.key() != d2.key());
617}
618
619QTEST_MAIN(tst_QOrganizerItemDetail)
620#include "tst_qorganizeritemdetail.moc"
621

source code of qtpim/tests/auto/organizer/qorganizeritemdetail/tst_qorganizeritemdetail.cpp