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#include <QtCore/QDateTime>
36#include <QtOrganizer/qorganizer.h>
37#include "../qorganizermanagerdataholder.h"
38
39QTORGANIZER_USE_NAMESPACE
40
41class tst_QOrganizerManagerDetails : public QObject
42{
43Q_OBJECT
44
45private:
46 void addManagers();
47
48 bool saveAndLoadItem(QOrganizerManager *manager, QOrganizerItem &original, QOrganizerItem &loaded);
49 void saveAndVerifyItem(QOrganizerManager *manager, QOrganizerItem &original);
50
51 QScopedPointer<QOrganizerManagerDataHolder> managerDataHolder;
52
53private slots:
54 void initTestCase();
55 void cleanupTestCase();
56
57 void testRecurrenceRule();
58 void testRecurrenceRule_data() {addManagers();}
59
60private slots:
61
62};
63
64void tst_QOrganizerManagerDetails::addManagers()
65{
66 QTest::addColumn<QString>(name: "uri");
67
68 QStringList managers = QOrganizerManager::availableManagers();
69
70 /* Known one that will not pass */
71 managers.removeAll(t: "invalid");
72 managers.removeAll(t: "skeleton");
73 managers.removeAll(t: "maliciousplugin");
74
75 foreach(QString mgr, managers) {
76 QMap<QString, QString> params;
77 QTest::newRow(dataTag: QString("mgr='%1'").arg(a: mgr).toLatin1().constData()) << QOrganizerManager::buildUri(managerName: mgr, params);
78 }
79}
80
81void tst_QOrganizerManagerDetails::initTestCase()
82{
83 managerDataHolder.reset(other: new QOrganizerManagerDataHolder());
84}
85
86void tst_QOrganizerManagerDetails::cleanupTestCase()
87{
88 managerDataHolder.reset(other: 0);
89}
90
91bool tst_QOrganizerManagerDetails::saveAndLoadItem(QOrganizerManager *manager, QOrganizerItem &original, QOrganizerItem &loaded)
92{
93 // Save item
94 if(manager->saveItem(item: &original) == false)
95 return false;
96
97 // Check the id
98 if(original.id().isNull())
99 return false;
100
101 // Load same item from database
102 loaded = manager->item(itemId: original.id());
103 if(manager->error())
104 return false;
105
106 // TODO: Ignore some details which are not relevant and will mess
107 // up direct comparison between two items.
108
109 return true;
110}
111
112void tst_QOrganizerManagerDetails::saveAndVerifyItem(QOrganizerManager *manager, QOrganizerItem &original)
113{
114 QOrganizerItem loaded;
115 QVERIFY(saveAndLoadItem(manager, original, loaded));
116 if (original != loaded) {
117 qDebug() << "expected: " << original;
118 qDebug() << "loaded: " << loaded;
119 QCOMPARE(loaded.details().count(), original.details().count());
120 QCOMPARE(loaded, original);
121 }
122}
123
124void tst_QOrganizerManagerDetails::testRecurrenceRule()
125{
126 QFETCH(QString, uri);
127 QScopedPointer<QOrganizerManager> manager(QOrganizerManager::fromUri(uri));
128
129 QOrganizerEvent event;
130 event.setDisplayLabel("recurring event");
131 event.setStartDateTime(QDateTime(QDate(2010, 1, 2), QTime(3, 4, 5)));
132 event.setEndDateTime(QDateTime(QDate(2010, 1, 2), QTime(4, 4, 5)));
133 QOrganizerRecurrenceRule rrule;
134 rrule.setFrequency(QOrganizerRecurrenceRule::Daily);
135 rrule.setLimit(QDate(2010, 1, 10));
136 event.setRecurrenceRule(rrule);
137
138 saveAndVerifyItem(manager: manager.data(), original&: event);
139
140}
141QTEST_MAIN(tst_QOrganizerManagerDetails)
142#include "tst_qorganizermanagerdetails.moc"
143

source code of qtpim/tests/auto/organizer/qorganizermanagerdetails/tst_qorganizermanagerdetails.cpp