diff options
author | Jan Kaluza <hanzz.k@gmail.com> | 2012-06-20 08:37:43 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2012-06-20 19:05:04 (GMT) |
commit | c64bfb54c72f5fab80cd6f3e3202f8c09064ecf3 (patch) | |
tree | 708cc5a09272a30e76952bb52532764774a63f11 /Swiften | |
parent | 7436b2bc3c52141cf18602b2f392b79ed7bded75 (diff) | |
download | swift-contrib-c64bfb54c72f5fab80cd6f3e3202f8c09064ecf3.zip swift-contrib-c64bfb54c72f5fab80cd6f3e3202f8c09064ecf3.tar.bz2 |
Parse node attribute in DiscoItemsParser and add DiscoItemsParser test
Copyright (c) 2012 Jan Kaluza
Licensed under the Simplified BSD license.
See Documentation/Licenses/BSD-simplified.txt for more information.
Diffstat (limited to 'Swiften')
-rw-r--r-- | Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp | 5 | ||||
-rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp | 43 | ||||
-rw-r--r-- | Swiften/SConscript | 1 |
3 files changed, 49 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp index d6ac94d..a56dc5a 100644 --- a/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoItemsParser.cpp @@ -17,6 +17,11 @@ void DiscoItemsParser::handleStartElement(const std::string& element, const std: getPayloadInternal()->addItem(DiscoItems::Item(attributes.getAttribute("name"), JID(attributes.getAttribute("jid")), attributes.getAttribute("node"))); } } + else if (level_ == TopLevel) { + if (element == "query") { + getPayloadInternal()->setNode(attributes.getAttribute("node")); + } + } ++level_; } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp new file mode 100644 index 0000000..ee234ad --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2012 Jan Kaluza + * Licensed under the Simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Parser/PayloadParsers/DiscoItemsParser.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +class DiscoItemsParserTest : public CppUnit::TestFixture { + CPPUNIT_TEST_SUITE(DiscoItemsParserTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); + + public: + void testParse() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "<query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/commands'>" + "<item jid='responder@domain' node='list' name='List Service Configurations'/>" + "<item jid='responder@domain' node='config' name='Configure Service'/>" + "</query>")); + + boost::shared_ptr<DiscoItems> payload = boost::dynamic_pointer_cast<DiscoItems>(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(payload->getItems().size())); + CPPUNIT_ASSERT_EQUAL(std::string("List Service Configurations"), payload->getItems()[0].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("list"), payload->getItems()[0].getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[0].getJID().toString()); + CPPUNIT_ASSERT_EQUAL(std::string("Configure Service"), payload->getItems()[1].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("config"), payload->getItems()[1].getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("responder@domain"), payload->getItems()[1].getJID().toString()); + CPPUNIT_ASSERT_EQUAL(std::string("http://jabber.org/protocol/commands"), payload->getNode()); + } + +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(DiscoItemsParserTest); diff --git a/Swiften/SConscript b/Swiften/SConscript index 340e8a5..de67983 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript @@ -300,6 +300,7 @@ if env["SCONS_STAGE"] == "build" : File("Network/UnitTest/BOSHConnectionPoolTest.cpp"), File("Parser/PayloadParsers/UnitTest/BodyParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp"), + File("Parser/PayloadParsers/UnitTest/DiscoItemsParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/ErrorParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/FormParserTest.cpp"), File("Parser/PayloadParsers/UnitTest/CommandParserTest.cpp"), |