diff options
Diffstat (limited to 'Swiften/Serializer')
4 files changed, 87 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index 9832bd5..c0ee620 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -50,6 +50,7 @@ #include <Swiften/Serializer/PayloadSerializers/MIXParticipantSerializer.h> #include <Swiften/Serializer/PayloadSerializers/MIXCreateSerializer.h> #include <Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h> #include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h> #include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h> #include <Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h> @@ -162,6 +163,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new MIXParticipantSerializer()); serializers_.push_back(new MIXCreateSerializer()); serializers_.push_back(new MIXUserPreferenceSerializer()); + serializers_.push_back(new MIXLeaveSerializer()); serializers_.push_back(new MIXJoinSerializer()); serializers_.push_back(new MIXDestroySerializer()); serializers_.push_back(new MAMResultSerializer(this)); diff --git a/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.cpp new file mode 100644 index 0000000..9025e3f --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.cpp @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h> + +#include <memory> + +#include <Swiften/Serializer/XML/XMLElement.h> + +namespace Swift { + +MIXLeaveSerializer::MIXLeaveSerializer() { +} + +MIXLeaveSerializer::~MIXLeaveSerializer() { +} + +std::string MIXLeaveSerializer::serializePayload(std::shared_ptr<MIXLeave> payload) const { + if (!payload) { + return ""; + } + XMLElement element("leave", "urn:xmpp:mix:1"); + if (payload->getChannel()) { + element.setAttribute("channel", *payload->getChannel()); + } + return element.serialize(); +} +} diff --git a/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h b/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h new file mode 100644 index 0000000..d44f471 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/MIXLeaveSerializer.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Tarun Gupta + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <memory> + +#include <Swiften/Base/API.h> +#include <Swiften/Base/Override.h> +#include <Swiften/Elements/MIXLeave.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> + +namespace Swift { + class SWIFTEN_API MIXLeaveSerializer : public GenericPayloadSerializer<MIXLeave> { + public: + MIXLeaveSerializer(); + virtual ~MIXLeaveSerializer(); + + virtual std::string serializePayload(std::shared_ptr<MIXLeave>) const SWIFTEN_OVERRIDE; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXLeaveSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXLeaveSerializerTest.cpp new file mode 100644 index 0000000..03e3e76 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXLeaveSerializerTest.cpp @@ -0,0 +1,30 @@ +/* + * 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/MIXLeaveSerializer.h> + +using namespace Swift; + +TEST(MIXLeaveSerializerTest, XEP0369_Example33) { + MIXLeaveSerializer testling; + + auto leave = std::shared_ptr<MIXLeave>(new MIXLeave()); + leave->setChannel(JID("coven@mix.shakespeare.example")); + + std::string expectedResult = "<leave channel=\"coven@mix.shakespeare.example\" xmlns=\"urn:xmpp:mix:1\"/>"; + ASSERT_EQ(expectedResult, testling.serialize(leave)); +} + +TEST(MIXLeaveSerializerTest, XEP0369_Example34) { + MIXLeaveSerializer testling; + + auto leave = std::shared_ptr<MIXLeave>(new MIXLeave()); + + std::string expectedResult = "<leave xmlns=\"urn:xmpp:mix:1\"/>"; + ASSERT_EQ(expectedResult, testling.serialize(leave)); +} |