/* * Copyright (c) 2010 Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include "Swiften/Parser/PayloadParsers/RosterParser.h" #include "Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h" using namespace Swift; class RosterParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(RosterParserTest); CPPUNIT_TEST(testParse); CPPUNIT_TEST(testParse_ItemWithUnknownContent); CPPUNIT_TEST_SUITE_END(); public: void testParse() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "" " " " Group 1" " Group 2" " " " " "")); RosterPayload* payload = dynamic_cast(parser.getPayload().get()); const RosterPayload::RosterItemPayloads& items = payload->getItems(); CPPUNIT_ASSERT_EQUAL(static_cast(2), items.size()); CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com"), items[0].getJID()); CPPUNIT_ASSERT_EQUAL(String("Foo @ Bar"), items[0].getName()); CPPUNIT_ASSERT_EQUAL(RosterItemPayload::From, items[0].getSubscription()); CPPUNIT_ASSERT(items[0].getSubscriptionRequested()); CPPUNIT_ASSERT_EQUAL(static_cast(2), items[0].getGroups().size()); CPPUNIT_ASSERT_EQUAL(String("Group 1"), items[0].getGroups()[0]); CPPUNIT_ASSERT_EQUAL(String("Group 2"), items[0].getGroups()[1]); CPPUNIT_ASSERT_EQUAL(JID("baz@blo.com"), items[1].getJID()); CPPUNIT_ASSERT_EQUAL(String("Baz"), items[1].getName()); CPPUNIT_ASSERT_EQUAL(RosterItemPayload::None, items[1].getSubscription()); CPPUNIT_ASSERT(!items[1].getSubscriptionRequested()); CPPUNIT_ASSERT_EQUAL(static_cast(0), items[1].getGroups().size()); } void testParse_ItemWithUnknownContent() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "" " " " Group 1" " Baz" " Group 2" " foo" " " "")); RosterPayload* payload = dynamic_cast(parser.getPayload().get()); const RosterPayload::RosterItemPayloads& items = payload->getItems(); CPPUNIT_ASSERT_EQUAL(static_cast(1), items.size()); CPPUNIT_ASSERT_EQUAL(String("Group 1"), items[0].getGroups()[0]); CPPUNIT_ASSERT_EQUAL(String("Group 2"), items[0].getGroups()[1]); CPPUNIT_ASSERT_EQUAL(String( "Baz" "foo" ), items[0].getUnknownContent()); } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterParserTest);