aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Lainé <jeremy.laine@m4x.org>2010-08-23 09:02:16 +0000
committerJeremy Lainé <jeremy.laine@m4x.org>2010-08-23 09:02:16 +0000
commit74859748cb4fe293fb2a41aef796e65622d9103b (patch)
treedabbc735e56beda26b0e187cf741a3a183c03f20
parentf3d107cc7a6c87ff3b5986f80b16e350d5211895 (diff)
downloadqxmpp-74859748cb4fe293fb2a41aef796e65622d9103b.tar.gz
fix and test QXmppArchiveListIq parsing/serialisation
-rw-r--r--src/QXmppArchiveIq.cpp52
-rw-r--r--src/QXmppArchiveIq.h27
-rw-r--r--tests/tests.cpp24
-rw-r--r--tests/tests.h1
4 files changed, 81 insertions, 23 deletions
diff --git a/src/QXmppArchiveIq.cpp b/src/QXmppArchiveIq.cpp
index 058ff5f7..d2bd238e 100644
--- a/src/QXmppArchiveIq.cpp
+++ b/src/QXmppArchiveIq.cpp
@@ -21,13 +21,13 @@
*
*/
+#include <QDomElement>
+
#include "QXmppArchiveIq.h"
#include "QXmppUtils.h"
-#include <QDebug>
-#include <QDomElement>
-
static const char *ns_archive = "urn:xmpp:archive";
+static const char *ns_rsm = "http://jabber.org/protocol/rsm";
QString QXmppArchiveMessage::body() const
{
@@ -118,13 +118,17 @@ bool QXmppArchiveChatIq::isArchiveChatIq(const QDomElement &element)
//return (chatElement.namespaceURI() == ns_archive);
}
-void QXmppArchiveChatIq::parse(const QDomElement &element)
+void QXmppArchiveChatIq::parseElementFromChild(const QDomElement &element)
{
- QXmppStanza::parse(element);
-
m_chat.parse(element.firstChildElement("chat"));
}
+void QXmppArchiveChatIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
+{
+ // TODO : implement serialization
+ Q_UNUSED(writer);
+}
+
QXmppArchiveListIq::QXmppArchiveListIq()
: QXmppIq(QXmppIq::Get), m_max(0)
{
@@ -181,12 +185,18 @@ bool QXmppArchiveListIq::isArchiveListIq(const QDomElement &element)
return (listElement.namespaceURI() == ns_archive);
}
-void QXmppArchiveListIq::parse(const QDomElement &element)
+void QXmppArchiveListIq::parseElementFromChild(const QDomElement &element)
{
- QXmppStanza::parse(element);
-
QDomElement listElement = element.firstChildElement("list");
- m_with = element.attribute("with");
+ m_with = listElement.attribute("with");
+ m_start = datetimeFromString(listElement.attribute("start"));
+ m_end = datetimeFromString(listElement.attribute("end"));
+
+ QDomElement setElement = listElement.firstChildElement("set");
+ if (setElement.namespaceURI() == ns_rsm)
+ {
+ m_max = setElement.firstChildElement("max").text().toInt();
+ }
QDomElement child = listElement.firstChildElement();
while (!child.isNull())
@@ -210,13 +220,12 @@ void QXmppArchiveListIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
if (m_start.isValid())
helperToXmlAddAttribute(writer, "start", datetimeToString(m_start));
if (m_end.isValid())
- helperToXmlAddAttribute(writer, "end", datetimeToString(m_start));
+ helperToXmlAddAttribute(writer, "end", datetimeToString(m_end));
if (m_max > 0)
{
writer->writeStartElement("set");
- helperToXmlAddAttribute(writer, "xmlns", "http://jabber.org/protocol/rsm");
- if (m_max > 0)
- helperToXmlAddTextElement(writer, "max", QString::number(m_max));
+ helperToXmlAddAttribute(writer, "xmlns", ns_rsm);
+ helperToXmlAddTextElement(writer, "max", QString::number(m_max));
writer->writeEndElement();
}
writer->writeEndElement();
@@ -228,12 +237,10 @@ bool QXmppArchivePrefIq::isArchivePrefIq(const QDomElement &element)
return (prefElement.namespaceURI() == ns_archive);
}
-void QXmppArchivePrefIq::parse(const QDomElement &element)
+void QXmppArchivePrefIq::parseElementFromChild(const QDomElement &element)
{
- QXmppStanza::parse(element);
-
QDomElement queryElement = element.firstChildElement("pref");
- //setId( element.attribute("id"));
+ Q_UNUSED(queryElement);
}
void QXmppArchivePrefIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
@@ -278,6 +285,13 @@ void QXmppArchiveRetrieveIq::setWith(const QString &with)
m_with = with;
}
+void QXmppArchiveRetrieveIq::parseElementFromChild(const QDomElement &element)
+{
+ // TODO : implement parsing
+ QDomElement retrieveElement = element.firstChildElement("retrieve");
+ Q_UNUSED(retrieveElement);
+}
+
void QXmppArchiveRetrieveIq::toXmlElementFromChild(QXmlStreamWriter *writer) const
{
writer->writeStartElement("retrieve");
@@ -287,7 +301,7 @@ void QXmppArchiveRetrieveIq::toXmlElementFromChild(QXmlStreamWriter *writer) con
if (m_max > 0)
{
writer->writeStartElement("set");
- helperToXmlAddAttribute(writer, "xmlns", "http://jabber.org/protocol/rsm");
+ helperToXmlAddAttribute(writer, "xmlns", ns_rsm);
if (m_max > 0)
helperToXmlAddTextElement(writer, "max", QString::number(m_max));
writer->writeEndElement();
diff --git a/src/QXmppArchiveIq.h b/src/QXmppArchiveIq.h
index a34f8455..904e21a5 100644
--- a/src/QXmppArchiveIq.h
+++ b/src/QXmppArchiveIq.h
@@ -77,10 +77,15 @@ private:
class QXmppArchiveChatIq : public QXmppIq
{
public:
+ QXmppArchiveChat chat() const;
+
static bool isArchiveChatIq(const QDomElement &element);
- void parse(const QDomElement &element);
- QXmppArchiveChat chat() const;
+protected:
+ /// \cond
+ void parseElementFromChild(const QDomElement &element);
+ void toXmlElementFromChild(QXmlStreamWriter *writer) const;
+ /// \endcond
private:
QXmppArchiveChat m_chat;
@@ -110,8 +115,12 @@ public:
void setEnd(const QDateTime &end );
static bool isArchiveListIq(const QDomElement &element);
- void parse(const QDomElement &element);
+
+protected:
+ /// \cond
+ void parseElementFromChild(const QDomElement &element);
void toXmlElementFromChild(QXmlStreamWriter *writer) const;
+ /// \endcond
private:
int m_max;
@@ -139,7 +148,13 @@ public:
QString with() const;
void setWith( const QString &with );
+ static bool isArchiveRetrieveIq(const QDomElement &element);
+
+protected:
+ /// \cond
+ void parseElementFromChild(const QDomElement &element);
void toXmlElementFromChild(QXmlStreamWriter *writer) const;
+ /// \endcond
private:
int m_max;
@@ -155,8 +170,12 @@ class QXmppArchivePrefIq : public QXmppIq
{
public:
static bool isArchivePrefIq(const QDomElement &element);
- void parse(const QDomElement &element);
+
+protected:
+ /// \cond
+ void parseElementFromChild(const QDomElement &element);
void toXmlElementFromChild(QXmlStreamWriter *writer) const;
+ /// \endcond
};
#endif // QXMPPARCHIVEIQ_H
diff --git a/tests/tests.cpp b/tests/tests.cpp
index d433954b..3eb90450 100644
--- a/tests/tests.cpp
+++ b/tests/tests.cpp
@@ -28,6 +28,7 @@
#include <QVariant>
#include <QtTest/QtTest>
+#include "QXmppArchiveIq.h"
#include "QXmppBindIq.h"
#include "QXmppJingleIq.h"
#include "QXmppMessage.h"
@@ -101,6 +102,29 @@ static void serializePacket(T &packet, const QByteArray &xml)
QCOMPARE(buffer.data(), xml);
}
+void TestPackets::testArchiveList()
+{
+ const QByteArray xml(
+ "<iq id=\"list_1\" type=\"get\">"
+ "<list xmlns=\"urn:xmpp:archive\" with=\"juliet@capulet.com\""
+ " start=\"1469-07-21T02:00:00Z\" end=\"1479-07-21T04:00:00Z\">"
+ "<set xmlns=\"http://jabber.org/protocol/rsm\">"
+ "<max>30</max>"
+ "</set>"
+ "</list>"
+ "</iq>");
+
+ QXmppArchiveListIq iq;
+ parsePacket(iq, xml);
+ QCOMPARE(iq.type(), QXmppIq::Get);
+ QCOMPARE(iq.id(), QLatin1String("list_1"));
+ QCOMPARE(iq.with(), QLatin1String("juliet@capulet.com"));
+ QCOMPARE(iq.start(), QDateTime(QDate(1469, 7, 21), QTime(2, 0, 0), Qt::UTC));
+ QCOMPARE(iq.end(), QDateTime(QDate(1479, 7, 21), QTime(4, 0, 0), Qt::UTC));
+ QCOMPARE(iq.max(), 30);
+ serializePacket(iq, xml);
+}
+
void TestPackets::testBindNoResource()
{
const QByteArray xml(
diff --git a/tests/tests.h b/tests/tests.h
index 05f891b6..f09032a8 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -38,6 +38,7 @@ class TestPackets : public QObject
Q_OBJECT
private slots:
+ void testArchiveList();
void testBindNoResource();
void testBindResource();
void testBindResult();