--- a/qtmobility/tests/benchmarks/contacts/tst_bm_contacts.cpp Fri Jun 11 14:26:25 2010 +0300
+++ b/qtmobility/tests/benchmarks/contacts/tst_bm_contacts.cpp Wed Jun 23 19:08:38 2010 +0300
@@ -64,30 +64,45 @@
QTM_USE_NAMESPACE
-//Q_DECLARE_METATYPE(QSystemInfo::Version);
-//Q_DECLARE_METATYPE(QSystemInfo::Feature);
-
class tst_Contact : public QObject
{
Q_OBJECT
+public:
+ enum platform {
+ QContacts,
+ Native
+ };
+
+
private slots:
void initTestCase();
void cleanupTestCase();
+ void tst_createTime_data();
void tst_createTime();
+ void tst_fetchAllContactIds_data();
void tst_fetchAllContactIds();
+ void tst_fetchOneContact_data();
void tst_fetchOneContact();
+ void tst_fetchTenContact_data();
void tst_fetchTenContact();
//void tst_fetchAllContact();
- void tst_createContact();
- void tst_saveContact();
+ void tst_createContact_data();
+ void tst_createContact();
+
+ void tst_saveContact_data();
+ void tst_saveContact();
+ void tst_nameFilter_data();
void tst_nameFilter();
+ void tst_removeOneContact_data();
void tst_removeOneContact();
+
+ void tst_removeAllContacts_data();
void tst_removeAllContacts();
@@ -107,20 +122,19 @@
void timeout();
void resultsAvailable();
void resultsAvailableFilter();
- void setBackend(QString);
+ //void setManager(QContactManager *mgr);
private:
- void createContact();
- void clearContacts();
- int countContacts();
-
- enum {
- BackendQContacts,
- BackendContactsModel
- } m_backend;
+ void createContact(QContactManager *mgr, enum platform p = QContacts);
+ void clearContacts(QContactManager *mgr, enum platform p = QContacts);
+ int countContacts(QContactManager *mgr, enum platform p = QContacts);
+
QString manager;
QEventLoop *loop;
- QContactManager *m_qm;
+// QContactManager *m_qm;
+ QContactManager *m_systemManager;
+ QList<QContactManager *> m_managers;
+// enum platform m_platform;
int m_num_contacts;
QList<QContactLocalId> id_list;
@@ -134,74 +148,36 @@
};
-void tst_Contact::setBackend(QString backend)
-{
- manager = backend;
- if(manager == "SymbianContactsModel") // Only one at the moment
- m_backend = BackendContactsModel;
- else
- m_backend = BackendQContacts;
- qWarning() << "Backend set to: " << manager;
-}
+Q_DECLARE_METATYPE(QContactManager *);
+Q_DECLARE_METATYPE(tst_Contact::platform);
void tst_Contact::initTestCase()
-{
+{
qDebug() << "Managers: " << QContactManager::availableManagers();
m_run = 0;
-
-#if defined(Q_WS_MAEMO_6)
- QStringList list = QContactManager::availableManagers();
- int found = 0;
- while(!list.empty()){
- if(list.takeFirst() == "tracker"){
- found = 1;
- break;
- }
- }
- if(!found)
- QFAIL("Unable to find Maemo 6 tracker plugin. Please check install");
+ m_systemManager = 0x0;
- if(manager.isEmpty())
- manager = "memory";
- m_qm = new QContactManager(manager);
-#elif defined(Q_WS_MAEMO_5)
- if(manager.isEmpty()){
- //Looking for a manager
- QStringList list = QContactManager::availableManagers();
- if (list.contains("maemo5")){
- manager = "maemo5";
- } else {
- QFAIL("Unable to find Maemo 5 plugin. Please check install");
+ QStringList list = QContactManager::availableManagers();
+ while(!list.empty()){
+ QString mgr = list.takeFirst();
+ if((mgr != "invalid") && (mgr != "testdummy") && (mgr != "maliciousplugin")){
+ m_managers.append(new QContactManager(mgr));
+ if((mgr == "symbian") || (mgr == "tracker") || (mgr == "maemo5")) {
+ qDebug() << "Found system manager: " << mgr;
+ m_systemManager = m_managers.last();
}
+ if(!m_systemManager && mgr == "memory"){
+ qDebug() << "Found system manager of last resort: " << mgr;
+ m_systemManager = m_managers.last();
+ }
+ }
}
- m_qm = new QContactManager(manager);
-
-#elif defined(Q_OS_SYMBIAN)
- if(m_backend != BackendContactsModel) {
- QStringList list = QContactManager::availableManagers();
- int found = 0;
- while(!list.empty()){
- if(list.takeFirst() == "symbian"){
- found = 1;
- break;
- }
- }
- if(!found) {
- QFAIL("Unable to find Symbian plugin. Please check install");
- }
-
- if(manager.isEmpty()) {
- manager = "symbian";
- }
- m_qm = new QContactManager(manager);
+ if(m_managers.isEmpty()) {
+ QFAIL("Unable to find valid managers. Please check install");
}
- else {
- m_qm = 0x0;
+ if(!m_systemManager){
+ QFAIL("Unable to find a default plugin to use, please install plugins or fix test");
}
-#else
- QFAIL("Platform not supported");
-#endif
-
// setup an event loop for waiting
loop = new QEventLoop;
@@ -209,15 +185,17 @@
firstNames << "Anahera" << "Anaru" << "Hemi" << "Hine" << "Kiri" << "Maata" << "Mere" << "Moana" << "Paora" << "Petera" << "Piripi" << "Ruiha" << "Tane" << "Whetu";
lastNames << "Ati Awa" << "Kai Taho" << "Moriori" << "Muaupoko" << "Nga Rauru" << "Taranaki" << "Opotoki" << "Aotea" << "Taninui" << "Tuhourangi" << "Tainui" << "Waitaha";
- m_num_start = countContacts();
+ m_num_start = countContacts(m_systemManager);
qDebug() << "Number of Contact: " << m_num_start;
for(int i = 0; i < 20; i++){
- createContact();
+ foreach(QContactManager *mgr, m_managers){
+ createContact(mgr);
+ }
}
- int after = countContacts();
+ int after = countContacts(m_systemManager);
if(after - m_num_start != 20){
qWarning() << "Failed to create 20 contacts";
}
@@ -227,12 +205,13 @@
}
-int tst_Contact::countContacts()
+int tst_Contact::countContacts(QContactManager *manager, enum platform platform)
{
- if(m_backend == BackendQContacts) {
- QList<QContactLocalId> qcl = m_qm->contactIds();
+ if(platform == tst_Contact::QContacts) {
+ QList<QContactLocalId> qcl = manager->contactIds();
return qcl.count();
- } else if(m_backend == BackendContactsModel){
+ }
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
CContactDatabase* contactsDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactsDb);
@@ -252,94 +231,232 @@
void tst_Contact::cleanupTestCase()
{
- clearContacts();
- int num_end = countContacts();
- if(m_num_start != num_end){
- QFAIL(QString("Number of contacts ending: %2 is different that starting number %1. Poor cleanup").arg(m_num_start).arg(num_end).toAscii());
- }
+ foreach(QContactManager *manager, m_managers) {
+ clearContacts(manager);
+ }
+ if(countContacts(0x0, Native))
+ clearContacts(0x0, tst_Contact::Native);
+ int num_end = countContacts(0x0, tst_Contact::Native);
+ if(num_end){
+ qWarning() << "Ended with: " << num_end << " contacts, should be 0";
+ }
}
-void tst_Contact::clearContacts()
+void tst_Contact::createContact(QContactManager *manager, enum platform platform)
{
- if(m_backend == BackendQContacts) {
- QMap<int, QContactManager::Error> errorMap;
- m_qm->removeContacts(id_list, &errorMap);
- id_list.clear();
+ if(platform == tst_Contact::QContacts) {
+ QContact *c = new QContact;
+ c->setType(QContactType::TypeContact);
+ QContactName cname;
+ QString name;
+ name = firstNames.takeFirst();
+ firstNames.push_back(name);
+ cname.setFirstName(name);
+ name = lastNames.takeFirst();
+ lastNames.push_back(name);
+ cname.setLastName(name);
+#ifndef Q_WS_MAEMO_5
+ cname.setPrefix("Mr");
+#endif
+ c->saveDetail(&cname);
+
+ if(!manager->saveContact(c)){
+ qDebug() << "Failed to create contact during setup";
+ return;
+ }
+ id_list.append(c->localId());
+ delete c;
}
- else if(m_backend == BackendContactsModel){
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
+ // Create a contact card and add a work phone number. Numeric values are
+ // stored in a text field (storage type = KStorageTypeText).
+
CContactDatabase* db = CContactDatabase::OpenL();
CleanupStack::PushL(db);
- CContactIdArray* idArray = CContactIdArray::NewLC();
- while(!id_list.isEmpty())
- idArray->AddL(id_list.takeFirst());
- db->DeleteContactsL(*idArray);
+ CContactCard* newCard = CContactCard::NewLC();
+
+ QString name;
+
+ // Create the firstName field and add the data to it
+ name = firstNames.takeFirst();
+ firstNames.push_back(name);
+ CContactItemField* firstName = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
+ TPtrC Firstname(reinterpret_cast<const TUint16*>(name.utf16()));
+ firstName->TextStorage()->SetTextL(Firstname);
+ newCard->AddFieldL(*firstName);
+ CleanupStack::Pop(firstName);
+
+ // Create the lastName field and add the data to it
+ name = lastNames.takeFirst();
+ lastNames.push_back(name);
+ CContactItemField* lastName= CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
+ TPtrC Lastname(reinterpret_cast<const TUint16*>(name.utf16()));
+ lastName->TextStorage()->SetTextL(Lastname);
+ newCard->AddFieldL(*lastName);
+ CleanupStack::Pop(lastName);
+
+ CContactItemField* prefix = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPrefixName);
+ _LIT(KPrefix, "Mr");
+ prefix->TextStorage()->SetTextL(KPrefix);
+ newCard->AddFieldL(*prefix);
+ CleanupStack::Pop(prefix);
+
+ // Add newCard to the database
+ const TContactItemId contactId = db->AddNewContactL(*newCard);
+ db->CloseContactL(contactId);
- CleanupStack::PopAndDestroy(2); //idArray, contactsDb
+ id_list.append(contactId);
+ CleanupStack::PopAndDestroy(2, db); //newCard, contactsDb
+#else
+ qWarning("No native test for createContact");
+#endif
+ }
+}
+
+void tst_Contact::clearContacts(QContactManager *manager, enum platform platform)
+{
+ if(platform == tst_Contact::QContacts) {
+ QMap<int, QContactManager::Error> errorMap;
+ manager->removeContacts(id_list, &errorMap);
+ id_list.clear();
+ }
+ else if(platform == tst_Contact::Native){
+#ifdef Q_OS_SYMBIAN
+ CContactDatabase* contactDb = CContactDatabase::OpenL();
+ CleanupStack::PushL(contactDb);
+
+ CCntFilter *filter = CCntFilter::NewL();
+ CleanupStack::PushL(filter);
+ //get all contact items (no groups, templates...)
+ filter->SetContactFilterTypeALL(EFalse);
+ filter->SetContactFilterTypeCard(ETrue);
+ TRAPD(err, contactDb->FilterDatabaseL(*filter));
+ if(err != KErrNone){
+ qWarning() << "clearContacts failed to get any contacts error: " << err;
+ CleanupStack::PopAndDestroy(2, contactDb);
+ return;
+ }
+
+ CContactIdArray *iContacts = 0;
+ TRAP(err, iContacts = CContactIdArray::NewL(filter->iIds));
+ if(err != KErrNone){
+ CleanupStack::PopAndDestroy(2, contactDb); //idArray, contactsDb
+ return;
+ }
+ CleanupStack::PushL(iContacts);
+
+ TRAP(err, contactDb->DeleteContactsL(*iContacts));
+ if(err != KErrNone)
+ qWarning() << "DeleteContacts failed with: " << err;
+
+ CleanupStack::PopAndDestroy(3, contactDb); //idArray, contactsDb
#endif
}
}
+void tst_Contact::tst_createTime_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
+}
+
void tst_Contact::tst_createTime()
{
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
- if(m_backend == BackendQContacts){
+ if(platform == tst_Contact::QContacts){
+
QContactManager *qm = 0x0;
QBENCHMARK {
- qm = new QContactManager(manager);
+ qm = new QContactManager(manager->managerName());
}
-
delete qm;
}
- else if(m_backend == BackendContactsModel){
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
CContactDatabase* db = 0x0;
QBENCHMARK {
db = CContactDatabase::OpenL();
}
CleanupStack::PushL(db);
- CleanupStack::PopAndDestroy(1); //db
+ CleanupStack::PopAndDestroy(db); //db
#endif
}
}
+void tst_Contact::tst_fetchAllContactIds_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
+}
+
+
void tst_Contact::tst_fetchAllContactIds()
-{
- if(m_backend == BackendQContacts) {
- QList<QContactLocalId> ql;
+{
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
+
+ if(platform == tst_Contact::QContacts) {
+ QList<QContactLocalId> ql;
+
QBENCHMARK {
- ql = m_qm->contactIds();
+ ql = manager->contactIds();
}
}
- else if(m_backend == BackendContactsModel){
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
//open database
// Open the default contact database
CContactDatabase* contactsDb = CContactDatabase::OpenL();
- CleanupStack::PushL(contactsDb);
+ CleanupStack::PushL(contactsDb);
CCntFilter *filter = CCntFilter::NewLC();
-
+
//get all contact items (no groups, templates...)
filter->SetContactFilterTypeALL(EFalse);
filter->SetContactFilterTypeCard(ETrue);
-
QBENCHMARK {
contactsDb->FilterDatabaseL(*filter);
CContactIdArray *iContacts = CContactIdArray::NewLC(filter->iIds);
+ CleanupStack::PopAndDestroy(iContacts);
}
-
- CleanupStack::PopAndDestroy(3); //iContacts, filter, contactsDb
+ CleanupStack::PopAndDestroy(2, contactsDb); //iContacts, filter, contactsDb
#endif
}
}
+void tst_Contact::tst_fetchOneContact_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
+}
+
void tst_Contact::tst_fetchOneContact()
{
- if(m_backend == BackendQContacts){
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
+
+ if(platform == tst_Contact::QContacts){
QContact c;
m_run++;
@@ -348,7 +465,7 @@
int ret;
QContactFetchRequest* req = new QContactFetchRequest;
- QList<QContactLocalId> qcl = m_qm->contactIds();
+ QList<QContactLocalId> qcl = manager->contactIds();
if(qcl.count() < 1)
QFAIL("No contacts to pull from tracker");
QList<QContactLocalId> one;
@@ -357,7 +474,7 @@
idFil.setIds(one);
req->setFilter(idFil);
- req->setManager(m_qm);
+ req->setManager(manager);
//connect(req, SIGNAL(progress(QContactFetchRequest*, bool)), this, SLOT(gotContact(QContactFetchRequest*,bool)));
//connect(req, SIGNAL(stateChanged(QContactAbstractRequest::State)), this, SLOT(stateChanged(QContactAbstractRequest::State)));
connect(req, SIGNAL(resultsAvailable()), this, SLOT(resultsAvailable()));
@@ -378,51 +495,70 @@
delete req;
#elif defined(Q_OS_SYMBIAN)
- QList<QContactLocalId> qcl = m_qm->contactIds();
+ QList<QContactLocalId> qcl = manager->contactIds();
if(qcl.count() < 1)
QFAIL("No contacts to pull from tracker");
QBENCHMARK {
- c = m_qm->contact(qcl.first());
+ c = manager->contact(qcl.first());
}
#endif
}
- else if(m_backend == BackendContactsModel){
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
//open database
// Open the default contact database
CContactDatabase* contactDb = CContactDatabase::OpenL();
- CleanupStack::PushL(contactDb);
-
- int id = id_list.takeFirst();
- id_list.append(id);
-
+ CleanupStack::PushL(contactDb);
CContactItem *item = 0;
TInt r;
-
- QBENCHMARK {
- TRAP(r, item = contactDb->ReadContactL(id));
- }
- CleanupStack::PushL(item);
+
+ CCntFilter *filter = CCntFilter::NewL();
+ CleanupStack::PushL(filter);
+
+ //get all contact items (no groups, templates...)
+ filter->SetContactFilterTypeALL(EFalse);
+ filter->SetContactFilterTypeCard(ETrue);
+ contactDb->FilterDatabaseL(*filter);
+ CContactIdArray *iContacts = CContactIdArray::NewL(filter->iIds);
+ CleanupStack::PushL(iContacts);
+ int cnt = iContacts->Count();
+ int i = 0;
+
+ QBENCHMARK {
+ TRAP(r, item = contactDb->ReadContactL((*iContacts)[i++]));
+ if(r == KErrNone)
+ delete item;
+ if(i >= cnt)
+ i = 0;
+ }
if(r != KErrNone){ qWarning() << "Error by OpenContactL: " << r; }
-
-// TRAP(r, contactDb->CloseContactL(id));
-// if(r != KErrNone){qWarning() << "Error by CloseContactL: " << r; }
-
- //qDebug() << "Call FetchContactDone: " << id;
-
- CleanupStack::PopAndDestroy(2); //contact, lock, contactsDb
+
+ CleanupStack::PopAndDestroy(3, contactDb); //contact, filter, IdArray
#endif
}
}
+void tst_Contact::tst_fetchTenContact_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
+}
void tst_Contact::tst_fetchTenContact()
{
- if(m_backend == BackendQContacts){
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
+
+ if(platform == tst_Contact::QContacts){
QContact c;
m_run++;
@@ -431,7 +567,7 @@
QContactFetchRequest* req = new QContactFetchRequest;
- QList<QContactLocalId> qcl = m_qm->contactIds();
+ QList<QContactLocalId> qcl = manager->contactIds();
if(qcl.count() < 10){
QFAIL("No enough contacts to get 10");
}
@@ -444,7 +580,7 @@
idFil.setIds(one);
req->setFilter(idFil);
- req->setManager(m_qm);
+ req->setManager(manager);
// connect(req, SIGNAL(progress(QContactFetchRequest*, bool)), this, SLOT(gotContact(QContactFetchRequest*,bool)));
connect(req, SIGNAL(resultsAvailable()), this, SLOT(resultsAvailable()));
@@ -465,7 +601,7 @@
delete req;
#elif defined(Q_OS_SYMBIAN)
- QList<QContactLocalId> qcl = m_qm->contactIds();
+ QList<QContactLocalId> qcl = manager->contactIds();
if(qcl.count() < 10){
QFAIL("No enough contacts to get 10");
}
@@ -479,7 +615,7 @@
QList<QContact> qlc;
QBENCHMARK {
- qlc = m_qm->contacts(idFil, QList<QContactSortOrder>(), QContactFetchHint());
+ qlc = manager->contacts(idFil, QList<QContactSortOrder>(), QContactFetchHint());
}
if(qlc.count() != 10){
@@ -488,73 +624,43 @@
#endif
}
- else if(m_backend == BackendContactsModel){
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
//open database
// Open the default contact database
CContactDatabase* contactDb = CContactDatabase::OpenL();
CleanupStack::PushL(contactDb);
-
- int id = id_list.takeFirst();
- id_list.append(id);
+
+ CCntFilter *filter = CCntFilter::NewL();
+ CleanupStack::PushL(filter);
+
+ //get all contact items (no groups, templates...)
+ filter->SetContactFilterTypeALL(EFalse);
+ filter->SetContactFilterTypeCard(ETrue);
+ contactDb->FilterDatabaseL(*filter);
+ CContactIdArray *iContacts = CContactIdArray::NewL(filter->iIds);
+ CleanupStack::PushL(iContacts);
+ if(iContacts->Count() <= 10){
+ QFAIL("There are less than 10 contacts to fetch");
+ }
TInt r;
+ int i = 0;
- CContactItem *item1 = 0;
- CContactItem *item2 = 0;
- CContactItem *item3 = 0;
- CContactItem *item4 = 0;
- CContactItem *item5 = 0;
- CContactItem *item6 = 0;
- CContactItem *item7 = 0;
- CContactItem *item8 = 0;
- CContactItem *item9 = 0;
- CContactItem *item10 = 0;
-
+ CContactItem *item = 0;
+
+ // there is no multiple fetch in symbian
+
+
QBENCHMARK {
- TRAP(r, item1 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item2 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item3 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item4 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item5 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item6 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item7 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item8 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item9 = contactDb->ReadContactL(id));
- id = id_list.takeFirst();
- id_list.append(id);
- TRAP(r, item10 = contactDb->ReadContactL(id));
+ for(i = 0; i < 10; i++){
+ TRAP(r, item = contactDb->ReadContactL((*iContacts)[i]));
+ if(r == KErrNone)
+ delete item;
+ }
}
- CleanupStack::PushL(item1);
- CleanupStack::PushL(item2);
- CleanupStack::PushL(item3);
- CleanupStack::PushL(item4);
- CleanupStack::PushL(item5);
- CleanupStack::PushL(item6);
- CleanupStack::PushL(item7);
- CleanupStack::PushL(item8);
- CleanupStack::PushL(item9);
- CleanupStack::PushL(item10);
-
- if(r != KErrNone){ qWarning() << "Error by OpenContactL: " << r; }
-
- CleanupStack::PopAndDestroy(11); //10*item + contactsDb
+
+ CleanupStack::PopAndDestroy(3, contactDb); //iContacts, filer, contactsDb
#endif
}
}
@@ -625,16 +731,44 @@
qDebug() << "Got state change";
}
+void tst_Contact::tst_createContact_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
+}
+
void tst_Contact::tst_createContact()
{
- QBENCHMARK {
- createContact();
- }
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
+
+ QBENCHMARK {
+ createContact(manager, platform);
+ }
+}
+
+void tst_Contact::tst_saveContact_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
}
void tst_Contact::tst_saveContact()
{
- if(m_backend == BackendQContacts) {
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
+
+ if(platform == tst_Contact::QContacts) {
QContact *c = new QContact;
c->setType("Contact");
QContactName cname;
@@ -653,7 +787,7 @@
int ret = 0;
QBENCHMARK {
- ret = m_qm->saveContact(c);
+ ret = manager->saveContact(c);
}
if(!ret){
qDebug() << "Failed to create contact durring setup";
@@ -662,83 +796,7 @@
id_list.append(c->localId());
delete c;
}
- else if(m_backend == BackendContactsModel){
-#ifdef Q_OS_SYMBIAN
- // Create a contact card and add a work phone number. Numeric values are
- // stored in a text field (storage type = KStorageTypeText).
-
- CContactDatabase* db = CContactDatabase::OpenL();
- CleanupStack::PushL(db);
-
- CContactCard* newCard = CContactCard::NewLC();
-
- QString name;
-
- // Create the firstName field and add the data to it
- name = firstNames.takeFirst();
- firstNames.push_back(name);
- CContactItemField* firstName = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
- TPtrC Firstname(reinterpret_cast<const TUint16*>(name.utf16()));
- firstName->TextStorage()->SetTextL(Firstname);
- newCard->AddFieldL(*firstName);
- CleanupStack::Pop(firstName);
-
- // Create the lastName field and add the data to it
- name = lastNames.takeFirst();
- lastNames.push_back(name);
- CContactItemField* lastName= CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
- TPtrC Lastname(reinterpret_cast<const TUint16*>(name.utf16()));
- lastName->TextStorage()->SetTextL(Lastname);
- newCard->AddFieldL(*lastName);
- CleanupStack::Pop(lastName);
-#ifndef Q_WS_MAEMO_5
- CContactItemField* prefix = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPrefixName);
- _LIT(KPrefix, "Mr");
- prefix->TextStorage()->SetTextL(KPrefix);
- newCard->AddFieldL(*prefix);
- CleanupStack::Pop(prefix);
-#endif
- QBENCHMARK {
- // Add newCard to the database
- const TContactItemId contactId = db->AddNewContactL(*newCard);
- db->CloseContactL(contactId);
- id_list.append(contactId);
- }
-
- CleanupStack::PopAndDestroy(2); //newCard, contactsDb
-#else
- qWarning("ContactModel set but Q_OS_SYMBIAN not set, this doesn't make sense");
-#endif
- }
-}
-
-
-void tst_Contact::createContact()
-{
- if(m_backend == BackendQContacts) {
- QContact *c = new QContact;
- c->setType(QContactType::TypeContact);
- QContactName cname;
- QString name;
- name = firstNames.takeFirst();
- firstNames.push_back(name);
- cname.setFirstName(name);
- name = lastNames.takeFirst();
- lastNames.push_back(name);
- cname.setLastName(name);
-#ifndef Q_WS_MAEMO_5
- cname.setPrefix("Mr");
-#endif
- c->saveDetail(&cname);
-
- if(!m_qm->saveContact(c)){
- qDebug() << "Failed to create contact during setup";
- return;
- }
- id_list.append(c->localId());
- delete c;
- }
- else if(m_backend == BackendContactsModel){
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
// Create a contact card and add a work phone number. Numeric values are
// stored in a text field (storage type = KStorageTypeText).
@@ -767,28 +825,45 @@
lastName->TextStorage()->SetTextL(Lastname);
newCard->AddFieldL(*lastName);
CleanupStack::Pop(lastName);
-#ifndef Q_WS_MAEMO_5
+
CContactItemField* prefix = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldPrefixName);
_LIT(KPrefix, "Mr");
prefix->TextStorage()->SetTextL(KPrefix);
newCard->AddFieldL(*prefix);
CleanupStack::Pop(prefix);
-#endif
- // Add newCard to the database
- const TContactItemId contactId = db->AddNewContactL(*newCard);
- db->CloseContactL(contactId);
-
- id_list.append(contactId);
- CleanupStack::PopAndDestroy(2); //newCard, contactsDb
+
+ QBENCHMARK {
+ // Add newCard to the database
+ const TContactItemId contactId = db->AddNewContactL(*newCard);
+ db->CloseContactL(contactId);
+ id_list.append(contactId);
+ }
+
+ CleanupStack::PopAndDestroy(2, db); //newCard, contactsDb
#else
- qWarning("ContactModel set but Q_OS_SYMBIAN not set, this doesn't make sense");
+ qWarning("No native test defined for this platform and tst_saveContact()");
#endif
}
}
+void tst_Contact::tst_nameFilter_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
+}
+
+
void tst_Contact::tst_nameFilter()
-{
- if(m_backend == BackendQContacts){
+{
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
+
+ if(platform == tst_Contact::QContacts){
QContactFilter fil = QContactName::match(firstNames.first(),""); // pick one first name to find
//QContactFilter fil = QContactName::match("sdfsdfsdfjhsjkdfshdkf", ""); // pick one first name to find
QContact c;
@@ -801,7 +876,7 @@
int ret;
QContactFetchRequest* req = new QContactFetchRequest;
req->setFilter(fil);
- req->setManager(m_qm);
+ req->setManager(manager);
connect(req, SIGNAL(resultsAvailable()), this, SLOT(resultsAvailableFilter()));
@@ -829,7 +904,7 @@
QList<QContact> qlc;
QBENCHMARK {
- qlc = m_qm->contacts(fil, QList<QContactSortOrder>(), QContactFetchHint());
+ qlc = manager->contacts(fil, QList<QContactSortOrder>(), QContactFetchHint());
}
// while(!qlc.isEmpty()){
@@ -838,7 +913,7 @@
// }
#endif
}
- else if(m_backend == BackendContactsModel){
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
//open database
// Open the default contact database
@@ -846,8 +921,46 @@
CleanupStack::PushL(contactDb);
CContactItem *item = 0x0;
-
- const TPtrC Firstname(reinterpret_cast<const TUint16*>(firstNames.first().utf16()));
+
+ CCntFilter *filter = CCntFilter::NewL();
+ CleanupStack::PushL(filter);
+
+ //get all contact items (no groups, templates...)
+ filter->SetContactFilterTypeALL(EFalse);
+ filter->SetContactFilterTypeCard(ETrue);
+ contactDb->FilterDatabaseL(*filter);
+ CContactIdArray *iContacts;
+ TRAPD(filter_err, iContacts = CContactIdArray::NewL(filter->iIds));
+ if(filter_err != KErrNone){
+ CleanupStack::PopAndDestroy(2, contactDb); // filter, contactDB
+ QFAIL("Failed to fetch a list of contacts");
+ }
+ CleanupStack::PushL(iContacts);
+
+ TBuf<100> Firstname(0);
+
+ for(int i = 0; i< iContacts->Count(); i++){
+ TRAPD(err, item = contactDb->ReadContactL((*iContacts)[0]));
+ if(err != KErrNone) {
+ CleanupStack::PopAndDestroy(3, contactDb); // iContacts, filers, db
+ QFAIL("Unable to fetch a sample item from the contacts file");
+ }
+ CleanupStack::PushL(item);
+
+ int fieldNum = item->CardFields().Find(KUidContactFieldGivenName);
+ if(fieldNum != KErrNotFound){
+ Firstname.Copy((item->CardFields())[fieldNum].TextStorage()->Text());
+ CleanupStack::PopAndDestroy(item); // item
+ break;
+ }
+ CleanupStack::PopAndDestroy(item); // item
+ }
+ if(Firstname.Length() == 0){
+ QFAIL("Unable to find a contact to search for");
+ }
+
+
+ //const TPtrC Firstname(reinterpret_cast<const TUint16*>(firstNames.first().utf16()));
CContactIdArray* idArray;
CContactItemFieldDef* fieldDef = new (ELeave) CContactItemFieldDef();
@@ -857,68 +970,110 @@
QBENCHMARK {
idArray = contactDb->FindLC(Firstname, fieldDef);
- if(idArray->Count() > 0)
- item = contactDb->ReadContactL((*idArray)[0]);
- else
- QFAIL("No contacts returned from CContactDatabase::FindLC");
- }
- CleanupStack::PushL(item);
+ if(idArray->Count() > 0) {
+ item = contactDb->ReadContactL((*idArray)[0]);
+ delete item;
+ CleanupStack::PopAndDestroy(idArray);
+ }
+ else {
+ qDebug() << "Number of contacts native: " << countContacts(0x0, Native);
+ qDebug() << "Number of contacts qt/system: " << countContacts(m_systemManager);
+ QFAIL("No contacts returned from CContactDatabase::FindLC");
+ }
+ }
- CleanupStack::PopAndDestroy(4); //item, idArray, fielddef, lock, contactsDb
+ CleanupStack::PopAndDestroy(4, contactDb); //item, idArray, fielddef, lock, contactsDb
#endif
}
}
+void tst_Contact::tst_removeOneContact_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
+}
+
void tst_Contact::tst_removeOneContact()
{
- if(m_backend == BackendQContacts){
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
+
+ if(platform == tst_Contact::QContacts){
QList<QContactLocalId> one;
QMap<int, QContactManager::Error> errorMap;
if(id_list.count() < 1){ // incase we run out of contacts
- createContact();
+ createContact(manager, platform);
}
-
+
one += id_list.takeFirst();
- QBENCHMARK {
- m_qm->removeContacts(one, &errorMap);
- }
+
+ QBENCHMARK_ONCE {
+ manager->removeContacts(one, &errorMap);
+ }
}
- else if(m_backend == BackendContactsModel){
+ else if(platform == tst_Contact::Native){
#ifdef Q_OS_SYMBIAN
- CContactDatabase* db = CContactDatabase::OpenL();
- CleanupStack::PushL(db);
-
- if(id_list.isEmpty())
- QFAIL("no contacts available to be removed for tst_removeOnContact()");
-
-
- TInt32 id = id_list.takeFirst();
-
- QBENCHMARK {
- db->DeleteContactL(id);
+ CContactDatabase* contactDb = CContactDatabase::OpenL();
+ CleanupStack::PushL(contactDb);
+
+ CCntFilter *filter = CCntFilter::NewL();
+ CleanupStack::PushL(filter);
+
+ //get all contact items (no groups, templates...)
+ filter->SetContactFilterTypeALL(EFalse);
+ filter->SetContactFilterTypeCard(ETrue);
+ contactDb->FilterDatabaseL(*filter);
+ CContactIdArray *iContacts = CContactIdArray::NewL(filter->iIds);
+ CleanupStack::PushL(iContacts);
+ int i = 0;
+
+ QBENCHMARK_ONCE { // Do it once only, to many removals becomes a problem
+ contactDb->DeleteContactL((*iContacts)[i++]);
+ if(i >= iContacts->Count()){
+ break;
+ }
}
- CleanupStack::PopAndDestroy(1); //idArray, contactsDb
+ CleanupStack::PopAndDestroy(3, contactDb); //idArray, contactsDb
#endif
}
}
-void tst_Contact::tst_removeAllContacts()
-{
- int before = countContacts();
+void tst_Contact::tst_removeAllContacts_data()
+{
+ QTest::addColumn<tst_Contact::platform>("platform");
+ QTest::addColumn<QContactManager *>("manager");
+
+ QTest::newRow("Native") << tst_Contact::Native << (QContactManager *)0x0;
+ foreach(QContactManager *mgr, m_managers){
+ QTest::newRow(QString("QContact-" + mgr->managerName()).toAscii()) << tst_Contact::QContacts << mgr;
+ }
+}
+
- if(before < 20) {
- for(int i = before; i < 20; i++){
- createContact();
- }
+void tst_Contact::tst_removeAllContacts()
+{
+ QFETCH(tst_Contact::platform, platform);
+ QFETCH(QContactManager *, manager);
+
+ int before = countContacts(manager, platform);
+
+ if(before < 20) {
+ for(int i = before; i < 20; i++){
+ createContact(manager, platform);
}
-
- QBENCHMARK {
- clearContacts();
- }
-
+ }
+
+ QBENCHMARK {
+ clearContacts(manager, platform);
+ }
}
int main(int argc, char **argv){
@@ -926,27 +1081,8 @@
QApplication app(argc, argv);
tst_Contact test1;
- test1.setBackend("memory");
QTest::qExec(&test1, argc, argv);
-// tst_Contact test2;
-// test2.setBackend("tracker");
-// QTest::qExec(&test2, argc, argv);
-#if defined(Q_WS_MAEMO_5)
- tst_Contact test2;
- test2.setBackend("maemo5");
- QTest::qExec(&test2, argc, argv);
-#endif
-#if defined(Q_OS_SYMBIAN)
- tst_Contact test2;
- test2.setBackend("symbian");
- QTest::qExec(&test2, argc, argv);
-
- tst_Contact test3;
- test3.setBackend("SymbianContactsModel");
- QTest::qExec(&test3, argc, argv);
-#endif
-
}
#include "tst_bm_contacts.moc"