From becafc386f14967df87659cd408b5cee5835227d Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Fri, 3 Aug 2012 15:46:40 +0200 Subject: add support for phone numbers to vCards --- tests/vcard.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 5 deletions(-) (limited to 'tests/vcard.cpp') diff --git a/tests/vcard.cpp b/tests/vcard.cpp index 89f8b46a..b92b269b 100644 --- a/tests/vcard.cpp +++ b/tests/vcard.cpp @@ -32,8 +32,11 @@ void tst_QXmppVCardIq::testEmail_data() QTest::addColumn("type"); QTest::newRow("none") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::None); - QTest::newRow("internet") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::Internet); - QTest::newRow("x400") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::X400); + QTest::newRow("HOME") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::Home); + QTest::newRow("WORK") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::Work); + QTest::newRow("INTERNET") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::Internet); + QTest::newRow("X400") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::X400); + QTest::newRow("PREF") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::Preferred); QTest::newRow("all") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::Home | QXmppVCardEmail::Work | QXmppVCardEmail::Internet | QXmppVCardEmail::Preferred | QXmppVCardEmail::X400); } @@ -49,6 +52,40 @@ void tst_QXmppVCardIq::testEmail() serializePacket(email, xml); } +void tst_QXmppVCardIq::testPhone_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("type"); + + QTest::newRow("none") << QByteArray("12345") << int(QXmppVCardPhone::None); + QTest::newRow("HOME") << QByteArray("12345") << int(QXmppVCardPhone::Home); + QTest::newRow("WORK") << QByteArray("12345") << int(QXmppVCardPhone::Work); + QTest::newRow("VOICE") << QByteArray("12345") << int(QXmppVCardPhone::Voice); + QTest::newRow("FAX") << QByteArray("12345") << int(QXmppVCardPhone::Fax); + QTest::newRow("PAGER") << QByteArray("12345") << int(QXmppVCardPhone::Pager); + QTest::newRow("MSG") << QByteArray("12345") << int(QXmppVCardPhone::Messaging); + QTest::newRow("CELL") << QByteArray("12345") << int(QXmppVCardPhone::Cell); + QTest::newRow("VIDEO") << QByteArray("") << int(QXmppVCardPhone::Video); + QTest::newRow("BBS") << QByteArray("12345") << int(QXmppVCardPhone::BBS); + QTest::newRow("MODEM") << QByteArray("12345") << int(QXmppVCardPhone::Modem); + QTest::newRow("IDSN") << QByteArray("12345") << int(QXmppVCardPhone::ISDN); + QTest::newRow("PCS") << QByteArray("12345") << int(QXmppVCardPhone::PCS); + QTest::newRow("PREF") << QByteArray("12345") << int(QXmppVCardPhone::Preferred); +} + +void tst_QXmppVCardIq::testPhone() +{ + QFETCH(QByteArray, xml); + QFETCH(int, type); + + QXmppVCardPhone phone; + parsePacket(phone, xml); + QCOMPARE(phone.number(), QLatin1String("12345")); + QCOMPARE(int(phone.type()), type); + serializePacket(phone, xml); +} + + void tst_QXmppVCardIq::testVCard() { const QByteArray xml( @@ -59,6 +96,8 @@ void tst_QXmppVCardIq::testVCard() "Foo Bar!" "FooBar" "FooWizBaz" + "12345" + "67890" "" "image/png" "" @@ -67,6 +106,7 @@ void tst_QXmppVCardIq::testVCard() "WfgYGBiQEHGJwSAK2BBQ1f3uvpAAAAAElFTkSuQmCC" "" "" + "http://code.google.com/p/qxmpp/" "" ""); @@ -74,18 +114,24 @@ void tst_QXmppVCardIq::testVCard() parsePacket(vcard, xml); QCOMPARE(vcard.birthday(), QDate(1983, 9, 14)); QCOMPARE(vcard.email(), QLatin1String("foo.bar@example.com")); + QCOMPARE(vcard.emails().size(), 1); + QCOMPARE(vcard.emails()[0].address(), QLatin1String("foo.bar@example.com")); + QCOMPARE(int(vcard.emails()[0].type()), int(QXmppVCardEmail::Internet)); QCOMPARE(vcard.nickName(), QLatin1String("FooBar")); QCOMPARE(vcard.fullName(), QLatin1String("Foo Bar!")); QCOMPARE(vcard.firstName(), QLatin1String("Foo")); QCOMPARE(vcard.middleName(), QLatin1String("Baz")); QCOMPARE(vcard.lastName(), QLatin1String("Wiz")); + QCOMPARE(vcard.phones().size(), 2); + QCOMPARE(vcard.phones()[0].number(), QLatin1String("12345")); + QCOMPARE(int(vcard.phones()[0].type()), int(QXmppVCardEmail::Home)); + QCOMPARE(vcard.phones()[1].number(), QLatin1String("67890")); + QCOMPARE(int(vcard.phones()[1].type()), int(QXmppVCardEmail::Work)); QCOMPARE(vcard.photo(), QByteArray::fromBase64( "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAAlwSFlzAAA" "UIgAAFCIBjw1HyAAAAAd0SU1FB9oIHQInNvuJovgAAAAiSURBVAjXY2TQ+s/AwMDAwPD/GiMDlP" "WfgYGBiQEHGJwSAK2BBQ1f3uvpAAAAAElFTkSuQmCC")); QCOMPARE(vcard.photoType(), QLatin1String("image/png")); - QCOMPARE(vcard.emails().size(), 1); - QCOMPARE(vcard.emails()[0].address(), QLatin1String("foo.bar@example.com")); - QCOMPARE(int(vcard.emails()[0].type()), int(QXmppVCardEmail::Internet)); + QCOMPARE(vcard.url(), QLatin1String("http://code.google.com/p/qxmpp/")); serializePacket(vcard, xml); } -- cgit v1.2.3