From 66710a8ee949f3a948c86dd7598acf529814a8d3 Mon Sep 17 00:00:00 2001 From: Mathias Hasselmann Date: Mon, 24 Oct 2011 16:29:42 +0200 Subject: [PATCH] Changes: Consider display name settings in unit tests Bug: NB#287273 RevBy: cocos --- src/engine/displaylabelgenerator.cpp | 2 +- src/engine/displaylabelgenerator.h | 2 +- .../ut_qtcontacts_trackerplugin.cpp | 168 ++++++++++++++------- .../ut_qtcontacts_trackerplugin.h | 7 +- 4 files changed, 119 insertions(+), 60 deletions(-) diff --git a/src/engine/displaylabelgenerator.cpp b/src/engine/displaylabelgenerator.cpp index 7e235dd..58cf547 100644 --- a/src/engine/displaylabelgenerator.cpp +++ b/src/engine/displaylabelgenerator.cpp @@ -230,7 +230,7 @@ QctDisplayLabelGenerator::createList(ListOptions options) QContactNickname::FieldNickname); } - // Choose among "FirstName LastName" and "LastName, FirstName" according settings + // Choose among "FirstName LastName" and "LastName FirstName" according settings switch(options & RealNameOptions) { case PreferFirstName: generators += firstNameLastNameGenerator(); diff --git a/src/engine/displaylabelgenerator.h b/src/engine/displaylabelgenerator.h index 6cd2026..8b73098 100644 --- a/src/engine/displaylabelgenerator.h +++ b/src/engine/displaylabelgenerator.h @@ -41,7 +41,7 @@ public: enum ListOption { // use "FirstName LastName" when considering real name for display label PreferFirstName = (0 << 0), - // use "LastName, FirstName" when considering real name for display label + // use "LastName FirstName" when considering real name for display label PreferLastName = (1 << 0), // mask for the "various" realname usage options RealNameOptions = (PreferFirstName | PreferLastName), diff --git a/tests/ut_qtcontacts_trackerplugin/ut_qtcontacts_trackerplugin.cpp b/tests/ut_qtcontacts_trackerplugin/ut_qtcontacts_trackerplugin.cpp index cc3d418..d34ad2c 100644 --- a/tests/ut_qtcontacts_trackerplugin/ut_qtcontacts_trackerplugin.cpp +++ b/tests/ut_qtcontacts_trackerplugin/ut_qtcontacts_trackerplugin.cpp @@ -53,11 +53,9 @@ CUBI_USE_NAMESPACE_RESOURCES //////////////////////////////////////////////////////////////////////////////////////////////////// -typedef QPair ContactDetailSample; typedef QPair PairOfStrings; typedef QHash > ImplictTypeHash; - //////////////////////////////////////////////////////////////////////////////////////////////////// static ContactDetailSample @@ -5425,57 +5423,63 @@ ut_qtcontacts_trackerplugin::testMeContact() QCOMPARE(name.firstName(), randomName); } -static const QList displayLabelDetailSamples() +const QList +ut_qtcontacts_trackerplugin::displayLabelDetailSamples(bool preferNickname, bool preferLastname) { - static QList detailList; + changeSetting(QctSettings::NameOrderKey, preferLastname ? QContactDisplayLabel__FieldOrderLastName + : QContactDisplayLabel__FieldOrderFirstName); + changeSetting(QctSettings::PreferNicknameKey, preferNickname); - if (detailList.isEmpty()) { - // match values in "test-account-1.ttl" - - // we resort to this file because presence properties are readonly - const QString accountUri1 = QLatin1String("no-presence@talk.com"); - const QString accountUri2 = QLatin1String("first.last@talk.com"); - const QString accountPath = QLatin1String("/org/freedesktop/fake/account"); + QList detailList; - QContactOnlineAccount onlineAccount1; - onlineAccount1.setValue(QContactOnlineAccount::FieldAccountUri, accountUri1); - onlineAccount1.setValue(QContactOnlineAccount__FieldAccountPath, accountPath); - onlineAccount1.setDetailUri(makeTelepathyIri(accountPath, accountUri1)); + // match values in "test-account-1.ttl" - + // we resort to this file because presence properties are readonly + const QString accountUri1 = QLatin1String("no-presence@talk.com"); + const QString accountUri2 = QLatin1String("first.last@talk.com"); + const QString accountPath = QLatin1String("/org/freedesktop/fake/account"); - QContactOnlineAccount onlineAccount2; - onlineAccount2.setValue(QContactOnlineAccount::FieldAccountUri, accountUri2); - onlineAccount2.setValue(QContactOnlineAccount__FieldAccountPath, accountPath); - onlineAccount2.setDetailUri(makeTelepathyIri(accountPath, accountUri2)); + QContactOnlineAccount onlineAccount1; + onlineAccount1.setValue(QContactOnlineAccount::FieldAccountUri, accountUri1); + onlineAccount1.setValue(QContactOnlineAccount__FieldAccountPath, accountPath); + onlineAccount1.setDetailUri(makeTelepathyIri(accountPath, accountUri1)); - QContactName customLabel; - customLabel.setCustomLabel(QLatin1String("Custom Label")); + QContactOnlineAccount onlineAccount2; + onlineAccount2.setValue(QContactOnlineAccount::FieldAccountUri, accountUri2); + onlineAccount2.setValue(QContactOnlineAccount__FieldAccountPath, accountPath); + onlineAccount2.setDetailUri(makeTelepathyIri(accountPath, accountUri2)); - QContactName name; - name.setFirstName(QLatin1String("FirstName")); - name.setLastName(QLatin1String("LastName")); - - detailList << makeDetailSample(QContactUrl::DefinitionName, - QContactUrl::FieldUrl, - QLatin1String("www.url.com")); - detailList << makeDetailSample(QContactPhoneNumber::DefinitionName, - QContactPhoneNumber::FieldNumber, - QLatin1String("555444333")); - detailList << makeDetailSample(QContactEmailAddress::DefinitionName, - QContactEmailAddress::FieldEmailAddress, - QLatin1String("first.last@mail.com")); - detailList << makeDetailSample(onlineAccount1, onlineAccount1.accountUri()); - detailList << makeDetailSample(onlineAccount2, QLatin1String("The Dude")); - detailList << makeDetailSample(QContactOrganization::DefinitionName, - QContactOrganization::FieldName, - QLatin1String("Company")); - detailList << makeDetailSample(QContactName::DefinitionName, - QContactName::FieldMiddleName, - QLatin1String("Great")); - detailList << makeDetailSample(customLabel, customLabel.customLabel()); - detailList << makeDetailSample(name, QString::fromLatin1("FirstName LastName")); - detailList << makeDetailSample(QContactNickname::DefinitionName, + QContactName customLabel; + customLabel.setCustomLabel(QLatin1String("Custom Label")); + + QContactName name; + name.setFirstName(QLatin1String("FirstName")); + name.setLastName(QLatin1String("LastName")); + + detailList << makeDetailSample(QContactUrl::DefinitionName, + QContactUrl::FieldUrl, + QLatin1String("www.url.com")); + detailList << makeDetailSample(QContactPhoneNumber::DefinitionName, + QContactPhoneNumber::FieldNumber, + QLatin1String("555444333")); + detailList << makeDetailSample(QContactEmailAddress::DefinitionName, + QContactEmailAddress::FieldEmailAddress, + QLatin1String("first.last@mail.com")); + detailList << makeDetailSample(onlineAccount1, onlineAccount1.accountUri()); + detailList << makeDetailSample(onlineAccount2, QLatin1String("The Dude")); + detailList << makeDetailSample(QContactOrganization::DefinitionName, + QContactOrganization::FieldName, + QLatin1String("Company")); + detailList << makeDetailSample(QContactName::DefinitionName, + QContactName::FieldMiddleName, + QLatin1String("Great")); + detailList << makeDetailSample(customLabel, customLabel.customLabel()); + detailList << makeDetailSample(name, preferLastname ? QLatin1String("LastName FirstName") + : QLatin1String("FirstName LastName")); + + detailList.insert(detailList.count() - (preferNickname ? 0 : 2), + makeDetailSample(QContactNickname::DefinitionName, QContactNickname::FieldNickname, - QLatin1String("The Great Dude")); - } + QLatin1String("The Great Dude"))); return detailList; } @@ -5498,11 +5502,26 @@ static QContactDetail getDetailFromSample(const ContactDetailSample &sample, } void +ut_qtcontacts_trackerplugin::testDisplayLabelSynthesized_data() +{ + QTest::addColumn("preferNickname"); + QTest::addColumn("preferLastname"); + + QTest::newRow("FirstName:Nickname") << false << false; + QTest::newRow("LastName:Nickname") << false << true; + QTest::newRow("Nickname:FirstName") << true << false; + QTest::newRow("Nickname:LastName") << true << true; +} + +void ut_qtcontacts_trackerplugin::testDisplayLabelSynthesized() { + QFETCH(bool, preferNickname); + QFETCH(bool, preferLastname); + QContact contact; - foreach(ContactDetailSample sample, displayLabelDetailSamples()) { + foreach(ContactDetailSample sample, displayLabelDetailSamples(preferNickname, preferLastname)) { QContactDetail detail = getDetailFromSample(sample, contact); QVERIFY(contact.saveDetail(&detail)); @@ -5522,11 +5541,26 @@ ut_qtcontacts_trackerplugin::testDisplayLabelSynthesized() } void +ut_qtcontacts_trackerplugin::testDisplayLabelSaved_data() +{ + QTest::addColumn("preferNickname"); + QTest::addColumn("preferLastname"); + + QTest::newRow("FirstName:Nickname") << false << false; + QTest::newRow("LastName:Nickname") << false << true; + QTest::newRow("Nickname:FirstName") << true << false; + QTest::newRow("Nickname:LastName") << true << true; +} + +void ut_qtcontacts_trackerplugin::testDisplayLabelSaved() { + QFETCH(bool, preferNickname); + QFETCH(bool, preferLastname); + QContact contact; - foreach(const ContactDetailSample &sample, displayLabelDetailSamples()) { + foreach(const ContactDetailSample &sample, displayLabelDetailSamples(preferNickname, preferLastname)) { // add another detail to the contact QContactDetail detail = getDetailFromSample(sample, contact); QVERIFY(contact.saveDetail(&detail)); @@ -5553,12 +5587,31 @@ ut_qtcontacts_trackerplugin::testDisplayLabelFetch_data() { QTest::addColumn("definitionHints"); QTest::addColumn("hasDisplayLabel"); + QTest::addColumn("preferNickname"); + QTest::addColumn("preferLastname"); + + for(int i = 0; i < 4; ++i) { + const bool preferNickname = bool(i / 2); + const bool preferLastname = bool(i % 2); - QTest::newRow("empty hints") << QStringList() << true; - QTest::newRow("display label") << (QStringList() << QContactDisplayLabel::DefinitionName) << true; - QTest::newRow("note detail") << (QStringList() << QContactNote::DefinitionName) << false; - QTest::newRow("note and display label") << (QStringList() << QContactNote::DefinitionName << - QContactDisplayLabel::DefinitionName) << true; + const QString tag = (QLatin1String(preferNickname ? "Nickname:" : "") + + QLatin1String(preferLastname ? "Lastname" : "Firstname") + + QLatin1String(preferNickname ? "" : ":Nickname")); + + QTest::newRow(tag + QLatin1String(":NoHints")) + << QStringList() + << true << preferNickname << preferLastname; + QTest::newRow(tag + QLatin1String(":DisplayLabel")) + << (QStringList() << QContactDisplayLabel::DefinitionName) + << true << preferNickname << preferLastname; + QTest::newRow(tag + QLatin1String(":Note")) + << (QStringList() << QContactNote::DefinitionName) + << false << preferNickname << preferLastname; + QTest::newRow(tag + QLatin1String(":NoteAndDisplayLabel")) + << (QStringList() << QContactNote::DefinitionName + << QContactDisplayLabel::DefinitionName) + << true << preferNickname << preferLastname; + } } void @@ -5566,13 +5619,14 @@ ut_qtcontacts_trackerplugin::testDisplayLabelFetch() { QFETCH(QStringList, definitionHints); QFETCH(bool, hasDisplayLabel); + QFETCH(bool, preferNickname); + QFETCH(bool, preferLastname); + QContact contact; QContactFetchHint fetchHint; fetchHint.setDetailDefinitionsHint(definitionHints); - QContact contact; - - foreach(ContactDetailSample sample, displayLabelDetailSamples()) { + foreach(ContactDetailSample sample, displayLabelDetailSamples(preferNickname, preferLastname)) { QContactDetail detail = getDetailFromSample(sample, contact); QVERIFY(contact.saveDetail(&detail)); @@ -5603,7 +5657,7 @@ ut_qtcontacts_trackerplugin::testDisplayLabelSynthesizedWithNameOrders_data() QTest::newRow("FirstName LastName") << QString::fromLatin1(QContactDisplayLabel__FieldOrderFirstName.latin1()) << QString::fromLatin1("FirstName LastName"); - QTest::newRow("LastName, FirstName") + QTest::newRow("LastName FirstName") << QString::fromLatin1(QContactDisplayLabel__FieldOrderLastName.latin1()) << QString::fromLatin1("LastName FirstName"); QTest::newRow("Default") // is like "first-last" diff --git a/tests/ut_qtcontacts_trackerplugin/ut_qtcontacts_trackerplugin.h b/tests/ut_qtcontacts_trackerplugin/ut_qtcontacts_trackerplugin.h index 19ec6bc..4249efd 100644 --- a/tests/ut_qtcontacts_trackerplugin/ut_qtcontacts_trackerplugin.h +++ b/tests/ut_qtcontacts_trackerplugin/ut_qtcontacts_trackerplugin.h @@ -31,6 +31,7 @@ // FIXME: This type name doesn't fit anything!!! struct editStruct; typedef class QMap QContactDetailFieldDefinitionMap; +typedef QPair ContactDetailSample; /** * QtContacts Tracker plugin unittests @@ -168,8 +169,10 @@ private slots: void testDisplayLabelFetch_data(); void testDisplayLabelFetch(); - void testDisplayLabelSynthesized(); + void testDisplayLabelSaved_data(); void testDisplayLabelSaved(); + void testDisplayLabelSynthesized_data(); + void testDisplayLabelSynthesized(); void testDisplayLabelSynthesizedWithNameOrders_data(); void testDisplayLabelSynthesizedWithNameOrders(); @@ -255,6 +258,8 @@ private: void fieldsWithoutContextAndSubType(QContactDetailFieldDefinitionMap &fields, const QString &contactType, const QString &definitionName); + const QList displayLabelDetailSamples(bool preferNickname, bool preferLastname); + private: QList addedContacts; }; -- 2.1.4