summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-06-10 17:23:25 (GMT)
committerTobias Markmann <tm@ayena.de>2017-06-18 15:40:29 (GMT)
commitb8c1d6fb59bd4ae528d807fc30b02dab45aafabf (patch)
treee03a723b0f7b9b64c68d38fa0e38817adab3be8a /Swiften/Serializer
parentccefa0d4d90fd89a6d7e9cd6167066f3797020d7 (diff)
downloadswift-b8c1d6fb59bd4ae528d807fc30b02dab45aafabf.zip
swift-b8c1d6fb59bd4ae528d807fc30b02dab45aafabf.tar.bz2
Adds MIX Participant Element, its Parsers and Serializers.
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Adds tests for MIX Participant Parser and Serializer from XEP-0369, which passes. Tested on Ubuntu 16.04 LTS. Change-Id: Iee2d96c8ebdf9461c28518f8f8c28c11d2a94524
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.cpp37
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h20
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXParticipantSerializerTest.cpp59
4 files changed, 118 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index bb3632b..080e3df 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -45,6 +45,7 @@
#include <Swiften/Serializer/PayloadSerializers/MAMFinSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MAMQuerySerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MAMResultSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h>
@@ -154,6 +155,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new ResultSetSerializer());
serializers_.push_back(new ForwardedSerializer(this));
+ serializers_.push_back(new MIXParticipantSerializer());
serializers_.push_back(new MAMResultSerializer(this));
serializers_.push_back(new MAMQuerySerializer());
serializers_.push_back(new MAMFinSerializer());
diff --git a/Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.cpp
new file mode 100644
index 0000000..3f79dfa
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.cpp
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h>
+
+#include <memory>
+
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLRawTextNode.h>
+#include <Swiften/Serializer/XML/XMLTextNode.h>
+
+namespace Swift {
+
+MIXParticipantSerializer::MIXParticipantSerializer() : GenericPayloadSerializer<MIXParticipant>() {
+}
+
+std::string MIXParticipantSerializer::serializePayload(std::shared_ptr<MIXParticipant> payload) const {
+ XMLElement participantElement("participant", "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()));
+ participantElement.addNode(nickElement);
+ }
+
+ if (payload->getJID()) {
+ std::shared_ptr<XMLElement> jidElement = std::make_shared<XMLElement>("jid");
+ jidElement->addNode(std::make_shared<XMLTextNode>(*payload->getJID()));
+ participantElement.addNode(jidElement);
+ }
+ return participantElement.serialize();
+}
+
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h b/Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h
new file mode 100644
index 0000000..ff6ca3a
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h
@@ -0,0 +1,20 @@
+/*
+ * 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/Elements/MIXParticipant.h>
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+
+namespace Swift {
+ class SWIFTEN_API MIXParticipantSerializer : public GenericPayloadSerializer<MIXParticipant> {
+ public:
+ MIXParticipantSerializer();
+
+ virtual std::string serializePayload(std::shared_ptr<MIXParticipant> participant) const;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXParticipantSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXParticipantSerializerTest.cpp
new file mode 100644
index 0000000..a298d78
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXParticipantSerializerTest.cpp
@@ -0,0 +1,59 @@
+/*
+ * 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/MIXParticipantSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+using namespace Swift;
+
+TEST(MIXParticipantSerializerTest, testSerializeEmpty) {
+ MIXParticipantSerializer testling;
+
+ std::shared_ptr<MIXParticipant> participant(new MIXParticipant());
+
+ std::string expectedResult = "<participant xmlns=\"urn:xmpp:mix:0\"/>";
+ ASSERT_EQ(expectedResult, testling.serialize(participant));
+}
+
+TEST(MIXParticipantSerializerTest, testSerializeNick) {
+ MIXParticipantSerializer testling;
+
+ std::shared_ptr<MIXParticipant> participant(new MIXParticipant());
+ participant->setNick("thirdwitch");
+
+ std::string expectedResult = "<participant xmlns=\"urn:xmpp:mix:0\">"
+ "<nick>thirdwitch</nick>"
+ "</participant>";
+ ASSERT_EQ(expectedResult, testling.serialize(participant));
+}
+
+TEST(MIXParticipantSerializerTest, testSerializeJID) {
+ MIXParticipantSerializer testling;
+
+ std::shared_ptr<MIXParticipant> participant(new MIXParticipant());
+ participant->setJID(JID("hecate@mix.shakespeare.example"));
+
+ std::string expectedResult = "<participant xmlns=\"urn:xmpp:mix:0\">"
+ "<jid>hecate@mix.shakespeare.example</jid>"
+ "</participant>";
+ ASSERT_EQ(expectedResult, testling.serialize(participant));
+}
+
+TEST(MIXParticipantSerializerTest, testSerializeJIDAndNick) {
+ MIXParticipantSerializer testling;
+
+ std::shared_ptr<MIXParticipant> participant(new MIXParticipant());
+ participant->setNick("thirdwitch");
+ participant->setJID(JID("hecate@mix.shakespeare.example"));
+
+ std::string expectedResult = "<participant xmlns=\"urn:xmpp:mix:0\">"
+ "<nick>thirdwitch</nick>"
+ "<jid>hecate@mix.shakespeare.example</jid>"
+ "</participant>";
+ ASSERT_EQ(expectedResult, testling.serialize(participant));
+}