summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r--Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.cpp11
-rw-r--r--Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h3
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/PubSubRetractSerializerTest.cpp57
3 files changed, 63 insertions, 8 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.cpp
index 752c234..99b425e 100644
--- a/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.cpp
@@ -4,15 +4,14 @@
* See the COPYING file for more information.
*/
-#pragma clang diagnostic ignored "-Wunused-private-field"
-
#include <Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h>
-#include <Swiften/Serializer/XML/XMLElement.h>
+
#include <memory>
-#include <Swiften/Serializer/PayloadSerializerCollection.h>
#include <Swiften/Base/foreach.h>
+#include <Swiften/Serializer/PayloadSerializerCollection.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h>
+#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
using namespace Swift;
@@ -32,7 +31,9 @@ std::string PubSubRetractSerializer::serializePayload(std::shared_ptr<PubSubRetr
foreach(std::shared_ptr<PubSubItem> item, payload->getItems()) {
element.addNode(std::make_shared<XMLRawTextNode>(PubSubItemSerializer(serializers).serialize(item)));
}
- element.setAttribute("notify", payload->isNotify() ? "true" : "false");
+ if (payload->isNotify().is_initialized()) {
+ element.setAttribute("notify", payload->isNotify().get() ? "true" : "false");
+ }
return element.serialize();
}
diff --git a/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h b/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h
index 0cb12e4..64737df 100644
--- a/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h
+++ b/Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h
@@ -24,9 +24,6 @@ namespace Swift {
virtual std::string serializePayload(std::shared_ptr<PubSubRetract>) const SWIFTEN_OVERRIDE;
private:
-
-
- private:
PayloadSerializerCollection* serializers;
};
}
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubRetractSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubRetractSerializerTest.cpp
new file mode 100644
index 0000000..f00eddc
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubRetractSerializerTest.cpp
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2016 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+#include <Swiften/Serializer/PayloadSerializers/PubSubRetractSerializer.h>
+
+using namespace Swift;
+
+class PubSubRetractSerializerTest: public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(PubSubRetractSerializerTest);
+ CPPUNIT_TEST(testSerializeDefault);
+ CPPUNIT_TEST(testSerializeNotify);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ PubSubRetractSerializerTest() {}
+
+ std::shared_ptr<PubSubItem> somePubSubItem() {
+ auto item = std::make_shared<PubSubItem>();
+ item->setID("ae890ac52d0df67ed7cfdf51b644e901");
+ return item;
+ }
+
+ void testSerializeDefault() {
+ PubSubRetractSerializer testling(&serializer);
+ auto retract = std::make_shared<PubSubRetract>();
+ retract->setNode("princely_musings");
+ retract->setItems({somePubSubItem()});
+ CPPUNIT_ASSERT_EQUAL(std::string("<retract node=\"princely_musings\" xmlns=\"http://jabber.org/protocol/pubsub\"><item id=\"ae890ac52d0df67ed7cfdf51b644e901\" xmlns=\"http://jabber.org/protocol/pubsub\"/></retract>"), testling.serialize(retract));
+ }
+
+ void testSerializeNotify() {
+ PubSubRetractSerializer testling(&serializer);
+ auto retract = std::make_shared<PubSubRetract>();
+ retract->setNode("princely_musings");
+ retract->setItems({somePubSubItem()});
+ retract->setNotify(true);
+ CPPUNIT_ASSERT_EQUAL(std::string("<retract node=\"princely_musings\" notify=\"true\" xmlns=\"http://jabber.org/protocol/pubsub\"><item id=\"ae890ac52d0df67ed7cfdf51b644e901\" xmlns=\"http://jabber.org/protocol/pubsub\"/></retract>"), testling.serialize(retract));
+
+ retract = std::make_shared<PubSubRetract>();
+ retract->setNode("princely_musings");
+ retract->setItems({somePubSubItem()});
+ retract->setNotify(false);
+ CPPUNIT_ASSERT_EQUAL(std::string("<retract node=\"princely_musings\" notify=\"false\" xmlns=\"http://jabber.org/protocol/pubsub\"><item id=\"ae890ac52d0df67ed7cfdf51b644e901\" xmlns=\"http://jabber.org/protocol/pubsub\"/></retract>"), testling.serialize(retract));
+ }
+
+ private:
+ FullPayloadSerializerCollection serializer;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PubSubRetractSerializerTest);