Merge lp:~renatofilho/address-book-service/fix-duplicated-fields into lp:address-book-service

Proposed by Renato Araujo Oliveira Filho
Status: Needs review
Proposed branch: lp:~renatofilho/address-book-service/fix-duplicated-fields
Merge into: lp:address-book-service
Prerequisite: lp:~renatofilho/address-book-service/fix-1269561
Diff against target: 181 lines (+139/-9)
3 files modified
lib/gee-utils.h (+8/-8)
tests/unittest/CMakeLists.txt (+1/-1)
tests/unittest/contact-edit-test.cpp (+130/-0)
To merge this branch: bzr merge lp:~renatofilho/address-book-service/fix-duplicated-fields
Reviewer Review Type Date Requested Status
system-apps-ci-bot continuous-integration Needs Fixing
Bill Filler (community) Needs Fixing
PS Jenkins bot continuous-integration Approve
Review via email: mp+208040@code.launchpad.net

Commit message

Added support to store contacts with duplicate details values.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Bill Filler (bfiller) wrote :

tested, doesn't work. same problem as before

review: Needs Fixing
Revision history for this message
system-apps-ci-bot (system-apps-ci-bot) wrote :
review: Needs Fixing (continuous-integration)

Unmerged revisions

120. By Renato Araujo Oliveira Filho

