diff options
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
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)); +} |