summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-06-19 09:42:31 (GMT)
committerTobias Markmann <tm@ayena.de>2017-07-05 20:38:46 (GMT)
commit1f69a24bc609ce40bab2bcb40b29438b63c9bc73 (patch)
tree585e7579abc5a906705f10d4b283883fd6b18da6 /Swiften/Serializer
parent93a0f41d4af17db3e3eedb61e786fec23dbd8db9 (diff)
downloadswift-1f69a24bc609ce40bab2bcb40b29438b63c9bc73.zip
swift-1f69a24bc609ce40bab2bcb40b29438b63c9bc73.tar.bz2
Adds MIXUserPreference Element, its Parser and Serializer
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Added tests for MIXUserPreference Parser and Serializer based on examples in XEP 0369, which passes. Change-Id: I06595325f4cc2b34d5ab5a93a6caa00330fe0737
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp33
-rw-r--r--Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h25
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp68
4 files changed, 128 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 4c3cf66..9832bd5 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/MIXUserPreferenceSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCAdminPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCDestroyPayloadSerializer.h>
#include <Swiften/Serializer/PayloadSerializers/MUCInvitationPayloadSerializer.h>
@@ -160,6 +161,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new ForwardedSerializer(this));
serializers_.push_back(new MIXParticipantSerializer());
serializers_.push_back(new MIXCreateSerializer());
+ serializers_.push_back(new MIXUserPreferenceSerializer());
serializers_.push_back(new MIXJoinSerializer());
serializers_.push_back(new MIXDestroySerializer());
serializers_.push_back(new MAMResultSerializer(this));
diff --git a/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp b/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp
new file mode 100644
index 0000000..2d057ad
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h>
+
+#include <memory>
+
+#include <Swiften/Serializer/PayloadSerializers/FormSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
+#include <Swiften/Serializer/XML/XMLRawTextNode.h>
+
+namespace Swift {
+
+MIXUserPreferenceSerializer::MIXUserPreferenceSerializer() {
+}
+
+MIXUserPreferenceSerializer::~MIXUserPreferenceSerializer() {
+}
+
+std::string MIXUserPreferenceSerializer::serializePayload(std::shared_ptr<MIXUserPreference> payload) const {
+ if (!payload) {
+ return "";
+ }
+ XMLElement element("user-preference", "urn:xmpp:mix:1");
+ if(payload->getData()) {
+ element.addNode(std::make_shared<XMLRawTextNode>(FormSerializer().serialize(payload->getData())));
+ }
+ return element.serialize();
+}
+}
diff --git a/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h b/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h
new file mode 100644
index 0000000..301083a
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/MIXUserPreferenceSerializer.h
@@ -0,0 +1,25 @@
+/*
+ * 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/MIXUserPreference.h>
+#include <Swiften/Serializer/GenericPayloadSerializer.h>
+
+namespace Swift {
+
+ class SWIFTEN_API MIXUserPreferenceSerializer : public GenericPayloadSerializer<MIXUserPreference> {
+ public:
+ MIXUserPreferenceSerializer();
+ virtual ~MIXUserPreferenceSerializer();
+
+ virtual std::string serializePayload(std::shared_ptr<MIXUserPreference>) const SWIFTEN_OVERRIDE;
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp
new file mode 100644
index 0000000..7cbfbfc
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUserPreferenceSerializerTest.cpp
@@ -0,0 +1,68 @@
+/*
+ * 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/MIXUserPreferenceSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+using namespace Swift;
+
+TEST(MIXUserPreferenceSerializerTest, XEP0369_Example31) {
+ MIXUserPreferenceSerializer testling;
+
+ auto userpreference = std::shared_ptr<MIXUserPreference>(new MIXUserPreference());
+ std::string expectedResult = "<user-preference xmlns=\"urn:xmpp:mix:1\"/>";
+ ASSERT_EQ(expectedResult, testling.serialize(userpreference));
+}
+
+TEST(MIXUserPreferenceSerializerTest, XEP0369_Example32) {
+ MIXUserPreferenceSerializer testling;
+
+ auto userpreference = std::shared_ptr<MIXUserPreference>(new MIXUserPreference());
+ std::shared_ptr<Form> parameters(std::make_shared<Form>());
+ parameters->setType(Form::Type::ResultType);
+
+ std::shared_ptr<FormField> fieldType = std::make_shared<FormField>(FormField::HiddenType);
+ fieldType->setName("FORM_TYPE");
+ fieldType->addValue("urn:xmpp:mix:1");
+ parameters->addField(fieldType);
+
+ std::shared_ptr<FormField> fieldJIDVisibility = std::make_shared<FormField>();
+ fieldJIDVisibility->setName("JID Visibility");
+ fieldJIDVisibility->addValue("never");
+ parameters->addField(fieldJIDVisibility);
+
+ std::shared_ptr<FormField> fieldprivateMessages = std::make_shared<FormField>();
+ fieldprivateMessages->setName("Private Messages");
+ fieldprivateMessages->addValue("allow");
+ parameters->addField(fieldprivateMessages);
+
+ std::shared_ptr<FormField> vCard = std::make_shared<FormField>();
+ vCard->setName("vCard");
+ vCard->addValue("block");
+ parameters->addField(vCard);
+
+ userpreference->setData(parameters);
+
+ std::string expectedResult = "<user-preference xmlns=\"urn:xmpp:mix:1\">"
+ "<x type=\"result\" xmlns=\"jabber:x:data\">"
+ "<field type=\"hidden\" var=\"FORM_TYPE\">"
+ "<value>urn:xmpp:mix:1</value>"
+ "</field>"
+ "<field var=\"JID Visibility\">"
+ "<value>never</value>"
+ "</field>"
+ "<field var=\"Private Messages\">"
+ "<value>allow</value>"
+ "</field>"
+ "<field var=\"vCard\">"
+ "<value>block</value>"
+ "</field>"
+ "</x>"
+ "</user-preference>";
+ ASSERT_EQ(expectedResult, testling.serialize(userpreference));
+}