/* * Copyright (C) 2008-2012 The QXmpp developers * * Author: * Jeremy Lainé * * Source: * http://code.google.com/p/qxmpp * * This file is a part of QXmpp library. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * */ #include "QXmppVCardIq.h" #include "tests.h" #include "vcard.h" void tst_QXmppVCardIq::testEmail_data() { QTest::addColumn("xml"); 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("all") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::Home | QXmppVCardEmail::Work | QXmppVCardEmail::Internet | QXmppVCardEmail::Preferred | QXmppVCardEmail::X400); } void tst_QXmppVCardIq::testEmail() { QFETCH(QByteArray, xml); QFETCH(int, type); QXmppVCardEmail email; parsePacket(email, xml); QCOMPARE(email.address(), QLatin1String("foo.bar@example.com")); QCOMPARE(int(email.type()), type); serializePacket(email, xml); } void tst_QXmppVCardIq::testVCard() { const QByteArray xml( "" "" "1983-09-14" "foo.bar@example.com" "Foo Bar!" "FooBar" "FooWizBaz" "" "image/png" "" "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAAlwSFlzAAA" "UIgAAFCIBjw1HyAAAAAd0SU1FB9oIHQInNvuJovgAAAAiSURBVAjXY2TQ+s/AwMDAwPD/GiMDlP" "WfgYGBiQEHGJwSAK2BBQ1f3uvpAAAAAElFTkSuQmCC" "" "" "" ""); QXmppVCardIq vcard; parsePacket(vcard, xml); QCOMPARE(vcard.birthday(), QDate(1983, 9, 14)); QCOMPARE(vcard.email(), QLatin1String("foo.bar@example.com")); 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.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)); serializePacket(vcard, xml); }