/* * Copyright (c) 2011 Kevin Smith * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include #include #include #include using namespace Swift; class MUCUserPayloadParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(MUCUserPayloadParserTest); CPPUNIT_TEST(testParseEmpty); CPPUNIT_TEST(testParse); CPPUNIT_TEST(testParseDestroy); CPPUNIT_TEST_SUITE_END(); public: MUCUserPayloadParserTest() {} void testParse() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("malice")); bool found110 = false; bool found210 = false; MUCUserPayload::ref payload = boost::dynamic_pointer_cast(parser.getPayload()); foreach (MUCUserPayload::StatusCode status, payload->getStatusCodes()) { if (status.code == 110) found110 = true; if (status.code == 210) found210 = true; } MUCItem item = payload->getItems()[0]; CPPUNIT_ASSERT_EQUAL(MUCOccupant::Owner, item.affiliation.get()); CPPUNIT_ASSERT_EQUAL(MUCOccupant::Visitor, item.role.get()); CPPUNIT_ASSERT_EQUAL(JID("kev@tester.lit"), item.actor.get()); CPPUNIT_ASSERT_EQUAL(std::string("malice"), item.reason.get()); CPPUNIT_ASSERT(found110); CPPUNIT_ASSERT(found210); } void testParseEmpty() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("")); MUCUserPayload::ref payload = boost::dynamic_pointer_cast(parser.getPayload()); CPPUNIT_ASSERT(payload); CPPUNIT_ASSERT(payload->getItems().empty()); } void testParseDestroy() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse("bert")); MUCUserPayload::ref payload = boost::dynamic_pointer_cast(parser.getPayload()); CPPUNIT_ASSERT(payload); MUCDestroyPayload::ref destroy = boost::dynamic_pointer_cast(payload->getPayload()); CPPUNIT_ASSERT(destroy); CPPUNIT_ASSERT_EQUAL(std::string("bert"), destroy->getReason()); CPPUNIT_ASSERT_EQUAL(JID("alice@wonderland.lit"), destroy->getNewVenue()); } }; CPPUNIT_TEST_SUITE_REGISTRATION(MUCUserPayloadParserTest);