~ubuntu-branches/ubuntu/quantal/qtmobility/quantal

« back to all changes in this revision

Viewing changes to plugins/organizer/symbian/tsrc/tst_symbianasynchapis/tst_symbianasynchfetchiteminstance/tst_symbianasynchfetchiteminstance.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2010-11-16 16:18:07 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20101116161807-k2dzt2nyse975r3l
Tags: 1.1.0-0ubuntu1
* New upstream release
* Syncronise with Debian, no remaining changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
**
3
 
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4
 
** All rights reserved.
5
 
** Contact: Nokia Corporation (qt-info@nokia.com)
6
 
**
7
 
** This file is part of the Qt Mobility Components.
8
 
**
9
 
** $QT_BEGIN_LICENSE:LGPL$
10
 
** Commercial Usage
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.
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
 
** 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.
35
 
**
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.
41
 
**
42
 
** If you are unsure which license is appropriate for your use, please
43
 
** contact the sales department at qt-sales@nokia.com.
44
 
** $QT_END_LICENSE$
45
 
**
46
 
****************************************************************************/
47
 
 
48
 
#include <QObject>
49
 
#include <qmobilityglobal.h>
50
 
#include <qnamespace.h>
51
 
#include <qtorganizer.h>
52
 
#include <QtTest/QtTest>
53
 
#include <QDebug>
54
 
 
55
 
QTM_USE_NAMESPACE
56
 
 
57
 
// Constants
58
 
const QString managerNameSymbian("symbian");
59
 
const int KNumberOfEntries = 5;
60
 
const int KNumberOfOccurrences = 5;
61
 
 
62
 
// We need to be able to pass QOrganizerItem as parameter from
63
 
// test data functions
64
 
Q_DECLARE_METATYPE(QOrganizerItem)
65
 
 
66
 
class TestFetchItemInstances : public QObject
67
 
{
68
 
   Q_OBJECT
69
 
   
70
 
private slots:
71
 
   void initTestCase();
72
 
   void cleanupTestCase();
73
 
   
74
 
private slots:
75
 
   void saveItems(); // Start the test case by saving items into Agenda DB
76
 
   void fetchItemInstances(); // Start the test case for fetching item instances
77
 
 
78
 
   
79
 
public slots:
80
 
   void fetchRequestStateChanged(
81
 
           QOrganizerItemAbstractRequest::State currentState);
82
 
   void fetchRequestResultsAvailable();
83
 
   void saveRequestStateChanged(
84
 
           QOrganizerItemAbstractRequest::State currentState);
85
 
   void saveRequestResultsAvailable();
86
 
 
87
 
   
88
 
private:
89
 
   QList<QOrganizerItem> createItems(int noOfItems);
90
 
   //void fetchItemInstances();
91
 
private:
92
 
    QOrganizerItemManager*              m_om;
93
 
    QOrganizerItemInstanceFetchRequest* m_fetchItemInstanceRequest;
94
 
    QOrganizerItemSaveRequest*          m_saveItemRequest;
95
 
};
96
 
 
97
 
void TestFetchItemInstances::initTestCase()
98
 
{
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);
103
 
    
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()));
113
 
 
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)), 
119
 
            this, 
120
 
            SLOT(fetchRequestStateChanged(QOrganizerItemAbstractRequest::State)));
121
 
    connect(m_fetchItemInstanceRequest, SIGNAL(resultsAvailable()), 
122
 
            this, SLOT(fetchRequestResultsAvailable()));
123
 
}
124
 
 
125
 
void TestFetchItemInstances::cleanupTestCase()
126
 
{
127
 
    if (m_om) {
128
 
        delete m_om;
129
 
        m_om = 0;
130
 
    }
131
 
}
132
 
 
133
 
void TestFetchItemInstances::saveItems()
134
 
{
135
 
    // Set items to be saved
136
 
    m_saveItemRequest->setItems(createItems(KNumberOfEntries));
137
 
    // Set item manager
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);
143
 
}
144
 
   
145
 
// Returns a list of noOfItems
146
 
QList<QOrganizerItem> TestFetchItemInstances::createItems(int noOfItems)
147
 
