From a6f8c4e4579b93b3e004229dcdeb098bd5b356a4 Mon Sep 17 00:00:00 2001 From: Kevin Smith Date: Tue, 4 Dec 2012 13:01:36 +0000 Subject: Add parsing for disco#info nodes Change-Id: Icf9a526183650add0b5b42243fb1c78757c960c7 diff --git a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp index 14ff79d..aeb0db8 100644 --- a/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp +++ b/Swiften/Parser/PayloadParsers/DiscoInfoParser.cpp @@ -5,6 +5,8 @@ */ #include + +#include #include namespace Swift { @@ -13,7 +15,12 @@ DiscoInfoParser::DiscoInfoParser() : level_(TopLevel), formParser_(NULL) { } void DiscoInfoParser::handleStartElement(const std::string& element, const std::string& ns, const AttributeMap& attributes) { - if (level_ == PayloadLevel) { + if (level_ == TopLevel) { + if (attributes.getAttributeValue("node")) { + getPayloadInternal()->setNode(*attributes.getAttributeValue("node")); + } + } + else if (level_ == PayloadLevel) { if (element == "identity") { getPayloadInternal()->addIdentity(DiscoInfo::Identity(attributes.getAttribute("name"), attributes.getAttribute("category"), attributes.getAttribute("type"), attributes.getAttribute("lang", "http://www.w3.org/XML/1998/namespace"))); } diff --git a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp index bfbc312..d01abd1 100644 --- a/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp +++ b/Swiften/Parser/PayloadParsers/UnitTest/DiscoInfoParserTest.cpp @@ -15,6 +15,7 @@ using namespace Swift; class DiscoInfoParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(DiscoInfoParserTest); CPPUNIT_TEST(testParse); + CPPUNIT_TEST(testParse_Node); CPPUNIT_TEST(testParse_Form); CPPUNIT_TEST_SUITE_END(); @@ -45,6 +46,36 @@ class DiscoInfoParserTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); + CPPUNIT_ASSERT(payload->getNode().empty()); + } + + void testParse_Node() { + PayloadsParserTester parser; + + CPPUNIT_ASSERT(parser.parse( + "" + "" + "" + "" + "" + "" + "")); + + DiscoInfo::ref payload = boost::dynamic_pointer_cast(parser.getPayload()); + CPPUNIT_ASSERT_EQUAL(2, static_cast(payload->getIdentities().size())); + CPPUNIT_ASSERT_EQUAL(std::string("Swift"), payload->getIdentities()[0].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[0].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[0].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("en"), payload->getIdentities()[0].getLanguage()); + CPPUNIT_ASSERT_EQUAL(std::string("Vlug"), payload->getIdentities()[1].getName()); + CPPUNIT_ASSERT_EQUAL(std::string("pc"), payload->getIdentities()[1].getType()); + CPPUNIT_ASSERT_EQUAL(std::string("client"), payload->getIdentities()[1].getCategory()); + CPPUNIT_ASSERT_EQUAL(std::string("nl"), payload->getIdentities()[1].getLanguage()); + CPPUNIT_ASSERT_EQUAL(3, static_cast(payload->getFeatures().size())); + CPPUNIT_ASSERT_EQUAL(std::string("foo-feature"), payload->getFeatures()[0]); + CPPUNIT_ASSERT_EQUAL(std::string("bar-feature"), payload->getFeatures()[1]); + CPPUNIT_ASSERT_EQUAL(std::string("baz-feature"), payload->getFeatures()[2]); + CPPUNIT_ASSERT_EQUAL(std::string("blahblah"), payload->getNode()); } void testParse_Form() { -- cgit v0.10.2-6-g49f6