diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2014-07-19 10:23:40 +0200 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2014-07-19 10:23:40 +0200 |
| commit | 70e7b6005de3e4a2e0237f18196825d96f4ee4d3 (patch) | |
| tree | 1b017e68025534d194362a6dc206f04a2ca8f553 | |
| parent | 68f89992207c592cf0be8567d5c3d5e43157f9b6 (diff) | |
| parent | 07ae4a63307928e1af97b75b3de23530c74beb3f (diff) | |
| download | qxmpp-70e7b6005de3e4a2e0237f18196825d96f4ee4d3.tar.gz | |
Merge branch 'master' of github.com:qxmpp-project/qxmpp
| -rw-r--r-- | CHANGELOG | 3 | ||||
| -rw-r--r-- | README.md | 46 | ||||
| -rw-r--r-- | src/base/QXmppConstants.cpp | 2 | ||||
| -rw-r--r-- | src/base/QXmppConstants.h | 2 | ||||
| -rw-r--r-- | src/base/QXmppGlobal.h | 2 | ||||
| -rw-r--r-- | src/base/QXmppMessage.cpp | 126 | ||||
| -rw-r--r-- | src/base/QXmppMessage.h | 23 | ||||
| -rw-r--r-- | src/base/QXmppVCardIq.cpp | 94 | ||||
| -rw-r--r-- | src/base/QXmppVCardIq.h | 15 | ||||
| -rw-r--r-- | src/client/QXmppClient.cpp | 8 | ||||
| -rw-r--r-- | src/client/QXmppClient.h | 1 | ||||
| -rw-r--r-- | src/client/QXmppConfiguration.h | 9 | ||||
| -rw-r--r-- | src/client/QXmppDiscoveryManager.cpp | 3 | ||||
| -rw-r--r-- | src/client/QXmppOutgoingClient.cpp | 11 | ||||
| -rw-r--r-- | tests/qxmppmessage/tst_qxmppmessage.cpp | 187 | ||||
| -rw-r--r-- | tests/qxmpputils/tst_qxmpputils.cpp | 2 | ||||
| -rw-r--r-- | tests/qxmppvcardiq/tst_qxmppvcardiq.cpp | 34 |
17 files changed, 532 insertions, 36 deletions
@@ -1,9 +1,12 @@ QXmpp 0.8.1 (UNRELEASED) +------------------------ - Use QString() instead of "" for default methods arguments, to enable building project which use QT_NO_CAST_FROM_ASCII. + - Add support for legacy SSL. QXmpp 0.8.0 (Mar 26, 2014) +-------------------------- - Fix QXmppServer incoming connections with Qt5 (issue 175). - Support for QXmppMessage extensions having tag names other than 'x'. @@ -3,7 +3,19 @@ ABOUT QXMPP =========== -QXmpp is cross-platform C++ client library for XMPP. It is based on Qt. +QXmpp is a cross-platform C++ XMPP client and server library. It is written +in C++ and uses Qt framework. + +QXmpp strives to be as easy to use as possible, the underlying TCP socket, +the core XMPP RFCs (RFC3920 and RFC3921) and XMPP extensions have been +nicely encapsulated into classes. QXmpp comes with full API +documentation, automatic tests and many examples. + +QXmpp uses Qt extensively, and as such users need to a have working knowledge +of C++ and Qt basics (Signals and Slots and Qt data types). + +Qt is the only third party library which is required to build QXmpp, but +libraries such as speex and theora enable additional features. QXmpp is released under the terms of the GNU Lesser General Public License, version 2.1 or later. @@ -11,10 +23,10 @@ version 2.1 or later. BUILDING QXMPP ============== -You need to have Qt 4.5 or higher (with SSL enabled) to build the QXmpp. -The project uses qmake build system of Qt. +QXmpp requires Qt 4.5 or higher (with SSL enabled) and it uses +the standard qmake build system of Qt. -Building from the command line: +Build from command line: cd <where qxmpp.pro is located> qmake <arguments> @@ -36,7 +48,7 @@ Note: by default QXmpp is built as a shared library. If you decide to build a static library instead, you will need to pass -DQXMPP_STATIC when building your programs against QXmpp. -Building using Qt Creator: +Build using Qt Creator: Open the qxmpp.pro file in Qt Creator and hit "Build All" to build all the examples and library. @@ -44,10 +56,11 @@ the examples and library. INSTALLING QXMPP ================ -After building QXmpp the you can install the Headers, Libraries +After building QXmpp, you can install the Headers, Libraries and Documentation using the following command: -Installing from the command line: +Install from command line: + <respective-make-cmd = gmake, make, mingw32-make, nmake> install Path of installations: @@ -62,7 +75,8 @@ to your C++ flags. EXAMPLES ======== -Look at the example directory for various examples. +Look at the example directory for various examples. Here is a description of +a few. * *example_0_connected* This example just connects to the xmpp server and start receiving presences @@ -81,14 +95,19 @@ the part of this library. DOCUMENTATION ============= -You can find information about QXmpp, on the project homepage: +You can find the API documentation for the latest QXmpp version here: -https://github.com/qxmpp-project/qxmpp +http://doc.qxmpp.org/qxmpp-snapshot/ SUPPORTED PLATFORMS =================== -For this release, the following platforms have been tested: +It should work on all the plaforms supported by Qt. For a complete list of +platforms support by Qt, see: + +http://qt-project.org/doc/supported-platforms.html + +In past, we have tested on variety of platforms: win32-g++ (Qt SDK) win32-msvc2008 (Qt MSVC-2008) @@ -97,11 +116,6 @@ For this release, the following platforms have been tested: linux-g++ (32-bit and 64-bit) macos-g++ (32-bit and 64-bit) -It should work on all the plaforms supported by Qt. For a complete list of -platforms support by Qt, see: - -http://qt-project.org/doc/supported-platforms.html - Please note that on Symbian, you will need to make sure your add the "NetworkServices" to your application to enable it to access the network. You can do this by adding the following to your .pro file: diff --git a/src/base/QXmppConstants.cpp b/src/base/QXmppConstants.cpp index ec314376..76098d58 100644 --- a/src/base/QXmppConstants.cpp +++ b/src/base/QXmppConstants.cpp @@ -114,3 +114,5 @@ const char* ns_attention = "urn:xmpp:attention:0"; const char* ns_bob = "urn:xmpp:bob"; // XEP-0249: Direct MUC Invitations const char* ns_conference = "jabber:x:conference"; +// XEP-0333: Chat Markers +const char* ns_chat_markers = "urn:xmpp:chat-markers:0"; diff --git a/src/base/QXmppConstants.h b/src/base/QXmppConstants.h index 85030c12..bf544159 100644 --- a/src/base/QXmppConstants.h +++ b/src/base/QXmppConstants.h @@ -115,5 +115,7 @@ extern const char* ns_attention; extern const char* ns_bob; // XEP-0249: Direct MUC Invitations extern const char* ns_conference; +// XEP-0333: Char Markers +extern const char* ns_chat_markers; #endif // QXMPPCONSTANTS_H diff --git a/src/base/QXmppGlobal.h b/src/base/QXmppGlobal.h index 52303f5f..ebddab73 100644 --- a/src/base/QXmppGlobal.h +++ b/src/base/QXmppGlobal.h @@ -52,7 +52,7 @@ /// available. /// -#define QXMPP_VERSION 0x000800 +#define QXMPP_VERSION 0x000801 QXMPP_EXPORT QString QXmppVersion(); diff --git a/src/base/QXmppMessage.cpp b/src/base/QXmppMessage.cpp index e32465b7..4bdc6329 100644 --- a/src/base/QXmppMessage.cpp +++ b/src/base/QXmppMessage.cpp @@ -48,6 +48,13 @@ static const char* message_types[] = { "headline" }; +static const char* marker_types[] = { + "", + "received", + "displayed", + "acknowledged" +}; + static const char *ns_xhtml = "http://www.w3.org/1999/xhtml"; enum StampType @@ -80,6 +87,12 @@ public: QString mucInvitationJid; QString mucInvitationPassword; QString mucInvitationReason; + + // XEP-0333: Chat Markers + bool markable; + QXmppMessage::Marker marker; + QString markedId; + QString markedThread; }; /// Constructs a QXmppMessage. @@ -101,6 +114,9 @@ QXmppMessage::QXmppMessage(const QString& from, const QString& to, const d->body = body; d->thread = thread; d->receiptRequested = false; + + d->markable = false; + d->marker = NoMarker; } /// Constructs a copy of \a other. @@ -363,6 +379,70 @@ namespace } } +/// Returns true if a message is markable, as defined +/// XEP-0333: Chat Markers. + +bool QXmppMessage::isMarkable() const +{ + return d->markable; +} + +/// Sets if the message is markable, as defined +/// XEP-0333: Chat Markers. + +void QXmppMessage::setMarkable(const bool markable) +{ + d->markable = markable; +} + +/// Returns the message's marker id, as defined +/// XEP-0333: Chat Markers. + +QString QXmppMessage::markedId() const +{ + return d->markedId; +} + +/// Sets the message's marker id, as defined +/// XEP-0333: Chat Markers. + +void QXmppMessage::setMarkerId(const QString &markerId) +{ + d->markedId = markerId; +} + +/// Returns the message's marker thread, as defined +/// XEP-0333: Chat Markers. + +QString QXmppMessage::markedThread() const +{ + return d->markedThread; +} + +/// Sets the message's marked thread, as defined +/// XEP-0333: Chat Markers. + +void QXmppMessage::setMarkedThread(const QString &markedThread) +{ + d->markedThread = markedThread; +} + +/// Returns the message's marker, as defined +/// XEP-0333: Chat Markers. + +QXmppMessage::Marker QXmppMessage::marker() const +{ + return d->marker; +} + +/// Sets the message's marker, as defined +/// XEP-0333: Chat Markers + +void QXmppMessage::setMarker(const Marker marker) +{ + d->marker = marker; +} + /// \cond void QXmppMessage::parse(const QDomElement &element) { @@ -433,6 +513,36 @@ void QXmppMessage::parse(const QDomElement &element) // XEP-0224: Attention d->attentionRequested = element.firstChildElement("attention").namespaceURI() == ns_attention; + // XEP-0333: Chat Markers + QDomElement markableElement = element.firstChildElement("markable"); + if (!markableElement.isNull()) + { + d->markable = true; + } + // check for all the marker types + QDomElement chatStateElement; + QXmppMessage::Marker marker = QXmppMessage::NoMarker; + for (int i = Received; i <= Acknowledged; i++) + { + chatStateElement = element.firstChildElement(marker_types[i]); + if (!chatStateElement.isNull() && + chatStateElement.namespaceURI() == ns_chat_markers) + { + marker = static_cast<QXmppMessage::Marker>(i); + break; + } + } + // if marker is present, check it's the right ns + if (!chatStateElement.isNull()) + { + if (chatStateElement.namespaceURI() == ns_chat_markers) + { + d->marker = marker; + d->markedId = chatStateElement.attribute("id", QString()); + d->markedThread = chatStateElement.attribute("thread", QString()); + } + } + const QList<QPair<QString, QString> > &knownElems = knownMessageSubelems(); QXmppElementList extensions; @@ -555,6 +665,22 @@ void QXmppMessage::toXml(QXmlStreamWriter *xmlWriter) const xmlWriter->writeEndElement(); } + // XEP-0333: Chat Markers + if (d->markable) { + xmlWriter->writeStartElement("markable"); + xmlWriter->writeAttribute("xmlns", ns_chat_markers); + xmlWriter->writeEndElement(); + } + if (d->marker != NoMarker) { + xmlWriter->writeStartElement(marker_types[d->marker]); + xmlWriter->writeAttribute("xmlns", ns_chat_markers); + xmlWriter->writeAttribute("id", d->markedId); + if (!d->markedThread.isNull() && !d->markedThread.isEmpty()) { + xmlWriter->writeAttribute("thread", d->markedThread); + } + xmlWriter->writeEndElement(); + } + // other extensions QXmppStanza::extensionsToXml(xmlWriter); diff --git a/src/base/QXmppMessage.h b/src/base/QXmppMessage.h index e927a85c..119dba3e 100644 --- a/src/base/QXmppMessage.h +++ b/src/base/QXmppMessage.h @@ -60,8 +60,18 @@ public: Paused, ///< User had been composing but now has stopped. }; + /// This enum describes a chat marker as defined by + /// XEP-0333 : Char Markers + enum Marker { + NoMarker = 0, + Received, + Displayed, + Acknowledged + }; + QXmppMessage(const QString& from = QString(), const QString& to = QString(), const QString& body = QString(), const QString& thread = QString()); + QXmppMessage(const QXmppMessage &other); ~QXmppMessage(); @@ -106,6 +116,19 @@ public: QString xhtml() const; void setXhtml(const QString &xhtml); + // XEP-0333 + bool isMarkable() const; + void setMarkable(const bool); + + QString markedId() const; + void setMarkerId(const QString&); + + QString markedThread() const; + void setMarkedThread(const QString&); + + Marker marker() const; + void setMarker(const Marker); + /// \cond void parse(const QDomElement &element); void toXml(QXmlStreamWriter *writer) const; diff --git a/src/base/QXmppVCardIq.cpp b/src/base/QXmppVCardIq.cpp index 6d9f1fdb..4a237200 100644 --- a/src/base/QXmppVCardIq.cpp +++ b/src/base/QXmppVCardIq.cpp @@ -86,6 +86,25 @@ QXmppVCardAddress& QXmppVCardAddress::operator=(const QXmppVCardAddress &other) return *this; } +/// \brief Checks if two address objects represent the same address. + +bool operator==(const QXmppVCardAddress &left, const QXmppVCardAddress &right) +{ + return left.type() == right.type() && + left.country() == right.country() && + left.locality() == right.locality() && + left.postcode() == right.postcode() && + left.region() == right.region() && + left.street() == right.street(); +} + +/// \brief Checks if two address objects represent different addresses. + +bool operator!=(const QXmppVCardAddress &left, const QXmppVCardAddress &right) +{ + return !(left == right); +} + /// Returns the country. QString QXmppVCardAddress::country() const @@ -250,6 +269,21 @@ QXmppVCardEmail& QXmppVCardEmail::operator=(const QXmppVCardEmail &other) return *this; } +/// \brief Checks if two email objects represent the same email address. + +bool operator==(const QXmppVCardEmail &left, const QXmppVCardEmail &right) +{ + return left.type() == right.type() && + left.address() == right.address(); +} + +/// \brief Checks if two email objects represent different email addresses. + +bool operator!=(const QXmppVCardEmail &left, const QXmppVCardEmail &right) +{ + return !(left == right); +} + /// Returns the e-mail address. QString QXmppVCardEmail::address() const @@ -353,6 +387,21 @@ QString QXmppVCardPhone::number() const return d->number; } +/// \brief Checks if two phone objects represent the same phone number. + +bool operator==(const QXmppVCardPhone &left, const QXmppVCardPhone &right) +{ + return left.type() == right.type() && + left.number() == right.number(); +} + +/// \brief Checks if two phone objects represent different phone numbers. + +bool operator!=(const QXmppVCardPhone &left, const QXmppVCardPhone &right) +{ + return !(left == right); +} + /// Sets the phone \a number. void QXmppVCardPhone::setNumber(const QString &number) @@ -475,6 +524,23 @@ QXmppVCardOrganization& QXmppVCardOrganization::operator=(const QXmppVCardOrgani return *this; } +/// \brief Checks if two organization objects represent the same organization. + +bool operator==(const QXmppVCardOrganization &left, const QXmppVCardOrganization &right) +{ + return left.organization() == right.organization() && + left.unit() == right.unit() && + left.title() == right.title() && + left.role() == right.role(); +} + +/// \brief Checks if two organization objects represent different organizations. + +bool operator!=(const QXmppVCardOrganization &left, const QXmppVCardOrganization &right) +{ + return !(left == right); +} + /// Returns the name of the organization. QString QXmppVCardOrganization::organization() const @@ -612,6 +678,34 @@ QXmppVCardIq& QXmppVCardIq::operator=(const QXmppVCardIq &other) return *this; } +/// \brief Checks if two VCard objects represent the same VCard. + +bool operator==(const QXmppVCardIq &left, const QXmppVCardIq &right) +{ + return left.birthday() == right.birthday() && + left.description() == right.description() && + left.email() == right.email() && + left.firstName() == right.firstName() && + left.fullName() == right.fullName() && + left.lastName() == right.lastName() && + left.middleName() == right.middleName() && + left.nickName() == right.nickName() && + left.photo() == right.photo() && + left.photoType() == right.photoType() && + left.url() == right.url() && + left.addresses() == right.addresses() && + left.emails() == right.emails() && + left.phones() == right.phones() && + left.organization() == right.organization(); +} + +/// \brief Checks if two VCard objects represent different VCards. + +bool operator!=(const QXmppVCardIq &left, const QXmppVCardIq &right) +{ + return !(left == right); +} + /// Returns the date of birth of the individual associated with the vCard. /// diff --git a/src/base/QXmppVCardIq.h b/src/base/QXmppVCardIq.h index cb54b91d..966ff632 100644 --- a/src/base/QXmppVCardIq.h +++ b/src/base/QXmppVCardIq.h @@ -84,6 +84,9 @@ private: QSharedDataPointer<QXmppVCardAddressPrivate> d; }; +QXMPP_EXPORT bool operator==(const QXmppVCardAddress&, const QXmppVCardAddress&); +QXMPP_EXPORT bool operator!=(const QXmppVCardAddress&, const QXmppVCardAddress&); + /// \brief Represents a vCard e-mail address. class QXMPP_EXPORT QXmppVCardEmail @@ -121,6 +124,9 @@ private: QSharedDataPointer<QXmppVCardEmailPrivate> d; }; +QXMPP_EXPORT bool operator==(const QXmppVCardEmail&, const QXmppVCardEmail&); +QXMPP_EXPORT bool operator!=(const QXmppVCardEmail&, const QXmppVCardEmail&); + /// \brief Represents a vCard phone number. class QXMPP_EXPORT QXmppVCardPhone @@ -166,6 +172,9 @@ private: QSharedDataPointer<QXmppVCardPhonePrivate> d; }; +QXMPP_EXPORT bool operator==(const QXmppVCardPhone&, const QXmppVCardPhone&); +QXMPP_EXPORT bool operator!=(const QXmppVCardPhone&, const QXmppVCardPhone&); + /// \brief Represents organization information in XMPP vCards. /// /// This contains both information about organization itself and @@ -201,6 +210,9 @@ private: QSharedDataPointer<QXmppVCardOrganizationPrivate> d; }; +QXMPP_EXPORT bool operator==(const QXmppVCardOrganization&, const QXmppVCardOrganization&); +QXMPP_EXPORT bool operator!=(const QXmppVCardOrganization&, const QXmppVCardOrganization&); + /// \brief Represents the XMPP vCard. /// /// The functions names are self explanatory. @@ -279,4 +291,7 @@ private: QSharedDataPointer<QXmppVCardIqPrivate> d; }; +QXMPP_EXPORT bool operator==(const QXmppVCardIq&, const QXmppVCardIq&); +QXMPP_EXPORT bool operator!=(const QXmppVCardIq&, const QXmppVCardIq&); + #endif // QXMPPVCARDIQ_H diff --git a/src/client/QXmppClient.cpp b/src/client/QXmppClient.cpp index 4a5eab9c..daf298be 100644 --- a/src/client/QXmppClient.cpp +++ b/src/client/QXmppClient.cpp @@ -456,6 +456,14 @@ QAbstractSocket::SocketError QXmppClient::socketError() return d->stream->socket()->error(); } +/// Returns the human-readable description of the last socket error if error() is QXmppClient::SocketError. +/// + +QString QXmppClient::socketErrorString() const +{ + return d->stream->socket()->errorString(); +} + /// Returns the XMPP stream error if QXmppClient::Error is QXmppClient::XmppStreamError. /// diff --git a/src/client/QXmppClient.h b/src/client/QXmppClient.h index 985ea97c..b2ca9b96 100644 --- a/src/client/QXmppClient.h +++ b/src/client/QXmppClient.h @@ -149,6 +149,7 @@ public: void setLogger(QXmppLogger *logger); QAbstractSocket::SocketError socketError(); + QString socketErrorString() const; State state() const; QXmppStanza::Error::Condition xmppStreamError(); diff --git a/src/client/QXmppConfiguration.h b/src/client/QXmppConfiguration.h index 513075c3..0de57e79 100644 --- a/src/client/QXmppConfiguration.h +++ b/src/client/QXmppConfiguration.h @@ -53,10 +53,11 @@ public: /// Depending upon all this user can specify following options. enum StreamSecurityMode { - TLSEnabled = 0, ///< Encryption is used if available (default) - TLSDisabled, ///< No encryption is server allows - TLSRequired ///< Encryption is a must otherwise connection would not - ///< be established + TLSEnabled = 0, ///< Encryption is used if available (default). + TLSDisabled, ///< No encryption even if the server offers it. + TLSRequired, ///< Encryption must be available, otherwise the + ///< connection will not be established. + LegacySSL ///< Use only legacy SSL mode. }; /// An enumeration for various Non-SASL authentication mechanisms available. diff --git a/src/client/QXmppDiscoveryManager.cpp b/src/client/QXmppDiscoveryManager.cpp index 5188a4e7..7c9a777e 100644 --- a/src/client/QXmppDiscoveryManager.cpp +++ b/src/client/QXmppDiscoveryManager.cpp @@ -115,7 +115,8 @@ QXmppDiscoveryIq QXmppDiscoveryManager::capabilities() << ns_chat_states // XEP-0085: Chat State Notifications << ns_capabilities // XEP-0115: Entity Capabilities << ns_ping // XEP-0199: XMPP Ping - << ns_attention; // XEP-0224: Attention + << ns_attention // XEP-0224: Attention + << ns_chat_markers; // XEP-0333: Chat Markers foreach(QXmppClientExtension* extension, client()->extensions()) { diff --git a/src/client/QXmppOutgoingClient.cpp b/src/client/QXmppOutgoingClient.cpp index 0ee1d1af..666b0365 100644 --- a/src/client/QXmppOutgoingClient.cpp +++ b/src/client/QXmppOutgoingClient.cpp @@ -129,7 +129,16 @@ void QXmppOutgoingClientPrivate::connectToHost(const QString &host, quint16 port #endif // connect to host - q->socket()->connectToHost(host, port); + const QXmppConfiguration::StreamSecurityMode localSecurity = q->configuration().streamSecurityMode(); + if (localSecurity == QXmppConfiguration::LegacySSL) { + if (!q->socket()->supportsSsl()) { + q->warning("Not connecting as legacy SSL was requested, but SSL support is not available"); + return; + } + q->socket()->connectToHostEncrypted(host, port); + } else { + q->socket()->connectToHost(host, port); + } } /// Constructs an outgoing client stream. diff --git a/tests/qxmppmessage/tst_qxmppmessage.cpp b/tests/qxmppmessage/tst_qxmppmessage.cpp index 218ff962..1ec4f18b 100644 --- a/tests/qxmppmessage/tst_qxmppmessage.cpp +++ b/tests/qxmppmessage/tst_qxmppmessage.cpp @@ -43,6 +43,7 @@ private slots: void testState(); void testXhtml(); void testSubextensions(); + void testChatMarkers(); }; void tst_QXmppMessage::testBasic_data() @@ -331,5 +332,191 @@ void tst_QXmppMessage::testSubextensions() serializePacket(message, xml); } +void tst_QXmppMessage::testChatMarkers() +{ + const QByteArray markableXml( + "<message " + "from='northumberland@shakespeare.lit/westminster' " + "id='message-1' " + "to='ingrichard@royalty.england.lit/throne'>" + "<thread>sleeping</thread>" + "<body>My lord, dispatch; read o'er these articles.</body>" + "<markable xmlns='urn:xmpp:chat-markers:0'/>" + "</message>"); + + QXmppMessage markableMessage; + parsePacket(markableMessage, markableXml); + QCOMPARE(markableMessage.isMarkable(), true); + QCOMPARE(markableMessage.marker(), QXmppMessage::NoMarker); + QCOMPARE(markableMessage.id(), QString("message-1")); + QCOMPARE(markableMessage.markedId(), QString()); + QCOMPARE(markableMessage.thread(), QString("sleeping")); + QCOMPARE(markableMessage.markedThread(), QString()); + + const QByteArray receivedXml( + "<message " + "from='kingrichard@royalty.england.lit/throne' " + "id='message-2' " + "to='northumberland@shakespeare.lit/westminster'>" + "<received xmlns='urn:xmpp:chat-markers:0' " + "id='message-1' " + "thread='sleeping'/>" + "</message>"); + + QXmppMessage receivedMessage; + parsePacket(receivedMessage, receivedXml); + QCOMPARE(receivedMessage.isMarkable(), false); + QCOMPARE(receivedMessage.marker(), QXmppMessage::Received); + QCOMPARE(receivedMessage.id(), QString("message-2")); + QCOMPARE(receivedMessage.markedId(), QString("message-1")); + QCOMPARE(receivedMessage.thread(), QString()); + QCOMPARE(receivedMessage.markedThread(), QString("sleeping")); + + const QByteArray displayedXml( + "<message " + "from='kingrichard@royalty.england.lit/throne' " + "id='message-2' " + "to='northumberland@shakespeare.lit/westminster'>" + "<displayed xmlns='urn:xmpp:chat-markers:0' " + "id='message-1' " + "thread='sleeping'/>" + "</message>"); + + QXmppMessage displayedMessage; + parsePacket(displayedMessage, displayedXml); + QCOMPARE(displayedMessage.isMarkable(), false); + QCOMPARE(displayedMessage.marker(), QXmppMessage::Displayed); + QCOMPARE(displayedMessage.id(), QString("message-2")); + QCOMPARE(displayedMessage.markedId(), QString("message-1")); + QCOMPARE(displayedMessage.thread(), QString()); + QCOMPARE(displayedMessage.markedThread(), QString("sleeping")); + + const QByteArray acknowledgedXml( + "<message " + "from='kingrichard@royalty.england.lit/throne' " + "id='message-2' " + "to='northumberland@shakespeare.lit/westminster'>" + "<acknowledged xmlns='urn:xmpp:chat-markers:0' " + "id='message-1' " + "thread='sleeping'/>" + "</message>"); + + QXmppMessage acknowledgedMessage; + parsePacket(acknowledgedMessage, acknowledgedXml); + QCOMPARE(acknowledgedMessage.isMarkable(), false); + QCOMPARE(acknowledgedMessage.marker(), QXmppMessage::Acknowledged); + QCOMPARE(acknowledgedMessage.id(), QString("message-2")); + QCOMPARE(acknowledgedMessage.markedId(), QString("message-1")); + QCOMPARE(acknowledgedMessage.thread(), QString()); + QCOMPARE(acknowledgedMessage.markedThread(), QString("sleeping")); + + const QByteArray emptyThreadXml( + "<message " + "from='kingrichard@royalty.england.lit/throne' " + "id='message-2' " + "to='northumberland@shakespeare.lit/westminster'>" + "<received xmlns='urn:xmpp:chat-markers:0' " + "id='message-1'/>" + "</message>"); + + QXmppMessage emptyThreadMessage; + parsePacket(emptyThreadMessage, emptyThreadXml); + QCOMPARE(emptyThreadMessage.isMarkable(), false); + QCOMPARE(emptyThreadMessage.marker(), QXmppMessage::Received); + QCOMPARE(emptyThreadMessage.id(), QString("message-2")); + QCOMPARE(emptyThreadMessage.markedId(), QString("message-1")); + QCOMPARE(emptyThreadMessage.thread(), QString()); + QCOMPARE(emptyThreadMessage.markedThread(), QString()); + + const QByteArray notMarkableSerialisation( + "<message " + "id=\"message-3\" " + "to=\"northumberland@shakespeare.lit/westminster\" " + "from=\"kingrichard@royalty.england.lit/throne\" " + "type=\"chat\"/>"); + + QXmppMessage serialisationMessage; + serialisationMessage.setFrom("kingrichard@royalty.england.lit/throne"); + serialisationMessage.setTo("northumberland@shakespeare.lit/westminster"); + serialisationMessage.setId("message-3"); + serialisationMessage.setMarkable(false); + serializePacket(serialisationMessage, notMarkableSerialisation); + + const QByteArray markableSerialisation( + "<message " + "id=\"message-3\" " + "to=\"northumberland@shakespeare.lit/westminster\" " + "from=\"kingrichard@royalty.england.lit/throne\" " + "type=\"chat\">" + "<markable xmlns=\"urn:xmpp:chat-markers:0\"/>" + "</message>"); + + serialisationMessage.setMarkable(true); + serializePacket(serialisationMessage, markableSerialisation); + + const QByteArray receivedSerialisation( + "<message " + "id=\"message-3\" " + "to=\"northumberland@shakespeare.lit/westminster\" " + "from=\"kingrichard@royalty.england.lit/throne\" " + "type=\"chat\">" + "<received xmlns=\"urn:xmpp:chat-markers:0\" " + "id=\"message-2\"/>" + "</message>"); + + serialisationMessage.setMarkable(false); + serialisationMessage.setMarker(QXmppMessage::Received); + serialisationMessage.setMarkerId("message-2"); + serializePacket(serialisationMessage, receivedSerialisation); + + const QByteArray receivedThreadSerialisation( + "<message " + "id=\"message-3\" " + "to=\"northumberland@shakespeare.lit/westminster\" " + "from=\"kingrichard@royalty.england.lit/throne\" " + "type=\"chat\">" + "<received xmlns=\"urn:xmpp:chat-markers:0\" " + "id=\"message-2\" " + "thread=\"sleeping\"/>" + "</message>"); + + serialisationMessage.setMarker(QXmppMessage::Received); + serialisationMessage.setMarkerId("message-2"); + serialisationMessage.setMarkedThread("sleeping"); + serializePacket(serialisationMessage, receivedThreadSerialisation); + + const QByteArray displayedThreadSerialisation( + "<message " + "id=\"message-3\" " + "to=\"northumberland@shakespeare.lit/westminster\" " + "from=\"kingrichard@royalty.england.lit/throne\" " + "type=\"chat\">" + "<displayed xmlns=\"urn:xmpp:chat-markers:0\" " + "id=\"message-2\" " + "thread=\"sleeping\"/>" + "</message>"); + + serialisationMessage.setMarker(QXmppMessage::Displayed); + serialisationMessage.setMarkerId("message-2"); + serialisationMessage.setMarkedThread("sleeping"); + serializePacket(serialisationMessage, displayedThreadSerialisation); + + const QByteArray acknowledgedThreadSerialisation( + "<message " + "id=\"message-3\" " + "to=\"northumberland@shakespeare.lit/westminster\" " + "from=\"kingrichard@royalty.england.lit/throne\" " + "type=\"chat\">" + "<acknowledged xmlns=\"urn:xmpp:chat-markers:0\" " + "id=\"message-2\" " + "thread=\"sleeping\"/>" + "</message>"); + + serialisationMessage.setMarker(QXmppMessage::Acknowledged); + serialisationMessage.setMarkerId("message-2"); + serialisationMessage.setMarkedThread("sleeping"); + serializePacket(serialisationMessage, acknowledgedThreadSerialisation); +} + QTEST_MAIN(tst_QXmppMessage) #include "tst_qxmppmessage.moc" diff --git a/tests/qxmpputils/tst_qxmpputils.cpp b/tests/qxmpputils/tst_qxmpputils.cpp index d725a738..3c15938e 100644 --- a/tests/qxmpputils/tst_qxmpputils.cpp +++ b/tests/qxmpputils/tst_qxmpputils.cpp @@ -114,7 +114,7 @@ void tst_QXmppUtils::testMime() void tst_QXmppUtils::testLibVersion() { - QCOMPARE(QXmppVersion(), QString("0.8.0")); + QCOMPARE(QXmppVersion(), QString("0.8.1")); } void tst_QXmppUtils::testTimezoneOffset() diff --git a/tests/qxmppvcardiq/tst_qxmppvcardiq.cpp b/tests/qxmppvcardiq/tst_qxmppvcardiq.cpp index f24c71df..5d12c1d1 100644 --- a/tests/qxmppvcardiq/tst_qxmppvcardiq.cpp +++ b/tests/qxmppvcardiq/tst_qxmppvcardiq.cpp @@ -48,18 +48,19 @@ void tst_QXmppVCardIq::testAddress_data() QTest::addColumn<QString>("postcode"); QTest::addColumn<QString>("region"); QTest::addColumn<QString>("street"); - - QTest::newRow("none") << QByteArray("<ADR/>") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << ""; - QTest::newRow("HOME") << QByteArray("<ADR><HOME/></ADR>") << int(QXmppVCardAddress::Home) << "" << "" << "" << "" << ""; - QTest::newRow("WORK") << QByteArray("<ADR><WORK/></ADR>") << int(QXmppVCardAddress::Work) << "" << "" << "" << "" << ""; - QTest::newRow("POSTAL") << QByteArray("<ADR><POSTAL/></ADR>") << int(QXmppVCardAddress::Postal) << "" << "" << "" << "" << ""; - QTest::newRow("PREF") << QByteArray("<ADR><PREF/></ADR>") << int(QXmppVCardAddress::Preferred) << "" << "" << "" << "" << ""; - - QTest::newRow("country") << QByteArray("<ADR><CTRY>France</CTRY></ADR>") << int(QXmppVCardAddress::None) << "France" << "" << "" << "" << ""; - QTest::newRow("locality") << QByteArray("<ADR><LOCALITY>Paris</LOCALITY></ADR>") << int(QXmppVCardAddress::None) << "" << "Paris" << "" << "" << ""; - QTest::newRow("postcode") << QByteArray("<ADR><PCODE>75008</PCODE></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "75008" << "" << ""; - QTest::newRow("region") << QByteArray("<ADR><REGION>Ile de France</REGION></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "" << "Ile de France" << ""; - QTest::newRow("street") << QByteArray("<ADR><STREET>55 rue du faubourg Saint-Honoré</STREET></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << QString::fromUtf8("55 rue du faubourg Saint-Honoré"); + QTest::addColumn<bool>("equalsEmpty"); + + QTest::newRow("none") << QByteArray("<ADR/>") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << "" << true; + QTest::newRow("HOME") << QByteArray("<ADR><HOME/></ADR>") << int(QXmppVCardAddress::Home) << "" << "" << "" << "" << "" << false; + QTest::newRow("WORK") << QByteArray("<ADR><WORK/></ADR>") << int(QXmppVCardAddress::Work) << "" << "" << "" << "" << "" << false; + QTest::newRow("POSTAL") << QByteArray("<ADR><POSTAL/></ADR>") << int(QXmppVCardAddress::Postal) << "" << "" << "" << "" << "" << false; + QTest::newRow("PREF") << QByteArray("<ADR><PREF/></ADR>") << int(QXmppVCardAddress::Preferred) << "" << "" << "" << "" << "" << false; + + QTest::newRow("country") << QByteArray("<ADR><CTRY>France</CTRY></ADR>") << int(QXmppVCardAddress::None) << "France" << "" << "" << "" << "" << false; + QTest::newRow("locality") << QByteArray("<ADR><LOCALITY>Paris</LOCALITY></ADR>") << int(QXmppVCardAddress::None) << "" << "Paris" << "" << "" << "" << false; + QTest::newRow("postcode") << QByteArray("<ADR><PCODE>75008</PCODE></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "75008" << "" << "" << false; + QTest::newRow("region") << QByteArray("<ADR><REGION>Ile de France</REGION></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "" << "Ile de France" << "" << false; + QTest::newRow("street") << QByteArray("<ADR><STREET>55 rue du faubourg Saint-Honoré</STREET></ADR>") << int(QXmppVCardAddress::None) << "" << "" << "" << "" << QString::fromUtf8("55 rue du faubourg Saint-Honoré") << false; } void tst_QXmppVCardIq::testAddress() @@ -71,6 +72,7 @@ void tst_QXmppVCardIq::testAddress() QFETCH(QString, postcode); QFETCH(QString, region); QFETCH(QString, street); + QFETCH(bool, equalsEmpty); QXmppVCardAddress address; parsePacket(address, xml); @@ -81,6 +83,14 @@ void tst_QXmppVCardIq::testAddress() QCOMPARE(address.region(), region); QCOMPARE(address.street(), street); serializePacket(address, xml); + + QXmppVCardAddress addressCopy = address; + QVERIFY2(addressCopy == address, "QXmppVCardAddres::operator==() fails"); + QVERIFY2(!(addressCopy != address), "QXmppVCardAddres::operator!=() fails"); + + QXmppVCardAddress emptyAddress; + QCOMPARE(emptyAddress == address, equalsEmpty); + QCOMPARE(emptyAddress != address, !equalsEmpty); } void tst_QXmppVCardIq::testEmail_data() |