{
148
 
    QList<QOrganizerItem> itemsList;
149
 
    
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");
161
 
        // Set display label
162
 
        organizerItem.setDisplayLabel(desplaylabel);
163
 
        
164
 
        // Set current time
165
 
        QOrganizerEventTimeRange timeRange;
166
 
        QDateTime startTime;
167
 
        startTime.currentDateTime();
168
 
        timeRange.setStartDateTime(startTime.currentDateTime());
169
 
        
170
 
        QVERIFY(organizerItem.saveDetail(&timeRange));
171
 
        
172
 
        QOrganizerItemRecurrenceRule rrule;
173
 
        rrule.setFrequency(QOrganizerItemRecurrenceRule::Daily);
174
 
        rrule.setCount(KNumberOfOccurrences);
175
 
 
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));
182
 
 
183
 
        itemsList.append(organizerItem);
184
 
    }
185
 
    
186
 
    return itemsList;
187
 
}
188
 
 
189
 
// request status changed for save request
190
 
void TestFetchItemInstances::saveRequestStateChanged(
191
 
        QOrganizerItemAbstractRequest::State currentState)
192
 
{
193
 
    switch(currentState) {
194
 
        case QOrganizerItemAbstractRequest::InactiveState: { 
195
 
            // Operation not yet started start the operation
196
 
            saveItems();
197
 
            break;
198
 
        }
199
 
        case QOrganizerItemAbstractRequest::ActiveState: { 
200
 
            // Operation started, not yet finished operation already started
201
 
        break;
202
 
        }
203
 
        case QOrganizerItemAbstractRequest::CanceledState: { 
204
 
            // Operation is finished due to cancellation test not completed, 
205
 
            // failed
206
 
        break;
207
 
        }
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 
212
 
            break;
213
 
        }
214
 
        default: {
215
 
            // Not handled
216
 
        }
217
 
    }
218
 
}
219
 
 
220
 
// Save request completed/results available
221
 
void TestFetchItemInstances::saveRequestResultsAvailable()
222
 
{
223
 
    QList<QOrganizerItem> items = m_saveItemRequest->items();
224
 
    // Compate the number of items saved
225
 
    QCOMPARE(KNumberOfEntries, items.count());
226
 
}
227
 
 
228
 
void TestFetchItemInstances::fetchItemInstances()
229
 
{
230
 
    QOrganizerItemLocalIdFilter localIdFilter;
231
 
    QList<QOrganizerItemLocalId> lUids;
232
 
    lUids.append(3);
233
 
    lUids.append(4);
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);
244
 
 
245
 
    // Set sorting order
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);
256
 
 
257
 
    // Set fetch hint
258
 
    QOrganizerItemFetchHint fetchHint;
259
 
    //fetchHint.setDetailDefinitionsHint();
260
 
    fetchHint.setOptimizationHints(QOrganizerItemFetchHint::AllRequired);
261
 
    m_fetchItemInstanceRequest->setFetchHint(fetchHint);
262
 
    
263
 
    // Set manager
264
 
    m_fetchItemInstanceRequest->setManager(m_om);
265
 
    // Start the request
266
 
    m_fetchItemInstanceRequest->start();
267
 
    // Wait for request to complete
268
 
    m_fetchItemInstanceRequest->waitForFinished(500);
269
 
}
270
 
 
271
 
// Fetch request state changed
272
 
void TestFetchItemInstances::fetchRequestStateChanged(
273
 
        QOrganizerItemAbstractRequest::State currentState)
274
 
{
275
 
    switch(currentState) {
276
 
        case QOrganizerItemAbstractRequest::InactiveState: { 
277
 
            // Operation not yet started start the operation
278
 
            fetchItemInstances();
279
 
            break;
280
 
        }
281
 
        case QOrganizerItemAbstractRequest::ActiveState: { 
282
 
            // Operation started, not yet finished operation already started
283
 
        break;
284
 
        }
285
 
        case QOrganizerItemAbstractRequest::CanceledState: { 
286
 
            // Operation is finished due to cancellation test not completed, 
287
 
            // failed
288
 
        break;
289
 
        }
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
294
 
        }
295
 
        default: {
296
 
            // Not handled
297
 
        }
298
 
    }
299
 
}
300
 
 
301
 
// Fetch request available compare results
302
 
void TestFetchItemInstances::fetchRequestResultsAvailable()
303
 
{
304
 
    QList<QOrganizerItem> items = m_fetchItemInstanceRequest->items();
305
 
    int count(items.count());
306
 
    QCOMPARE(KNumberOfEntries*KNumberOfOccurrences, items.count());
307
 
}
308
 
 
309
 
QTEST_MAIN(TestFetchItemInstances);
310
 
 
311
 
#include "tst_symbianasynchfetchiteminstance.moc"