|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 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 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 #include <QApplication> |
|
42 #include <QtTest/QtTest> |
|
43 #include <QDebug> |
|
44 #include <QEventLoop> |
|
45 #include <QTimer> |
|
46 |
|
47 #include "qmessagemanager.h" |
|
48 #include "qmessage.h" |
|
49 |
|
50 #ifdef Q_OS_SYMBIAN |
|
51 #include <msvapi.h> |
|
52 #include <msvids.h> // KMsvGlobalInBoxIndexEntryId |
|
53 #include <mtclreg.h> // CClientMtmRegistry |
|
54 #include <smsclnt.h> // CSmsClientMtm |
|
55 #include <smut.h> // KUidMsgTypeSMS |
|
56 #include <txtrich.h> // CRichText |
|
57 #include <cemailaccounts.h> |
|
58 #include <mmsconst.h> |
|
59 #include <MIUTMSG.H> |
|
60 #include <MSVFIND.H> |
|
61 #include <IMPCMTM.H> |
|
62 #include <mmsclient.h> |
|
63 #endif |
|
64 |
|
65 #include <qdebug.h> |
|
66 |
|
67 QTM_USE_NAMESPACE |
|
68 |
|
69 class OsNative; |
|
70 |
|
71 #if defined(Q_OS_SYMBIAN) |
|
72 class OsNative : public MMsvSessionObserver { |
|
73 public: |
|
74 OsNative() |
|
75 { |
|
76 }; |
|
77 |
|
78 void HandleSessionEventL(TMsvSessionEvent aEvent, TAny* aArg1, TAny* aArg2, TAny* aArg3) { }; |
|
79 |
|
80 void getFolders(RArray<TMsvId> &folders); |
|
81 |
|
82 TMsvId makeSMS(TMsvId folder); |
|
83 TMsvId makeIMAP4(TMsvId folder); |
|
84 |
|
85 CMsvSession *iSession; |
|
86 CClientMtmRegistry *iMtmRegistry; |
|
87 CSmsClientMtm *iSmsMtm; |
|
88 CImap4ClientMtm *iImap4Mtm; |
|
89 CMmsClientMtm *iMmsMtm; |
|
90 |
|
91 RArray<TMsvId> iFolders; |
|
92 RArray<TMsvId> iNewMsgs; |
|
93 |
|
94 }; |
|
95 |
|
96 TMsvId OsNative::makeSMS(TMsvId folder){ |
|
97 TBuf<10> aAddress(_L("Nokia")); |
|
98 TBuf<20> aDescription(_L("Important Message")); |
|
99 |
|
100 _LIT(KTxt1,"Hi phone owner, how r u?"); |
|
101 |
|
102 TBuf<150> iMessage; |
|
103 iMessage.Copy(KTxt1); |
|
104 |
|
105 // m_native->iSmsMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId); //inbox KMsvDraftEntryId |
|
106 iSmsMtm->SwitchCurrentEntryL(folder); |
|
107 |
|
108 iSmsMtm->CreateMessageL(KUidMsgTypeSMS.iUid); |
|
109 |
|
110 CSmsHeader& iHeader = iSmsMtm->SmsHeader(); |
|
111 iHeader.SetFromAddressL(aAddress); |
|
112 |
|
113 |
|
114 CRichText& body = iSmsMtm->Body(); |
|
115 body.Reset(); |
|
116 body.InsertL(0, iMessage); |
|
117 |
|
118 TMsvEntry entry = iSmsMtm->Entry().Entry(); |
|
119 entry.SetInPreparation(EFalse); |
|
120 entry.SetVisible(ETrue); |
|
121 entry.iDate.HomeTime(); |
|
122 entry.iDescription.Set(aDescription); |
|
123 entry.iDetails.Set(aAddress); |
|
124 entry.SetUnread(EFalse); |
|
125 |
|
126 |
|
127 iSmsMtm->Entry().ChangeL(entry); |
|
128 iSmsMtm->SaveMessageL(); |
|
129 |
|
130 return entry.Id(); |
|
131 } |
|
132 |
|
133 TMsvId OsNative::makeIMAP4(TMsvId folder){ |
|
134 TBuf<20> aSubject(_L("Test Subject")); |
|
135 TBuf<20> aFrom(_L("Nokia@foo.com")); |
|
136 TBuf<20> aTo(_L("Boo@bar.com")); |
|
137 TBuf<20> aDescription(_L("Test Message")); |
|
138 |
|
139 _LIT(KTo, "Boo@bar.com"); |
|
140 _LIT(KTxt1,"Test autogenerated message by benchmark/tst_messaging for performance testing"); |
|
141 |
|
142 TBuf<150> iMessage; |
|
143 iMessage.Copy(KTxt1); |
|
144 |
|
145 // m_native->iSmsMtm->SwitchCurrentEntryL(KMsvGlobalInBoxIndexEntryId); //inbox KMsvDraftEntryId |
|
146 iImap4Mtm->SwitchCurrentEntryL(folder); |
|
147 |
|
148 // Set the context to the folder in which message has to be created |
|
149 CMsvEntry* entry = CMsvEntry::NewL(*iSession,folder,TMsvSelectionOrdering()); |
|
150 CleanupStack::PushL(entry); |
|
151 entry->SetEntryL(folder); |
|
152 |
|
153 CMsvOperationActiveSchedulerWait* waiter=CMsvOperationActiveSchedulerWait::NewLC(); |
|
154 //CleanupStack::PushL(waiter); |
|
155 |
|
156 TMsvEmailTypeList msvEmailTypeList = 0; |
|
157 TMsvPartList partList = (KMsvMessagePartBody | KMsvMessagePartAttachments); |
|
158 |
|
159 CImEmailOperation* emailOperation = CImEmailOperation::CreateNewL(waiter->iStatus, *iSession,KMsvGlobalOutBoxIndexEntryId, partList, msvEmailTypeList, KUidMsgTypeSMTP); |
|
160 CleanupStack::PushL(emailOperation); |
|
161 waiter->Start(); |
|
162 |
|
163 TMsvId temp; |
|
164 TPckgC<TMsvId> paramPack(temp); |
|
165 const TDesC8& progBuf = emailOperation->ProgressL(); |
|
166 paramPack.Set(progBuf); |
|
167 TMsvId newMessageId; |
|
168 newMessageId = paramPack(); |
|
169 |
|
170 entry->SetEntryL(newMessageId); |
|
171 |
|
172 CMsvStore* store = entry->EditStoreL(); |
|
173 CleanupStack::PushL(store); |
|
174 CImHeader* emailEntry = CImHeader::NewLC(); |
|
175 emailEntry->RestoreL(*store); |
|
176 emailEntry->SetFromL((TDesC8&)aFrom); |
|
177 emailEntry->SetSubjectL((TDesC&)aDescription); |
|
178 emailEntry->ToRecipients().AppendL(KTo); |
|
179 |
|
180 // Paragraph format layer for the rich text object |
|
181 CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(); |
|
182 CleanupStack::PushL(paraFormatLayer); |
|
183 // Character format layer for the rich text object |
|
184 CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(); |
|
185 CleanupStack::PushL(charFormatLayer); |
|
186 |
|
187 CRichText* bodyText = CRichText::NewL(paraFormatLayer, charFormatLayer, CEditableText::EFlatStorage, 256); |
|
188 CleanupStack::PushL(bodyText); |
|
189 |
|
190 // Insert the contents of a buffer into the document at specified position |
|
191 bodyText->InsertL(0, KTxt1); |
|
192 store->StoreBodyTextL(*bodyText); |
|
193 emailEntry->StoreL(*store); |
|
194 // Store the changes permanently |
|
195 store->CommitL(); |
|
196 |
|
197 CleanupStack::PopAndDestroy(8,entry); // bodyText,charFormatLayer,paraFormatLayer,emailEntry,store, emailOperationg,waiter,entry |
|
198 |
|
199 return entry->EntryId(); |
|
200 } |
|
201 |
|
202 #else |
|
203 class OsNative { |
|
204 |
|
205 }; |
|
206 #endif |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 //Q_DECLARE_METATYPE(QSystemInfo::Feature); |
|
212 |
|
213 class tst_messaging : public QObject |
|
214 { |
|
215 Q_OBJECT |
|
216 |
|
217 public: |
|
218 enum platform { |
|
219 QMessaging = 0, |
|
220 Native = 1 |
|
221 }; |
|
222 |
|
223 enum bases { |
|
224 Accounts = 0, |
|
225 AccountsImap, |
|
226 AccountsPop, |
|
227 AccountsSmtp, |
|
228 Folders, |
|
229 FoldersEmail, |
|
230 FoldersSMS, |
|
231 FoldersMMS, |
|
232 Messages, |
|
233 MessagesAlt, |
|
234 |
|
235 }; |
|
236 |
|
237 enum filter { |
|
238 Id = 0, |
|
239 Type, |
|
240 Sender, |
|
241 Recipients, |
|
242 Subject, |
|
243 TimeStamp, |
|
244 Status, |
|
245 Priority, |
|
246 Size, |
|
247 AllId, |
|
248 AllSender |
|
249 }; |
|
250 |
|
251 enum types { |
|
252 Sms = 0, |
|
253 Mms, |
|
254 Email |
|
255 }; |
|
256 |
|
257 |
|
258 private slots: |
|
259 void initTestCase(); |
|
260 void cleanupTestCase(); |
|
261 |
|
262 void tst_createTime_data(); |
|
263 void tst_createTime(); |
|
264 |
|
265 void tst_counts_data(); |
|
266 void tst_counts(); |
|
267 |
|
268 void tst_query_data(); |
|
269 void tst_query(); |
|
270 |
|
271 void tst_fetch_data(); |
|
272 void tst_fetch(); |
|
273 |
|
274 void tst_fetchAll_data(); |
|
275 void tst_fetchAll(); |
|
276 |
|
277 void tst_fetchFilter_data(); |
|
278 void tst_fetchFilter(); |
|
279 |
|
280 void tst_addMessage_data(); |
|
281 void tst_addMessage(); |
|
282 |
|
283 void tst_removeMessage_data(); |
|
284 void tst_removeMessage(); |
|
285 |
|
286 void tst_removeAllMessage_data(); |
|
287 void tst_removeAllMessage(); |
|
288 |
|
289 private: |
|
290 QMessage *createMessage(); |
|
291 QMessage *messageTemplate(); |
|
292 QMessageId addMessage(QMessage *); |
|
293 |
|
294 void clearMessages(); |
|
295 int countMessages(); |
|
296 |
|
297 QMessageManager *m_mgr; |
|
298 |
|
299 QMessageIdList msg_list; |
|
300 |
|
301 QMessageAccount m_act; |
|
302 //QMessageFolder m_fol; |
|
303 |
|
304 |
|
305 OsNative *m_native; |
|
306 }; |
|
307 |
|
308 Q_DECLARE_METATYPE(tst_messaging::platform); |
|
309 Q_DECLARE_METATYPE(tst_messaging::bases); |
|
310 Q_DECLARE_METATYPE(tst_messaging::filter); |
|
311 Q_DECLARE_METATYPE(tst_messaging::types); |
|
312 |
|
313 void tst_messaging::initTestCase() |
|
314 { |
|
315 |
|
316 #if defined(Q_WS_MAEMO_6) |
|
317 QFAIL("Maemo 6 not supported by tst_messaging"); |
|
318 #elif defined(Q_WS_MAEMO_5) |
|
319 QFAIL("Maemo 5 does not support tst_messageing"); |
|
320 #elif defined(Q_OS_SYMBIAN) |
|
321 |
|
322 #else |
|
323 QFAIL("Platform not supported"); |
|
324 #endif |
|
325 |
|
326 m_mgr = new QMessageManager(); |
|
327 |
|
328 QMessageAccountIdList list; |
|
329 list = m_mgr->queryAccounts(); |
|
330 while(!list.empty()) { |
|
331 QMessageAccount act = m_mgr->account(list.takeFirst()); |
|
332 qDebug() << "Account: " << act.name(); |
|
333 #if defined(Q_OS_SYMBIAN) |
|
334 if(act.name() == "Personal"){ |
|
335 m_act = act; |
|
336 break; |
|
337 } |
|
338 #endif |
|
339 } |
|
340 |
|
341 // QMessageFolderIdList flist = m_mgr->queryFolders(); |
|
342 // while(!flist.empty()) { |
|
343 // QMessageFolder fol = m_mgr->folder(flist.takeFirst()); |
|
344 // qDebug() << "Folder: " << fol.name(); |
|
345 //#if defined(Q_OS_SYMBIAN) |
|
346 // if(fol.name() == "Inbox"){ |
|
347 // m_fol = fol; |
|
348 // break; |
|
349 // } |
|
350 //#endif |
|
351 // } |
|
352 |
|
353 #if defined(Q_OS_SYMBIAN) |
|
354 // define/init native features we need native |
|
355 m_native = new OsNative; |
|
356 m_native->iSession = CMsvSession::OpenSyncL(*m_native); |
|
357 m_native->iMtmRegistry = CClientMtmRegistry::NewL(*m_native->iSession); |
|
358 m_native->iSmsMtm = STATIC_CAST(CSmsClientMtm*, m_native->iMtmRegistry->NewMtmL(KUidMsgTypeSMS)); |
|
359 m_native->iImap4Mtm = STATIC_CAST(CImap4ClientMtm*, m_native->iMtmRegistry->NewMtmL(KUidMsgTypeIMAP4)); |
|
360 m_native->iMmsMtm = STATIC_CAST(CMmsClientMtm*, m_native->iMtmRegistry->NewMtmL(KUidMsgTypeMultimedia)); |
|
361 |
|
362 #endif |
|
363 |
|
364 for(int i = 0; i < 20; i++) |
|
365 createMessage(); |
|
366 |
|
367 } |
|
368 |
|
369 void tst_messaging::cleanupTestCase() |
|
370 { |
|
371 |
|
372 #if defined(Q_OS_SYMBIAN) |
|
373 delete m_native->iMmsMtm; |
|
374 delete m_native->iImap4Mtm; |
|
375 delete m_native->iSmsMtm; |
|
376 delete m_native->iMtmRegistry; |
|
377 delete m_native->iSession; |
|
378 delete m_native; |
|
379 #endif |
|
380 |
|
381 clearMessages(); |
|
382 delete m_mgr; |
|
383 |
|
384 |
|
385 } |
|
386 |
|
387 |
|
388 void tst_messaging::tst_createTime_data() |
|
389 { |
|
390 QTest::addColumn<tst_messaging::platform>("platform"); |
|
391 |
|
392 QTest::newRow("Qt-Create") << tst_messaging::QMessaging; |
|
393 QTest::newRow("Native-Create") << tst_messaging::Native; |
|
394 } |
|
395 |
|
396 |
|
397 void tst_messaging::tst_createTime() |
|
398 { |
|
399 QFETCH(tst_messaging::platform, platform); |
|
400 |
|
401 //qDebug() << "Platform: " << platform; |
|
402 |
|
403 if(platform == tst_messaging::QMessaging){ |
|
404 QMessageManager *mgr = 0x0; |
|
405 |
|
406 QBENCHMARK { |
|
407 mgr = new QMessageManager(); |
|
408 } |
|
409 |
|
410 delete mgr; |
|
411 |
|
412 } |
|
413 else if(platform == tst_messaging::Native){ |
|
414 #ifdef Q_OS_SYMBIAN |
|
415 |
|
416 __UHEAP_MARK; |
|
417 |
|
418 if(m_native){ |
|
419 delete m_native->iMmsMtm; |
|
420 delete m_native->iImap4Mtm; |
|
421 delete m_native->iSmsMtm; |
|
422 delete m_native->iMtmRegistry; |
|
423 delete m_native->iSession; |
|
424 delete m_native; |
|
425 } |
|
426 |
|
427 QBENCHMARK { |
|
428 // define/init native features we need native |
|
429 m_native = new OsNative; |
|
430 m_native->iSession = CMsvSession::OpenSyncL(*m_native); |
|
431 m_native->iMtmRegistry = CClientMtmRegistry::NewL(*m_native->iSession); |
|
432 m_native->iSmsMtm = STATIC_CAST(CSmsClientMtm*, m_native->iMtmRegistry->NewMtmL(KUidMsgTypeSMS)); |
|
433 m_native->iImap4Mtm = STATIC_CAST(CImap4ClientMtm*, m_native->iMtmRegistry->NewMtmL(KUidMsgTypeIMAP4)); |
|
434 m_native->iMmsMtm = STATIC_CAST(CMmsClientMtm*, m_native->iMtmRegistry->NewMtmL(KUidMsgTypeMultimedia)); |
|
435 } |
|
436 |
|
437 __UHEAP_MARKEND; |
|
438 #endif |
|
439 } |
|
440 |
|
441 } |
|
442 |
|
443 void tst_messaging::tst_counts_data() |
|
444 { |
|
445 QTest::addColumn<tst_messaging::platform>("platform"); |
|
446 QTest::addColumn<tst_messaging::bases>("base"); |
|
447 |
|
448 QTest::newRow("Qt-Accounts") << tst_messaging::QMessaging << tst_messaging::Accounts; |
|
449 // QTest::newRow("Native-Accounts") << tst_messaging::Native << tst_messaging::Accounts; |
|
450 QTest::newRow("Qt-Folders") << tst_messaging::QMessaging << tst_messaging::Folders; |
|
451 QTest::newRow("Native-Folders") << tst_messaging::Native << tst_messaging::Folders; |
|
452 QTest::newRow("Qt-Messages") << tst_messaging::QMessaging << tst_messaging::Messages; |
|
453 QTest::newRow("Qt-MessagesAlt") << tst_messaging::QMessaging << tst_messaging::MessagesAlt; |
|
454 QTest::newRow("Native-Messages") << tst_messaging::Native << tst_messaging::Messages; |
|
455 |
|
456 } |
|
457 |
|
458 void tst_messaging::tst_counts() |
|
459 { |
|
460 QFETCH(tst_messaging::platform, platform); |
|
461 QFETCH(tst_messaging::bases, base); |
|
462 |
|
463 if(platform == tst_messaging::QMessaging){ |
|
464 int cnt; |
|
465 Q_UNUSED(cnt); |
|
466 if(base == tst_messaging::Accounts){ |
|
467 QBENCHMARK { |
|
468 cnt = m_mgr->countAccounts(); |
|
469 } |
|
470 } |
|
471 else if(base == tst_messaging::Folders){ |
|
472 QBENCHMARK { |
|
473 cnt = m_mgr->countFolders(); |
|
474 } |
|
475 } |
|
476 else if(base == tst_messaging::Messages){ |
|
477 QBENCHMARK { |
|
478 cnt = m_mgr->countMessages(); |
|
479 } |
|
480 } |
|
481 else if(base == tst_messaging::MessagesAlt){ |
|
482 QMessageIdList list; |
|
483 QBENCHMARK { |
|
484 list = m_mgr->queryMessages(); |
|
485 cnt = list.count(); |
|
486 } |
|
487 } |
|
488 //qDebug() << "Got cnt: " << cnt; |
|
489 } |
|
490 else if(platform == tst_messaging::Native){ |
|
491 #ifdef Q_OS_SYMBIAN |
|
492 QBENCHMARK { |
|
493 // Access the Inbox |
|
494 TMsvSelectionOrdering sort; |
|
495 CMsvEntry* inboxContext = CMsvEntry::NewL(*m_native->iSession, KMsvGlobalInBoxIndexEntryId, sort); |
|
496 CleanupStack::PushL(inboxContext); |
|
497 |
|
498 // Get all entries in the Inbox |
|
499 CMsvEntrySelection* entries = inboxContext->ChildrenL(); |
|
500 CleanupStack::PushL(entries); |
|
501 |
|
502 |
|
503 TInt messages = entries->Count(); |
|
504 |
|
505 CleanupStack::PopAndDestroy(2, inboxContext); |
|
506 } |
|
507 #endif |
|
508 } |
|
509 |
|
510 } |
|
511 |
|
512 void tst_messaging::tst_query_data() |
|
513 { |
|
514 QTest::addColumn<tst_messaging::platform>("platform"); |
|
515 QTest::addColumn<tst_messaging::bases>("base"); |
|
516 |
|
517 QTest::newRow("Qt-Accounts") << tst_messaging::QMessaging << tst_messaging::Accounts; |
|
518 // QTest::newRow("Qt-Folders") << tst_messaging::QMessaging << tst_messaging::Folders; |
|
519 QTest::newRow("Qt-Messages") << tst_messaging::QMessaging << tst_messaging::Messages; |
|
520 |
|
521 QTest::newRow("Native-Accounts") << tst_messaging::Native << tst_messaging::Accounts; |
|
522 QTest::newRow("Native-Accounts-Imap") << tst_messaging::Native << tst_messaging::AccountsImap; |
|
523 QTest::newRow("Native-Accounts-Pop") << tst_messaging::Native << tst_messaging::AccountsPop; |
|
524 QTest::newRow("Native-Accounts-Smtp") << tst_messaging::Native << tst_messaging::AccountsSmtp; |
|
525 QTest::newRow("Native-Folders") << tst_messaging::Native << tst_messaging::Folders; |
|
526 // QTest::newRow("Native-Folders") << tst_messaging::Native << tst_messaging::FoldersEmail; |
|
527 // QTest::newRow("Native-Folders") << tst_messaging::Native << tst_messaging::FoldersSMS; |
|
528 // QTest::newRow("Native-Folders") << tst_messaging::Native << tst_messaging::FoldersMMS; |
|
529 QTest::newRow("Native-Messages") << tst_messaging::Native << tst_messaging::Messages; |
|
530 |
|
531 } |
|
532 |
|
533 void tst_messaging::tst_query() |
|
534 { |
|
535 QFETCH(tst_messaging::platform, platform); |
|
536 QFETCH(tst_messaging::bases, base); |
|
537 |
|
538 if(platform == tst_messaging::QMessaging){ |
|
539 // int cnt; |
|
540 if(base == tst_messaging::Accounts){ |
|
541 QMessageAccountIdList list; |
|
542 QBENCHMARK { |
|
543 list = m_mgr->queryAccounts(); |
|
544 } |
|
545 } |
|
546 else if(base == tst_messaging::Folders){ |
|
547 QMessageFolderIdList list; |
|
548 QBENCHMARK { |
|
549 list = m_mgr->queryFolders(); |
|
550 } |
|
551 // XXX The library returns inbox/drafts/sent for all default accounts and greatly exagerates the number of folders |
|
552 // qDebug() << "Number of folders: " << list.count(); |
|
553 // while(!list.empty()){ |
|
554 // QMessageFolder f(list.takeFirst()); |
|
555 // qDebug() << "Folder: " << f.name(); |
|
556 // } |
|
557 } |
|
558 else if(base == tst_messaging::Messages){ |
|
559 QMessageIdList list; |
|
560 QBENCHMARK { |
|
561 list = m_mgr->queryMessages(); |
|
562 } |
|
563 } |
|
564 //qDebug() << "Got cnt: " << cnt; |
|
565 } |
|
566 else if(platform == tst_messaging::Native){ |
|
567 #ifdef Q_OS_SYMBIAN |
|
568 if(base == tst_messaging::Accounts){ |
|
569 CEmailAccounts *email = CEmailAccounts::NewLC(); |
|
570 RArray<TPopAccount> aPop; |
|
571 RArray<TImapAccount> aImap; |
|
572 RArray<TSmtpAccount> aSmtp; |
|
573 |
|
574 QBENCHMARK { |
|
575 email->GetPopAccountsL(aPop); |
|
576 email->GetImapAccountsL(aImap); |
|
577 email->GetSmtpAccountsL(aSmtp); |
|
578 } |
|
579 CleanupStack::PopAndDestroy(email); |
|
580 } |
|
581 else if(base == tst_messaging::AccountsImap) { |
|
582 CEmailAccounts *email = CEmailAccounts::NewLC(); |
|
583 RArray<TImapAccount> aImap; |
|
584 |
|
585 QBENCHMARK { |
|
586 email->GetImapAccountsL(aImap); |
|
587 } |
|
588 CleanupStack::PopAndDestroy(email); |
|
589 |
|
590 } |
|
591 else if(base == tst_messaging::AccountsPop) { |
|
592 CEmailAccounts *email = CEmailAccounts::NewLC(); |
|
593 RArray<TPopAccount> aPop; |
|
594 |
|
595 QBENCHMARK { |
|
596 email->GetPopAccountsL(aPop); |
|
597 } |
|
598 CleanupStack::PopAndDestroy(email); |
|
599 |
|
600 } |
|
601 else if(base == tst_messaging::AccountsSmtp) { |
|
602 CEmailAccounts *email = CEmailAccounts::NewLC(); |
|
603 RArray<TSmtpAccount> aSmtp; |
|
604 |
|
605 QBENCHMARK { |
|
606 email->GetSmtpAccountsL(aSmtp); |
|
607 } |
|
608 CleanupStack::PopAndDestroy(email); |
|
609 |
|
610 } |
|
611 else if(base == tst_messaging::Folders){ |
|
612 |
|
613 __UHEAP_MARK; |
|
614 |
|
615 CEmailAccounts *email = CEmailAccounts::NewLC(); |
|
616 RArray<TPopAccount> aPop; |
|
617 RArray<TImapAccount> aImap; |
|
618 RArray<TSmtpAccount> aSmtp; |
|
619 |
|
620 email->GetPopAccountsL(aPop); |
|
621 email->GetImapAccountsL(aImap); |
|
622 email->GetSmtpAccountsL(aSmtp); |
|
623 |
|
624 |
|
625 RArray<TMsvId> aService; |
|
626 |
|
627 // qDebug() << "Pop Service: " << aPop.Count(); |
|
628 // qDebug() << "Imap Service: " << aImap.Count(); |
|
629 // qDebug() << "Smtp Service: " << aSmtp.Count(); |
|
630 |
|
631 for(int i = 0; i < aPop.Count(); i++){ |
|
632 aService.Append(aPop[i].iPopService); |
|
633 } |
|
634 for(int i = 0; i < aImap.Count(); i++){ |
|
635 aService.Append(aImap[i].iImapService); |
|
636 } |
|
637 for(int i = 0; i < aSmtp.Count(); i++){ |
|
638 aService.Append(aSmtp[i].iSmtpService); |
|
639 } |
|
640 |
|
641 |
|
642 if(aService.Count() == 0) |
|
643 QFAIL("No folders avaailable to query"); |
|
644 |
|
645 // qDebug() << "Total services: " << aService.Count(); |
|
646 |
|
647 int total; |
|
648 |
|
649 |
|
650 CMsvEntry* pEntry = NULL; |
|
651 TRAPD(err, pEntry = m_native->iSession->GetEntryL(aService[0])); |
|
652 if(err) |
|
653 QFAIL("Can't create entry object"); |
|
654 CleanupStack::PushL(pEntry); |
|
655 |
|
656 |
|
657 QBENCHMARK { |
|
658 total = 0; |
|
659 for(int i = 0; i < aService.Count(); i++){ |
|
660 |
|
661 TMsvId msvid = aService[i]; |
|
662 |
|
663 TRAP(err, pEntry->SetEntryL(msvid)); // faster to call set, saves .2ms out of 2.7ms. |
|
664 if(err){ |
|
665 qDebug() << "Failed: " << err; |
|
666 continue; |
|
667 } |
|
668 |
|
669 |
|
670 const TMsvEntry& entry = pEntry->Entry(); |
|
671 |
|
672 if (entry.iMtm == KUidMsgTypeSMS || entry.iMtm == KUidMsgTypeMultimedia || entry.iMtm == KUidMsgTypeSMTP) { |
|
673 total += 4; |
|
674 #define KDocumentsEntryIdValue 0x1008 |
|
675 pEntry->SetEntryL(KDocumentsEntryIdValue); |
|
676 } |
|
677 |
|
678 if (entry.iMtm == KUidMsgTypePOP3) { |
|
679 total+=1; |
|
680 continue; |
|
681 } |
|
682 |
|
683 CMsvEntryFilter* pFilter = CMsvEntryFilter::NewLC(); |
|
684 pFilter->SetService(msvid); |
|
685 pFilter->SetType(KUidMsvFolderEntry); |
|
686 |
|
687 CMsvEntrySelection* pSelection = new(ELeave) CMsvEntrySelection; |
|
688 CleanupStack::PushL(pSelection); |
|
689 |
|
690 m_native->iSession->GetChildIdsL(pEntry->Entry().Id(), *pFilter, *pSelection); |
|
691 if (pSelection->Count() > 0) { |
|
692 for(TInt i = 0; i < pSelection->Count(); i++) { |
|
693 // ids.append(createQMessageFolderId(folderServiceEntryId, pSelection->At(i))); |
|
694 // qDebug() << "serviceId: " << msvid << " Got one: " << "selected: " << pSelection->At(i); |
|
695 total++; |
|
696 m_native->iFolders.Append(pSelection->At(i)); |
|
697 } |
|
698 } |
|
699 else { |
|
700 // QString details = QString::fromUtf16(entry.iDetails.Ptr(),entry.iDetails.Length()); |
|
701 // QString desc = QString::fromUtf16(entry.iDescription.Ptr(),entry.iDescription.Length()); |
|
702 // qDebug() << "Nothing returned for: " << msvid << "entry: " << details << " - " << desc; |
|
703 } |
|
704 CleanupStack::PopAndDestroy(pSelection); |
|
705 CleanupStack::PopAndDestroy(pFilter); |
|
706 |
|
707 } |
|
708 } |
|
709 |
|
710 // qDebug() << "Number of Folders: " << total; |
|
711 |
|
712 aPop.Close(); |
|
713 aImap.Close(); |
|
714 aSmtp.Close(); |
|
715 aService.Close(); |
|
716 |
|
717 CleanupStack::PopAndDestroy(pEntry); |
|
718 CleanupStack::PopAndDestroy(email); |
|
719 |
|
720 __UHEAP_MARKEND; |
|
721 |
|
722 } |
|
723 else if(base == tst_messaging::Messages) { |
|
724 |
|
725 RArray<TMsvId> aFolders; |
|
726 |
|
727 aFolders.Append(KMsvGlobalInBoxIndexEntryId); |
|
728 aFolders.Append(KMsvGlobalOutBoxIndexEntryId); |
|
729 aFolders.Append(KMsvDraftEntryId); |
|
730 aFolders.Append(KMsvSentEntryId); |
|
731 for(int i = 0; i < m_native->iFolders.Count(); i++) |
|
732 aFolders.Append(m_native->iFolders[i]); |
|
733 |
|
734 // Access the Inbox |
|
735 QBENCHMARK { |
|
736 |
|
737 for(int i = 0; i < aFolders.Count(); i++){ |
|
738 TMsvSelectionOrdering sort; |
|
739 CMsvEntry* inboxContext = CMsvEntry::NewL(*m_native->iSession, aFolders[i], sort); |
|
740 CleanupStack::PushL(inboxContext); |
|
741 |
|
742 // Get all entries in the Inbox |
|
743 CMsvEntrySelection* entries = inboxContext->ChildrenL(); |
|
744 CleanupStack::PushL(entries); |
|
745 |
|
746 TInt messages = entries->Count(); |
|
747 for (TInt i = 0; i < messages; i++) { |
|
748 TMsvId entryID = entries->At(i); |
|
749 m_native->iSmsMtm->SwitchCurrentEntryL(entryID); |
|
750 |
|
751 CMsvEntry* entry; |
|
752 |
|
753 entry = m_native->iSession->GetEntryL((*entries)[i]); |
|
754 |
|
755 delete entry; |
|
756 |
|
757 } |
|
758 |
|
759 CleanupStack::PopAndDestroy(2, inboxContext); |
|
760 } |
|
761 } |
|
762 } |
|
763 #endif |
|
764 } |
|
765 |
|
766 } |
|
767 |
|
768 void tst_messaging::tst_fetch_data() |
|
769 { |
|
770 //qDebug() << "Start fetch_data"; |
|
771 QTest::addColumn<tst_messaging::platform>("platform"); |
|
772 QTest::addColumn<tst_messaging::bases>("base"); |
|
773 |
|
774 QTest::newRow("Qt-Accounts") << tst_messaging::QMessaging << tst_messaging::Accounts; |
|
775 QTest::newRow("Native-Accounts") << tst_messaging::Native << tst_messaging::Accounts; |
|
776 QTest::newRow("Qt-Folders") << tst_messaging::QMessaging << tst_messaging::Folders; |
|
777 QTest::newRow("Native-Folders") << tst_messaging::Native << tst_messaging::Folders; |
|
778 QTest::newRow("Qt-Messages") << tst_messaging::QMessaging << tst_messaging::Messages; |
|
779 QTest::newRow("Native-Messages") << tst_messaging::Native << tst_messaging::Messages; |
|
780 //qDebug() << "End fetch_data"; |
|
781 } |
|
782 |
|
783 void tst_messaging::tst_fetch() |
|
784 { |
|
785 |
|
786 QFETCH(tst_messaging::platform, platform); |
|
787 QFETCH(tst_messaging::bases, base); |
|
788 |
|
789 //qDebug() << "Start fetch" << platform << " base: " << base; |
|
790 if(platform == tst_messaging::QMessaging){ |
|
791 int cnt; |
|
792 Q_UNUSED(cnt); |
|
793 if(base == tst_messaging::Accounts){ |
|
794 QMessageAccountIdList list; |
|
795 QMessageAccount acc; |
|
796 list = m_mgr->queryAccounts(); |
|
797 |
|
798 if(!list.empty()){ |
|
799 QBENCHMARK_ONCE { // XXX Maybe a bug here, if you call account a lot system crashes |
|
800 acc = m_mgr->account(list.takeFirst()); |
|
801 } |
|
802 } |
|
803 if(m_mgr->error()){ |
|
804 QFAIL(QString("Failed fetching accounts: %1").arg(m_mgr->error()).toAscii()); |
|
805 } |
|
806 } |
|
807 else if(base == tst_messaging::Folders){ |
|
808 QMessageFolderIdList list; |
|
809 QMessageFolder fol; |
|
810 list = m_mgr->queryFolders(); |
|
811 |
|
812 if(!list.empty()) { |
|
813 QBENCHMARK { |
|
814 fol = m_mgr->folder(list.takeFirst()); |
|
815 } |
|
816 } |
|
817 } |
|
818 else if(base == tst_messaging::Messages){ |
|
819 QMessageIdList list; |
|
820 QMessage msg; |
|
821 list = m_mgr->queryMessages(); |
|
822 |
|
823 if(!list.empty()){ |
|
824 QBENCHMARK { |
|
825 msg = m_mgr->message(list.takeFirst()); |
|
826 } |
|
827 } |
|
828 } |
|
829 //qDebug() << "Got cnt: " << cnt; |
|
830 } |
|
831 else if(platform == tst_messaging::Native){ |
|
832 #ifdef Q_OS_SYMBIAN |
|
833 if(base == tst_messaging::Messages){ |
|
834 __UHEAP_MARK; |
|
835 // Access the Inbox |
|
836 QBENCHMARK { |
|
837 |
|
838 TMsvSelectionOrdering sort; |
|
839 sort.SetSorting(EMsvSortByDateReverse); |
|
840 sort.SetShowInvisibleEntries(ETrue); |
|
841 |
|
842 CMsvEntry* inboxContext = CMsvEntry::NewL(*m_native->iSession, |
|
843 KMsvGlobalInBoxIndexEntryId, sort); |
|
844 CleanupStack::PushL(inboxContext); |
|
845 |
|
846 // Get all entries in the Inbox |
|
847 CMsvEntrySelection* entries = inboxContext->ChildrenL(); |
|
848 CleanupStack::PushL(entries); |
|
849 |
|
850 TMsvId entryID = entries->At(0); |
|
851 const TUid mtm = inboxContext->ChildDataL(entryID).iMtm; |
|
852 |
|
853 if (mtm == KUidMsgTypeSMS) { |
|
854 |
|
855 m_native->iSmsMtm->SwitchCurrentEntryL(entryID); |
|
856 TRAPD(err, m_native->iSmsMtm->LoadMessageL()); |
|
857 if(err){ |
|
858 qDebug() << "LoadMessageL failed: " << err; |
|
859 continue; |
|
860 } |
|
861 CSmsHeader& header = m_native->iSmsMtm->SmsHeader(); |
|
862 } |
|
863 else if (mtm == KUidMsgTypeMultimedia) { |
|
864 |
|
865 // TODO None of these have a data store...skip until it can be fixed |
|
866 QFAIL("MMS message handeling is broken, change setup to use non-MMS type"); |
|
867 } |
|
868 else if (mtm == KUidMsgTypeIMAP4) { |
|
869 m_native->iImap4Mtm->SwitchCurrentEntryL(entryID); |
|
870 m_native->iImap4Mtm->LoadMessageL(); |
|
871 } |
|
872 else { |
|
873 qDebug() << "Got Type: " << mtm.iUid; |
|
874 } |
|
875 CleanupStack::PopAndDestroy(2, inboxContext); |
|
876 } |
|
877 __UHEAP_MARKEND; |
|
878 } |
|
879 |
|
880 #endif |
|
881 } |
|
882 //qDebug() <<"End fetch"; |
|
883 } |
|
884 |
|
885 void tst_messaging::tst_fetchAll_data() |
|
886 { |
|
887 QTest::addColumn<tst_messaging::platform>("platform"); |
|
888 QTest::addColumn<tst_messaging::bases>("base"); |
|
889 |
|
890 QTest::newRow("Qt-Accounts") << tst_messaging::QMessaging << tst_messaging::Accounts; |
|
891 QTest::newRow("Native-Accounts") << tst_messaging::Native << tst_messaging::Accounts; |
|
892 // QTest::newRow("Qt-Folders") << tst_messaging::QMessaging << tst_messaging::Folders; |
|
893 QTest::newRow("Native-Folders") << tst_messaging::Native << tst_messaging::Folders; |
|
894 QTest::newRow("Qt-Messages") << tst_messaging::QMessaging << tst_messaging::Messages; |
|
895 QTest::newRow("Native-Messages") << tst_messaging::Native << tst_messaging::Messages; |
|
896 |
|
897 } |
|
898 |
|
899 |
|
900 void tst_messaging::tst_fetchAll() |
|
901 { |
|
902 QFETCH(tst_messaging::platform, platform); |
|
903 QFETCH(tst_messaging::bases, base); |
|
904 |
|
905 if(platform == tst_messaging::QMessaging){ |
|
906 if(base == tst_messaging::Accounts){ |
|
907 QMessageAccountIdList list; |
|
908 QMessageAccount acc; |
|
909 list = m_mgr->queryAccounts(); |
|
910 |
|
911 QBENCHMARK { |
|
912 while(!list.empty()) |
|
913 acc = m_mgr->account(list.takeFirst()); |
|
914 } |
|
915 } |
|
916 else if(base == tst_messaging::Folders){ |
|
917 QMessageFolderIdList list; |
|
918 QMessageFolder fol; |
|
919 list = m_mgr->queryFolders(); |
|
920 |
|
921 QBENCHMARK { |
|
922 while(!list.empty()) |
|
923 fol = m_mgr->folder(list.takeFirst()); |
|
924 } |
|
925 } |
|
926 else if(base == tst_messaging::Messages){ |
|
927 QMessageIdList list; |
|
928 QMessage msg; |
|
929 list = m_mgr->queryMessages(); |
|
930 qDebug() << "Total fetched messages: " << list.count(); |
|
931 QBENCHMARK { |
|
932 while(!list.empty()) |
|
933 msg = m_mgr->message(list.takeFirst()); |
|
934 } |
|
935 // TODO this selects messages in built "My Folders" which the test for symbian native doesn't. Fix me. |
|
936 // list = m_mgr->queryMessages(); |
|
937 // while(!list.empty()) { |
|
938 // msg = m_mgr->message(list.takeFirst()); |
|
939 // qDebug() << "From: " << msg.from().recipient() << " subject: " << msg.subject(); |
|
940 // } |
|
941 |
|
942 } |
|
943 //qDebug() << "Got cnt: " << cnt; |
|
944 } |
|
945 else if(platform == tst_messaging::Native){ |
|
946 #ifdef Q_OS_SYMBIAN |
|
947 if(base == tst_messaging::Messages){ |
|
948 |
|
949 __UHEAP_MARK; |
|
950 |
|
951 RArray<TMsvId> aFolders; |
|
952 int total = 0; |
|
953 int skipped = 0; |
|
954 |
|
955 m_native->getFolders(aFolders); |
|
956 |
|
957 // Access the Inbox |
|
958 QBENCHMARK { |
|
959 |
|
960 for(int i = 0; i < aFolders.Count(); i++){ |
|
961 TMsvSelectionOrdering sort; |
|
962 //sort.SetSorting(EMsvSortByDateReverse); |
|
963 sort.SetSorting(EMsvSortByNone); |
|
964 sort.SetShowInvisibleEntries(ETrue); |
|
965 |
|
966 CMsvEntry* inboxContext = CMsvEntry::NewL(*m_native->iSession, |
|
967 aFolders[i], sort); |
|
968 CleanupStack::PushL(inboxContext); |
|
969 |
|
970 // Get all entries in the Inbox |
|
971 CMsvEntrySelection* entries = inboxContext->ChildrenL(); |
|
972 CleanupStack::PushL(entries); |
|
973 |
|
974 for (TInt i = 0; i < entries->Count(); i++) { |
|
975 |
|
976 TMsvId entryID = entries->At(i); |
|
977 |
|
978 const TUid mtm = inboxContext->ChildDataL(entryID).iMtm; |
|
979 |
|
980 // qDebug() << "Entry: " << i << " mtm: " << hex << mtm.iUid; |
|
981 |
|
982 if (mtm == KUidMsgTypeSMS) { |
|
983 |
|
984 TRAP_IGNORE(m_native->iSmsMtm->SwitchCurrentEntryL(entryID)); |
|
985 TRAPD(err, m_native->iSmsMtm->LoadMessageL()); |
|
986 if(err){ |
|
987 qDebug() << "LoadMessageL failed: " << err; |
|
988 continue; |
|
989 } |
|
990 //CSmsHeader& header = m_native->iSmsMtm->SmsHeader(); |
|
991 total++; |
|
992 } |
|
993 else if (mtm == KUidMsgTypeMultimedia) { |
|
994 |
|
995 // TODO None of these have a data store...skip until it can be fixed |
|
996 |
|
997 // CMsvEntry* pEntry = NULL; |
|
998 // pEntry = m_native->iSession->GetEntryL(entryID); |
|
999 // const TMsvEntry& entry = pEntry->Entry(); |
|
1000 // |
|
1001 // QString details = QString::fromUtf16(entry.iDetails.Ptr(),entry.iDetails.Length()); |
|
1002 // QString desc = QString::fromUtf16(entry.iDescription.Ptr(),entry.iDescription.Length()); |
|
1003 // qDebug() << "Nothing returned for entry: " << entryID << "/" << entry.Id() << " " << details << " - " << desc << " Has store: " << pEntry->HasStoreL(); |
|
1004 //// m_native->iImap4Mtm->SwitchCurrentEntryL(entry.Id()); |
|
1005 |
|
1006 |
|
1007 // m_native->iMmsMtm->SwitchCurrentEntryL(entryID); |
|
1008 // TRAPD(err, m_native->iMmsMtm->LoadMessageL()); |
|
1009 // if(err){ |
|
1010 // qDebug() << "LoadMessageL failed: " << err << "entryId/mtm" << entryID << "/" << mtm.iUid; |
|
1011 // continue; |
|
1012 // } |
|
1013 skipped++; |
|
1014 } |
|
1015 else if (mtm == KUidMsgTypeIMAP4) { |
|
1016 CMsvEntry* pEntry = NULL; |
|
1017 pEntry = m_native->iSession->GetEntryL(entryID); |
|
1018 |
|
1019 CImEmailMessage *pMsg = CImEmailMessage::NewLC(*pEntry); |
|
1020 |
|
1021 CMsvStore *store; |
|
1022 TRAPD(err, store = pEntry->ReadStoreL()); |
|
1023 if(err){ |
|
1024 // TPtrC sub; |
|
1025 // m_native->iImap4Mtm->SwitchCurrentEntryL(entryID); |
|
1026 // m_native->iImap4Mtm->LoadMessageL(); |
|
1027 // TRAP(err,sub.Set(m_native->iImap4Mtm->SubjectL())); |
|
1028 // if(err){ |
|
1029 // qDebug() << "No subject either: " << err; |
|
1030 // } |
|
1031 // qDebug() << "Can't read store: " << err << hex << entryID << " Details: " << QString::fromUtf16(sub.Ptr(), sub.Length()); |
|
1032 skipped++; |
|
1033 CleanupStack::PopAndDestroy(pMsg); |
|
1034 continue; |
|
1035 } |
|
1036 CleanupStack::PushL(store); |
|
1037 |
|
1038 CImHeader* header = CImHeader::NewLC(); |
|
1039 header->RestoreL(*store); |
|
1040 |
|
1041 //subject buffer contains the "subject" of the mail. |
|
1042 TBuf<50> subject = header->Subject(); |
|
1043 |
|
1044 //header buffer contains the "header" of the mail. |
|
1045 TBuf<50> from = header->From(); |
|
1046 |
|
1047 // TODO: Find out why we don't select messages from the system My Folder store. |
|
1048 // QString qsubject = QString::fromUtf16(subject.Ptr(),subject.Length()); |
|
1049 // QString qfrom = QString::fromUtf16(from.Ptr(),from.Length()); |
|
1050 // qDebug() << "From: " << qfrom << " subject: " << qsubject; |
|
1051 |
|
1052 CleanupStack::PopAndDestroy(header); |
|
1053 CleanupStack::PopAndDestroy(store); |
|
1054 CleanupStack::PopAndDestroy(pMsg); |
|
1055 |
|
1056 total++; |
|
1057 } |
|
1058 else { |
|
1059 // qDebug() << "Got Type: " << mtm.iUid; |
|
1060 } |
|
1061 } |
|
1062 CleanupStack::PopAndDestroy(2, inboxContext); |
|
1063 } |
|
1064 } |
|
1065 qDebug() << "Total messages fetched: " << total << " skipped: " << skipped; |
|
1066 __UHEAP_MARKEND; |
|
1067 } |
|
1068 #endif |
|
1069 } |
|
1070 |
|
1071 } |
|
1072 |
|
1073 |
|
1074 |
|
1075 void tst_messaging::tst_fetchFilter_data() |
|
1076 { |
|
1077 QTest::addColumn<tst_messaging::platform>("platform"); |
|
1078 QTest::addColumn<tst_messaging::filter>("filter"); |
|
1079 |
|
1080 QTest::newRow("Qt-Id") << tst_messaging::QMessaging << tst_messaging::Id; |
|
1081 QTest::newRow("Qt-Type") << tst_messaging::QMessaging << tst_messaging::Type; |
|
1082 QTest::newRow("Qt-Sender") << tst_messaging::QMessaging << tst_messaging::Sender; |
|
1083 QTest::newRow("Qt-Subject") << tst_messaging::QMessaging << tst_messaging::Subject; |
|
1084 QTest::newRow("Qt-TimeStamp") << tst_messaging::QMessaging << tst_messaging::TimeStamp; |
|
1085 QTest::newRow("Qt-Status") << tst_messaging::QMessaging << tst_messaging::Status; |
|
1086 QTest::newRow("Qt-Priority") << tst_messaging::QMessaging << tst_messaging::Priority; |
|
1087 QTest::newRow("Qt-Size") << tst_messaging::QMessaging << tst_messaging::Size; |
|
1088 QTest::newRow("Qt-AllId") << tst_messaging::QMessaging << tst_messaging::AllId; |
|
1089 QTest::newRow("Qt-AllSender") << tst_messaging::QMessaging << tst_messaging::AllSender; |
|
1090 |
|
1091 QTest::newRow("Native-Id") << tst_messaging::Native << tst_messaging::Id; |
|
1092 QTest::newRow("Native-Type") << tst_messaging::Native << tst_messaging::Type; |
|
1093 QTest::newRow("Native-Sender") << tst_messaging::Native << tst_messaging::Sender; |
|
1094 QTest::newRow("Native-Subject") << tst_messaging::Native << tst_messaging::Subject; |
|
1095 QTest::newRow("Native-TimeStamp") << tst_messaging::Native << tst_messaging::TimeStamp; |
|
1096 QTest::newRow("Native-Status") << tst_messaging::Native << tst_messaging::Status; |
|
1097 QTest::newRow("Native-Priority") << tst_messaging::Native << tst_messaging::Priority; |
|
1098 QTest::newRow("Native-Size") << tst_messaging::Native << tst_messaging::Size; |
|
1099 QTest::newRow("Native-AllId") << tst_messaging::Native << tst_messaging::AllId; |
|
1100 QTest::newRow("Native-AllSender") << tst_messaging::Native << tst_messaging::AllSender; |
|
1101 |
|
1102 // QTest::newRow("Native-Size") << tst_messaging::Native << tst_messaging::Size; |
|
1103 } |
|
1104 |
|
1105 void tst_messaging::tst_fetchFilter() |
|
1106 { |
|
1107 QFETCH(tst_messaging::platform, platform); |
|
1108 QFETCH(tst_messaging::filter, filter); |
|
1109 |
|
1110 if(platform == tst_messaging::QMessaging){ |
|
1111 |
|
1112 QMessageId msgId; |
|
1113 QMessageFilter mf; |
|
1114 QMessageId id; |
|
1115 // let's assume we want equal tests for all the filters. |
|
1116 // So let's try and filter out 1 message from each filter request. |
|
1117 if(filter == tst_messaging::Id){ |
|
1118 mf = QMessageFilter::byId(id); |
|
1119 msg_list.push_back(id); |
|
1120 } |
|
1121 else if(filter == tst_messaging::Type){ |
|
1122 QMessage *msg = messageTemplate(); |
|
1123 // XXX this segfault |
|
1124 //msg->setType(QMessage::Sms); |
|
1125 |
|
1126 msgId = addMessage(msg); |
|
1127 mf = QMessageFilter::byType(QMessage::Sms); |
|
1128 |
|
1129 } |
|
1130 else if(filter == tst_messaging::Sender){ |
|
1131 QString email = "singletst@boo.com"; |
|
1132 QMessage *msg = messageTemplate(); |
|
1133 QMessageAddress addr; |
|
1134 addr.setAddressee(email); |
|
1135 msg->setFrom(addr); |
|
1136 msgId = addMessage(msg); |
|
1137 |
|
1138 id = msg_list.takeFirst(); |
|
1139 mf = QMessageFilter::bySender(email); |
|
1140 } |
|
1141 else if(filter == tst_messaging::TimeStamp){ |
|
1142 QMessage *msg = messageTemplate(); |
|
1143 QDateTime dt = QDateTime::currentDateTime(); |
|
1144 dt.addDays(1); |
|
1145 msg->setReceivedDate(dt); |
|
1146 msg->setDate(dt); |
|
1147 msgId = addMessage(msg); |
|
1148 |
|
1149 mf = QMessageFilter::byTimeStamp(dt, QMessageDataComparator::Equal); |
|
1150 } |
|
1151 else if(filter == tst_messaging::Status){ |
|
1152 QMessage *msg = messageTemplate(); |
|
1153 msg->setStatus(QMessage::Incoming); |
|
1154 msgId = addMessage(msg); |
|
1155 |
|
1156 mf = QMessageFilter::byStatus(QMessage::Incoming); |
|
1157 } |
|
1158 else if(filter == tst_messaging::Subject){ |
|
1159 QMessage *msg = messageTemplate(); |
|
1160 QString subject = "skdflkdsjfl sdfklke werewr"; |
|
1161 msg->setSubject(subject); |
|
1162 msgId = addMessage(msg); |
|
1163 |
|
1164 mf = QMessageFilter::bySubject(subject); |
|
1165 } |
|
1166 else if(filter == tst_messaging::Priority){ |
|
1167 QMessage *msg = messageTemplate(); |
|
1168 msg->setPriority(QMessage::LowPriority); |
|
1169 msgId = addMessage(msg); |
|
1170 |
|
1171 mf = QMessageFilter::byPriority(QMessage::LowPriority); |
|
1172 } |
|
1173 else if(filter == tst_messaging::Size){ |
|
1174 QString body; |
|
1175 body.fill('x', 5120); |
|
1176 QMessage *msg = messageTemplate(); |
|
1177 msg->setBody(body); |
|
1178 msgId = addMessage(msg); |
|
1179 |
|
1180 mf = QMessageFilter::bySize(5000, QMessageDataComparator::GreaterThan); |
|
1181 } |
|
1182 else if(filter == tst_messaging::AllId){ |
|
1183 mf = QMessageFilter::byId(msg_list); |
|
1184 } |
|
1185 else if(filter == tst_messaging::AllSender){ |
|
1186 id = msg_list.takeFirst(); |
|
1187 msg_list.push_back(id); |
|
1188 QMessage msg = m_mgr->message(id); |
|
1189 |
|
1190 mf = QMessageFilter::bySender(msg.from().addressee()); |
|
1191 } |
|
1192 if(!mf.isSupported()){ |
|
1193 QFAIL("QMessage filter returned unsupported"); |
|
1194 } |
|
1195 else if(mf.isEmpty()){ |
|
1196 QFAIL("Empty filter provided"); |
|
1197 } |
|
1198 else { |
|
1199 QMessageIdList list; |
|
1200 QMessageSortOrder sortOrder(QMessageSortOrder::byReceptionTimeStamp(Qt::DescendingOrder)); |
|
1201 |
|
1202 QBENCHMARK { |
|
1203 list = m_mgr->queryMessages(mf, sortOrder, 100); |
|
1204 } |
|
1205 |
|
1206 if(list.count() != 1 && filter != tst_messaging::AllId && filter != tst_messaging::AllSender) |
|
1207 qDebug() << "Wanted 1 message got: " << list.count(); |
|
1208 } |
|
1209 |
|
1210 if(msgId.isValid()){ |
|
1211 m_mgr->removeMessage(msgId); |
|
1212 } |
|
1213 } |
|
1214 else if(platform == tst_messaging::Native){ |
|
1215 #ifdef Q_OS_SYMBIAN |
|
1216 if(filter == tst_messaging::Id){ |
|
1217 // Access the Inbox |
|
1218 QBENCHMARK { |
|
1219 TMsvSelectionOrdering sort; |
|
1220 //sort.SetSorting(EMsvSortByDateReverse); |
|
1221 sort.SetSorting(EMsvSortById); |
|
1222 sort.SetShowInvisibleEntries(ETrue); |
|
1223 |
|
1224 CMsvEntry* inboxContext = CMsvEntry::NewL(*m_native->iSession, |
|
1225 KMsvGlobalInBoxIndexEntryId, sort); |
|
1226 CleanupStack::PushL(inboxContext); |
|
1227 |
|
1228 // Get all entries in the Inbox |
|
1229 CMsvEntrySelection* entries = inboxContext->ChildrenL(); |
|
1230 CleanupStack::PushL(entries); |
|
1231 |
|
1232 TMsvId entryID = entries->At(0); |
|
1233 |
|
1234 const TUid mtm = inboxContext->ChildDataL(entryID).iMtm; |
|
1235 |
|
1236 CleanupStack::PopAndDestroy(2, inboxContext); |
|
1237 } |
|
1238 } |
|
1239 else if(filter == tst_messaging::Type){ // look for SMS messages |
|
1240 // Access the Inbox |
|
1241 RArray<TMsvId> msvids; |
|
1242 RArray<TMsvId> aFolders; |
|
1243 |
|
1244 m_native->getFolders(aFolders); |
|
1245 |
|
1246 //qDebug() << "Total folders: " << aFolders.Count(); |
|
1247 |
|
1248 QBENCHMARK { |
|
1249 msvids.Close(); // zero it out |
|
1250 for(int i = 0; i < aFolders.Count(); i++){ |
|
1251 |
|
1252 TMsvSelectionOrdering sort; |
|
1253 //sort.SetSorting(EMsvSortByDateReverse); |
|
1254 sort.SetSorting(EMsvSortByNone); |
|
1255 sort.SetShowInvisibleEntries(ETrue); |
|
1256 |
|
1257 CMsvEntry* inboxContext = CMsvEntry::NewL(*m_native->iSession, |
|
1258 aFolders[i], sort); |
|
1259 CleanupStack::PushL(inboxContext); |
|
1260 |
|
1261 // Get all entries in the Inbox |
|
1262 CMsvEntrySelection* entries = inboxContext->ChildrenL(); |
|
1263 CleanupStack::PushL(entries); |
|
1264 |
|
1265 for (TInt j = 0; j < entries->Count(); j++) { |
|
1266 TMsvId entryID = entries->At(j); |
|
1267 const TUid mtm = inboxContext->ChildDataL(entryID).iMtm; |
|
1268 |
|
1269 if (mtm == KUidMsgTypeSMS) { |
|
1270 msvids.AppendL(entryID); |
|
1271 } |
|
1272 } |
|
1273 CleanupStack::PopAndDestroy(2, inboxContext); |
|
1274 } |
|
1275 } |
|
1276 msvids.Close(); |
|
1277 } |
|
1278 else if(filter == tst_messaging::Sender || |
|
1279 filter == tst_messaging::Subject || |
|
1280 filter == tst_messaging::TimeStamp){ |
|
1281 // Access the Inbox |
|
1282 |
|
1283 TMsvPartList part = KMsvMessagePartDescription; |
|
1284 TPtrC text = _L("tst"); |
|
1285 |
|
1286 if(filter == tst_messaging::Sender){ |
|
1287 part = KMsvMessagePartOriginator; |
|
1288 text.Set(_L("Millicent")); |
|
1289 } |
|
1290 else if(filter == tst_messaging::Subject){ |
|
1291 part = KMsvMessagePartDescription; |
|
1292 text.Set(_L("Free Bottle")); |
|
1293 } |
|
1294 else if(filter == tst_messaging::TimeStamp){ |
|
1295 part = KMsvMessagePartDate; |
|
1296 text.Set(_L("Sep")); |
|
1297 } |
|
1298 |
|
1299 CMsvOperationActiveSchedulerWait* waiter=CMsvOperationActiveSchedulerWait::NewLC(); |
|
1300 |
|
1301 CMsvFindOperation *finder = CMsvFindOperation::FindInChildrenL(*m_native->iSession, text, KMsvRootIndexEntryId, part, waiter->iStatus); |
|
1302 CleanupStack::PushL(finder); |
|
1303 |
|
1304 QBENCHMARK { |
|
1305 waiter->Start(); |
|
1306 } |
|
1307 if(finder->GetFindResult().Count() != 1) |
|
1308 qDebug() << "Wanted 1 message, got: " << finder->GetFindResult().Count(); |
|
1309 |
|
1310 // qDebug() << "Status: " << finder->GetFindResult().Count(); |
|
1311 // for(int i = 0; i < finder->GetFindResult().Count(); i++){ |
|
1312 // CMsvEntry *pEntry; |
|
1313 // TRAPD(err, pEntry = m_native->iSession->GetEntryL(finder->GetFindResult().At(i).iId)); |
|
1314 // if(err){ |
|
1315 // qDebug() << "Failed to fetch: " << i << " - " << finder->GetFindResult().At(i).iId; |
|
1316 // continue; |
|
1317 // } |
|
1318 // CleanupStack::PushL(pEntry); |
|
1319 // TMsvEntry entry = pEntry->Entry(); |
|
1320 // QString details = QString::fromUtf16(entry.iDetails.Ptr(),entry.iDetails.Length()); |
|
1321 // QString desc = QString::fromUtf16(entry.iDescription.Ptr(),entry.iDescription.Length()); |
|
1322 // qDebug() << "Got entry: " << details << " - " << desc; |
|
1323 // CleanupStack::PopAndDestroy(1); // |
|
1324 // } |
|
1325 |
|
1326 CleanupStack::PopAndDestroy(2, waiter); |
|
1327 |
|
1328 } |
|
1329 else if(filter == tst_messaging::Priority) { |
|
1330 RArray<TMsvId> msvids; |
|
1331 |
|
1332 CMsvOperationActiveSchedulerWait* waiter=CMsvOperationActiveSchedulerWait::NewLC(); |
|
1333 |
|
1334 TBufC<10> null(_L(" ")); |
|
1335 CMsvFindOperation *finder = CMsvFindOperation::FindInChildrenL(*m_native->iSession, null, KMsvRootIndexEntryId, KMsvMessagePartDescription, waiter->iStatus); |
|
1336 CleanupStack::PushL(finder); |
|
1337 |
|
1338 QBENCHMARK { |
|
1339 waiter->Start(); |
|
1340 |
|
1341 const CMsvFindResultSelection &res = finder->GetFindResult(); |
|
1342 |
|
1343 for(int i = 0; i < res.Count(); i++){ |
|
1344 CMsvEntry *pEntry; |
|
1345 TRAPD(err, pEntry = m_native->iSession->GetEntryL(res.At(i).iId)); |
|
1346 if(err){ |
|
1347 qDebug() << "Failed to fetch: " << i << " - " << res.At(i).iId; |
|
1348 continue; |
|
1349 } |
|
1350 CleanupStack::PushL(pEntry); |
|
1351 TMsvEntry entry = pEntry->Entry(); |
|
1352 |
|
1353 if(entry.Priority() == EMsvLowPriority) |
|
1354 msvids.Append(entry.Id()); |
|
1355 |
|
1356 CleanupStack::PopAndDestroy(1); // |
|
1357 } |
|
1358 } |
|
1359 msvids.Close(); |
|
1360 CleanupStack::PopAndDestroy(2, waiter); |
|
1361 } |
|
1362 else if(filter == tst_messaging::Size){ |
|
1363 RArray<TMsvId> msvids; |
|
1364 |
|
1365 CMsvOperationActiveSchedulerWait* waiter=CMsvOperationActiveSchedulerWait::NewLC(); |
|
1366 |
|
1367 TBufC<10> null(_L(" ")); |
|
1368 CMsvFindOperation *finder = CMsvFindOperation::FindInChildrenL(*m_native->iSession, null, KMsvRootIndexEntryId, KMsvMessagePartDescription, waiter->iStatus); |
|
1369 CleanupStack::PushL(finder); |
|
1370 |
|
1371 QBENCHMARK { |
|
1372 waiter->Start(); |
|
1373 |
|
1374 const CMsvFindResultSelection &res = finder->GetFindResult(); |
|
1375 |
|
1376 for(int i = 0; i < res.Count(); i++){ |
|
1377 CMsvEntry *pEntry; |
|
1378 TRAPD(err, pEntry = m_native->iSession->GetEntryL(res.At(i).iId)); |
|
1379 if(err){ |
|
1380 qDebug() << "Failed to fetch: " << i << " - " << res.At(i).iId; |
|
1381 continue; |
|
1382 } |
|
1383 CleanupStack::PushL(pEntry); |
|
1384 TMsvEntry entry = pEntry->Entry(); |
|
1385 |
|
1386 if(entry.iSize == 550) |
|
1387 msvids.Append(entry.Id()); |
|
1388 |
|
1389 CleanupStack::PopAndDestroy(1); // |
|
1390 } |
|
1391 } |
|
1392 msvids.Close(); |
|
1393 CleanupStack::PopAndDestroy(2, waiter); |
|
1394 } |
|
1395 if(filter == tst_messaging::AllId){ |
|
1396 // Access the Inbox |
|
1397 QBENCHMARK { |
|
1398 RArray<TMsvId> msvids; |
|
1399 |
|
1400 TMsvSelectionOrdering sort; |
|
1401 //sort.SetSorting(EMsvSortByDateReverse); |
|
1402 sort.SetSorting(EMsvSortById); |
|
1403 sort.SetShowInvisibleEntries(ETrue); |
|
1404 |
|
1405 CMsvEntry* inboxContext = CMsvEntry::NewL(*m_native->iSession, |
|
1406 KMsvGlobalInBoxIndexEntryId, sort); |
|
1407 CleanupStack::PushL(inboxContext); |
|
1408 |
|
1409 // Get all entries in the Inbox |
|
1410 CMsvEntrySelection* entries = inboxContext->ChildrenL(); |
|
1411 CleanupStack::PushL(entries); |
|
1412 |
|
1413 for(int i = 0; i < entries->Count(); i++){ |
|
1414 msvids.Append(entries->At(i)); |
|
1415 } |
|
1416 |
|
1417 msvids.Close(); |
|
1418 |
|
1419 CleanupStack::PopAndDestroy(2, inboxContext); |
|
1420 } |
|
1421 } |
|
1422 else if(filter == tst_messaging::AllSender){ |
|
1423 RArray<TMsvId> msvids; |
|
1424 |
|
1425 CMsvOperationActiveSchedulerWait* waiter=CMsvOperationActiveSchedulerWait::NewLC(); |
|
1426 |
|
1427 TBufC<10> null(_L("@")); |
|
1428 CMsvFindOperation *finder = CMsvFindOperation::FindInChildrenL(*m_native->iSession, null, KMsvRootIndexEntryId, KMsvMessagePartOriginator, waiter->iStatus); |
|
1429 CleanupStack::PushL(finder); |
|
1430 |
|
1431 QBENCHMARK { |
|
1432 waiter->Start(); |
|
1433 |
|
1434 const CMsvFindResultSelection &res = finder->GetFindResult(); |
|
1435 TMsvSelectionOrdering order; |
|
1436 |
|
1437 CMsvEntry *pEntry = CMsvEntry::NewL(*m_native->iSession, KMsvRootIndexEntryId, TMsvSelectionOrdering(KMsvNoGrouping, EMsvSortByNone)); |
|
1438 CleanupStack::PushL(pEntry); |
|
1439 |
|
1440 for(int i = 0; i < res.Count(); i++){ |
|
1441 TRAPD(err, pEntry->SetEntryL(res.At(i).iId)); |
|
1442 if(err){ |
|
1443 qDebug() << "Failed to fetch: " << i << " - " << res.At(i).iId; |
|
1444 continue; |
|
1445 } |
|
1446 TMsvEntry entry = pEntry->Entry(); |
|
1447 |
|
1448 msvids.Append(entry.Id()); |
|
1449 |
|
1450 } |
|
1451 |
|
1452 CleanupStack::PopAndDestroy(pEntry); |
|
1453 } |
|
1454 msvids.Close(); |
|
1455 CleanupStack::PopAndDestroy(2, waiter); |
|
1456 } |
|
1457 #endif |
|
1458 } |
|
1459 } |
|
1460 |
|
1461 void tst_messaging::clearMessages() |
|
1462 { |
|
1463 QMessageId id; |
|
1464 while(!msg_list.empty()) |
|
1465 m_mgr->removeMessage(msg_list.takeFirst()); |
|
1466 } |
|
1467 |
|
1468 QMessage *tst_messaging::messageTemplate() |
|
1469 { |
|
1470 QMessage *msg = new QMessage; |
|
1471 |
|
1472 msg->setDate(QDateTime::currentDateTime()); |
|
1473 msg->setSubject("test"); |
|
1474 QMessageAddress addr; |
|
1475 addr.setAddressee("abr@foo.com"); |
|
1476 addr.setType(QMessageAddress::Email); |
|
1477 msg->setTo(addr); |
|
1478 addr.setAddressee("from@bar.com"); |
|
1479 addr.setType(QMessageAddress::Email); |
|
1480 msg->setFrom(addr); |
|
1481 |
|
1482 // XXX one or more of these cause problems |
|
1483 // msg->setType(QMessage::Email); |
|
1484 // msg->setStatus(QMessage::Read); |
|
1485 |
|
1486 // msg->setBody("I have a body!"); |
|
1487 // msg->setParentAccountId(m_fol.parentAccountId()); |
|
1488 |
|
1489 return msg; |
|
1490 } |
|
1491 |
|
1492 QMessageId tst_messaging::addMessage(QMessage *msg) |
|
1493 { |
|
1494 m_mgr->addMessage(msg); |
|
1495 msg_list.append(msg->id()); |
|
1496 |
|
1497 //qDebug() << "id: " << msg->id().toString(); |
|
1498 |
|
1499 return msg->id(); |
|
1500 } |
|
1501 |
|
1502 QMessage *tst_messaging::createMessage() |
|
1503 { |
|
1504 QMessage *msg = messageTemplate(); |
|
1505 addMessage(msg); |
|
1506 return msg; |
|
1507 } |
|
1508 |
|
1509 int tst_messaging::countMessages() |
|
1510 { |
|
1511 QMessageIdList list; |
|
1512 list = m_mgr->queryMessages(); |
|
1513 return list.count(); |
|
1514 } |
|
1515 |
|
1516 void tst_messaging::tst_addMessage_data() |
|
1517 { |
|
1518 QTest::addColumn<tst_messaging::platform>("platform"); |
|
1519 QTest::addColumn<tst_messaging::types>("type"); |
|
1520 |
|
1521 QTest::newRow("Qt-Email") << tst_messaging::QMessaging << tst_messaging::Email; |
|
1522 QTest::newRow("Native-SMS") << tst_messaging::Native << tst_messaging::Sms; |
|
1523 QTest::newRow("Native-Email") << tst_messaging::Native << tst_messaging::Email; |
|
1524 |
|
1525 } |
|
1526 |
|
1527 void tst_messaging::tst_addMessage() |
|
1528 { |
|
1529 QFETCH(tst_messaging::platform, platform); |
|
1530 QFETCH(tst_messaging::types, type); |
|
1531 |
|
1532 if(platform == tst_messaging::QMessaging){ |
|
1533 QBENCHMARK { |
|
1534 QMessage *msg = createMessage(); |
|
1535 addMessage(msg); |
|
1536 } |
|
1537 } |
|
1538 else if(platform == tst_messaging::Native){ |
|
1539 #ifdef Q_OS_SYMBIAN |
|
1540 if(type == tst_messaging::Sms){ |
|
1541 TMsvId id; |
|
1542 QBENCHMARK { |
|
1543 id = m_native->makeSMS(KMsvDraftEntryIdValue); |
|
1544 } |
|
1545 m_native->iNewMsgs.Append(id); |
|
1546 } |
|
1547 else if(type == tst_messaging::Email){ |
|
1548 TMsvId id; |
|
1549 QBENCHMARK { |
|
1550 m_native->makeIMAP4(KMsvDraftEntryIdValue); |
|
1551 } |
|
1552 m_native->iNewMsgs.Append(id); |
|
1553 } |
|
1554 #else |
|
1555 Q_UNUSED(type); |
|
1556 #endif |
|
1557 } |
|
1558 |
|
1559 } |
|
1560 |
|
1561 void tst_messaging::tst_removeMessage_data() |
|
1562 { |
|
1563 QTest::addColumn<tst_messaging::platform>("platform"); |
|
1564 |
|
1565 QTest::newRow("Qt-remove") << tst_messaging::QMessaging; |
|
1566 QTest::newRow("Native-remove") << tst_messaging::Native; |
|
1567 } |
|
1568 |
|
1569 void tst_messaging::tst_removeMessage() |
|
1570 { |
|
1571 QFETCH(tst_messaging::platform, platform); |
|
1572 |
|
1573 if(platform == tst_messaging::QMessaging){ |
|
1574 #ifdef Q_OS_SYMBIAN |
|
1575 TMsvId id; |
|
1576 id = m_native->makeIMAP4(KMsvDraftEntryIdValue); |
|
1577 QString str; |
|
1578 str.setNum(id); |
|
1579 QMessageId qmid = str; |
|
1580 #else |
|
1581 QMessageId qmid = msg_list.takeFirst(); |
|
1582 #endif |
|
1583 |
|
1584 QBENCHMARK_ONCE { |
|
1585 m_mgr->removeMessage(qmid); |
|
1586 } |
|
1587 } |
|
1588 else if(platform == tst_messaging::Native){ |
|
1589 #ifdef Q_OS_SYMBIAN |
|
1590 TMsvId id; |
|
1591 id = m_native->makeIMAP4(KMsvDraftEntryIdValue); |
|
1592 CMsvEntry *pEntry = CMsvEntry::NewL(*m_native->iSession, id, TMsvSelectionOrdering()); |
|
1593 CleanupStack::PushL(pEntry); |
|
1594 QBENCHMARK_ONCE { // We're only guaranteed one entry to delete. Not a fast process anyways.s |
|
1595 TRAPD(err, pEntry->DeleteL(id)); // slightly dangerous since we never want this failing, but it can fail too something, should debug TODO |
|
1596 if(err){ |
|
1597 QFAIL(QString("Message delete failed with error: " + QString::number(err)).toAscii()); |
|
1598 } |
|
1599 } |
|
1600 CleanupStack::PopAndDestroy(pEntry); |
|
1601 #endif |
|
1602 } |
|
1603 |
|
1604 } |
|
1605 |
|
1606 void tst_messaging::tst_removeAllMessage_data() |
|
1607 { |
|
1608 QTest::addColumn<tst_messaging::platform>("platform"); |
|
1609 |
|
1610 QTest::newRow("Qt-removeAll") << tst_messaging::QMessaging; |
|
1611 QTest::newRow("Native-removeAll") << tst_messaging::Native; |
|
1612 } |
|
1613 |
|
1614 void tst_messaging::tst_removeAllMessage() |
|
1615 { |
|
1616 QFETCH(tst_messaging::platform, platform); |
|
1617 |
|
1618 if(platform == tst_messaging::QMessaging){ |
|
1619 QBENCHMARK { |
|
1620 while(!msg_list.empty()) |
|
1621 m_mgr->removeMessage(msg_list.takeFirst()); |
|
1622 } |
|
1623 } |
|
1624 else if(platform == tst_messaging::Native){ |
|
1625 #ifdef Q_OS_SYMBIAN |
|
1626 // make sure there's enough messages to delete |
|
1627 while(m_native->iNewMsgs.Count() < 30) { |
|
1628 TMsvId id; |
|
1629 id = m_native->makeSMS(KMsvDraftEntryIdValue); |
|
1630 m_native->iNewMsgs.Append(id); |
|
1631 } |
|
1632 |
|
1633 QBENCHMARK { |
|
1634 CMsvEntry *pEntry; |
|
1635 TRAPD(err, pEntry = CMsvEntry::NewL(*m_native->iSession, KMsvRootIndexEntryId, TMsvSelectionOrdering())); |
|
1636 if(err){ |
|
1637 qDebug() << "Failed to init CMsvEntryL " << err; |
|
1638 return; |
|
1639 } |
|
1640 CleanupStack::PushL(pEntry); |
|
1641 while(m_native->iNewMsgs.Count() != 0) { |
|
1642 TMsvId id = m_native->iNewMsgs[0]; |
|
1643 m_native->iNewMsgs.Remove(0); |
|
1644 //pEntry->SetEntryL(id); |
|
1645 TRAP_IGNORE(pEntry->DeleteL(id)); |
|
1646 } |
|
1647 CleanupStack::PopAndDestroy(pEntry); |
|
1648 } |
|
1649 #endif |
|
1650 } |
|
1651 |
|
1652 } |
|
1653 |
|
1654 #if defined(Q_OS_SYMBIAN) |
|
1655 |
|
1656 void OsNative::getFolders(RArray<TMsvId> &folders) { |
|
1657 __UHEAP_MARK; |
|
1658 |
|
1659 CEmailAccounts *email = CEmailAccounts::NewLC(); |
|
1660 RArray<TPopAccount> aPop; |
|
1661 RArray<TImapAccount> aImap; |
|
1662 RArray<TSmtpAccount> aSmtp; |
|
1663 |
|
1664 #ifndef KDocumentsEntryIdValue |
|
1665 #define KDocumentsEntryIdValue 0x1008 |
|
1666 #endif |
|
1667 |
|
1668 folders.Append(KMsvRootIndexEntryId); |
|
1669 folders.Append(KMsvLocalServiceIndexEntryId); |
|
1670 folders.Append(KMsvGlobalInBoxIndexEntryId); |
|
1671 folders.Append(KMsvGlobalOutBoxIndexEntryId); |
|
1672 folders.Append(KMsvDraftEntryId); |
|
1673 folders.Append(KMsvSentEntryId); |
|
1674 folders.Append(KMsvDeletedEntryFolderEntryId); |
|
1675 folders.Append(KDocumentsEntryIdValue); |
|
1676 |
|
1677 email->GetPopAccountsL(aPop); |
|
1678 email->GetImapAccountsL(aImap); |
|
1679 email->GetSmtpAccountsL(aSmtp); |
|
1680 |
|
1681 RArray<TMsvId> aService; |
|
1682 |
|
1683 for(int i = 0; i < aPop.Count(); i++){ |
|
1684 aService.Append(aPop[i].iPopService); |
|
1685 } |
|
1686 for(int i = 0; i < aImap.Count(); i++){ |
|
1687 aService.Append(aImap[i].iImapService); |
|
1688 } |
|
1689 for(int i = 0; i < aSmtp.Count(); i++){ |
|
1690 aService.Append(aSmtp[i].iSmtpService); |
|
1691 } |
|
1692 |
|
1693 TSmtpAccount sacc; |
|
1694 if(email->DefaultSmtpAccountL(sacc)) |
|
1695 aService.Append(sacc.iSmtpService); |
|
1696 |
|
1697 if(aService.Count() == 0) |
|
1698 QFAIL("No folders avaailable to query"); |
|
1699 |
|
1700 CMsvEntry* pEntry = NULL; |
|
1701 pEntry = iSession->GetEntryL(aService[0]); |
|
1702 CleanupStack::PushL(pEntry); |
|
1703 |
|
1704 for(int i = 0; i < aService.Count(); i++){ |
|
1705 TMsvId msvid = aService[i]; |
|
1706 |
|
1707 pEntry->SetEntryL(msvid); // faster to call set, saves .2ms out of 2.7ms. |
|
1708 |
|
1709 const TMsvEntry& entry = pEntry->Entry(); |
|
1710 |
|
1711 CMsvEntryFilter* pFilter = CMsvEntryFilter::NewLC(); |
|
1712 pFilter->SetService(msvid); |
|
1713 pFilter->SetType(KUidMsvFolderEntry); |
|
1714 |
|
1715 CMsvEntrySelection* pSelection = new(ELeave) CMsvEntrySelection; |
|
1716 CleanupStack::PushL(pSelection); |
|
1717 |
|
1718 if (entry.iMtm == KUidMsgTypeSMS || entry.iMtm == KUidMsgTypeMultimedia || entry.iMtm == KUidMsgTypeSMTP) |
|
1719 pEntry->SetEntryL(KDocumentsEntryIdValue); |
|
1720 |
|
1721 //iSession->GetChildIdsL(pEntry->Entry().Id(), *pFilter, *pSelection); |
|
1722 iSession->GetChildIdsL(pEntry->Entry().Id(), *pFilter, *pSelection); |
|
1723 |
|
1724 for(TInt i = 0; i < pSelection->Count(); i++) { |
|
1725 folders.Append(pSelection->At(i)); |
|
1726 } |
|
1727 |
|
1728 CleanupStack::PopAndDestroy(pSelection); |
|
1729 CleanupStack::PopAndDestroy(pFilter); |
|
1730 |
|
1731 } |
|
1732 |
|
1733 aPop.Close(); |
|
1734 aImap.Close(); |
|
1735 aSmtp.Close(); |
|
1736 aService.Close(); |
|
1737 |
|
1738 CleanupStack::PopAndDestroy(pEntry); |
|
1739 CleanupStack::PopAndDestroy(email); |
|
1740 __UHEAP_MARKEND; |
|
1741 } |
|
1742 #endif |
|
1743 |
|
1744 int main(int argc, char **argv){ |
|
1745 |
|
1746 QApplication app(argc, argv); |
|
1747 |
|
1748 tst_messaging test1; |
|
1749 QTest::qExec(&test1, argc, argv); |
|
1750 |
|
1751 } |
|
1752 //QTEST_MAIN(tst_messaging); |
|
1753 |
|
1754 |
|
1755 #include "tst_messaging.moc" |
|
1756 |