/* * 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 "QXmppPresence.h" #include "presence.h" #include "tests.h" void tst_QXmppPresence::testPresence_data() { QTest::addColumn("xml"); QTest::addColumn("type"); QTest::addColumn("priority"); QTest::addColumn("statusType"); QTest::addColumn("statusText"); QTest::addColumn("vcardUpdate"); QTest::addColumn("photoHash"); QTest::newRow("empty") << QByteArray("") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); QTest::newRow("unavailable") << QByteArray("") << int(QXmppPresence::Unavailable) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); QTest::newRow("error") << QByteArray("") << int(QXmppPresence::Error) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); QTest::newRow("away") << QByteArray("awayIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::Away) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); QTest::newRow("dnd") << QByteArray("dndIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::DND) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); QTest::newRow("chat") << QByteArray("chatIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::Chat) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); QTest::newRow("xa") << QByteArray("xaIn a meeting5") << int(QXmppPresence::Available) << 5 << int(QXmppPresence::Status::XA) << "In a meeting" << int(QXmppPresence::VCardUpdateNone) << QByteArray(); QTest::newRow("vcard-photo") << QByteArray( "" "" "73b908bc" "" "") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateValidPhoto) << QByteArray::fromHex("73b908bc"); QTest::newRow("vard-not-ready") << QByteArray( "" "" "") << int(QXmppPresence::Available) << 0 << int(QXmppPresence::Status::Online) << "" << int(QXmppPresence::VCardUpdateNotReady) << QByteArray(); } void tst_QXmppPresence::testPresence() { QFETCH(QByteArray, xml); QFETCH(int, type); QFETCH(int, priority); QFETCH(int, statusType); QFETCH(QString, statusText); QFETCH(int, vcardUpdate); QFETCH(QByteArray, photoHash); QXmppPresence presence; parsePacket(presence, xml); QCOMPARE(int(presence.type()), type); QCOMPARE(presence.status().priority(), priority); QCOMPARE(int(presence.status().type()), statusType); QCOMPARE(presence.status().statusText(), statusText); QCOMPARE(int(presence.vCardUpdateType()), vcardUpdate); QCOMPARE(presence.photoHash(), photoHash); serializePacket(presence, xml); } void tst_QXmppPresence::testPresenceWithCapability() { const QByteArray xml( "" "away" "In a meeting" "5" "" "73b908bc" "" "" ""); QXmppPresence presence; parsePacket(presence, xml); QCOMPARE(presence.to(), QString("foo@example.com/QXmpp")); QCOMPARE(presence.from(), QString("bar@example.com/QXmpp")); QCOMPARE(presence.status().type(), QXmppPresence::Status::Away); QCOMPARE(presence.status().statusText(), QString("In a meeting")); QCOMPARE(presence.status().priority(), 5); QCOMPARE(presence.photoHash(), QByteArray::fromHex("73b908bc")); QCOMPARE(presence.vCardUpdateType(), QXmppPresence::VCardUpdateValidPhoto); QCOMPARE(presence.capabilityHash(), QString("sha-1")); QCOMPARE(presence.capabilityNode(), QString("http://code.google.com/p/qxmpp")); QCOMPARE(presence.capabilityVer(), QByteArray::fromBase64("QgayPKawpkPSDYmwT/WM94uAlu0=")); serializePacket(presence, xml); } void tst_QXmppPresence::testPresenceWithMuc() { const QByteArray xml( "" "" "" "" "Avaunt, you cullion!" "" "" "" ""); QXmppPresence presence; parsePacket(presence, xml); QCOMPARE(presence.to(), QLatin1String("pistol@shakespeare.lit/harfleur")); QCOMPARE(presence.from(), QLatin1String("harfleur@henryv.shakespeare.lit/pistol")); QCOMPARE(presence.type(), QXmppPresence::Unavailable); QCOMPARE(presence.mucItem().actor(), QLatin1String("fluellen@shakespeare.lit")); QCOMPARE(presence.mucItem().affiliation(), QXmppMucItem::NoAffiliation); QCOMPARE(presence.mucItem().jid(), QString()); QCOMPARE(presence.mucItem().reason(), QLatin1String("Avaunt, you cullion!")); QCOMPARE(presence.mucItem().role(), QXmppMucItem::NoRole); QCOMPARE(presence.mucStatusCodes(), QList() << 307); serializePacket(presence, xml); }