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/Parser/PayloadParsers
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/Parser/PayloadParsers')
-rw-r--r--Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp11
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/PubSubRetractParserTest.cpp73
2 files changed, 79 insertions, 5 deletions
diff --git a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp
index b011b76..d5d5c0a 100644
--- a/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp
+++ b/Swiften/Parser/PayloadParsers/PubSubRetractParser.cpp
@@ -4,15 +4,12 @@
* See the COPYING file for more information.
*/
-#pragma clang diagnostic ignored "-Wunused-private-field"
-
#include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h>
#include <boost/optional.hpp>
-
-#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParserFactory.h>
+#include <Swiften/Parser/PayloadParserFactoryCollection.h>
#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h>
using namespace Swift;
@@ -29,7 +26,11 @@ void PubSubRetractParser::handleStartElement(const std::string& element, const s
getPayloadInternal()->setNode(*attributeValue);
}
if (boost::optional<std::string> attributeValue = attributes.getAttributeValue("notify")) {
- getPayloadInternal()->setNotify(*attributeValue == "true" ? true : false);
+ boost::optional<bool> notify;
+ if (attributeValue.is_initialized()) {
+ notify = (attributeValue.get() == "true" || attributeValue.get() == "1") ? true : false;
+ }
+ getPayloadInternal()->setNotify(notify);
}
}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/PubSubRetractParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/PubSubRetractParserTest.cpp
new file mode 100644
index 0000000..91bc123
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/PubSubRetractParserTest.cpp
@@ -0,0 +1,73 @@
+/*
+ * 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/Elements/ContainerPayload.h>
+#include <Swiften/Parser/PayloadParsers/PubSubRetractParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+class PubSubRetractParserTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(PubSubRetractParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST(testParseNotify);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testParse() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse("<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
+ "<retract node='princely_musings' xmlns='http://jabber.org/protocol/pubsub'>"
+ "<item id='ae890ac52d0df67ed7cfdf51b644e901' xmlns='http://jabber.org/protocol/pubsub'/>"
+ "</retract>"
+ "</pubsub>"));
+
+ auto payload = parser.getPayload<ContainerPayload<PubSubPayload>>();
+ std::shared_ptr<PubSubRetract> retract = std::dynamic_pointer_cast<PubSubRetract>(payload->getPayload());
+ CPPUNIT_ASSERT(retract);
+ CPPUNIT_ASSERT_EQUAL(std::string("princely_musings"), retract->getNode());
+ CPPUNIT_ASSERT_EQUAL(false, retract->isNotify().is_initialized());
+ }
+
+ void testParseNotify() {
+ {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse("<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
+ "<retract node='princely_musings' notify='true' xmlns='http://jabber.org/protocol/pubsub'>"
+ "<item id='ae890ac52d0df67ed7cfdf51b644e901' xmlns='http://jabber.org/protocol/pubsub'/>"
+ "</retract>"
+ "</pubsub>"));
+
+ auto payload = parser.getPayload<ContainerPayload<PubSubPayload>>();
+ std::shared_ptr<PubSubRetract> retract = std::dynamic_pointer_cast<PubSubRetract>(payload->getPayload());
+ CPPUNIT_ASSERT(retract);
+ CPPUNIT_ASSERT_EQUAL(std::string("princely_musings"), retract->getNode());
+ CPPUNIT_ASSERT_EQUAL(true, retract->isNotify().get());
+ }
+
+ {
+ PayloadsParserTester parser;
+ CPPUNIT_ASSERT(parser.parse("<pubsub xmlns='http://jabber.org/protocol/pubsub'>"
+ "<retract node='princely_musings' notify='0' xmlns='http://jabber.org/protocol/pubsub'>"
+ "<item id='ae890ac52d0df67ed7cfdf51b644e901' xmlns='http://jabber.org/protocol/pubsub'/>"
+ "</retract>"
+ "</pubsub>"));
+
+ auto payload = parser.getPayload<ContainerPayload<PubSubPayload>>();
+ auto retract = std::dynamic_pointer_cast<PubSubRetract>(payload->getPayload());
+ CPPUNIT_ASSERT(retract);
+ CPPUNIT_ASSERT_EQUAL(std::string("princely_musings"), retract->getNode());
+ CPPUNIT_ASSERT_EQUAL(false, retract->isNotify().get());
+ }
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PubSubRetractParserTest);