summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r--Swiften/Serializer/PayloadSerializers/BodySerializer.h20
-rw-r--r--Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp20
-rw-r--r--Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp36
-rw-r--r--Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp56
-rw-r--r--Swiften/Serializer/PayloadSerializers/ErrorSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp49
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h19
-rw-r--r--Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp13
-rw-r--r--Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/Makefile.inc13
-rw-r--r--Swiften/Serializer/PayloadSerializers/PrioritySerializer.h20
-rw-r--r--Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp28
-rw-r--r--Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp45
-rw-r--r--Swiften/Serializer/PayloadSerializers/RosterSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp38
-rw-r--r--Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp30
-rw-r--r--Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp23
-rw-r--r--Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h16
-rw-r--r--Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h20
-rw-r--r--Swiften/Serializer/PayloadSerializers/StatusSerializer.h22
-rw-r--r--Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h33
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp25
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp38
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp25
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc12
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp25
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp49
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp48
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp43
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp52
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp25
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp25
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp58
38 files changed, 1054 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/BodySerializer.h b/Swiften/Serializer/PayloadSerializers/BodySerializer.h
new file mode 100644
index 0000000..7fba561
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/BodySerializer.h
@@ -0,0 +1,20 @@
+#ifndef SWIFTEN_BodySerializer_H
+#define SWIFTEN_BodySerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Serializer/XML/XMLTextNode.h"
+#include "Swiften/Elements/Body.h"
+
+namespace Swift {
+ class BodySerializer : public GenericPayloadSerializer<Body> {
+ public:
+ BodySerializer() : GenericPayloadSerializer<Body>() {}
+
+ virtual String serializePayload(boost::shared_ptr<Body> body) const {
+ XMLTextNode textNode(body->getText());
+ return "<body>" + textNode.serialize() + "</body>";
+ }
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp
new file mode 100644
index 0000000..fbb72af
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp
@@ -0,0 +1,20 @@
+#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Serializer/XML/XMLElement.h"
+
+namespace Swift {
+
+CapsInfoSerializer::CapsInfoSerializer() : GenericPayloadSerializer<CapsInfo>() {
+}
+
+String CapsInfoSerializer::serializePayload(boost::shared_ptr<CapsInfo> capsInfo) const {
+ XMLElement capsElement("c", "http://jabber.org/protocol/caps");
+ capsElement.setAttribute("node", capsInfo->getNode());
+ capsElement.setAttribute("hash", capsInfo->getHash());
+ capsElement.setAttribute("ver", capsInfo->getVersion());
+ return capsElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h
new file mode 100644
index 0000000..cb4fa33
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_CapsInfoSerializer_H
+#define SWIFTEN_CapsInfoSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/CapsInfo.h"
+
+namespace Swift {
+ class CapsInfoSerializer : public GenericPayloadSerializer<CapsInfo> {
+ public:
+ CapsInfoSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<CapsInfo>) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp
new file mode 100644
index 0000000..4c39574
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp
@@ -0,0 +1,36 @@
+#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Base/foreach.h"
+#include "Swiften/Serializer/XML/XMLElement.h"
+
+namespace Swift {
+
+DiscoInfoSerializer::DiscoInfoSerializer() : GenericPayloadSerializer<DiscoInfo>() {
+}
+
+String DiscoInfoSerializer::serializePayload(boost::shared_ptr<DiscoInfo> discoInfo) const {
+ XMLElement queryElement("query", "http://jabber.org/protocol/disco#info");
+ if (!discoInfo->getNode().isEmpty()) {
+ queryElement.setAttribute("node", discoInfo->getNode());
+ }
+ foreach(const DiscoInfo::Identity& identity, discoInfo->getIdentities()) {
+ boost::shared_ptr<XMLElement> identityElement(new XMLElement("identity"));
+ if (!identity.getLanguage().isEmpty()) {
+ identityElement->setAttribute("xml:lang", identity.getLanguage());
+ }
+ identityElement->setAttribute("category", identity.getCategory());
+ identityElement->setAttribute("name", identity.getName());
+ identityElement->setAttribute("type", identity.getType());
+ queryElement.addNode(identityElement);
+ }
+ foreach(const String& feature, discoInfo->getFeatures()) {
+ boost::shared_ptr<XMLElement> featureElement(new XMLElement("feature"));
+ featureElement->setAttribute("var", feature);
+ queryElement.addNode(featureElement);
+ }
+ return queryElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h
new file mode 100644
index 0000000..929a455
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_DiscoInfoSerializer_H
+#define SWIFTEN_DiscoInfoSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/DiscoInfo.h"
+
+namespace Swift {
+ class DiscoInfoSerializer : public GenericPayloadSerializer<DiscoInfo> {
+ public:
+ DiscoInfoSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<DiscoInfo>) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp
new file mode 100644
index 0000000..347e1a5
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp
@@ -0,0 +1,56 @@
+#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h"
+#include "Swiften/Serializer/XML/XMLTextNode.h"
+
+namespace Swift {
+
+ErrorSerializer::ErrorSerializer() : GenericPayloadSerializer<Error>() {
+}
+
+String ErrorSerializer::serializePayload(boost::shared_ptr<Error> error) const {
+ String result("<error type=\"");
+ switch (error->getType()) {
+ case Error::Continue: result += "continue"; break;
+ case Error::Modify: result += "modify"; break;
+ case Error::Auth: result += "auth"; break;
+ case Error::Wait: result += "wait"; break;
+ default: result += "cancel"; break;
+ }
+ result += "\">";
+
+ String conditionElement;
+ switch (error->getCondition()) {
+ case Error::BadRequest: conditionElement = "bad-request"; break;
+ case Error::Conflict: conditionElement = "conflict"; break;
+ case Error::FeatureNotImplemented: conditionElement = "feature-not-implemented"; break;
+ case Error::Forbidden: conditionElement = "forbidden"; break;
+ case Error::Gone: conditionElement = "gone"; break;
+ case Error::InternalServerError: conditionElement = "internal-server-error"; break;
+ case Error::ItemNotFound: conditionElement = "item-not-found"; break;
+ case Error::JIDMalformed: conditionElement = "jid-malformed"; break;
+ case Error::NotAcceptable: conditionElement = "not-acceptable"; break;
+ case Error::NotAllowed: conditionElement = "not-allowed"; break;
+ case Error::NotAuthorized: conditionElement = "not-authorized"; break;
+ case Error::PaymentRequired: conditionElement = "payment-required"; break;
+ case Error::RecipientUnavailable: conditionElement = "recipient-unavailable"; break;
+ case Error::Redirect: conditionElement = "redirect"; break;
+ case Error::RegistrationRequired: conditionElement = "registration-required"; break;
+ case Error::RemoteServerNotFound: conditionElement = "remote-server-not-found"; break;
+ case Error::RemoteServerTimeout: conditionElement = "remote-server-timeout"; break;
+ case Error::ResourceConstraint: conditionElement = "resource-constraint"; break;
+ case Error::ServiceUnavailable: conditionElement = "service-unavailable"; break;
+ case Error::SubscriptionRequired: conditionElement = "subscription-required"; break;
+ case Error::UnexpectedRequest: conditionElement = "unexpected-request"; break;
+ default: conditionElement = "undefined-condition"; break;
+ }
+ result += "<" + conditionElement + " xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/>";
+
+ if (!error->getText().isEmpty()) {
+ XMLTextNode textNode(error->getText());
+ result += "<text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">" + textNode.serialize() + "</text>";
+ }
+
+ result += "</error>";
+ return result;
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h
new file mode 100644
index 0000000..ecf73dc
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/ErrorSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_ErrorSerializer_H
+#define SWIFTEN_ErrorSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/Error.h"
+
+namespace Swift {
+ class ErrorSerializer : public GenericPayloadSerializer<Error> {
+ public:
+ ErrorSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<Error> error) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
new file mode 100644
index 0000000..9799802
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -0,0 +1,49 @@
+#include "Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h"
+#include "Swiften/Base/foreach.h"
+#include "Swiften/Serializer/PayloadSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/BodySerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/PrioritySerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h"
+
+namespace Swift {
+
+FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
+ serializers_.push_back(new BodySerializer());
+ serializers_.push_back(new PrioritySerializer());
+ serializers_.push_back(new ErrorSerializer());
+ serializers_.push_back(new RosterSerializer());
+ serializers_.push_back(new MUCPayloadSerializer());
+ serializers_.push_back(new SoftwareVersionSerializer());
+ serializers_.push_back(new StatusSerializer());
+ serializers_.push_back(new StatusShowSerializer());
+ serializers_.push_back(new DiscoInfoSerializer());
+ serializers_.push_back(new CapsInfoSerializer());
+ serializers_.push_back(new ResourceBindSerializer());
+ serializers_.push_back(new StartSessionSerializer());
+ serializers_.push_back(new SecurityLabelSerializer());
+ serializers_.push_back(new SecurityLabelsCatalogSerializer());
+ foreach(PayloadSerializer* serializer, serializers_) {
+ addSerializer(serializer);
+ }
+}
+
+FullPayloadSerializerCollection::~FullPayloadSerializerCollection() {
+ foreach(PayloadSerializer* serializer, serializers_) {
+ removeSerializer(serializer);
+ delete serializer;
+ }
+ serializers_.clear();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h
new file mode 100644
index 0000000..e1655b5
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h
@@ -0,0 +1,19 @@
+#ifndef SWIFTEN_FULLPAYLOADSERIALIZERCOLLECTION_H
+#define SWIFTEN_FULLPAYLOADSERIALIZERCOLLECTION_H
+
+#include <vector>
+
+#include "Swiften/Serializer/PayloadSerializerCollection.h"
+
+namespace Swift {
+ class FullPayloadSerializerCollection : public PayloadSerializerCollection {
+ public:
+ FullPayloadSerializerCollection();
+ ~FullPayloadSerializerCollection();
+
+ private:
+ std::vector<PayloadSerializer*> serializers_;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp
new file mode 100644
index 0000000..9c701cc
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp
@@ -0,0 +1,13 @@
+#include "Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h"
+
+namespace Swift {
+
+MUCPayloadSerializer::MUCPayloadSerializer() : GenericPayloadSerializer<MUCPayload>() {
+}
+
+String MUCPayloadSerializer::serializePayload(boost::shared_ptr<MUCPayload>) const {
+ String result("<x xmlns='http://jabber.org/protocol/muc'/>");
+ return result;
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h
new file mode 100644
index 0000000..504c969
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_MUCPayloadSerializer_H
+#define SWIFTEN_MUCPayloadSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/MUCPayload.h"
+
+namespace Swift {
+ class MUCPayloadSerializer : public GenericPayloadSerializer<MUCPayload> {
+ public:
+ MUCPayloadSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<MUCPayload> version) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/Makefile.inc b/Swiften/Serializer/PayloadSerializers/Makefile.inc
new file mode 100644
index 0000000..61f603a
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/Makefile.inc
@@ -0,0 +1,13 @@
+SWIFTEN_SOURCES += \
+ Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp \
+ Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp \
+ Swiften/Serializer/PayloadSerializers/ErrorSerializer.cpp \
+ Swiften/Serializer/PayloadSerializers/MUCPayloadSerializer.cpp \
+ Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp \
+ Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.cpp \
+ Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.cpp \
+ Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp \
+ Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp \
+ Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp
+
+include Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc
diff --git a/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h b/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h
new file mode 100644
index 0000000..f132b6e
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/PrioritySerializer.h
@@ -0,0 +1,20 @@
+#ifndef SWIFTEN_PrioritySerializer_H
+#define SWIFTEN_PrioritySerializer_H
+
+#include <boost/lexical_cast.hpp>
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/Priority.h"
+
+namespace Swift {
+ class PrioritySerializer : public GenericPayloadSerializer<Priority> {
+ public:
+ PrioritySerializer() : GenericPayloadSerializer<Priority>() {}
+
+ virtual String serializePayload(boost::shared_ptr<Priority> priority) const {
+ return "<priority>" + boost::lexical_cast<std::string>(priority->getPriority()) + "</priority>";
+ }
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp
new file mode 100644
index 0000000..93ab136
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp
@@ -0,0 +1,28 @@
+#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Serializer/XML/XMLElement.h"
+#include "Swiften/Serializer/XML/XMLTextNode.h"
+
+namespace Swift {
+
+ResourceBindSerializer::ResourceBindSerializer() : GenericPayloadSerializer<ResourceBind>() {
+}
+
+String ResourceBindSerializer::serializePayload(boost::shared_ptr<ResourceBind> resourceBind) const {
+ XMLElement bindElement("bind", "urn:ietf:params:xml:ns:xmpp-bind");
+ if (resourceBind->getJID().isValid()) {
+ boost::shared_ptr<XMLElement> jidNode(new XMLElement("jid"));
+ jidNode->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(resourceBind->getJID().toString())));
+ bindElement.addNode(jidNode);
+ }
+ else if (!resourceBind->getResource().isEmpty()) {
+ boost::shared_ptr<XMLElement> resourceNode(new XMLElement("resource"));
+ resourceNode->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(resourceBind->getResource())));
+ bindElement.addNode(resourceNode);
+ }
+ return bindElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h
new file mode 100644
index 0000000..61cf539
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_ResourceBindSerializer_H
+#define SWIFTEN_ResourceBindSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/ResourceBind.h"
+
+namespace Swift {
+ class ResourceBindSerializer : public GenericPayloadSerializer<ResourceBind> {
+ public:
+ ResourceBindSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<ResourceBind>) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp b/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp
new file mode 100644
index 0000000..6329f86
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/RosterSerializer.cpp
@@ -0,0 +1,45 @@
+#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h"
+
+#include <boost/shared_ptr.hpp>
+
+#include "Swiften/Base/foreach.h"
+#include "Swiften/Serializer/XML/XMLTextNode.h"
+#include "Swiften/Serializer/XML/XMLElement.h"
+
+namespace Swift {
+
+RosterSerializer::RosterSerializer() : GenericPayloadSerializer<RosterPayload>() {
+}
+
+String RosterSerializer::serializePayload(boost::shared_ptr<RosterPayload> roster) const {
+ XMLElement queryElement("query", "jabber:iq:roster");
+ foreach(const RosterItemPayload& item, roster->getItems()) {
+ boost::shared_ptr<XMLElement> itemElement(new XMLElement("item"));
+ itemElement->setAttribute("jid", item.getJID());
+ itemElement->setAttribute("name", item.getName());
+
+ switch (item.getSubscription()) {
+ case RosterItemPayload::To: itemElement->setAttribute("subscription", "to"); break;
+ case RosterItemPayload::From: itemElement->setAttribute("subscription", "from"); break;
+ case RosterItemPayload::Both: itemElement->setAttribute("subscription", "both"); break;
+ case RosterItemPayload::Remove: itemElement->setAttribute("subscription", "remove"); break;
+ case RosterItemPayload::None: itemElement->setAttribute("subscription", "none"); break;
+ }
+
+ if (item.getSubscriptionRequested()) {
+ itemElement->setAttribute("ask", "subscribe");
+ }
+
+ foreach(const String& group, item.getGroups()) {
+ boost::shared_ptr<XMLElement> groupElement(new XMLElement("group"));
+ groupElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(group)));
+ itemElement->addNode(groupElement);
+ }
+
+ queryElement.addNode(itemElement);
+ }
+
+ return queryElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/RosterSerializer.h b/Swiften/Serializer/PayloadSerializers/RosterSerializer.h
new file mode 100644
index 0000000..fb6a713
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/RosterSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_RosterSerializer_H
+#define SWIFTEN_RosterSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/RosterPayload.h"
+
+namespace Swift {
+ class RosterSerializer : public GenericPayloadSerializer<RosterPayload> {
+ public:
+ RosterSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<RosterPayload>) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp
new file mode 100644
index 0000000..e53c6b7
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp
@@ -0,0 +1,38 @@
+#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h"
+#include "Swiften/Base/foreach.h"
+#include "Swiften/Serializer/XML/XMLRawTextNode.h"
+#include "Swiften/Serializer/XML/XMLTextNode.h"
+#include "Swiften/Serializer/XML/XMLElement.h"
+
+namespace Swift {
+
+SecurityLabelSerializer::SecurityLabelSerializer() : GenericPayloadSerializer<SecurityLabel>() {
+}
+
+String SecurityLabelSerializer::serializePayload(boost::shared_ptr<SecurityLabel> label) const {
+ XMLElement element("securitylabel", "urn:xmpp:sec-label:0");
+ if (!label->getDisplayMarking().isEmpty()) {
+ boost::shared_ptr<XMLElement> displayMarking(new XMLElement("displaymarking"));
+ if (!label->getForegroundColor().isEmpty()) {
+ displayMarking->setAttribute("fgcolor", label->getForegroundColor());
+ }
+ if (!label->getBackgroundColor().isEmpty()) {
+ displayMarking->setAttribute("bgcolor", label->getBackgroundColor());
+ }
+ displayMarking->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(label->getDisplayMarking())));
+ element.addNode(displayMarking);
+ }
+ if (!label->getLabel().isEmpty()) {
+ boost::shared_ptr<XMLElement> labelElement(new XMLElement("label"));
+ labelElement->addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(label->getLabel())));
+ element.addNode(labelElement);
+ }
+ foreach(const String& equivalentLabel, label->getEquivalentLabels()) {
+ boost::shared_ptr<XMLElement> equivalentLabelElement(new XMLElement("equivalentlabel"));
+ equivalentLabelElement->addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(equivalentLabel)));
+ element.addNode(equivalentLabelElement);
+ }
+ return element.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h
new file mode 100644
index 0000000..b0b0804
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_SecurityLabelSerializer_H
+#define SWIFTEN_SecurityLabelSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/SecurityLabel.h"
+
+namespace Swift {
+ class SecurityLabelSerializer : public GenericPayloadSerializer<SecurityLabel> {
+ public:
+ SecurityLabelSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<SecurityLabel> version) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp
new file mode 100644
index 0000000..bc6a41f
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp
@@ -0,0 +1,30 @@
+#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h"
+#include "Swiften/Base/foreach.h"
+#include "Swiften/Serializer/XML/XMLElement.h"
+#include "Swiften/Serializer/XML/XMLRawTextNode.h"
+#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h"
+
+namespace Swift {
+
+SecurityLabelsCatalogSerializer::SecurityLabelsCatalogSerializer() : GenericPayloadSerializer<SecurityLabelsCatalog>() {
+}
+
+String SecurityLabelsCatalogSerializer::serializePayload(boost::shared_ptr<SecurityLabelsCatalog> catalog) const {
+ XMLElement element("catalog", "urn:xmpp:sec-label:catalog:0");
+ if (!catalog->getName().isEmpty()) {
+ element.setAttribute("name", catalog->getName());
+ }
+ if (catalog->getTo().isValid()) {
+ element.setAttribute("to", catalog->getTo());
+ }
+ if (!catalog->getDescription().isEmpty()) {
+ element.setAttribute("desc", catalog->getDescription());
+ }
+ foreach (const SecurityLabel& label, catalog->getLabels()) {
+ String serializedLabel = SecurityLabelSerializer().serialize(boost::shared_ptr<SecurityLabel>(new SecurityLabel(label)));
+ element.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializedLabel)));
+ }
+ return element.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h
new file mode 100644
index 0000000..d086c79
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_SecurityLabelsCatalogSerializer_H
+#define SWIFTEN_SecurityLabelsCatalogSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/SecurityLabelsCatalog.h"
+
+namespace Swift {
+ class SecurityLabelsCatalogSerializer : public GenericPayloadSerializer<SecurityLabelsCatalog> {
+ public:
+ SecurityLabelsCatalogSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<SecurityLabelsCatalog> version) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp
new file mode 100644
index 0000000..71ad9a2
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.cpp
@@ -0,0 +1,23 @@
+#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h"
+
+namespace Swift {
+
+SoftwareVersionSerializer::SoftwareVersionSerializer() : GenericPayloadSerializer<SoftwareVersion>() {
+}
+
+String SoftwareVersionSerializer::serializePayload(boost::shared_ptr<SoftwareVersion> version) const {
+ String result("<query xmlns=\"jabber:iq:version\">");
+ if (!version->getName().isEmpty()) {
+ result += "<name>" + version->getName() + "</name>";
+ }
+ if (!version->getVersion().isEmpty()) {
+ result += "<version>" + version->getVersion() + "</version>";
+ }
+ if (!version->getOS().isEmpty()) {
+ result += "<os>" + version->getOS() + "</os>";
+ }
+ result += "</query>";
+ return result;
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h
new file mode 100644
index 0000000..50242f2
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h
@@ -0,0 +1,16 @@
+#ifndef SWIFTEN_SoftwareVersionSerializer_H
+#define SWIFTEN_SoftwareVersionSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/SoftwareVersion.h"
+
+namespace Swift {
+ class SoftwareVersionSerializer : public GenericPayloadSerializer<SoftwareVersion> {
+ public:
+ SoftwareVersionSerializer();
+
+ virtual String serializePayload(boost::shared_ptr<SoftwareVersion> version) const;
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h b/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h
new file mode 100644
index 0000000..df35054
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/StartSessionSerializer.h
@@ -0,0 +1,20 @@
+#ifndef SWIFTEN_StartSessionSerializer_H
+#define SWIFTEN_StartSessionSerializer_H
+
+#include <boost/lexical_cast.hpp>
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/StartSession.h"
+
+namespace Swift {
+ class StartSessionSerializer : public GenericPayloadSerializer<StartSession> {
+ public:
+ StartSessionSerializer() : GenericPayloadSerializer<StartSession>() {}
+
+ virtual String serializePayload(boost::shared_ptr<StartSession>) const {
+ return XMLElement("session", "urn:ietf:params:xml:ns:xmpp-session").serialize();
+ }
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/StatusSerializer.h b/Swiften/Serializer/PayloadSerializers/StatusSerializer.h
new file mode 100644
index 0000000..dc5f6d1
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/StatusSerializer.h
@@ -0,0 +1,22 @@
+#ifndef SWIFTEN_StatusSerializer_H
+#define SWIFTEN_StatusSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Serializer/XML/XMLElement.h"
+#include "Swiften/Serializer/XML/XMLTextNode.h"
+#include "Swiften/Elements/Status.h"
+
+namespace Swift {
+ class StatusSerializer : public GenericPayloadSerializer<Status> {
+ public:
+ StatusSerializer() : GenericPayloadSerializer<Status>() {}
+
+ virtual String serializePayload(boost::shared_ptr<Status> status) const {
+ XMLElement element("status");
+ element.addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(status->getText())));
+ return element.serialize();
+ }
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h b/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h
new file mode 100644
index 0000000..f66c09c
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h
@@ -0,0 +1,33 @@
+#ifndef SWIFTEN_StatusShowSerializer_H
+#define SWIFTEN_StatusShowSerializer_H
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/StatusShow.h"
+
+namespace Swift {
+ class StatusShowSerializer : public GenericPayloadSerializer<StatusShow> {
+ public:
+ StatusShowSerializer() : GenericPayloadSerializer<StatusShow>() {}
+
+ virtual String serializePayload(boost::shared_ptr<StatusShow> statusShow) const {
+ if (statusShow->getType () == StatusShow::Online || statusShow->getType() == StatusShow::None) {
+ return "";
+ }
+ else {
+ String result("<show>");
+ switch (statusShow->getType()) {
+ case StatusShow::Away: result += "away"; break;
+ case StatusShow::XA: result += "xa"; break;
+ case StatusShow::FFC: result += "chat"; break;
+ case StatusShow::DND: result += "dnd"; break;
+ case StatusShow::Online: assert(false); break;
+ case StatusShow::None: assert(false); break;
+ }
+ result += "</show>";
+ return result;
+ }
+ }
+ };
+}
+
+#endif
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp
new file mode 100644
index 0000000..650a7ee
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp
@@ -0,0 +1,25 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/CapsInfoSerializer.h"
+
+using namespace Swift;
+
+class CapsInfoSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(CapsInfoSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ CapsInfoSerializerTest() {}
+
+ void testSerialize() {
+ CapsInfoSerializer testling;
+ boost::shared_ptr<CapsInfo> priority(new CapsInfo("http://swift.im", "myversion", "sha-1"));
+
+ CPPUNIT_ASSERT_EQUAL(String("<c hash=\"sha-1\" node=\"http://swift.im\" ver=\"myversion\" xmlns=\"http://jabber.org/protocol/caps\"/>"), testling.serialize(priority));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(CapsInfoSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp
new file mode 100644
index 0000000..d3e247f
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp
@@ -0,0 +1,38 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/DiscoInfoSerializer.h"
+
+using namespace Swift;
+
+class DiscoInfoSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(DiscoInfoSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ DiscoInfoSerializerTest() {}
+
+ void testSerialize() {
+ DiscoInfoSerializer testling;
+ boost::shared_ptr<DiscoInfo> discoInfo(new DiscoInfo());
+ discoInfo->addIdentity(DiscoInfo::Identity("Swift", "client", "pc"));
+ discoInfo->addIdentity(DiscoInfo::Identity("Vlug", "client", "pc", "nl"));
+ discoInfo->addFeature("http://jabber.org/protocol/caps");
+ discoInfo->addFeature("http://jabber.org/protocol/disco#info");
+ discoInfo->setNode("http://swift.im#bla");
+
+ String expectedResult =
+ "<query node=\"http://swift.im#bla\" xmlns=\"http://jabber.org/protocol/disco#info\">"
+ "<identity category=\"client\" name=\"Swift\" type=\"pc\"/>"
+ "<identity category=\"client\" name=\"Vlug\" type=\"pc\" xml:lang=\"nl\"/>"
+ "<feature var=\"http://jabber.org/protocol/caps\"/>"
+ "<feature var=\"http://jabber.org/protocol/disco#info\"/>"
+ "</query>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(discoInfo));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp
new file mode 100644
index 0000000..2d68a3d
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp
@@ -0,0 +1,25 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/ErrorSerializer.h"
+
+using namespace Swift;
+
+class ErrorSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ErrorSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ ErrorSerializerTest() {}
+
+ void testSerialize() {
+ ErrorSerializer testling;
+ boost::shared_ptr<Error> error(new Error(Error::BadRequest, Error::Cancel, "My Error"));
+
+ CPPUNIT_ASSERT_EQUAL(String("<error type=\"cancel\"><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">My Error</text></error>"), testling.serialize(error));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ErrorSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc b/Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc
new file mode 100644
index 0000000..fce7ab9
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc
@@ -0,0 +1,12 @@
+UNITTEST_SOURCES += \
+ Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp \
+ Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp
new file mode 100644
index 0000000..5f6432b
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp
@@ -0,0 +1,25 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/PrioritySerializer.h"
+
+using namespace Swift;
+
+class PrioritySerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(PrioritySerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ PrioritySerializerTest() {}
+
+ void testSerialize() {
+ PrioritySerializer testling;
+ boost::shared_ptr<Priority> priority(new Priority(-113));
+
+ CPPUNIT_ASSERT_EQUAL(String("<priority>-113</priority>"), testling.serialize(priority));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PrioritySerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp
new file mode 100644
index 0000000..ff09966
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp
@@ -0,0 +1,49 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.h"
+
+using namespace Swift;
+
+class ResourceBindSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(ResourceBindSerializerTest);
+ CPPUNIT_TEST(testSerialize_JID);
+ CPPUNIT_TEST(testSerialize_Resource);
+ CPPUNIT_TEST(testSerialize_Empty);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ ResourceBindSerializerTest() {}
+
+ void testSerialize_JID() {
+ ResourceBindSerializer testling;
+ boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind());
+ resourceBind->setJID(JID("somenode@example.com/someresource"));
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">"
+ "<jid>somenode@example.com/someresource</jid>"
+ "</bind>"), testling.serialize(resourceBind));
+ }
+
+ void testSerialize_Resource() {
+ ResourceBindSerializer testling;
+ boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind());
+ resourceBind->setResource("someresource");
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">"
+ "<resource>someresource</resource>"
+ "</bind>"), testling.serialize(resourceBind));
+ }
+
+ void testSerialize_Empty() {
+ ResourceBindSerializer testling;
+ boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind());
+
+ CPPUNIT_ASSERT_EQUAL(String("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"), testling.serialize(resourceBind));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ResourceBindSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp
new file mode 100644
index 0000000..81fdc09
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp
@@ -0,0 +1,48 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/RosterSerializer.h"
+
+using namespace Swift;
+
+class RosterSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(RosterSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ RosterSerializerTest() {}
+
+ void testSerialize() {
+ RosterSerializer testling;
+ boost::shared_ptr<RosterPayload> roster(new RosterPayload());
+
+ RosterItemPayload item1;
+ item1.setJID(JID("foo@bar.com"));
+ item1.setName("Foo @ Bar");
+ item1.setSubscription(RosterItemPayload::From);
+ item1.addGroup("Group 1");
+ item1.addGroup("Group 2");
+ item1.setSubscriptionRequested();
+ roster->addItem(item1);
+
+ RosterItemPayload item2;
+ item2.setJID(JID("baz@blo.com"));
+ item2.setName("Baz");
+ roster->addItem(item2);
+
+ String expectedResult =
+ "<query xmlns=\"jabber:iq:roster\">"
+ "<item ask=\"subscribe\" jid=\"foo@bar.com\" name=\"Foo @ Bar\" subscription=\"from\">"
+ "<group>Group 1</group>"
+ "<group>Group 2</group>"
+ "</item>"
+ "<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\"/>"
+ "</query>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(RosterSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp
new file mode 100644
index 0000000..e8b89ad
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp
@@ -0,0 +1,43 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h"
+
+using namespace Swift;
+
+class SecurityLabelSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(SecurityLabelSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ SecurityLabelSerializerTest() {}
+
+ void testSerialize() {
+ SecurityLabelSerializer testling;
+ boost::shared_ptr<SecurityLabel> securityLabel(new SecurityLabel());
+ securityLabel->setDisplayMarking("SECRET");
+ securityLabel->setForegroundColor("black");
+ securityLabel->setBackgroundColor("red");
+ securityLabel->setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>");
+ securityLabel->addEquivalentLabel("<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>");
+ securityLabel->addEquivalentLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>");
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">"
+ "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>"
+ "<label>"
+ "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"
+ "</label>"
+ "<equivalentlabel>"
+ "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>"
+ "</equivalentlabel>"
+ "<equivalentlabel>"
+ "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"
+ "</equivalentlabel>"
+ "</securitylabel>"), testling.serialize(securityLabel));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp
new file mode 100644
index 0000000..acea1e4
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp
@@ -0,0 +1,52 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h"
+
+using namespace Swift;
+
+class SecurityLabelsCatalogSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(SecurityLabelsCatalogSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ SecurityLabelsCatalogSerializerTest() {}
+
+ void testSerialize() {
+ SecurityLabelsCatalogSerializer testling;
+ boost::shared_ptr<SecurityLabelsCatalog> catalog(new SecurityLabelsCatalog());
+ catalog->setTo(JID("example.com"));
+ catalog->setName("Default");
+ catalog->setDescription("an example set of labels");
+
+ SecurityLabel securityLabel1;
+ securityLabel1.setDisplayMarking("SECRET");
+ securityLabel1.setForegroundColor("black");
+ securityLabel1.setBackgroundColor("red");
+ securityLabel1.setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>");
+ catalog->addLabel(securityLabel1);
+
+ SecurityLabel securityLabel2;
+ securityLabel2.setDisplayMarking("CONFIDENTIAL");
+ securityLabel2.setForegroundColor("black");
+ securityLabel2.setBackgroundColor("navy");
+ securityLabel2.setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>");
+ catalog->addLabel(securityLabel2);
+
+ CPPUNIT_ASSERT_EQUAL(String(
+ "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:0\">"
+ "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">"
+ "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>"
+ "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>"
+ "</securitylabel>"
+ "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">"
+ "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>"
+ "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>"
+ "</securitylabel>"
+ "</catalog>"), testling.serialize(catalog));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelsCatalogSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp
new file mode 100644
index 0000000..fd5dba5
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp
@@ -0,0 +1,25 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/SoftwareVersionSerializer.h"
+
+using namespace Swift;
+
+class SoftwareVersionSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(SoftwareVersionSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ SoftwareVersionSerializerTest() {}
+
+ void testSerialize() {
+ SoftwareVersionSerializer testling;
+ boost::shared_ptr<SoftwareVersion> softwareVersion(new SoftwareVersion("Swift", "0.1", "Mac OS X"));
+
+ CPPUNIT_ASSERT_EQUAL(String("<query xmlns=\"jabber:iq:version\"><name>Swift</name><version>0.1</version><os>Mac OS X</os></query>"), testling.serialize(softwareVersion));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(SoftwareVersionSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp
new file mode 100644
index 0000000..6dedacd
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp
@@ -0,0 +1,25 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/StatusSerializer.h"
+
+using namespace Swift;
+
+class StatusSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(StatusSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ StatusSerializerTest() {}
+
+ void testSerialize() {
+ StatusSerializer testling;
+ boost::shared_ptr<Status> status(new Status("I am away"));
+
+ CPPUNIT_ASSERT_EQUAL(String("<status>I am away</status>"), testling.serialize(status));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(StatusSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp
new file mode 100644
index 0000000..42e1c7c
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp
@@ -0,0 +1,58 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/StatusShowSerializer.h"
+
+using namespace Swift;
+
+class StatusShowSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(StatusShowSerializerTest);
+ CPPUNIT_TEST(testSerialize_Online);
+ CPPUNIT_TEST(testSerialize_Away);
+ CPPUNIT_TEST(testSerialize_FFC);
+ CPPUNIT_TEST(testSerialize_XA);
+ CPPUNIT_TEST(testSerialize_DND);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ StatusShowSerializerTest() {}
+
+ void testSerialize_Online() {
+ StatusShowSerializer testling;
+ boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::Online));
+ CPPUNIT_ASSERT_EQUAL(String(""), testling.serialize(statusShow));
+ }
+
+ void testSerialize_Away() {
+ StatusShowSerializer testling;
+ boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::Away));
+ CPPUNIT_ASSERT_EQUAL(String("<show>away</show>"), testling.serialize(statusShow));
+ }
+
+ void testSerialize_FFC() {
+ StatusShowSerializer testling;
+ boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::FFC));
+ CPPUNIT_ASSERT_EQUAL(String("<show>chat</show>"), testling.serialize(statusShow));
+ }
+
+ void testSerialize_XA() {
+ StatusShowSerializer testling;
+ boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::XA));
+ CPPUNIT_ASSERT_EQUAL(String("<show>xa</show>"), testling.serialize(statusShow));
+ }
+
+ void testSerialize_DND() {
+ StatusShowSerializer testling;
+ boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::DND));
+ CPPUNIT_ASSERT_EQUAL(String("<show>dnd</show>"), testling.serialize(statusShow));
+ }
+
+ void testSerialize_None() {
+ StatusShowSerializer testling;
+ boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::None));
+ CPPUNIT_ASSERT_EQUAL(String(""), testling.serialize(statusShow));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(StatusShowSerializerTest);