summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2014-05-19 13:08:55 (GMT)
committerSwift Review <review@swift.im>2014-05-26 17:40:21 (GMT)
commitb249168a5c7dfd4846729dcb79445afc2cf37391 (patch)
tree130bbb00157888a0847b007ea830e08146e6bb5b /Swiften
parent168538129a69fa37a19e768149b32ca262bb85a3 (diff)
downloadswift-contrib-b249168a5c7dfd4846729dcb79445afc2cf37391.zip
swift-contrib-b249168a5c7dfd4846729dcb79445afc2cf37391.tar.bz2
Fix serialization of PubSubItem id attribute
Extended the serialization unit tests with PubSubItem and PubSubItems test, also added a warning when serializing PubSubItems without a node name. Change-Id: Ie4c4021b1cca593187c4aa333aa43dd34239b1ca
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/SConscript2
-rw-r--r--Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp4
-rw-r--r--Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.cpp4
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp59
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp77
5 files changed, 145 insertions, 1 deletions
diff --git a/Swiften/SConscript b/Swiften/SConscript
index 7656c83..7dbb19d 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -480,6 +480,8 @@ if env["SCONS_STAGE"] == "build" :
File("Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/MAMArchivedSerializerTest.cpp"),
+ File("Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp"),
+ File("Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp"),
File("Serializer/UnitTest/StreamFeaturesSerializerTest.cpp"),
File("Serializer/UnitTest/AuthSuccessSerializerTest.cpp"),
File("Serializer/UnitTest/AuthChallengeSerializerTest.cpp"),
diff --git a/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp
index 707f183..fbd4d53 100644
--- a/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp
@@ -30,7 +30,9 @@ std::string PubSubItemSerializer::serializePayload(boost::shared_ptr<PubSubItem>
foreach(boost::shared_ptr<Payload> item, payload->getData()) {
element.addNode(boost::make_shared<XMLRawTextNode>(serializers->getPayloadSerializer(item)->serialize(item)));
}
- element.setAttribute("id", payload->getID());
+ if (!payload->getID().empty()) {
+ element.setAttribute("id", payload->getID());
+ }
return element.serialize();
}
diff --git a/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.cpp
index e2f7d6e..7c6d1f1 100644
--- a/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.cpp
+++ b/Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.cpp
@@ -13,6 +13,7 @@
#include <Swiften/Serializer/PayloadSerializerCollection.h>
#include <Swiften/Base/foreach.h>
+#include <Swiften/Base/Log.h>
#include <Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h>
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
@@ -29,6 +30,9 @@ std::string PubSubItemsSerializer::serializePayload(boost::shared_ptr<PubSubItem
return "";
}
XMLElement element("items", "http://jabber.org/protocol/pubsub");
+ if (payload->getNode().empty()) {
+ SWIFT_LOG(warning) << "Serializing PubSubItems with empty node attribute";
+ }
element.setAttribute("node", payload->getNode());
foreach(boost::shared_ptr<PubSubItem> item, payload->getItems()) {
element.addNode(boost::make_shared<XMLRawTextNode>(PubSubItemSerializer(serializers).serialize(item)));
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp
new file mode 100644
index 0000000..4ece9db
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Elements/PubSubItem.h>
+#include <Swiften/Elements/RawXMLPayload.h>
+#include <Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+using namespace Swift;
+
+class PubSubItemSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(PubSubItemSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST(testSerializeEmptyID);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize() {
+ PubSubItemSerializer serializer(&serializers);
+
+ boost::shared_ptr<RawXMLPayload> payload(boost::make_shared<RawXMLPayload>());
+ payload->setRawXML("<payload xmlns=\"tmp\"/>");
+
+ boost::shared_ptr<PubSubItem> item(boost::make_shared<PubSubItem>());
+ item->addData(payload);
+ item->setID("pubsub-item-1");
+
+ std::string expectedResult =
+ "<item id=\"pubsub-item-1\" xmlns=\"http://jabber.org/protocol/pubsub\">"
+ "<payload xmlns=\"tmp\"/>"
+ "</item>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(item));
+ }
+
+ void testSerializeEmptyID() {
+ PubSubItemSerializer serializer(&serializers);
+
+ boost::shared_ptr<PubSubItem> item(boost::make_shared<PubSubItem>());
+
+ std::string expectedResult =
+ "<item xmlns=\"http://jabber.org/protocol/pubsub\"/>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(item));
+ }
+
+ private:
+ FullPayloadSerializerCollection serializers;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PubSubItemSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp
new file mode 100644
index 0000000..dff2bce
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (c) 2014 Kevin Smith and Remko Tronçon
+ * Licensed under the GNU General Public License v3.
+ * See Documentation/Licenses/GPLv3.txt for more information.
+ */
+
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Elements/PubSubItems.h>
+#include <Swiften/Elements/RawXMLPayload.h>
+#include <Swiften/Serializer/PayloadSerializers/PubSubItemsSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+
+using namespace Swift;
+
+class PubSubItemsSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(PubSubItemsSerializerTest);
+ CPPUNIT_TEST(testSerialize);
+ CPPUNIT_TEST(testSerializeEmptyItems);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize() {
+ PubSubItemsSerializer serializer(&serializers);
+
+ boost::shared_ptr<RawXMLPayload> payload1(boost::make_shared<RawXMLPayload>());
+ payload1->setRawXML("<payload xmlns=\"tmp\"/>");
+
+ boost::shared_ptr<PubSubItem> item1(boost::make_shared<PubSubItem>());
+ item1->addData(payload1);
+ item1->setID("pubsub-item-1");
+
+ boost::shared_ptr<RawXMLPayload> payload2(boost::make_shared<RawXMLPayload>());
+ payload2->setRawXML("<payload xmlns=\"other-tmp\"/>");
+
+ boost::shared_ptr<PubSubItem> item2(boost::make_shared<PubSubItem>());
+ item2->addData(payload2);
+ item2->setID("pubsub-item-2");
+
+ boost::shared_ptr<PubSubItems> items(boost::make_shared<PubSubItems>());
+ items->setNode("test-node");
+ items->setSubscriptionID(std::string("sub-id"));
+ items->addItem(item1);
+ items->addItem(item2);
+
+ std::string expectedResult =
+ "<items node=\"test-node\" subid=\"sub-id\" xmlns=\"http://jabber.org/protocol/pubsub\">"
+ "<item id=\"pubsub-item-1\" xmlns=\"http://jabber.org/protocol/pubsub\">"
+ "<payload xmlns=\"tmp\"/>"
+ "</item>"
+ "<item id=\"pubsub-item-2\" xmlns=\"http://jabber.org/protocol/pubsub\">"
+ "<payload xmlns=\"other-tmp\"/>"
+ "</item>"
+ "</items>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(items));
+ }
+
+ void testSerializeEmptyItems() {
+ PubSubItemsSerializer serializer(&serializers);
+
+ boost::shared_ptr<PubSubItems> items(boost::make_shared<PubSubItems>());
+
+ std::string expectedResult =
+ "<items node=\"\" xmlns=\"http://jabber.org/protocol/pubsub\"/>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(items));
+ }
+
+ private:
+ FullPayloadSerializerCollection serializers;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PubSubItemsSerializerTest);