1
/****************************************************************************
3
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
** All rights reserved.
5
** Contact: Nokia Corporation (qt-info@nokia.com)
7
** This file is part of the Qt Mobility Components.
9
** $QT_BEGIN_LICENSE:LGPL$
11
** Licensees holding valid Qt Commercial licenses may use this file in
12
** accordance with the Qt Solutions Commercial License Agreement provided
13
** with the Software or, alternatively, in accordance with the terms
14
** contained in a written agreement between you and Nokia.
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.
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.
28
** GNU General Public License Usage
29
** Alternatively, this file may be used under the terms of the GNU
30
** General Public License version 3.0 as published by the Free Software
31
** Foundation and appearing in the file LICENSE.GPL included in the
32
** packaging of this file. Please review the following information to
33
** ensure the GNU General Public License version 3.0 requirements will be
34
** met: http://www.gnu.org/copyleft/gpl.html.
36
** Please note Third Party Software included with Qt Solutions may impose
37
** additional restrictions and it is the user's responsibility to ensure
38
** that they have met the licensing requirements of the GPL, LGPL, or Qt
39
** Solutions Commercial license and the relevant license of the Third
40
** Party Software they are using.
42
** If you are unsure which license is appropriate for your use, please
43
** contact the sales department at qt-sales@nokia.com.
46
****************************************************************************/
49
#include <qmobilityglobal.h>
50
#include <qnamespace.h>
51
#include <qtorganizer.h>
52
#include <QtTest/QtTest>
58
const QString managerNameSymbian("symbian");
59
const int KNumberOfEntries = 5;
60
const int KNumberOfOccurrences = 5;
62
// We need to be able to pass QOrganizerItem as parameter from
63
// test data functions
64
Q_DECLARE_METATYPE(QOrganizerItem)
66
class TestFetchItemInstances : public QObject
72
void cleanupTestCase();
75
void saveItems(); // Start the test case by saving items into Agenda DB
76
void fetchItemInstances(); // Start the test case for fetching item instances
80
void fetchRequestStateChanged(
81
QOrganizerItemAbstractRequest::State currentState);
82
void fetchRequestResultsAvailable();
83
void saveRequestStateChanged(
84
QOrganizerItemAbstractRequest::State currentState);
85
void saveRequestResultsAvailable();
89
QList<QOrganizerItem> createItems(int noOfItems);
90
//void fetchItemInstances();
92
QOrganizerItemManager* m_om;
93
QOrganizerItemInstanceFetchRequest* m_fetchItemInstanceRequest;
94
QOrganizerItemSaveRequest* m_saveItemRequest;
97
void TestFetchItemInstances::initTestCase()
99
// Create a new item manager instance
100
m_om = new QOrganizerItemManager(managerNameSymbian);
101
// Cleanup by deleting all items
102
m_om->removeItems(m_om->itemIds(), 0);
104
// Create an item save request before fetching an item
105
// Create asynchronous request to save an item
106
m_saveItemRequest = new QOrganizerItemSaveRequest(this);
107
// Connect for the state change signal
108
connect(m_saveItemRequest,
109
SIGNAL(stateChanged(QOrganizerItemAbstractRequest::State)), this,
110
SLOT(saveRequestStateChanged(QOrganizerItemAbstractRequest::State)));
111
connect(m_saveItemRequest, SIGNAL(resultsAvailable()),
112
this, SLOT(saveRequestResultsAvailable()));
114
// Create an item fetch request
115
m_fetchItemInstanceRequest = new QOrganizerItemInstanceFetchRequest(this);
116
// Connect for the state change signal
117
connect(m_fetchItemInstanceRequest,
118
SIGNAL(stateChanged(QOrganizerItemAbstractRequest::State)),
120
SLOT(fetchRequestStateChanged(QOrganizerItemAbstractRequest::State)));
121
connect(m_fetchItemInstanceRequest, SIGNAL(resultsAvailable()),
122
this, SLOT(fetchRequestResultsAvailable()));
125
void TestFetchItemInstances::cleanupTestCase()
133
void TestFetchItemInstances::saveItems()
135
// Set items to be saved
136
m_saveItemRequest->setItems(createItems(KNumberOfEntries));
138
m_saveItemRequest->setManager(m_om);
139
// Start save request
140
m_saveItemRequest->start();
141
// Wait for the request to be completed
142
m_saveItemRequest->waitForFinished(1000);
145
// Returns a list of noOfItems
146
QList<QOrganizerItem> TestFetchItemInstances::createItems(int noOfItems)
148
QList<QOrganizerItem> itemsList;
150
for (int index(0); index < noOfItems; index++) {
151
// Create a new organizer item
152
QOrganizerItem organizerItem;
153
// Set the organizer item type
154
organizerItem.setType(QOrganizerItemType::TypeEvent);
155
// Create description string
156
QString description("myDescription");
157
// Set organizer item description
158
organizerItem.setDescription(description);
159
// Create desplay label
160
QString desplaylabel("myDescription");
162
organizerItem.setDisplayLabel(desplaylabel);
165
QOrganizerEventTimeRange timeRange;
167
startTime.currentDateTime();
168
timeRange.setStartDateTime(startTime.currentDateTime());
170
QVERIFY(organizerItem.saveDetail(&timeRange));
172
QOrganizerItemRecurrenceRule rrule;
173
rrule.setFrequency(QOrganizerItemRecurrenceRule::Daily);
174
rrule.setCount(KNumberOfOccurrences);
176
// Add recurrence rules to the item
177
QList<QOrganizerItemRecurrenceRule> rrules;
178
rrules.append(rrule);
179
QOrganizerItemRecurrence recurrence;
180
recurrence.setRecurrenceRules(rrules);
181
QVERIFY(organizerItem.saveDetail(&recurrence));
183
itemsList.append(organizerItem);
189
// request status changed for save request
190
void TestFetchItemInstances::saveRequestStateChanged(
191
QOrganizerItemAbstractRequest::State currentState)
193
switch(currentState) {
194
case QOrganizerItemAbstractRequest::InactiveState: {
195
// Operation not yet started start the operation
199
case QOrganizerItemAbstractRequest::ActiveState: {
200
// Operation started, not yet finished operation already started
203
case QOrganizerItemAbstractRequest::CanceledState: {
204
// Operation is finished due to cancellation test not completed,
208
case QOrganizerItemAbstractRequest::FinishedState: {
209
// Operation either completed successfully or failed.
210
// No further results will be available.
211
// test completed, compare the results when results available
220
// Save request completed/results available
221
void TestFetchItemInstances::saveRequestResultsAvailable()
223
QList<QOrganizerItem> items = m_saveItemRequest->items();
224
// Compate the number of items saved
225
QCOMPARE(KNumberOfEntries, items.count());
228
void TestFetchItemInstances::fetchItemInstances()
230
QOrganizerItemLocalIdFilter localIdFilter;
231
QList<QOrganizerItemLocalId> lUids;
234
localIdFilter.setIds(lUids);
235
//m_fetchItemInstanceRequest->setFilter(localIdFilter);
236
// Set ItemDetailsFilter
237
QOrganizerItemDetailFilter detailsFilter;
238
detailsFilter.setDetailDefinitionName(
239
QOrganizerItemDisplayLabel::DefinitionName,
240
QOrganizerItemDisplayLabel::FieldLabel);
241
detailsFilter.setValue("myDescription");
242
detailsFilter.setMatchFlags(QOrganizerItemFilter::MatchContains);
243
m_fetchItemInstanceRequest->setFilter(detailsFilter);
246
QList<QOrganizerItemSortOrder> sortOrderlist;
247
QOrganizerItemSortOrder sorting;
248
sorting.setDetailDefinitionName(
249
QOrganizerItemDisplayLabel::DefinitionName,
250
QOrganizerItemDisplayLabel::FieldLabel);
251
sorting.setBlankPolicy(QOrganizerItemSortOrder::BlanksLast);
252
//sorting.setDirection(SortOrder::AscendingOrder);
253
//sorting.setCaseSensitivity(CaseSensitivity::CaseInsensitive);
254
sortOrderlist.append(sorting);
255
m_fetchItemInstanceRequest->setSorting(sortOrderlist);
258
QOrganizerItemFetchHint fetchHint;
259
//fetchHint.setDetailDefinitionsHint();
260
fetchHint.setOptimizationHints(QOrganizerItemFetchHint::AllRequired);
261
m_fetchItemInstanceRequest->setFetchHint(fetchHint);
264
m_fetchItemInstanceRequest->setManager(m_om);
266
m_fetchItemInstanceRequest->start();
267
// Wait for request to complete
268
m_fetchItemInstanceRequest->waitForFinished(500);
271
// Fetch request state changed
272
void TestFetchItemInstances::fetchRequestStateChanged(
273
QOrganizerItemAbstractRequest::State currentState)
275
switch(currentState) {
276
case QOrganizerItemAbstractRequest::InactiveState: {
277
// Operation not yet started start the operation
278
fetchItemInstances();
281
case QOrganizerItemAbstractRequest::ActiveState: {
282
// Operation started, not yet finished operation already started
285
case QOrganizerItemAbstractRequest::CanceledState: {
286
// Operation is finished due to cancellation test not completed,
290
case QOrganizerItemAbstractRequest::FinishedState: {
291
// Operation either completed successfully or failed.
292
// No further results will be available.
293
// test completed, compate the results while available
301
// Fetch request available compare results
302
void TestFetchItemInstances::fetchRequestResultsAvailable()
304
QList<QOrganizerItem> items = m_fetchItemInstanceRequest->items();
305
int count(items.count());
306
QCOMPARE(KNumberOfEntries*KNumberOfOccurrences, items.count());
309
QTEST_MAIN(TestFetchItemInstances);
311
#include "tst_symbianasynchfetchiteminstance.moc"