Merge lp:~renatofilho/address-book-service/fix-addr-update into lp:address-book-service
- fix-addr-update
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Bill Filler |
Approved revision: | 146 |
Merged at revision: | 146 |
Proposed branch: | lp:~renatofilho/address-book-service/fix-addr-update |
Merge into: | lp:address-book-service |
Diff against target: |
211 lines (+49/-22) 3 files modified
lib/qindividual.cpp (+27/-22) lib/qindividual.h (+2/-0) tests/unittest/qcontacts-test.cpp (+20/-0) |
To merge this branch: | bzr merge lp:~renatofilho/address-book-service/fix-addr-update |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Bill Filler (community) | Approve | ||
PS Jenkins bot | continuous-integration | Approve | |
Review via email: mp+240587@code.launchpad.net |
Commit message
Save address fields in single lines. To avoid problems with folks.
Description of the change
- 145. By Renato Araujo Oliveira Filho
-
Remove spaces at the end and new line symbols from street field.
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:145
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Bill Filler (bfiller) wrote : | # |
shouldn't we do this with all fields, not just address fields?
Bill Filler (bfiller) wrote : | # |
also, please add some unit tests to test for this case of unexpected characters in the fields
- 146. By Renato Araujo Oliveira Filho
-
Convert any multi line field into a single line value.
Create unit test.
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:146
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'lib/qindividual.cpp' | |||
2 | --- lib/qindividual.cpp 2014-10-14 15:45:14 +0000 | |||
3 | +++ lib/qindividual.cpp 2014-11-06 15:44:29 +0000 | |||
4 | @@ -230,23 +230,23 @@ | |||
5 | 230 | if (sn) { | 230 | if (sn) { |
6 | 231 | const char *name = folks_structured_name_get_given_name(sn); | 231 | const char *name = folks_structured_name_get_given_name(sn); |
7 | 232 | if (name && strlen(name)) { | 232 | if (name && strlen(name)) { |
9 | 233 | detail.setFirstName(QString::fromUtf8(name)); | 233 | detail.setFirstName(qStringFromGChar(name)); |
10 | 234 | } | 234 | } |
11 | 235 | name = folks_structured_name_get_additional_names(sn); | 235 | name = folks_structured_name_get_additional_names(sn); |
12 | 236 | if (name && strlen(name)) { | 236 | if (name && strlen(name)) { |
14 | 237 | detail.setMiddleName(QString::fromUtf8(name)); | 237 | detail.setMiddleName(qStringFromGChar(name)); |
15 | 238 | } | 238 | } |
16 | 239 | name = folks_structured_name_get_family_name(sn); | 239 | name = folks_structured_name_get_family_name(sn); |
17 | 240 | if (name && strlen(name)) { | 240 | if (name && strlen(name)) { |
19 | 241 | detail.setLastName(QString::fromUtf8(name)); | 241 | detail.setLastName(qStringFromGChar(name)); |
20 | 242 | } | 242 | } |
21 | 243 | name = folks_structured_name_get_prefixes(sn); | 243 | name = folks_structured_name_get_prefixes(sn); |
22 | 244 | if (name && strlen(name)) { | 244 | if (name && strlen(name)) { |
24 | 245 | detail.setPrefix(QString::fromUtf8(name)); | 245 | detail.setPrefix(qStringFromGChar(name)); |
25 | 246 | } | 246 | } |
26 | 247 | name = folks_structured_name_get_suffixes(sn); | 247 | name = folks_structured_name_get_suffixes(sn); |
27 | 248 | if (name && strlen(name)) { | 248 | if (name && strlen(name)) { |
29 | 249 | detail.setSuffix(QString::fromUtf8(name)); | 249 | detail.setSuffix(qStringFromGChar(name)); |
30 | 250 | } | 250 | } |
31 | 251 | detail.setDetailUri(QString("%1.1").arg(index)); | 251 | detail.setDetailUri(QString("%1.1").arg(index)); |
32 | 252 | } | 252 | } |
33 | @@ -262,7 +262,7 @@ | |||
34 | 262 | QContactDisplayLabel detail; | 262 | QContactDisplayLabel detail; |
35 | 263 | const gchar *fullName = folks_name_details_get_full_name(FOLKS_NAME_DETAILS(persona)); | 263 | const gchar *fullName = folks_name_details_get_full_name(FOLKS_NAME_DETAILS(persona)); |
36 | 264 | if (fullName) { | 264 | if (fullName) { |
38 | 265 | detail.setLabel(QString::fromUtf8(fullName)); | 265 | detail.setLabel(qStringFromGChar(fullName)); |
39 | 266 | detail.setDetailUri(QString("%1.1").arg(index)); | 266 | detail.setDetailUri(QString("%1.1").arg(index)); |
40 | 267 | } | 267 | } |
41 | 268 | 268 | ||
42 | @@ -278,7 +278,7 @@ | |||
43 | 278 | QContactNickname detail; | 278 | QContactNickname detail; |
44 | 279 | const gchar* nickname = folks_name_details_get_nickname(FOLKS_NAME_DETAILS(persona)); | 279 | const gchar* nickname = folks_name_details_get_nickname(FOLKS_NAME_DETAILS(persona)); |
45 | 280 | if (nickname && strlen(nickname)) { | 280 | if (nickname && strlen(nickname)) { |
47 | 281 | detail.setNickname(QString::fromUtf8(nickname)); | 281 | detail.setNickname(qStringFromGChar(nickname)); |
48 | 282 | detail.setDetailUri(QString("%1.1").arg(index)); | 282 | detail.setDetailUri(QString("%1.1").arg(index)); |
49 | 283 | } | 283 | } |
50 | 284 | return detail; | 284 | return detail; |
51 | @@ -317,6 +317,11 @@ | |||
52 | 317 | } | 317 | } |
53 | 318 | } | 318 | } |
54 | 319 | 319 | ||
55 | 320 | QString QIndividual::qStringFromGChar(const gchar *str) | ||
56 | 321 | { | ||
57 | 322 | return QString::fromUtf8(str).remove(QRegExp("[\r\n]")); | ||
58 | 323 | } | ||
59 | 324 | |||
60 | 320 | QtContacts::QContactDetail QIndividual::getPersonaPhoto(FolksPersona *persona, int index) const | 325 | QtContacts::QContactDetail QIndividual::getPersonaPhoto(FolksPersona *persona, int index) const |
61 | 321 | { | 326 | { |
62 | 322 | QContactAvatar avatar; | 327 | QContactAvatar avatar; |
63 | @@ -399,15 +404,15 @@ | |||
64 | 399 | QContactOrganization org; | 404 | QContactOrganization org; |
65 | 400 | QString field; | 405 | QString field; |
66 | 401 | 406 | ||
68 | 402 | field = QString::fromUtf8(folks_role_get_organisation_name(role)); | 407 | field = qStringFromGChar(folks_role_get_organisation_name(role)); |
69 | 403 | if (!field.isEmpty()) { | 408 | if (!field.isEmpty()) { |
70 | 404 | org.setName(field); | 409 | org.setName(field); |
71 | 405 | } | 410 | } |
73 | 406 | field = QString::fromUtf8(folks_role_get_title(role)); | 411 | field = qStringFromGChar(folks_role_get_title(role)); |
74 | 407 | if (!field.isEmpty()) { | 412 | if (!field.isEmpty()) { |
75 | 408 | org.setTitle(field); | 413 | org.setTitle(field); |
76 | 409 | } | 414 | } |
78 | 410 | field = QString::fromUtf8(folks_role_get_role(role)); | 415 | field = qStringFromGChar(folks_role_get_role(role)); |
79 | 411 | if (!field.isEmpty()) { | 416 | if (!field.isEmpty()) { |
80 | 412 | org.setRole(field); | 417 | org.setRole(field); |
81 | 413 | } | 418 | } |
82 | @@ -447,7 +452,7 @@ | |||
83 | 447 | const gchar *email = (const gchar*) folks_abstract_field_details_get_value(fd); | 452 | const gchar *email = (const gchar*) folks_abstract_field_details_get_value(fd); |
84 | 448 | 453 | ||
85 | 449 | QContactEmailAddress addr; | 454 | QContactEmailAddress addr; |
87 | 450 | addr.setEmailAddress(QString::fromUtf8(email)); | 455 | addr.setEmailAddress(qStringFromGChar(email)); |
88 | 451 | bool isPref = false; | 456 | bool isPref = false; |
89 | 452 | DetailContextParser::parseParameters(addr, fd, &isPref); | 457 | DetailContextParser::parseParameters(addr, fd, &isPref); |
90 | 453 | addr.setDetailUri(QString("%1.%2").arg(index).arg(fieldIndex++)); | 458 | addr.setDetailUri(QString("%1.%2").arg(index).arg(fieldIndex++)); |
91 | @@ -483,7 +488,7 @@ | |||
92 | 483 | const gchar *phone = (const char*) folks_abstract_field_details_get_value(fd); | 488 | const gchar *phone = (const char*) folks_abstract_field_details_get_value(fd); |
93 | 484 | 489 | ||
94 | 485 | QContactPhoneNumber number; | 490 | QContactPhoneNumber number; |
96 | 486 | number.setNumber(QString::fromUtf8(phone)); | 491 | number.setNumber(qStringFromGChar(phone)); |
97 | 487 | bool isPref = false; | 492 | bool isPref = false; |
98 | 488 | DetailContextParser::parseParameters(number, fd, &isPref); | 493 | DetailContextParser::parseParameters(number, fd, &isPref); |
99 | 489 | number.setDetailUri(QString("%1.%2").arg(index).arg(fieldIndex++)); | 494 | number.setDetailUri(QString("%1.%2").arg(index).arg(fieldIndex++)); |
100 | @@ -521,32 +526,32 @@ | |||
101 | 521 | QContactAddress address; | 526 | QContactAddress address; |
102 | 522 | const char *field = folks_postal_address_get_country(addr); | 527 | const char *field = folks_postal_address_get_country(addr); |
103 | 523 | if (field && strlen(field)) { | 528 | if (field && strlen(field)) { |
105 | 524 | address.setCountry(QString::fromUtf8(field)); | 529 | address.setCountry(qStringFromGChar(field)); |
106 | 525 | } | 530 | } |
107 | 526 | 531 | ||
108 | 527 | field = folks_postal_address_get_locality(addr); | 532 | field = folks_postal_address_get_locality(addr); |
109 | 528 | if (field && strlen(field)) { | 533 | if (field && strlen(field)) { |
111 | 529 | address.setLocality(QString::fromUtf8(field)); | 534 | address.setLocality(qStringFromGChar(field)); |
112 | 530 | } | 535 | } |
113 | 531 | 536 | ||
114 | 532 | field = folks_postal_address_get_po_box(addr); | 537 | field = folks_postal_address_get_po_box(addr); |
115 | 533 | if (field && strlen(field)) { | 538 | if (field && strlen(field)) { |
117 | 534 | address.setPostOfficeBox(QString::fromUtf8(field)); | 539 | address.setPostOfficeBox(qStringFromGChar(field)); |
118 | 535 | } | 540 | } |
119 | 536 | 541 | ||
120 | 537 | field = folks_postal_address_get_postal_code(addr); | 542 | field = folks_postal_address_get_postal_code(addr); |
121 | 538 | if (field && strlen(field)) { | 543 | if (field && strlen(field)) { |
123 | 539 | address.setPostcode(QString::fromUtf8(field)); | 544 | address.setPostcode(qStringFromGChar(field)); |
124 | 540 | } | 545 | } |
125 | 541 | 546 | ||
126 | 542 | field = folks_postal_address_get_region(addr); | 547 | field = folks_postal_address_get_region(addr); |
127 | 543 | if (field && strlen(field)) { | 548 | if (field && strlen(field)) { |
129 | 544 | address.setRegion(QString::fromUtf8(field)); | 549 | address.setRegion(qStringFromGChar(field)); |
130 | 545 | } | 550 | } |
131 | 546 | 551 | ||
132 | 547 | field = folks_postal_address_get_street(addr); | 552 | field = folks_postal_address_get_street(addr); |
133 | 548 | if (field && strlen(field)) { | 553 | if (field && strlen(field)) { |
135 | 549 | address.setStreet(QString::fromUtf8(field)); | 554 | address.setStreet(qStringFromGChar(field)); |
136 | 550 | } | 555 | } |
137 | 551 | 556 | ||
138 | 552 | bool isPref = false; | 557 | bool isPref = false; |
139 | @@ -594,8 +599,8 @@ | |||
140 | 594 | } | 599 | } |
141 | 595 | 600 | ||
142 | 596 | QContactOnlineAccount account; | 601 | QContactOnlineAccount account; |
145 | 597 | account.setAccountUri(QString::fromUtf8(uri)); | 602 | account.setAccountUri(qStringFromGChar(uri)); |
146 | 598 | int protocolId = DetailContextParser::accountProtocolFromString(QString::fromUtf8(key)); | 603 | int protocolId = DetailContextParser::accountProtocolFromString(qStringFromGChar(key)); |
147 | 599 | account.setProtocol(static_cast<QContactOnlineAccount::Protocol>(protocolId)); | 604 | account.setProtocol(static_cast<QContactOnlineAccount::Protocol>(protocolId)); |
148 | 600 | 605 | ||
149 | 601 | bool isPref = false; | 606 | bool isPref = false; |
150 | @@ -636,7 +641,7 @@ | |||
151 | 636 | const char *url = (const char*) folks_abstract_field_details_get_value(fd); | 641 | const char *url = (const char*) folks_abstract_field_details_get_value(fd); |
152 | 637 | 642 | ||
153 | 638 | QContactUrl detail; | 643 | QContactUrl detail; |
155 | 639 | detail.setUrl(QString::fromUtf8(url)); | 644 | detail.setUrl(qStringFromGChar(url)); |
156 | 640 | bool isPref = false; | 645 | bool isPref = false; |
157 | 641 | DetailContextParser::parseParameters(detail, fd, &isPref); | 646 | DetailContextParser::parseParameters(detail, fd, &isPref); |
158 | 642 | detail.setDetailUri(QString("%1.%2").arg(index).arg(fieldIndex++)); | 647 | detail.setDetailUri(QString("%1.%2").arg(index).arg(fieldIndex++)); |
159 | @@ -780,7 +785,7 @@ | |||
160 | 780 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); | 785 | GeeIterator *iter = gee_iterable_iterator(GEE_ITERABLE(personas)); |
161 | 781 | while(gee_iterator_next(iter)) { | 786 | while(gee_iterator_next(iter)) { |
162 | 782 | FolksPersona *persona = FOLKS_PERSONA(gee_iterator_get(iter)); | 787 | FolksPersona *persona = FOLKS_PERSONA(gee_iterator_get(iter)); |
164 | 783 | m_personas.insert(QString::fromUtf8(folks_persona_get_iid(persona)), persona); | 788 | m_personas.insert(qStringFromGChar(folks_persona_get_iid(persona)), persona); |
165 | 784 | } | 789 | } |
166 | 785 | 790 | ||
167 | 786 | g_object_unref(iter); | 791 | g_object_unref(iter); |
168 | 787 | 792 | ||
169 | === modified file 'lib/qindividual.h' | |||
170 | --- lib/qindividual.h 2014-10-13 19:33:46 +0000 | |||
171 | +++ lib/qindividual.h 2014-11-06 15:44:29 +0000 | |||
172 | @@ -168,6 +168,8 @@ | |||
173 | 168 | static void folksIndividualChanged (FolksIndividual *individual, | 168 | static void folksIndividualChanged (FolksIndividual *individual, |
174 | 169 | GParamSpec *pspec, | 169 | GParamSpec *pspec, |
175 | 170 | QIndividual *self); | 170 | QIndividual *self); |
176 | 171 | |||
177 | 172 | static QString qStringFromGChar (const gchar *str); | ||
178 | 171 | }; | 173 | }; |
179 | 172 | 174 | ||
180 | 173 | } //namespace | 175 | } //namespace |
181 | 174 | 176 | ||
182 | === modified file 'tests/unittest/qcontacts-test.cpp' | |||
183 | --- tests/unittest/qcontacts-test.cpp 2014-10-13 19:33:46 +0000 | |||
184 | +++ tests/unittest/qcontacts-test.cpp 2014-11-06 15:44:29 +0000 | |||
185 | @@ -489,6 +489,26 @@ | |||
186 | 489 | } | 489 | } |
187 | 490 | QCOMPARE(address.size(), 0); | 490 | QCOMPARE(address.size(), 0); |
188 | 491 | } | 491 | } |
189 | 492 | |||
190 | 493 | /* | ||
191 | 494 | * Test saving a contact with a multi line field | ||
192 | 495 | * BUG: #240587 | ||
193 | 496 | */ | ||
194 | 497 | void testFieldWithNewLineChar() | ||
195 | 498 | { | ||
196 | 499 | // create a contact | ||
197 | 500 | QContact contact = testContact(); | ||
198 | 501 | QContactAddress addr; | ||
199 | 502 | addr.setCountry("Line1\nLine2\r\nLine3"); | ||
200 | 503 | contact.saveDetail(&addr); | ||
201 | 504 | QSignalSpy spyContactAdded(m_manager, SIGNAL(contactsAdded(QList<QContactId>))); | ||
202 | 505 | bool result = m_manager->saveContact(&contact); | ||
203 | 506 | QCOMPARE(result, true); | ||
204 | 507 | QTRY_COMPARE(spyContactAdded.count(), 1); | ||
205 | 508 | |||
206 | 509 | addr = contact.detail<QContactAddress>(); | ||
207 | 510 | QCOMPARE(addr.country(), QStringLiteral("Line1Line2Line3")); | ||
208 | 511 | } | ||
209 | 492 | }; | 512 | }; |
210 | 493 | 513 | ||
211 | 494 | QTEST_MAIN(QContactsTest) | 514 | QTEST_MAIN(QContactsTest) |
FAILED: Continuous integration, rev:144 jenkins. qa.ubuntu. com/job/ address- book-service- ci/314/ jenkins. qa.ubuntu. com/job/ address- book-service- utopic- armhf-ci/ 86 jenkins. qa.ubuntu. com/job/ address- book-service- utopic- armhf-ci/ 86/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ address- book-service- utopic- i386-ci/ 86/console jenkins. qa.ubuntu. com/job/ generic- deb-autopilot- utopic- touch/6453 jenkins. qa.ubuntu. com/job/ generic- mediumtests- utopic/ 4281/console jenkins. qa.ubuntu. com/job/ generic- deb-autopilot- runner- mako/6051 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- utopic- armhf/7705 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- utopic- armhf/7705/ artifact/ work/output/ *zip*/output. zip s-jenkins. ubuntu- ci:8080/ job/touch- flash-device/ 15409 jenkins. qa.ubuntu. com/job/ autopilot- testrunner- otto-utopic/ 3634/console jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- utopic- amd64/4675 jenkins. qa.ubuntu. com/job/ generic- mediumtests- builder- utopic- amd64/4675/ artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
deb: http://
FAILURE: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/address- book-service- ci/314/ rebuild
http://