summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h22
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp30
3 files changed, 54 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 0f05580..a1f412b 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -41,6 +41,7 @@
#include "Swiften/Serializer/PayloadSerializers/InBandRegistrationPayloadSerializer.h"
#include "Swiften/Serializer/PayloadSerializers/NicknameSerializer.h"
#include "Swiften/Serializer/PayloadSerializers/SearchPayloadSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h"
namespace Swift {
@@ -79,6 +80,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new InBandRegistrationPayloadSerializer());
serializers_.push_back(new NicknameSerializer());
serializers_.push_back(new SearchPayloadSerializer());
+ serializers_.push_back(new ReplaceSerializer());
foreach(PayloadSerializer* serializer, serializers_) {
addSerializer(serializer);
}
diff --git a/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h b/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h
new file mode 100644
index 0000000..303b2b8
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2011 Vlad Voicu
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#pragma once
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Serializer/XML/XMLTextNode.h"
+#include "Swiften/Elements/Replace.h"
+
+namespace Swift {
+ class ReplaceSerializer : public GenericPayloadSerializer<Replace> {
+ public:
+ ReplaceSerializer() : GenericPayloadSerializer<Replace>() {}
+
+ virtual std::string serializePayload(boost::shared_ptr<Replace> replace) const {
+ return "<replace id = '" + replace->getId() + "' xmlns='http://swift.im/protocol/replace'/>";
+ }
+ };
+}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp
new file mode 100644
index 0000000..8fe96e5
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2011 Vlad Voicu
+ * Licensed under the Simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Serializer/PayloadSerializers/ReplaceSerializer.h"
+
+using namespace Swift;
+
+class ReplaceSerializerTest: public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(ReplaceSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ ReplaceSerializerTest() {}
+
+ void testSerialize() {
+ ReplaceSerializer testling;
+ boost::shared_ptr<Replace> replace(new Replace());
+ replace->setId("bad1");
+ CPPUNIT_ASSERT_EQUAL(std::string("<replace id = 'bad1' xmlns='http://swift.im/protocol/replace'/>"), testling.serialize(replace));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(ReplaceSerializerTest);