summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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);