summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-05-11 15:38:57 (GMT)
committerKevin Smith <kevin.smith@isode.com>2016-06-14 20:28:20 (GMT)
commit9b1c1ec6922047fa30c19c0744619dc458a12b78 (patch)
tree230a96de2a104324b8ab179834a7b9914c0443f9 /Swiften/Serializer/PayloadSerializers
parent0d5dcec01a396ab64c559a5b0cd04eb38f2f1954 (diff)
downloadswift-9b1c1ec6922047fa30c19c0744619dc458a12b78.zip
swift-9b1c1ec6922047fa30c19c0744619dc458a12b78.tar.bz2
Fix handling of notify attribute in PubSub retract elements
Test-Information: Added serializer and parser unit tests. All tests pass on Mac OS X 10.11.4. Change-Id: I8550c76ba182a67613d55634c72c0f2979f8b80a
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);