summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.cpp44
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.h21
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXPayloadSerializerTest.cpp61
4 files changed, 128 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index c0ee620..1a04435 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -49,6 +49,7 @@
#include <Swiften/Serializer/PayloadSerializers/MIXDestroySerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h>
@@ -162,6 +163,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new ForwardedSerializer(this));
serializers_.push_back(new MIXParticipantSerializer());
serializers_.push_back(new MIXCreateSerializer());
+ serializers_.push_back(new MIXPayloadSerializer());
serializers_.push_back(new MIXUserPreferenceSerializer());
serializers_.push_back(new MIXLeaveSerializer());
serializers_.push_back(new MIXJoinSerializer());
diff --git a/Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.cpp
new file mode 100644
index 0000000..843270a
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.cpp
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.h>
+
+#include <memory>
+
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLRawTextNode.h>
+#include <Swiften/Serializer/XML/XMLTextNode.h>
+
+namespace Swift {
+
+MIXPayloadSerializer::MIXPayloadSerializer() : GenericPayloadSerializer<MIXPayload>() {
+}
+
+std::string MIXPayloadSerializer::serializePayload(std::shared_ptr<MIXPayload> payload) const {
+ XMLElement mixElement("mix", "urn:xmpp:mix:0");
+
+ if (payload->getNick()) {
+ std::shared_ptr<XMLElement> nickElement = std::make_shared<XMLElement>("nick");
+ nickElement->addNode(std::make_shared<XMLTextNode>(*payload->getNick()));
+ mixElement.addNode(nickElement);
+ }
+
+ if (payload->getJID()) {
+ std::shared_ptr<XMLElement> jidElement = std::make_shared<XMLElement>("jid");
+ jidElement->addNode(std::make_shared<XMLTextNode>(*payload->getJID()));
+ mixElement.addNode(jidElement);
+ }
+
+ if (payload->getSubmissionID()) {
+ std::shared_ptr<XMLElement> subIDElement = std::make_shared<XMLElement>("submission-id");
+ subIDElement->addNode(std::make_shared<XMLTextNode>(*payload->getSubmissionID()));
+ mixElement.addNode(subIDElement);
+ }
+
+ return mixElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.h
new file mode 100644
index 0000000..3481ca8
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include <Swiften/Base/API.h>
+#include <Swiften/Base/Override.h>
+#include <Swiften/Elements/MIXPayload.h>
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXPayloadSerializer : public GenericPayloadSerializer<MIXPayload> {
+ public:
+ MIXPayloadSerializer();
+
+ virtual std::string serializePayload(std::shared_ptr<MIXPayload> payload) const SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXPayloadSerializerTest.cpp
new file mode 100644
index 0000000..266b066
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXPayloadSerializerTest.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <gtest/gtest.h>
+
+#include <Swiften/Serializer/PayloadSerializers/MIXPayloadSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+using namespace Swift;
+
+TEST(MIXPayloadSerializerTest, testSerializeEmpty) {
+ MIXPayloadSerializer testling;
+
+ auto mix = std::shared_ptr<MIXPayload>(new MIXPayload());
+
+ std::string expectedResult = "<mix xmlns=\"urn:xmpp:mix:0\"/>";
+ ASSERT_EQ(expectedResult, testling.serialize(mix));
+}
+
+TEST(MIXPayloadSerializerTest, testSerializeNick) {
+ MIXPayloadSerializer testling;
+
+ auto mix = std::shared_ptr<MIXPayload>(new MIXPayload());
+ mix->setNick("thirdwitch");
+
+ std::string expectedResult = "<mix xmlns=\"urn:xmpp:mix:0\">"
+ "<nick>thirdwitch</nick>"
+ "</mix>";
+ ASSERT_EQ(expectedResult, testling.serialize(mix));
+}
+
+TEST(MIXPayloadSerializerTest, testSerializeJID) {
+ MIXPayloadSerializer testling;
+
+ auto mix = std::shared_ptr<MIXPayload>(new MIXPayload());
+ mix->setJID(JID("hecate@mix.shakespeare.example"));
+
+ std::string expectedResult = "<mix xmlns=\"urn:xmpp:mix:0\">"
+ "<jid>hecate@mix.shakespeare.example</jid>"
+ "</mix>";
+ ASSERT_EQ(expectedResult, testling.serialize(mix));
+}
+
+TEST(MIXPayloadSerializerTest, testSerializeAll) {
+ MIXPayloadSerializer testling;
+
+ auto mix = std::shared_ptr<MIXPayload>(new MIXPayload());
+ mix->setNick("thirdwitch");
+ mix->setJID(JID("hecate@mix.shakespeare.example"));
+ mix->setSubmissionID("92vax143g");
+
+ std::string expectedResult = "<mix xmlns=\"urn:xmpp:mix:0\">"
+ "<nick>thirdwitch</nick>"
+ "<jid>hecate@mix.shakespeare.example</jid>"
+ "<submission-id>92vax143g</submission-id>"
+ "</mix>";
+ ASSERT_EQ(expectedResult, testling.serialize(mix));
+}