322 newMRow("Phone number = 555-1212", manager) << manager << phonenumber << number << QVariant("555-1212") << (int) QContactFilter::MatchExactly << "a"; |
331 newMRow("Phone number = 555-1212", manager) << manager << phonenumber << number << QVariant("555-1212") << (int) QContactFilter::MatchExactly << "a"; |
323 newMRow("Phone number = 34, contains", manager) << manager << phonenumber << number << QVariant("34") << (int) QContactFilter::MatchContains << "b"; |
332 newMRow("Phone number = 34, contains", manager) << manager << phonenumber << number << QVariant("34") << (int) QContactFilter::MatchContains << "b"; |
324 newMRow("Phone number = 555, starts with", manager) << manager << phonenumber << number << QVariant("555") << (int) QContactFilter::MatchStartsWith << "ab"; |
333 newMRow("Phone number = 555, starts with", manager) << manager << phonenumber << number << QVariant("555") << (int) QContactFilter::MatchStartsWith << "ab"; |
325 newMRow("Phone number = 1212, ends with", manager) << manager << phonenumber << number << QVariant("1212") << (int) QContactFilter::MatchEndsWith << "a"; |
334 newMRow("Phone number = 1212, ends with", manager) << manager << phonenumber << number << QVariant("1212") << (int) QContactFilter::MatchEndsWith << "a"; |
326 newMRow("Phone number = 555-1212, match phone number", manager) << manager << phonenumber << number << QVariant("555-1212") << (int) QContactFilter::MatchPhoneNumber << "a"; |
335 newMRow("Phone number = 555-1212, match phone number", manager) << manager << phonenumber << number << QVariant("555-1212") << (int) QContactFilter::MatchPhoneNumber << "a"; |
327 newMRow("Phone number = 555, keypad collation", manager) << manager << phonenumber << number << QVariant("555") << (int) QContactFilter::MatchKeypadCollation << "ab"; |
336 newMRow("Phone number = 555, keypad collation", manager) << manager << phonenumber << number << QVariant("555") << (int) (QContactFilter::MatchKeypadCollation | QContactFilter::MatchStartsWith) << "ab"; |
328 |
337 |
329 /* Converting other types to strings */ |
338 /* Converting other types to strings */ |
330 QPair<QString, QString> defAndFieldNames = defAndFieldNamesForTypePerManager.value(manager).value("Integer"); |
339 QPair<QString, QString> defAndFieldNames = defAndFieldNamesForTypePerManager.value(manager).value("Integer"); |
331 if (!defAndFieldNames.first.isEmpty() && !defAndFieldNames.second.isEmpty()) { |
340 if (!defAndFieldNames.first.isEmpty() && !defAndFieldNames.second.isEmpty()) { |
332 QTest::newRow("integer == 20") << manager << defAndFieldNames.first << defAndFieldNames.second << QVariant("20") << 0 << es; |
341 QTest::newRow("integer == 20") << manager << defAndFieldNames.first << defAndFieldNames.second << QVariant("20") << 0 << es; |
365 |
374 |
366 ids = cm->contactIds(df); |
375 ids = cm->contactIds(df); |
367 |
376 |
368 QString output = convertIds(contacts, ids); |
377 QString output = convertIds(contacts, ids); |
369 QEXPECT_FAIL("integer == 20", "Not sure if this should pass or fail", Continue); |
378 QEXPECT_FAIL("integer == 20", "Not sure if this should pass or fail", Continue); |
|
379 QCOMPARE_UNSORTED(output, expected); |
|
380 } |
|
381 |
|
382 void tst_QContactManagerFiltering::detailPhoneNumberFiltering_data() |
|
383 { |
|
384 QTest::addColumn<QContactManager *>("cm"); |
|
385 QTest::addColumn<QString>("defname"); |
|
386 QTest::addColumn<QString>("fieldname"); |
|
387 QTest::addColumn<QVariant>("value"); |
|
388 QTest::addColumn<int>("matchflags"); |
|
389 QTest::addColumn<QString>("expected"); |
|
390 |
|
391 // ITU-T standard keypad collation: |
|
392 // 2 = abc, 3 = def, 4 = ghi, 5 = jkl, 6 = mno, 7 = pqrs, 8 = tuv, 9 = wxyz, 0 = space |
|
393 |
|
394 QString phoneDef = QContactPhoneNumber::DefinitionName; |
|
395 QString phoneField = QContactPhoneNumber::FieldNumber; |
|
396 QString nameDef = QContactName::DefinitionName; |
|
397 QString nameField = QContactName::FieldFirstName; // just test the first name. |
|
398 |
|
399 // purely to test phone number filtering. |
|
400 for (int i = 0; i < managers.size(); i++) { |
|
401 QContactManager *manager = managers.at(i); |
|
402 |
|
403 // first, keypad collation testing (ITU-T / T9 testing) |
|
404 QTest::newRow("t9 aaron") << manager << nameDef << nameField << QVariant(QString("22766")) << (int)(QContactFilter::MatchKeypadCollation) << "a"; |
|
405 QTest::newRow("t9 bob") << manager << nameDef << nameField << QVariant(QString("262")) << (int)(QContactFilter::MatchKeypadCollation) << "b"; |
|
406 QTest::newRow("t9 john") << manager << nameDef << nameField << QVariant(QString("5646")) << (int)(QContactFilter::MatchKeypadCollation) << "efg"; |
|
407 QTest::newRow("t9 bo") << manager << nameDef << nameField << QVariant(QString("26")) << (int)(QContactFilter::MatchKeypadCollation | QContactFilter::MatchStartsWith) << "bc"; // bob, boris |
|
408 QTest::newRow("t9 zzzz") << manager << nameDef << nameField << QVariant(QString("9999")) << (int)(QContactFilter::MatchKeypadCollation) << ""; // nobody. |
|
409 |
|
410 // now do phone number matching - first, aaron's phone number |
|
411 QTest::newRow("a phone hyphen") << manager << phoneDef << phoneField << QVariant(QString("555-1212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
412 QTest::newRow("a phone plus") << manager << phoneDef << phoneField << QVariant(QString("+5551212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
413 QTest::newRow("a phone brackets") << manager << phoneDef << phoneField << QVariant(QString("(555)1212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
414 QTest::newRow("a phone nospaces") << manager << phoneDef << phoneField << QVariant(QString("5551212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
415 QTest::newRow("a phone single space") << manager << phoneDef << phoneField << QVariant(QString("555 1212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
416 QTest::newRow("a phone random spaces") << manager << phoneDef << phoneField << QVariant(QString("55 512 12")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
417 QTest::newRow("a phone every space") << manager << phoneDef << phoneField << QVariant(QString("5 5 5 1 2 1 2")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
418 QTest::newRow("a phone plus hyphen") << manager << phoneDef << phoneField << QVariant(QString("+555-1212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
419 QTest::newRow("a phone plus brackets") << manager << phoneDef << phoneField << QVariant(QString("+5(55)1212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
420 QTest::newRow("a phone plus brackets hyphen") << manager << phoneDef << phoneField << QVariant(QString("+5(55)1-212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
421 QTest::newRow("a phone plus brackets hyphen spaces") << manager << phoneDef << phoneField << QVariant(QString("+5 (55) 1-212")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; |
|
422 |
|
423 // XXX TODO: should we test for character to number conversions (eg, dial 1800-PESTCONTROL) etc |
|
424 //QTest::newRow("a phone characters") << manager << phoneDef << phoneField << QVariant(QString("jjj1a1a")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; // 5551212 |
|
425 //QTest::newRow("a phone characters") << manager << phoneDef << phoneField << QVariant(QString("jkl1b1a")) << (int)(QContactFilter::MatchPhoneNumber) << "a"; // 5551212 |
|
426 |
|
427 // then matches bob's phone number |
|
428 QTest::newRow("b phone hyphen") << manager << phoneDef << phoneField << QVariant(QString("555-3456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
429 QTest::newRow("b phone plus") << manager << phoneDef << phoneField << QVariant(QString("+5553456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
430 QTest::newRow("b phone brackets") << manager << phoneDef << phoneField << QVariant(QString("(555)3456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
431 QTest::newRow("b phone nospaces") << manager << phoneDef << phoneField << QVariant(QString("5553456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
432 QTest::newRow("b phone single space") << manager << phoneDef << phoneField << QVariant(QString("555 3456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
433 QTest::newRow("b phone random spaces") << manager << phoneDef << phoneField << QVariant(QString("55 534 56")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
434 QTest::newRow("b phone every space") << manager << phoneDef << phoneField << QVariant(QString("5 5 5 3 4 5 6")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
435 QTest::newRow("b phone plus hyphen") << manager << phoneDef << phoneField << QVariant(QString("+555-3456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
436 QTest::newRow("b phone plus brackets") << manager << phoneDef << phoneField << QVariant(QString("+5(55)3456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
437 QTest::newRow("b phone plus brackets hyphen") << manager << phoneDef << phoneField << QVariant(QString("+5(55)3-456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
438 QTest::newRow("b phone plus brackets hyphen spaces") << manager << phoneDef << phoneField << QVariant(QString("+5 (55) 3-456")) << (int)(QContactFilter::MatchPhoneNumber) << "b"; |
|
439 |
|
440 // then match no phone numbers (negative testing) -- 555-9999 matches nobody in our test set. |
|
441 QTest::newRow("no phone hyphen") << manager << phoneDef << phoneField << QVariant(QString("555-9999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
442 QTest::newRow("no phone plus") << manager << phoneDef << phoneField << QVariant(QString("+5559999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
443 QTest::newRow("no phone brackets") << manager << phoneDef << phoneField << QVariant(QString("(555)9999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
444 QTest::newRow("no phone nospaces") << manager << phoneDef << phoneField << QVariant(QString("5559999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
445 QTest::newRow("no phone single space") << manager << phoneDef << phoneField << QVariant(QString("555 9999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
446 QTest::newRow("no phone random spaces") << manager << phoneDef << phoneField << QVariant(QString("55 599 99")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
447 QTest::newRow("no phone every space") << manager << phoneDef << phoneField << QVariant(QString("5 5 5 9 9 9 9")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
448 QTest::newRow("no phone plus hyphen") << manager << phoneDef << phoneField << QVariant(QString("+555-9999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
449 QTest::newRow("no phone plus brackets") << manager << phoneDef << phoneField << QVariant(QString("+5(55)9999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
450 QTest::newRow("no phone plus brackets hyphen") << manager << phoneDef << phoneField << QVariant(QString("+5(55)9-999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
451 QTest::newRow("no phone plus brackets hyphen spaces") << manager << phoneDef << phoneField << QVariant(QString("+5 (55) 9-999")) << (int)(QContactFilter::MatchPhoneNumber) << ""; |
|
452 |
|
453 // then match both aaron and bob via starts with |
|
454 QTest::newRow("ab phone starts nospace") << manager << phoneDef << phoneField << QVariant(QString("555")) << (int)(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith) << "ab"; |
|
455 QTest::newRow("ab phone starts hyphen") << manager << phoneDef << phoneField << QVariant(QString("555-")) << (int)(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith) << "ab"; |
|
456 QTest::newRow("ab phone starts space") << manager << phoneDef << phoneField << QVariant(QString("55 5")) << (int)(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith) << "ab"; |
|
457 QTest::newRow("ab phone starts brackets") << manager << phoneDef << phoneField << QVariant(QString("(555)")) << (int)(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith) << "ab"; |
|
458 QTest::newRow("ab phone starts plus") << manager << phoneDef << phoneField << QVariant(QString("+555")) << (int)(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith) << "ab"; |
|
459 QTest::newRow("ab phone starts hyphen space") << manager << phoneDef << phoneField << QVariant(QString("5 55-")) << (int)(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith) << "ab"; |
|
460 QTest::newRow("ab phone starts hyphen space brackets") << manager << phoneDef << phoneField << QVariant(QString("5 (55)-")) << (int)(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith) << "ab"; |
|
461 QTest::newRow("ab phone starts hyphen space brackets plus") << manager << phoneDef << phoneField << QVariant(QString("+5 (55)-")) << (int)(QContactFilter::MatchPhoneNumber | QContactFilter::MatchStartsWith) << "ab"; |
|
462 } |
|
463 } |
|
464 |
|
465 void tst_QContactManagerFiltering::detailPhoneNumberFiltering() |
|
466 { |
|
467 QFETCH(QContactManager*, cm); |
|
468 QFETCH(QString, defname); |
|
469 QFETCH(QString, fieldname); |
|
470 QFETCH(QVariant, value); |
|
471 QFETCH(int, matchflags); |
|
472 QFETCH(QString, expected); |
|
473 |
|
474 // note: this test is exactly the same as string filtering, but uses different fields and specific matchflags. |
|
475 |
|
476 QList<QContactLocalId> contacts = contactsAddedToManagers.values(cm); |
|
477 QList<QContactLocalId> ids; |
|
478 |
|
479 QContactDetailFilter df; |
|
480 df.setDetailDefinitionName(defname, fieldname); |
|
481 df.setValue(value); |
|
482 df.setMatchFlags(QContactFilter::MatchFlags(matchflags)); |
|
483 |
|
484 if (cm->managerName() == "memory") { |
|
485 /* At this point, since we're using memory, assume the filter isn't really supported */ |
|
486 QVERIFY(cm->isFilterSupported(df) == false); |
|
487 } |
|
488 |
|
489 ids = cm->contactIds(df); |
|
490 |
|
491 QString output = convertIds(contacts, ids); |
|
492 //QSKIP("TODO: fix default implementation of phone number matching!", SkipSingle); |
370 QCOMPARE_UNSORTED(output, expected); |
493 QCOMPARE_UNSORTED(output, expected); |
371 } |
494 } |
372 |
495 |
373 void tst_QContactManagerFiltering::detailVariantFiltering_data() |
496 void tst_QContactManagerFiltering::detailVariantFiltering_data() |
374 { |
497 { |
1716 |
1839 |
1717 for (int i = 0; i < managers.size(); i++) { |
1840 for (int i = 0; i < managers.size(); i++) { |
1718 QContactManager *manager = managers.at(i); |
1841 QContactManager *manager = managers.at(i); |
1719 |
1842 |
1720 // HasMember |
1843 // HasMember |
1721 QTest::newRow("RF-1") << manager << static_cast<int>(QContactRelationshipFilter::Second) << QString(QLatin1String(QContactRelationship::HasMember)) << static_cast<unsigned int>(0) << QString() << "a"; |
1844 QTest::newRow("RF-1") << manager << static_cast<int>(QContactRelationship::Second) << QString(QLatin1String(QContactRelationship::HasMember)) << static_cast<unsigned int>(0) << QString() << "a"; |
1722 QTest::newRow("RF-2") << manager << static_cast<int>(QContactRelationshipFilter::First) << QString(QLatin1String(QContactRelationship::HasMember)) << static_cast<unsigned int>(0) << QString() << "b"; |
1845 QTest::newRow("RF-2") << manager << static_cast<int>(QContactRelationship::First) << QString(QLatin1String(QContactRelationship::HasMember)) << static_cast<unsigned int>(0) << QString() << "b"; |
1723 QTest::newRow("RF-3") << manager << static_cast<int>(QContactRelationshipFilter::Either) << QString(QLatin1String(QContactRelationship::HasMember)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1846 QTest::newRow("RF-3") << manager << static_cast<int>(QContactRelationship::Either) << QString(QLatin1String(QContactRelationship::HasMember)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1724 |
1847 |
1725 // match any contact that has an assistant |
1848 // match any contact that has an assistant |
1726 QTest::newRow("RF-4") << manager << static_cast<int>(QContactRelationshipFilter::Second) << QString(QLatin1String(QContactRelationship::HasAssistant)) << static_cast<unsigned int>(0) << QString() << "a"; |
1849 QTest::newRow("RF-4") << manager << static_cast<int>(QContactRelationship::Second) << QString(QLatin1String(QContactRelationship::HasAssistant)) << static_cast<unsigned int>(0) << QString() << "a"; |
1727 // match any contact that is an assistant |
1850 // match any contact that is an assistant |
1728 QTest::newRow("RF-5") << manager << static_cast<int>(QContactRelationshipFilter::First) << QString(QLatin1String(QContactRelationship::HasAssistant)) << static_cast<unsigned int>(0) << QString() << "b"; |
1851 QTest::newRow("RF-5") << manager << static_cast<int>(QContactRelationship::First) << QString(QLatin1String(QContactRelationship::HasAssistant)) << static_cast<unsigned int>(0) << QString() << "b"; |
1729 // match any contact that has an assistant or is an assistant |
1852 // match any contact that has an assistant or is an assistant |
1730 QTest::newRow("RF-6") << manager << static_cast<int>(QContactRelationshipFilter::Either) << QString(QLatin1String(QContactRelationship::HasAssistant)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1853 QTest::newRow("RF-6") << manager << static_cast<int>(QContactRelationship::Either) << QString(QLatin1String(QContactRelationship::HasAssistant)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1731 |
1854 |
1732 // IsSameAs |
1855 // IsSameAs |
1733 QTest::newRow("RF-7") << manager << static_cast<int>(QContactRelationshipFilter::Second) << QString(QLatin1String(QContactRelationship::IsSameAs)) << static_cast<unsigned int>(0) << QString() << "a"; |
1856 QTest::newRow("RF-7") << manager << static_cast<int>(QContactRelationship::Second) << QString(QLatin1String(QContactRelationship::IsSameAs)) << static_cast<unsigned int>(0) << QString() << "a"; |
1734 QTest::newRow("RF-8") << manager << static_cast<int>(QContactRelationshipFilter::First) << QString(QLatin1String(QContactRelationship::IsSameAs)) << static_cast<unsigned int>(0) << QString() << "b"; |
1857 QTest::newRow("RF-8") << manager << static_cast<int>(QContactRelationship::First) << QString(QLatin1String(QContactRelationship::IsSameAs)) << static_cast<unsigned int>(0) << QString() << "b"; |
1735 QTest::newRow("RF-9") << manager << static_cast<int>(QContactRelationshipFilter::Either) << QString(QLatin1String(QContactRelationship::IsSameAs)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1858 QTest::newRow("RF-9") << manager << static_cast<int>(QContactRelationship::Either) << QString(QLatin1String(QContactRelationship::IsSameAs)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1736 |
1859 |
1737 // Aggregates |
1860 // Aggregates |
1738 QTest::newRow("RF-10") << manager << static_cast<int>(QContactRelationshipFilter::Second) << QString(QLatin1String(QContactRelationship::Aggregates)) << static_cast<unsigned int>(0) << QString() << "a"; |
1861 QTest::newRow("RF-10") << manager << static_cast<int>(QContactRelationship::Second) << QString(QLatin1String(QContactRelationship::Aggregates)) << static_cast<unsigned int>(0) << QString() << "a"; |
1739 QTest::newRow("RF-11") << manager << static_cast<int>(QContactRelationshipFilter::First) << QString(QLatin1String(QContactRelationship::Aggregates)) << static_cast<unsigned int>(0) << QString() << "b"; |
1862 QTest::newRow("RF-11") << manager << static_cast<int>(QContactRelationship::First) << QString(QLatin1String(QContactRelationship::Aggregates)) << static_cast<unsigned int>(0) << QString() << "b"; |
1740 QTest::newRow("RF-12") << manager << static_cast<int>(QContactRelationshipFilter::Either) << QString(QLatin1String(QContactRelationship::Aggregates)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1863 QTest::newRow("RF-12") << manager << static_cast<int>(QContactRelationship::Either) << QString(QLatin1String(QContactRelationship::Aggregates)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1741 |
1864 |
1742 // HasManager |
1865 // HasManager |
1743 QTest::newRow("RF-13") << manager << static_cast<int>(QContactRelationshipFilter::Second) << QString(QLatin1String(QContactRelationship::HasManager)) << static_cast<unsigned int>(0) << QString() << "a"; |
1866 QTest::newRow("RF-13") << manager << static_cast<int>(QContactRelationship::Second) << QString(QLatin1String(QContactRelationship::HasManager)) << static_cast<unsigned int>(0) << QString() << "a"; |
1744 QTest::newRow("RF-14") << manager << static_cast<int>(QContactRelationshipFilter::First) << QString(QLatin1String(QContactRelationship::HasManager)) << static_cast<unsigned int>(0) << QString() << "b"; |
1867 QTest::newRow("RF-14") << manager << static_cast<int>(QContactRelationship::First) << QString(QLatin1String(QContactRelationship::HasManager)) << static_cast<unsigned int>(0) << QString() << "b"; |
1745 QTest::newRow("RF-15") << manager << static_cast<int>(QContactRelationshipFilter::Either) << QString(QLatin1String(QContactRelationship::HasManager)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1868 QTest::newRow("RF-15") << manager << static_cast<int>(QContactRelationship::Either) << QString(QLatin1String(QContactRelationship::HasManager)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1746 |
1869 |
1747 // HasSpouse |
1870 // HasSpouse |
1748 QTest::newRow("RF-16") << manager << static_cast<int>(QContactRelationshipFilter::Second) << QString(QLatin1String(QContactRelationship::HasSpouse)) << static_cast<unsigned int>(0) << QString() << "a"; |
1871 QTest::newRow("RF-16") << manager << static_cast<int>(QContactRelationship::Second) << QString(QLatin1String(QContactRelationship::HasSpouse)) << static_cast<unsigned int>(0) << QString() << "a"; |
1749 QTest::newRow("RF-17") << manager << static_cast<int>(QContactRelationshipFilter::First) << QString(QLatin1String(QContactRelationship::HasSpouse)) << static_cast<unsigned int>(0) << QString() << "b"; |
1872 QTest::newRow("RF-17") << manager << static_cast<int>(QContactRelationship::First) << QString(QLatin1String(QContactRelationship::HasSpouse)) << static_cast<unsigned int>(0) << QString() << "b"; |
1750 QTest::newRow("RF-18") << manager << static_cast<int>(QContactRelationshipFilter::Either) << QString(QLatin1String(QContactRelationship::HasSpouse)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1873 QTest::newRow("RF-18") << manager << static_cast<int>(QContactRelationship::Either) << QString(QLatin1String(QContactRelationship::HasSpouse)) << static_cast<unsigned int>(0) << QString() << "ab"; |
1751 |
1874 |
1752 // Unknown relationship |
1875 // Unknown relationship |
1753 QTest::newRow("RF-19") << manager << static_cast<int>(QContactRelationshipFilter::Second) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << ""; |
1876 if (manager->hasFeature(QContactManager::ArbitraryRelationshipTypes)) { |
1754 QTest::newRow("RF-20") << manager << static_cast<int>(QContactRelationshipFilter::First) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << ""; |
1877 QTest::newRow("RF-19") << manager << static_cast<int>(QContactRelationship::Second) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << "a"; |
1755 QTest::newRow("RF-21") << manager << static_cast<int>(QContactRelationshipFilter::Either) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << ""; |
1878 QTest::newRow("RF-20") << manager << static_cast<int>(QContactRelationship::First) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << "b"; |
|
1879 QTest::newRow("RF-21") << manager << static_cast<int>(QContactRelationship::Either) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << "ab"; |
|
1880 } else { |
|
1881 QTest::newRow("RF-19") << manager << static_cast<int>(QContactRelationship::Second) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << ""; |
|
1882 QTest::newRow("RF-20") << manager << static_cast<int>(QContactRelationship::First) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << ""; |
|
1883 QTest::newRow("RF-21") << manager << static_cast<int>(QContactRelationship::Either) << QString(QLatin1String("UnknownRelationship")) << static_cast<unsigned int>(0) << QString() << ""; |
|
1884 } |
1756 |
1885 |
1757 // match any contact that is the related contact in a relationship with contact-A |
1886 // match any contact that is the related contact in a relationship with contact-A |
1758 //QTest::newRow("RF-19") << manager << static_cast<int>(QContactRelationshipFilter::Second) << QString() << static_cast<unsigned int>(contactAId.value(manager).localId()) << contactAId.value(manager).managerUri() << "h"; |
1887 //QTest::newRow("RF-19") << manager << static_cast<int>(QContactRelationship::Second) << QString() << static_cast<unsigned int>(contactAId.value(manager).localId()) << contactAId.value(manager).managerUri() << "h"; |
1759 // match any contact has contact-A as the related contact |
1888 // match any contact has contact-A as the related contact |
1760 //QTest::newRow("RF-20") << manager << static_cast<int>(QContactRelationshipFilter::First) << QString() << static_cast<unsigned int>(contactAId.value(manager).localId()) << contactAId.value(manager).managerUri() << "i"; |
1889 //QTest::newRow("RF-20") << manager << static_cast<int>(QContactRelationship::First) << QString() << static_cast<unsigned int>(contactAId.value(manager).localId()) << contactAId.value(manager).managerUri() << "i"; |
1761 // match any contact that has any relationship with contact-A |
1890 // match any contact that has any relationship with contact-A |
1762 //QTest::newRow("RF-21") << manager << static_cast<int>(QContactRelationshipFilter::Either) << QString() << static_cast<unsigned int>(contactAId.value(manager).localId()) << contactAId.value(manager).managerUri() << "hi"; |
1891 //QTest::newRow("RF-21") << manager << static_cast<int>(QContactRelationship::Either) << QString() << static_cast<unsigned int>(contactAId.value(manager).localId()) << contactAId.value(manager).managerUri() << "hi"; |
1763 } |
1892 } |
1764 } |
1893 } |
1765 |
1894 |
1766 QContact tst_QContactManagerFiltering::createContact(QContactManager* cm, QString type, QString name) |
1895 QContact tst_QContactManagerFiltering::createContact(QContactManager* cm, QString type, QString name) |
1767 { |
1896 { |
3034 dumpContact(c); |
3176 dumpContact(c); |
3035 } |
3177 } |
3036 } |
3178 } |
3037 |
3179 |
3038 /* Static actions for testing matching */ |
3180 /* Static actions for testing matching */ |
3039 class QIntegerAction : public QContactAction |
3181 |
|
3182 class DummyAction : public QContactAction |
|
3183 { |
|
3184 public: |
|
3185 QVariantMap metaData() const {return QVariantMap();} |
|
3186 |
|
3187 bool invokeAction(const QContact&, const QContactDetail&, const QVariantMap&) |
|
3188 { |
|
3189 // Well, do something |
|
3190 emit stateChanged(QContactAction::FinishedState); |
|
3191 return true; |
|
3192 } |
|
3193 |
|
3194 QVariantMap results() const |
|
3195 { |
|
3196 return QVariantMap(); |
|
3197 } |
|
3198 |
|
3199 State state() const {return QContactAction::FinishedState;} |
|
3200 |
|
3201 }; |
|
3202 |
|
3203 class QIntegerAction : public DummyAction |
3040 { |
3204 { |
3041 Q_OBJECT |
3205 Q_OBJECT |
3042 |
3206 |
3043 public: |
3207 public: |
3044 QIntegerAction() {} |
3208 QIntegerAction() {} |
3045 ~QIntegerAction() {} |
3209 ~QIntegerAction() {} |
3046 |
3210 |
3047 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("Number", "IntegerCo", 5); } |
3211 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("Number", "IntegerCo", 5); } |
3048 QVariantMap metadata() const {return QVariantMap();} |
|
3049 QVariantMap metaData() const {return QVariantMap();} |
|
3050 |
3212 |
3051 QContactFilter contactFilter(const QVariant& value) const |
3213 QContactFilter contactFilter(const QVariant& value) const |
3052 { |
3214 { |
3053 QContactDetailFilter df; |
3215 QContactDetailFilter df; |
3054 QPair<QString, QString> defAndFieldName = defAndFieldNamesForTypeForActions.value("Integer"); |
3216 QPair<QString, QString> defAndFieldName = defAndFieldNamesForTypeForActions.value("Integer"); |
3055 df.setDetailDefinitionName(defAndFieldName.first, defAndFieldName.second); |
3217 df.setDetailDefinitionName(defAndFieldName.first, defAndFieldName.second); |
3056 df.setValue(value); |
3218 df.setValue(value); |
3057 return df; |
3219 return df; |
3058 } |
3220 } |
3059 bool supportsDetail(const QContactDetail& detail) const |
3221 bool isDetailSupported(const QContactDetail &detail, const QContact &) const |
3060 { |
3222 { |
3061 return detail.definitionName() == defAndFieldNamesForTypeForActions.value("Integer").first |
3223 return detail.definitionName() == defAndFieldNamesForTypeForActions.value("Integer").first |
3062 && !detail.variantValue(defAndFieldNamesForTypeForActions.value("Integer").second).isNull(); |
3224 && !detail.variantValue(defAndFieldNamesForTypeForActions.value("Integer").second).isNull(); |
3063 } |
3225 } |
3064 |
3226 QList<QContactDetail> supportedDetails(const QContact& contact) const |
3065 void invokeAction(const QContact& contact, const QContactDetail& detail = QContactDetail()) |
|
3066 { |
3227 { |
3067 Q_UNUSED(contact); |
3228 return contact.details(defAndFieldNamesForTypeForActions.value("Integer").first); |
3068 Q_UNUSED(detail); |
|
3069 // Well, do something |
|
3070 emit progress(QContactAction::FinishedState, QVariantMap()); |
|
3071 } |
|
3072 |
|
3073 QVariantMap result() const |
|
3074 { |
|
3075 return QVariantMap(); |
|
3076 } |
3229 } |
3077 }; |
3230 }; |
3078 |
3231 |
3079 /* Static actions for testing matching */ |
3232 /* Static actions for testing matching */ |
3080 class QPhoneNumberAction : public QContactAction |
3233 class QPhoneNumberAction : public DummyAction |
3081 { |
3234 { |
3082 Q_OBJECT |
3235 Q_OBJECT |
3083 |
3236 |
3084 public: |
3237 public: |
3085 QPhoneNumberAction() {} |
3238 QPhoneNumberAction() {} |
3086 ~QPhoneNumberAction() {} |
3239 ~QPhoneNumberAction() {} |
3087 |
3240 |
3088 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("PhoneNumber", "PhoneNumberCo", 4); } |
3241 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("PhoneNumber", "PhoneNumberCo", 4); } |
3089 QVariantMap metadata() const {return QVariantMap();} |
|
3090 QVariantMap metaData() const {return QVariantMap();} |
|
3091 |
3242 |
3092 QContactFilter contactFilter(const QVariant& value) const |
3243 QContactFilter contactFilter(const QVariant& value) const |
3093 { |
3244 { |
3094 QContactDetailFilter df; |
3245 QContactDetailFilter df; |
3095 df.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); |
3246 df.setDetailDefinitionName(QContactPhoneNumber::DefinitionName, QContactPhoneNumber::FieldNumber); |
3096 df.setValue(value); |
3247 df.setValue(value); |
3097 return df; |
3248 return df; |
3098 } |
3249 } |
3099 bool supportsDetail(const QContactDetail& detail) const |
3250 bool isDetailSupported(const QContactDetail& detail, const QContact&) const |
3100 { |
3251 { |
3101 return detail.definitionName() == QContactPhoneNumber::DefinitionName |
3252 return detail.definitionName() == QContactPhoneNumber::DefinitionName |
3102 && !detail.variantValue(QContactPhoneNumber::FieldNumber).isNull(); |
3253 && !detail.variantValue(QContactPhoneNumber::FieldNumber).isNull(); |
3103 } |
3254 } |
3104 |
3255 QList<QContactDetail> supportedDetails(const QContact& contact) const |
3105 void invokeAction(const QContact& contact, const QContactDetail& detail = QContactDetail()) |
|
3106 { |
3256 { |
3107 Q_UNUSED(contact); |
3257 return contact.details(QContactPhoneNumber::DefinitionName); |
3108 Q_UNUSED(detail); |
|
3109 // Well, do something |
|
3110 emit progress(QContactAction::FinishedState, QVariantMap()); |
|
3111 } |
|
3112 |
|
3113 QVariantMap result() const |
|
3114 { |
|
3115 return QVariantMap(); |
|
3116 } |
3258 } |
3117 }; |
3259 }; |
3118 |
3260 |
3119 /* Static actions for testing matching */ |
3261 /* Static actions for testing matching */ |
3120 class QDateAction : public QContactAction |
3262 class QDateAction : public DummyAction |
3121 { |
3263 { |
3122 Q_OBJECT |
3264 Q_OBJECT |
3123 |
3265 |
3124 public: |
3266 public: |
3125 QDateAction() {} |
3267 QDateAction() {} |
3126 ~QDateAction() {} |
3268 ~QDateAction() {} |
3127 |
3269 |
3128 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("Date", "DateCo", 9); } |
3270 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("Date", "DateCo", 9); } |
3129 QVariantMap metadata() const {return QVariantMap();} |
|
3130 QVariantMap metaData() const {return QVariantMap();} |
|
3131 |
3271 |
3132 QContactFilter contactFilter(const QVariant& value) const |
3272 QContactFilter contactFilter(const QVariant& value) const |
3133 { |
3273 { |
3134 QContactDetailFilter df; |
3274 QContactDetailFilter df; |
3135 QPair<QString, QString> defAndFieldName = defAndFieldNamesForTypeForActions.value("Date"); |
3275 QPair<QString, QString> defAndFieldName = defAndFieldNamesForTypeForActions.value("Date"); |
3136 df.setDetailDefinitionName(defAndFieldName.first, defAndFieldName.second); |
3276 df.setDetailDefinitionName(defAndFieldName.first, defAndFieldName.second); |
3137 df.setValue(value); |
3277 df.setValue(value); |
3138 return df; |
3278 return df; |
3139 } |
3279 } |
3140 bool supportsDetail(const QContactDetail& detail) const |
3280 |
|
3281 bool isDetailSupported(const QContactDetail &detail, const QContact &) const |
3141 { |
3282 { |
3142 return detail.definitionName() == defAndFieldNamesForTypeForActions.value("Date").first |
3283 return detail.definitionName() == defAndFieldNamesForTypeForActions.value("Date").first |
3143 && !detail.variantValue(defAndFieldNamesForTypeForActions.value("Date").second).isNull(); |
3284 && !detail.variantValue(defAndFieldNamesForTypeForActions.value("Date").second).isNull(); |
3144 } |
3285 } |
3145 |
3286 QList<QContactDetail> supportedDetails(const QContact& contact) const |
3146 void invokeAction(const QContact& contact, const QContactDetail& detail = QContactDetail()) |
|
3147 { |
3287 { |
3148 Q_UNUSED(contact); |
3288 return contact.details(defAndFieldNamesForTypeForActions.value("Date").first); |
3149 Q_UNUSED(detail); |
|
3150 // Well, do something |
|
3151 emit progress(QContactAction::FinishedState, QVariantMap()); |
|
3152 } |
|
3153 |
|
3154 QVariantMap result() const |
|
3155 { |
|
3156 return QVariantMap(); |
|
3157 } |
3289 } |
3158 }; |
3290 }; |
3159 |
3291 |
3160 class QNumberAction : public QContactAction |
3292 class QNumberAction : public DummyAction |
3161 { |
3293 { |
3162 Q_OBJECT |
3294 Q_OBJECT |
3163 |
3295 |
3164 public: |
3296 public: |
3165 QNumberAction() {} |
3297 QNumberAction() {} |
3166 ~QNumberAction() {} |
3298 ~QNumberAction() {} |
3167 |
3299 |
3168 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("Number", "NumberCo", 42); } |
3300 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("Number", "NumberCo", 42); } |
3169 QVariantMap metadata() const {return QVariantMap();} |
|
3170 QVariantMap metaData() const {return QVariantMap();} |
|
3171 |
3301 |
3172 QContactFilter contactFilter(const QVariant& value) const |
3302 QContactFilter contactFilter(const QVariant& value) const |
3173 { |
3303 { |
3174 QContactDetailFilter df; |
3304 QContactDetailFilter df; |
3175 QPair<QString, QString> defAndFieldName = defAndFieldNamesForTypeForActions.value("Double"); |
3305 QPair<QString, QString> defAndFieldName = defAndFieldNamesForTypeForActions.value("Double"); |
3236 return df; |
3358 return df; |
3237 } else { |
3359 } else { |
3238 return QContactInvalidFilter(); |
3360 return QContactInvalidFilter(); |
3239 } |
3361 } |
3240 } |
3362 } |
3241 bool supportsDetail(const QContactDetail& detail) const |
3363 bool isDetailSupported(const QContactDetail &detail, const QContact &) const |
3242 { |
3364 { |
3243 return detail.definitionName() == defAndFieldNamesForTypeForActions.value("Bool").first |
3365 return detail.definitionName() == defAndFieldNamesForTypeForActions.value("Bool").first |
3244 && (detail.value<bool>(defAndFieldNamesForTypeForActions.value("Bool").second) == true); |
3366 && (detail.value<bool>(defAndFieldNamesForTypeForActions.value("Bool").second) == true); |
3245 } |
3367 } |
3246 |
3368 QList<QContactDetail> supportedDetails(const QContact& contact) const |
3247 void invokeAction(const QContact& contact, const QContactDetail& detail = QContactDetail()) |
|
3248 { |
3369 { |
3249 Q_UNUSED(contact); |
3370 return contact.details(defAndFieldNamesForTypeForActions.value("Bool").first); |
3250 Q_UNUSED(detail); |
|
3251 // Well, do something |
|
3252 emit progress(QContactAction::FinishedState, QVariantMap()); |
|
3253 } |
|
3254 |
|
3255 QVariantMap result() const |
|
3256 { |
|
3257 return QVariantMap(); |
|
3258 } |
3371 } |
3259 }; |
3372 }; |
3260 |
3373 |
3261 class RecursiveAction : public QContactAction |
3374 class RecursiveAction : public DummyAction |
3262 { |
3375 { |
3263 Q_OBJECT |
3376 Q_OBJECT |
3264 |
3377 |
3265 public: |
3378 public: |
3266 RecursiveAction() {} |
3379 RecursiveAction() {} |
3267 ~RecursiveAction() {} |
3380 ~RecursiveAction() {} |
3268 |
3381 |
3269 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("Recursive", "RecursiveCo", 3); } |
3382 QContactActionDescriptor actionDescriptor() const { return QContactActionDescriptor("Recursive", "RecursiveCo", 3); } |
3270 QVariantMap metadata() const {return QVariantMap();} |
|
3271 QVariantMap metaData() const {return QVariantMap();} |
|
3272 |
3383 |
3273 QContactFilter contactFilter(const QVariant& value) const |
3384 QContactFilter contactFilter(const QVariant& value) const |
3274 { |
3385 { |
3275 /* Return a filter that selects us again.. */ |
3386 /* Return a filter that selects us again.. */ |
3276 QContactActionFilter af; |
3387 QContactActionFilter af; |
3277 af.setActionName("Recursive"); |
3388 af.setActionName("Recursive"); |
3278 af.setVendor("RecursiveCo", 3); |
3389 af.setVendor("RecursiveCo", 3); |
3279 af.setValue(value); |
3390 af.setValue(value); |
3280 return af; |
3391 return af; |
3281 } |
3392 } |
3282 bool supportsDetail(const QContactDetail&) const |
3393 bool isDetailSupported(const QContactDetail&, const QContact&) const |
3283 { |
3394 { |
3284 return false; |
3395 return false; |
3285 } |
3396 } |
3286 void invokeAction(const QContact&, const QContactDetail&) |
3397 QList<QContactDetail> supportedDetails(const QContact&) const |
3287 { |
3398 { |
3288 emit progress(QContactAction::FinishedState, QVariantMap()); |
3399 return QList<QContactDetail>(); |
3289 } |
|
3290 |
|
3291 QVariantMap result() const |
|
3292 { |
|
3293 return QVariantMap(); |
|
3294 } |
3400 } |
3295 }; |
3401 }; |
3296 |
3402 |
3297 class AnotherRecursiveAction : public RecursiveAction { |
3403 class AnotherRecursiveAction : public RecursiveAction { |
3298 Q_OBJECT |
3404 Q_OBJECT |