2
* Copyright 2013 Canonical Ltd.
4
* This file is part of contact-service-app.
6
* contact-service-app is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 3.
10
* contact-service-app is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
using namespace QtContacts;
28
class ContactCollectionTest : public QObject
32
QContactManager *m_manager;
37
QCoreApplication::setLibraryPaths(QStringList() << QT_PLUGINS_BINARY_DIR);
38
// wait for address-book-service
44
m_manager = new QContactManager("galera");
53
* Test create a new collection
55
void testCreateAddressBook()
58
c.setType(QContactType::TypeGroup);
59
QContactDisplayLabel label;
60
QString uniqueName = QString("source@%1").arg(QUuid::createUuid().toString().remove("{").remove("}"));
61
label.setLabel(uniqueName);
64
bool saveResult = m_manager->saveContact(&c);
67
QContactDetailFilter filter;
68
filter.setDetailType(QContactDetail::TypeType, QContactType::FieldType);
69
filter.setValue(QContactType::TypeGroup);
71
QList<QContact> contacts = m_manager->contacts(filter);
72
Q_FOREACH(const QContact &contact, contacts) {
73
if ((contact.detail<QContactDisplayLabel>().label() == uniqueName) &&
74
(contact.id() == c.id())) {
78
QFAIL("New collection not found");
82
* Test remove a collection
84
void testRemoveAddressBook()
88
c.setType(QContactType::TypeGroup);
89
QContactDisplayLabel label;
90
QString uniqueName = QString("source@%1").arg(QUuid::createUuid().toString().remove("{").remove("}"));
91
label.setLabel(uniqueName);
94
bool saveResult = m_manager->saveContact(&c);
97
// try to remove new source
98
// WORKAROUND: Since qcontacts does not cotains a API to remove address book we use the contact label as id
99
// for addressbook. This Id must contain a "@" to be handled as address book name.
100
QContactId addressBookId = QContactId::fromString(QString("qtcontacts:galera::%1").arg(uniqueName));
101
bool removeResult = m_manager->removeContact(addressBookId);
102
QVERIFY(removeResult);
104
// check if the source was removed
105
QContactDetailFilter filter;
106
filter.setDetailType(QContactDetail::TypeType, QContactType::FieldType);
107
filter.setValue(QContactType::TypeGroup);
108
QList<QContact> contacts = m_manager->contacts(filter);
109
Q_FOREACH(const QContact &contact, contacts) {
110
if (contact.id() == c.id()) {
111
QFAIL("Collection not removed");
117
* Test query for collections using the contact group type
119
void testQueryAddressBook()
121
// filter all contact groups/addressbook
122
QContactDetailFilter filter;
123
filter.setDetailType(QContactDetail::TypeType, QContactType::FieldType);
124
filter.setValue(QContactType::TypeGroup);
126
// check result for the default source
127
QList<QContact> contacts = m_manager->contacts(filter);
128
Q_FOREACH(const QContact &c, contacts) {
129
QCOMPARE(c.type(), QContactType::TypeGroup);
130
if (c.id().toString() == QStringLiteral("qtcontacts:galera::system-address-book")) {
131
QContactDisplayLabel label = c.detail(QContactDisplayLabel::Type);
132
QCOMPARE(label.label(), QStringLiteral("Personal"));
136
QFAIL("Fail to query for collections");
140
QTEST_MAIN(ContactCollectionTest)
142
#include "contact-collection-test.moc"