Added support to store contacts with duplicate details values.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/gee-utils.h'
2--- lib/gee-utils.h 2013-10-30 19:07:49 +0000
3+++ lib/gee-utils.h 2014-02-24 23:23:25 +0000
4@@ -43,10 +43,10 @@
5 #define SET_AFD_NEW() \
6 GEE_SET(gee_hash_set_new(FOLKS_TYPE_ABSTRACT_FIELD_DETAILS, \
7 (GBoxedCopyFunc) g_object_ref, g_object_unref, \
8- _folks_abstract_field_details_hash_data_func, \
9- NULL, \
10- NULL, \
11- _folks_abstract_field_details_equal_data_func, \
12+ NULL, \
13+ NULL, \
14+ NULL, \
15+ NULL, \
16 NULL, \
17 NULL))
18
19@@ -71,10 +71,10 @@
20 NULL, \
21 NULL, \
22 NULL, \
23- _folks_abstract_field_details_hash_data_func, \
24- NULL, \
25- NULL, \
26- _folks_abstract_field_details_equal_data_func, \
27+ NULL, \
28+ NULL, \
29+ NULL, \
30+ NULL, \
31 NULL, \
32 NULL))
33
34
35=== modified file 'tests/unittest/CMakeLists.txt'
36--- tests/unittest/CMakeLists.txt 2014-02-24 23:23:25 +0000
37+++ tests/unittest/CMakeLists.txt 2014-02-24 23:23:25 +0000
38@@ -71,7 +71,7 @@
39 declare_test(addressbook-test True ${BASE_CLIENT_TEST_SRC})
40 declare_test(service-life-cycle-test True ${BASE_CLIENT_TEST_SRC})
41 declare_test(contact-link-test True ${BASE_CLIENT_TEST_SRC})
42-
43+ declare_test(contact-edit-test True ${BASE_CLIENT_TEST_SRC})
44 elseif()
45 message(STATUS "DBus test runner not found. Some tests will be disabled")
46 endif()
47
48=== added file 'tests/unittest/contact-edit-test.cpp'
49--- tests/unittest/contact-edit-test.cpp 1970-01-01 00:00:00 +0000
50+++ tests/unittest/contact-edit-test.cpp 2014-02-24 23:23:25 +0000
51@@ -0,0 +1,130 @@
52+/*
53+ * Copyright 2013 Canonical Ltd.
54+ *
55+ * This file is part of contact-service-app.
56+ *
57+ * contact-service-app is free software; you can redistribute it and/or modify
58+ * it under the terms of the GNU General Public License as published by
59+ * the Free Software Foundation; version 3.
60+ *
61+ * contact-service-app is distributed in the hope that it will be useful,
62+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
63+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64+ * GNU General Public License for more details.
65+ *
66+ * You should have received a copy of the GNU General Public License
67+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
68+ */
69+
70+#include "base-client-test.h"
71+#include "lib/source.h"
72+#include "common/dbus-service-defs.h"
73+#include "common/vcard-parser.h"
74+
75+#include <QObject>
76+#include <QtDBus>
77+#include <QtTest>
78+#include <QDebug>
79+#include <QtVersit>
80+
81+class ContactEditTest : public BaseClientTest
82+{
83+ Q_OBJECT
84+private:
85+ QString m_basicVcard;
86+
87+private Q_SLOTS:
88+ void initTestCase()
89+ {
90+ BaseClientTest::initTestCase();
91+ m_basicVcard = QStringLiteral("BEGIN:VCARD\n"
92+ "VERSION:3.0\n"
93+ "N:Tal;Fulano_;de;;\n"
94+ "EMAIL:fulano_@ubuntu.com\n"
95+ "EMAIL:fulano_@ubuntu.com\n"
96+ "TEL;TYPE=CELL:8888888\n"
97+ "TEL;TYPE=ISDN:8888888\n"
98+ "END:VCARD");
99+ }
100+
101+ void testSaveDuplicatedEmail()
102+ {
103+ // call create contact
104+ QDBusReply<QString> reply = m_serverIface->call("createContact", m_basicVcard, "dummy-store");
105+
106+ // check if the returned id is valid
107+ QString newContactId = reply.value();
108+ QVERIFY(!newContactId.isEmpty());
109+
110+ // query created contact
111+ QDBusReply<QStringList> reply2 = m_dummyIface->call("listContacts");
112+ QCOMPARE(reply2.value().count(), 1);
113+ QList<QtContacts::QContact> contactsCreated = galera::VCardParser::vcardToContact(reply2.value());
114+ QCOMPARE(contactsCreated.count(), 1);
115+
116+ // check if the contact has the 2 emails
117+ QList<QtContacts::QContactEmailAddress> emails = contactsCreated[0].details<QtContacts::QContactEmailAddress>();
118+ QCOMPARE(emails.size(), 2);
119+ QCOMPARE(emails[0].emailAddress(), QStringLiteral("fulano_@ubuntu.com"));
120+ QCOMPARE(emails[1].emailAddress(), QStringLiteral("fulano_@ubuntu.com"));
121+
122+ // check if the contact has the 2 phones
123+ QList<QtContacts::QContactPhoneNumber> phones = contactsCreated[0].details<QtContacts::QContactPhoneNumber>();
124+ QCOMPARE(phones.size(), 2);
125+ QCOMPARE(phones[0].number(), QStringLiteral("8888888"));
126+ QCOMPARE(phones[1].number(), QStringLiteral("8888888"));
127+ }
128+
129+ void testAddANewEmailWithTheSameAddress()
130+ {
131+ // call create contact
132+ QDBusReply<QString> replyString = m_serverIface->call("createContact", m_basicVcard, "dummy-store");
133+
134+ // check if the returned id is valid
135+ QString newContactId = replyString.value();
136+ QVERIFY(!newContactId.isEmpty());
137+
138+ // query created contact
139+ QDBusReply<QStringList> replyStringList = m_dummyIface->call("listContacts");
140+ QCOMPARE(replyStringList.value().count(), 1);
141+ QList<QtContacts::QContact> contacts = galera::VCardParser::vcardToContact(replyStringList.value());
142+ QCOMPARE(contacts.count(), 1);
143+
144+ // add a email with the same address but different context
145+ QtContacts::QContact contact = contacts[0];
146+ QtContacts::QContactEmailAddress email;
147+ email.setEmailAddress("fulano_@ubuntu.com");
148+ QList<int> contexts;
149+ contexts << QtContacts::QContactDetail::ContextWork;
150+ email.setContexts(contexts);
151+ contact.saveDetail(&email);
152+
153+ // save the changes
154+ QStringList vcards = galera::VCardParser::contactToVcard(QList<QtContacts::QContact>() << contact);
155+ replyStringList = m_serverIface->call("updateContacts", vcards);
156+
157+ // query updated contacts
158+ replyStringList = m_dummyIface->call("listContacts");
159+ QCOMPARE(replyStringList.value().count(), 1);
160+ contacts = galera::VCardParser::vcardToContact(replyStringList.value());
161+ QCOMPARE(contacts.count(), 1);
162+
163+ // check if the contact has the 3 emails
164+ QList<QtContacts::QContactEmailAddress> emails = contacts[0].details<QtContacts::QContactEmailAddress>();
165+ QCOMPARE(emails.size(), 3);
166+ bool hasWorkEmail = false;
167+ Q_FOREACH(QtContacts::QContactEmailAddress email, emails) {
168+ QCOMPARE(email.emailAddress(), QStringLiteral("fulano_@ubuntu.com"));
169+ if (email.contexts() == contexts) {
170+ // we only have one work e-mail
171+ QCOMPARE(hasWorkEmail, false);
172+ hasWorkEmail = true;
173+ }
174+ }
175+ QCOMPARE(hasWorkEmail, true);
176+ }
177+};
178+
179+QTEST_MAIN(ContactEditTest)
180+
181+#include "contact-edit-test.moc"

Subscribers

People subscribed via source and target branches