diff options
Diffstat (limited to 'Swiften/Serializer')
4 files changed, 71 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/ClientStateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/ClientStateSerializer.cpp new file mode 100644 index 0000000..1485dcb --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ClientStateSerializer.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2017 Tarun Gupta. + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/Serializer/PayloadSerializers/ClientStateSerializer.h> + +namespace Swift { + +ClientStateSerializer::ClientStateSerializer() : GenericPayloadSerializer<ClientState>() { +} + +std::string ClientStateSerializer::serializePayload(std::shared_ptr<ClientState> clientState) const { + std::string result("<"); + switch (clientState->getClientState()) { + case ClientState::ClientStateType::Active: result += "active"; break; + case ClientState::ClientStateType::Inactive: result += "inactive"; break; + } + result += " xmlns=\"urn:xmpp:csi:0\"/>"; + return result; +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/ClientStateSerializer.h b/Swiften/Serializer/PayloadSerializers/ClientStateSerializer.h new file mode 100644 index 0000000..1c4f977 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/ClientStateSerializer.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/ClientState.h> +#include <Swiften/Serializer/GenericPayloadSerializer.h> + +namespace Swift { + class SWIFTEN_API ClientStateSerializer : public GenericPayloadSerializer<ClientState> { + public: + ClientStateSerializer(); + + virtual std::string serializePayload(std::shared_ptr<ClientState> error) const; + }; +} diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index cf0b54c..bb3632b 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -20,6 +20,7 @@ #include <Swiften/Serializer/PayloadSerializers/CarbonsReceivedSerializer.h> #include <Swiften/Serializer/PayloadSerializers/CarbonsSentSerializer.h> #include <Swiften/Serializer/PayloadSerializers/ChatStateSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/ClientStateSerializer.h> #include <Swiften/Serializer/PayloadSerializers/CommandSerializer.h> #include <Swiften/Serializer/PayloadSerializers/DelaySerializer.h> #include <Swiften/Serializer/PayloadSerializers/DeliveryReceiptRequestSerializer.h> @@ -90,6 +91,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new SubjectSerializer()); serializers_.push_back(new ThreadSerializer()); serializers_.push_back(new ChatStateSerializer()); + serializers_.push_back(new ClientStateSerializer()); serializers_.push_back(new PrioritySerializer()); serializers_.push_back(new ErrorSerializer(this)); serializers_.push_back(new RosterSerializer()); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ClientStateSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ClientStateSerializerTest.cpp new file mode 100644 index 0000000..1622354 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ClientStateSerializerTest.cpp @@ -0,0 +1,25 @@ +/* + * 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/ClientStateSerializer.h> + +using namespace Swift; + +TEST(ClientStateSerializerTest, testSerialize_ActiveState) { + ClientStateSerializer testling; + std::shared_ptr<ClientState> priority(new ClientState(ClientState::ClientStateType::Active)); + + ASSERT_EQ(std::string("<active xmlns=\"urn:xmpp:csi:0\"/>"), testling.serialize(priority)); +} + +TEST(ClientStateSerializerTest, testSerialize_InacativeState) { + ClientStateSerializer testling; + std::shared_ptr<ClientState> priority(new ClientState(ClientState::ClientStateType::Inactive)); + + ASSERT_EQ(std::string("<inactive xmlns=\"urn:xmpp:csi:0\"/>"), testling.serialize(priority)); +} |