From 13d9d646f76725c09d74f7e8f3f996b6ca290187 Mon Sep 17 00:00:00 2001 From: Jeremy Lainé Date: Thu, 27 Sep 2012 15:30:37 +0200 Subject: split vcard tests --- tests/all/all.pro | 6 +- tests/all/si.h | 37 ------ tests/all/vcard.cpp | 187 ----------------------------- tests/qxmppvcardiq/qxmppvcardiq.pro | 3 + tests/qxmppvcardiq/tst_qxmppvcardiq.cpp | 203 ++++++++++++++++++++++++++++++++ tests/tests.pro | 6 +- 6 files changed, 213 insertions(+), 229 deletions(-) delete mode 100644 tests/all/si.h delete mode 100644 tests/all/vcard.cpp create mode 100644 tests/qxmppvcardiq/qxmppvcardiq.pro create mode 100644 tests/qxmppvcardiq/tst_qxmppvcardiq.cpp (limited to 'tests') diff --git a/tests/all/all.pro b/tests/all/all.pro index 43ddf061..da74f3cb 100644 --- a/tests/all/all.pro +++ b/tests/all/all.pro @@ -13,8 +13,7 @@ SOURCES += \ rtp.cpp \ stanza.cpp \ stun.cpp \ - tests.cpp \ - vcard.cpp + tests.cpp HEADERS += \ dataform.h \ jingle.h \ @@ -25,8 +24,7 @@ HEADERS += \ rtp.h \ stanza.h \ stun.h \ - tests.h \ - vcard.h + tests.h !isEmpty(QXMPP_AUTOTEST_INTERNAL) { HEADERS += codec.h sasl.h si.h diff --git a/tests/all/si.h b/tests/all/si.h deleted file mode 100644 index 97e325b8..00000000 --- a/tests/all/si.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2008-2012 The QXmpp developers - * - * Authors: - * Olivier Goffart - * 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 - -class tst_QXmppStreamInitiationIq : public QObject -{ - Q_OBJECT - -private slots: - void testFileInfo_data(); - void testFileInfo(); - void testOffer(); - void testResult(); -}; - diff --git a/tests/all/vcard.cpp b/tests/all/vcard.cpp deleted file mode 100644 index 350e8a7e..00000000 --- a/tests/all/vcard.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * 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 "util.h" -#include "vcard.h" - -void tst_QXmppVCardIq::testAddress_data() -{ - QTest::addColumn("xml"); - QTest::addColumn("type"); - QTest::addColumn("country"); - QTest::addColumn("locality"); - QTest::addColumn("postcode"); - QTest::addColumn("region"); - QTest::addColumn("street"); - - QTest::newRow("none") << QByteArray("") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << ""; - QTest::newRow("HOME") << QByteArray("") << int(QXmppVCardAddress::Home) << "" << "" << "" << "" << ""; - QTest::newRow("WORK") << QByteArray("") << int(QXmppVCardAddress::Work) << "" << "" << "" << "" << ""; - QTest::newRow("POSTAL") << QByteArray("") << int(QXmppVCardAddress::Postal) << "" << "" << "" << "" << ""; - QTest::newRow("PREF") << QByteArray("") << int(QXmppVCardAddress::Preferred) << "" << "" << "" << "" << ""; - - QTest::newRow("country") << QByteArray("France") << int(QXmppVCardAddress::None) << "France" << "" << "" << "" << ""; - QTest::newRow("locality") << QByteArray("Paris") << int(QXmppVCardAddress::None) << "" << "Paris" << "" << "" << ""; - QTest::newRow("postcode") << QByteArray("75008") << int(QXmppVCardAddress::None) << "" << "" << "75008" << "" << ""; - QTest::newRow("region") << QByteArray("Ile de France") << int(QXmppVCardAddress::None) << "" << "" << "" << "Ile de France" << ""; - QTest::newRow("street") << QByteArray("55 rue du faubourg Saint-Honoré") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << QString::fromUtf8("55 rue du faubourg Saint-Honoré"); -} - -void tst_QXmppVCardIq::testAddress() -{ - QFETCH(QByteArray, xml); - QFETCH(int, type); - QFETCH(QString, country); - QFETCH(QString, locality); - QFETCH(QString, postcode); - QFETCH(QString, region); - QFETCH(QString, street); - - QXmppVCardAddress address; - parsePacket(address, xml); - QCOMPARE(int(address.type()), type); - QCOMPARE(address.country(), country); - QCOMPARE(address.locality(), locality); - QCOMPARE(address.postcode(), postcode); - QCOMPARE(address.region(), region); - QCOMPARE(address.street(), street); - serializePacket(address, xml); -} - -void tst_QXmppVCardIq::testEmail_data() -{ - QTest::addColumn("xml"); - QTest::addColumn("type"); - - QTest::newRow("none") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::None); - 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); -} - -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::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( - "" - "" - "France" - "1983-09-14" - "I like XMPP." - "foo.bar@example.com" - "Foo Bar!" - "FooBar" - "FooWizBaz" - "12345" - "67890" - "" - "image/png" - "" - "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAAlwSFlzAAA" - "UIgAAFCIBjw1HyAAAAAd0SU1FB9oIHQInNvuJovgAAAAiSURBVAjXY2TQ+s/AwMDAwPD/GiMDlP" - "WfgYGBiQEHGJwSAK2BBQ1f3uvpAAAAAElFTkSuQmCC" - "" - "" - "http://code.google.com/p/qxmpp/" - "" - ""); - - QXmppVCardIq vcard; - parsePacket(vcard, xml); - QCOMPARE(vcard.addresses().size(), 1); - QCOMPARE(vcard.addresses()[0].country(), QLatin1String("France")); - QCOMPARE(int(vcard.addresses()[0].type()), int(QXmppVCardEmail::None)); - QCOMPARE(vcard.birthday(), QDate(1983, 9, 14)); - QCOMPARE(vcard.description(), QLatin1String("I like XMPP.")); - 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.url(), QLatin1String("http://code.google.com/p/qxmpp/")); - serializePacket(vcard, xml); -} diff --git a/tests/qxmppvcardiq/qxmppvcardiq.pro b/tests/qxmppvcardiq/qxmppvcardiq.pro new file mode 100644 index 00000000..ca5081e6 --- /dev/null +++ b/tests/qxmppvcardiq/qxmppvcardiq.pro @@ -0,0 +1,3 @@ +include(../tests.pri) +TARGET = tst_qxmppvcardiq +SOURCES += tst_qxmppvcardiq.cpp diff --git a/tests/qxmppvcardiq/tst_qxmppvcardiq.cpp b/tests/qxmppvcardiq/tst_qxmppvcardiq.cpp new file mode 100644 index 00000000..2041e2d7 --- /dev/null +++ b/tests/qxmppvcardiq/tst_qxmppvcardiq.cpp @@ -0,0 +1,203 @@ +/* + * 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 +#include "QXmppVCardIq.h" +#include "util.h" + +class tst_QXmppVCardIq : public QObject +{ + Q_OBJECT + +private slots: + void testAddress_data(); + void testAddress(); + void testEmail_data(); + void testEmail(); + void testPhone_data(); + void testPhone(); + void testVCard(); +}; + +void tst_QXmppVCardIq::testAddress_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("type"); + QTest::addColumn("country"); + QTest::addColumn("locality"); + QTest::addColumn("postcode"); + QTest::addColumn("region"); + QTest::addColumn("street"); + + QTest::newRow("none") << QByteArray("") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << ""; + QTest::newRow("HOME") << QByteArray("") << int(QXmppVCardAddress::Home) << "" << "" << "" << "" << ""; + QTest::newRow("WORK") << QByteArray("") << int(QXmppVCardAddress::Work) << "" << "" << "" << "" << ""; + QTest::newRow("POSTAL") << QByteArray("") << int(QXmppVCardAddress::Postal) << "" << "" << "" << "" << ""; + QTest::newRow("PREF") << QByteArray("") << int(QXmppVCardAddress::Preferred) << "" << "" << "" << "" << ""; + + QTest::newRow("country") << QByteArray("France") << int(QXmppVCardAddress::None) << "France" << "" << "" << "" << ""; + QTest::newRow("locality") << QByteArray("Paris") << int(QXmppVCardAddress::None) << "" << "Paris" << "" << "" << ""; + QTest::newRow("postcode") << QByteArray("75008") << int(QXmppVCardAddress::None) << "" << "" << "75008" << "" << ""; + QTest::newRow("region") << QByteArray("Ile de France") << int(QXmppVCardAddress::None) << "" << "" << "" << "Ile de France" << ""; + QTest::newRow("street") << QByteArray("55 rue du faubourg Saint-Honoré") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << QString::fromUtf8("55 rue du faubourg Saint-Honoré"); +} + +void tst_QXmppVCardIq::testAddress() +{ + QFETCH(QByteArray, xml); + QFETCH(int, type); + QFETCH(QString, country); + QFETCH(QString, locality); + QFETCH(QString, postcode); + QFETCH(QString, region); + QFETCH(QString, street); + + QXmppVCardAddress address; + parsePacket(address, xml); + QCOMPARE(int(address.type()), type); + QCOMPARE(address.country(), country); + QCOMPARE(address.locality(), locality); + QCOMPARE(address.postcode(), postcode); + QCOMPARE(address.region(), region); + QCOMPARE(address.street(), street); + serializePacket(address, xml); +} + +void tst_QXmppVCardIq::testEmail_data() +{ + QTest::addColumn("xml"); + QTest::addColumn("type"); + + QTest::newRow("none") << QByteArray("foo.bar@example.com") << int(QXmppVCardEmail::None); + 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); +} + +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::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( + "" + "" + "France" + "1983-09-14" + "I like XMPP." + "foo.bar@example.com" + "Foo Bar!" + "FooBar" + "FooWizBaz" + "12345" + "67890" + "" + "image/png" + "" + "iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAAXNSR0IArs4c6QAAAAlwSFlzAAA" + "UIgAAFCIBjw1HyAAAAAd0SU1FB9oIHQInNvuJovgAAAAiSURBVAjXY2TQ+s/AwMDAwPD/GiMDlP" + "WfgYGBiQEHGJwSAK2BBQ1f3uvpAAAAAElFTkSuQmCC" + "" + "" + "http://code.google.com/p/qxmpp/" + "" + ""); + + QXmppVCardIq vcard; + parsePacket(vcard, xml); + QCOMPARE(vcard.addresses().size(), 1); + QCOMPARE(vcard.addresses()[0].country(), QLatin1String("France")); + QCOMPARE(int(vcard.addresses()[0].type()), int(QXmppVCardEmail::None)); + QCOMPARE(vcard.birthday(), QDate(1983, 9, 14)); + QCOMPARE(vcard.description(), QLatin1String("I like XMPP.")); + 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.url(), QLatin1String("http://code.google.com/p/qxmpp/")); + serializePacket(vcard, xml); +} + +QTEST_MAIN(tst_QXmppVCardIq) +#include "tst_qxmppvcardiq.moc" diff --git a/tests/tests.pro b/tests/tests.pro index c7f6bcb8..a2814ebe 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -4,4 +4,8 @@ SUBDIRS = \ qxmppiq \ qxmppmessage \ qxmpppresence \ - qxmppstreaminitiationiq + qxmppvcardiq + +!isEmpty(QXMPP_AUTOTEST_INTERNAL) { + SUBDIRS += qxmppstreaminitiationiq +} -- cgit v1.2.3