/* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Swift; class JingleParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(JingleParserTest); CPPUNIT_TEST(testParse_Xep0166_Example3); CPPUNIT_TEST(testParse_Xep0166_Example8); CPPUNIT_TEST(testParse_Xep0261_Example1); CPPUNIT_TEST(testParse_Xep0261_Example3); CPPUNIT_TEST(testParse_Xep0261_Example9); CPPUNIT_TEST(testParse_Xep0261_Example13); CPPUNIT_TEST(testParse_Xep0234_Example1); CPPUNIT_TEST(testParse_Xep0234_Example3); CPPUNIT_TEST(testParse_Xep0234_Example5); CPPUNIT_TEST(testParse_Xep0234_Example8); CPPUNIT_TEST(testParse_Xep0234_Example10); CPPUNIT_TEST(testParse_Xep0234_Example11); CPPUNIT_TEST(testParse_Xep0234_Example12); CPPUNIT_TEST(testParse_Xep0260_Example1); CPPUNIT_TEST(testParse_Xep0260_Example3); CPPUNIT_TEST(testParse_Xep0167_Example1); CPPUNIT_TEST(testParse_Xep0167_Example48); CPPUNIT_TEST(testParse_Xep0177_Example3); CPPUNIT_TEST_SUITE_END(); public: //http://xmpp.org/extensions/xep-0166.html#example-3 void testParse_Xep0166_Example3() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); } //http://xmpp.org/extensions/xep-0166.html#example-8 void testParse_Xep0166_Example8() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " Sorry, gotta go!\n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).type); CPPUNIT_ASSERT_EQUAL(std::string("Sorry, gotta go!"), jingle->getReason().get_value_or(JinglePayload::Reason(JinglePayload::Reason::UnknownType, "")).text); } // IBB Transport Method Examples // http://xmpp.org/extensions/xep-0261.html#example-1 void testParse_Xep0261_Example1() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); std::vector payloads = jingle->getContents(); CPPUNIT_ASSERT_EQUAL(static_cast(1), payloads.size()); JingleContentPayload::ref payload = payloads[0]; CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); CPPUNIT_ASSERT_EQUAL(static_cast(1), payload->getTransports().size()); JingleIBBTransportPayload::ref transportPaylod = payload->getTransport(); CPPUNIT_ASSERT(transportPaylod); CPPUNIT_ASSERT_EQUAL(4096, transportPaylod->getBlockSize()); CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); } // http://xmpp.org/extensions/xep-0261.html#example-1 void testParse_Xep0261_Example3() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" " \n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), jingle->getResponder()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); std::vector payloads = jingle->getContents(); CPPUNIT_ASSERT_EQUAL(static_cast(1), payloads.size()); JingleContentPayload::ref payload = payloads[0]; CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); CPPUNIT_ASSERT_EQUAL(static_cast(1), payload->getTransports().size()); JingleIBBTransportPayload::ref transportPaylod = payload->getTransport(); CPPUNIT_ASSERT(transportPaylod); CPPUNIT_ASSERT_EQUAL(2048, transportPaylod->getBlockSize()); CPPUNIT_ASSERT_EQUAL(std::string("ch3d9s71"), transportPaylod->getSessionID()); } // http://xmpp.org/extensions/xep-0261.html#example-9 void testParse_Xep0261_Example9() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); std::vector payloads = jingle->getContents(); CPPUNIT_ASSERT_EQUAL(static_cast(1), payloads.size()); JingleContentPayload::ref payload = payloads[0]; CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, payload->getCreator()); CPPUNIT_ASSERT_EQUAL(std::string("ex"), payload->getName()); JingleIBBTransportPayload::ref transportPaylod = payload->getTransport(); CPPUNIT_ASSERT(transportPaylod); CPPUNIT_ASSERT_EQUAL(2048, transportPaylod->getBlockSize()); CPPUNIT_ASSERT_EQUAL(std::string("bt8a71h6"), transportPaylod->getSessionID()); } // http://xmpp.org/extensions/xep-0261.html#example-13 void testParse_Xep0261_Example13() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionTerminate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); CPPUNIT_ASSERT_EQUAL(JinglePayload::Reason::Success, jingle->getReason().get_value_or(JinglePayload::Reason()).type); } // Jingle File Transfer Examples // http://xmpp.org/extensions/xep-0234.html#example-1 void testParse_Xep0234_Example1() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" " This is a test. If this were a real file...\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); std::vector contents = jingle->getContents(); CPPUNIT_ASSERT_EQUAL(static_cast(1), contents.size()); JingleFileTransferDescription::ref description = contents[0]->getDescription(); std::vector offers = description->getOffers(); CPPUNIT_ASSERT_EQUAL(static_cast(1), offers.size()); CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), offers[0].getName()); CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), offers[0].getHash()); CPPUNIT_ASSERT(1022 == offers[0].getSize()); CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), offers[0].getDescription()); CPPUNIT_ASSERT_EQUAL(true, offers[0].getSupportsRangeRequests()); CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == offers[0].getDate()); CPPUNIT_ASSERT_EQUAL(std::string("md5"), offers[0].getAlgo()); } // http://xmpp.org/extensions/xep-0234.html#example-3 void testParse_Xep0234_Example3() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" " This is a test. If this were a real file...\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("851ba2"), jingle->getSessionID()); std::vector contents = jingle->getContents(); CPPUNIT_ASSERT_EQUAL(static_cast(1), contents.size()); JingleFileTransferDescription::ref description = contents[0]->getDescription(); std::vector offers = description->getOffers(); CPPUNIT_ASSERT_EQUAL(static_cast(1), offers.size()); CPPUNIT_ASSERT_EQUAL(std::string("test.txt"), offers[0].getName()); CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), offers[0].getHash()); CPPUNIT_ASSERT(1022 == offers[0].getSize()); CPPUNIT_ASSERT_EQUAL(std::string("This is a test. If this were a real file..."), offers[0].getDescription()); CPPUNIT_ASSERT_EQUAL(true, offers[0].getSupportsRangeRequests()); CPPUNIT_ASSERT(stringToDateTime("1969-07-21T02:56:15Z") == offers[0].getDate()); CPPUNIT_ASSERT_EQUAL(std::string("md5"), offers[0].getAlgo()); } // http://xmpp.org/extensions/xep-0234.html#example-5 void testParse_Xep0234_Example5() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::TransportInfo, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); std::vector contents = jingle->getContents(); CPPUNIT_ASSERT_EQUAL(static_cast(1), contents.size()); JingleS5BTransportPayload::ref transport = contents[0]->getTransport(); CPPUNIT_ASSERT(transport); CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), transport->getSessionID()); CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), transport->getCandidateUsed()); } // http://xmpp.org/extensions/xep-0234.html#example-8 void testParse_Xep0234_Example8() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " 552da749930852c69ae5d2141d3766b1\n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInfo, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); JingleFileTransferHash::ref hash = jingle->getPayload(); CPPUNIT_ASSERT(hash); CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), hash->getHashes().find("sha-1")->second); } // http://xmpp.org/extensions/xep-0234.html#example-10 void testParse_Xep0234_Example10() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("uj3b2"), jingle->getSessionID()); JingleContentPayload::ref content = jingle->getPayload(); CPPUNIT_ASSERT(content); StreamInitiationFileInfo file = content->getDescription()->getRequests()[0]; CPPUNIT_ASSERT_EQUAL(std::string("552da749930852c69ae5d2141d3766b1"), file.getHash()); CPPUNIT_ASSERT_EQUAL(static_cast(270336), file.getRangeOffset()); CPPUNIT_ASSERT_EQUAL(true, file.getSupportsRangeRequests()); } // http://xmpp.org/extensions/xep-0234.html#example-11 void testParse_Xep0234_Example11() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("h2va419i"), jingle->getSessionID()); JingleContentPayload::ref content = jingle->getPayload(); CPPUNIT_ASSERT(content); CPPUNIT_ASSERT_EQUAL(JingleContentPayload::InitiatorCreator, content->getCreator()); CPPUNIT_ASSERT_EQUAL(std::string("a-file-offer"), content->getName()); std::vector offers = content->getDescription()->getOffers(); CPPUNIT_ASSERT_EQUAL(static_cast(3), offers.size()); } // http://xmpp.org/extensions/xep-0234.html#example-12 void testParse_Xep0234_Example12() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInfo, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); boost::shared_ptr received = jingle->getPayload(); CPPUNIT_ASSERT(received); CPPUNIT_ASSERT_EQUAL(std::string("a749930852c69ae5d2141d3766b1552d"), received->getFileInfo().getHash()); } // http://xmpp.org/extensions/xep-0260.html#example-1 void testParse_Xep0260_Example1() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); JingleContentPayload::ref content = jingle->getPayload(); CPPUNIT_ASSERT(content); JingleS5BTransportPayload::ref s5bPayload = content->getTransport(); CPPUNIT_ASSERT(s5bPayload); CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); CPPUNIT_ASSERT_EQUAL(static_cast(2), s5bPayload->getCandidates().size()); JingleS5BTransportPayload::Candidate candidate; candidate = s5bPayload->getCandidates()[0]; CPPUNIT_ASSERT_EQUAL(std::string("hft54dqy"), candidate.cid); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); CPPUNIT_ASSERT(HostAddressPort(HostAddress("192.168.4.1"), 5086) == candidate.hostPort); CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); candidate = s5bPayload->getCandidates()[1]; CPPUNIT_ASSERT_EQUAL(std::string("hutr46fe"), candidate.cid); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), candidate.jid); CPPUNIT_ASSERT(HostAddressPort(HostAddress("24.24.24.1"), 5087) == candidate.hostPort); CPPUNIT_ASSERT_EQUAL(8258636, candidate.priority); CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); } // http://xmpp.org/extensions/xep-0260.html#example-3 void testParse_Xep0260_Example3() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" "\n" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); JingleContentPayload::ref content = jingle->getPayload(); CPPUNIT_ASSERT(content); JingleS5BTransportPayload::ref s5bPayload = content->getTransport(); CPPUNIT_ASSERT(s5bPayload); CPPUNIT_ASSERT_EQUAL(std::string("vj3hs98y"), s5bPayload->getSessionID()); CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::TCPMode, s5bPayload->getMode()); CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasCandidateError()); CPPUNIT_ASSERT_EQUAL(false, s5bPayload->hasProxyError()); CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getActivated()); CPPUNIT_ASSERT_EQUAL(std::string(), s5bPayload->getCandidateUsed()); CPPUNIT_ASSERT_EQUAL(static_cast(3), s5bPayload->getCandidates().size()); JingleS5BTransportPayload::Candidate candidate; candidate = s5bPayload->getCandidates()[0]; CPPUNIT_ASSERT_EQUAL(std::string("ht567dq"), candidate.cid); CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); CPPUNIT_ASSERT(HostAddressPort(HostAddress("192.169.1.10"), 6539) == candidate.hostPort); CPPUNIT_ASSERT_EQUAL(8257636, candidate.priority); CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); candidate = s5bPayload->getCandidates()[1]; CPPUNIT_ASSERT_EQUAL(std::string("hr65dqyd"), candidate.cid); CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); CPPUNIT_ASSERT(HostAddressPort(HostAddress("134.102.201.180"), 16453) == candidate.hostPort); CPPUNIT_ASSERT_EQUAL(7929856, candidate.priority); CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::AssistedType, candidate.type); candidate = s5bPayload->getCandidates()[2]; CPPUNIT_ASSERT_EQUAL(std::string("grt654q2"), candidate.cid); CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), candidate.jid); CPPUNIT_ASSERT(HostAddressPort(HostAddress("2001:638:708:30c9:219:d1ff:fea4:a17d"), 6539) == candidate.hostPort); CPPUNIT_ASSERT_EQUAL(8257606, candidate.priority); CPPUNIT_ASSERT_EQUAL(JingleS5BTransportPayload::Candidate::DirectType, candidate.type); } // http://xmpp.org/extensions/xep-0167.html#example-1 void testParse_Xep0167_Example1() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "" "" "" "" "" "" "" //"" "" "" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionInitiate, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); JingleContentPayload::ref content = jingle->getPayload(); CPPUNIT_ASSERT(content); CPPUNIT_ASSERT_EQUAL(std::string("voice"), content->getName()); JingleRTPDescription::ref desc = content->getDescription(); CPPUNIT_ASSERT(desc); CPPUNIT_ASSERT_EQUAL(JingleRTPDescription::Audio, desc->getMedia()); CPPUNIT_ASSERT_EQUAL(static_cast(3), desc->getPayloadTypes().size()); const RTPPayloadType& payloadType1 = desc->getPayloadTypes()[0]; CPPUNIT_ASSERT_EQUAL(static_cast(16000), payloadType1.getClockrate()); CPPUNIT_ASSERT_EQUAL(static_cast(96), payloadType1.getID()); CPPUNIT_ASSERT_EQUAL(std::string("speex"), payloadType1.getName()); const RTPPayloadType& payloadType2 = desc->getPayloadTypes()[1]; CPPUNIT_ASSERT_EQUAL(static_cast(18), payloadType2.getID()); CPPUNIT_ASSERT_EQUAL(std::string("G729"), payloadType2.getName()); const RTPPayloadType& payloadType3 = desc->getPayloadTypes()[2]; CPPUNIT_ASSERT_EQUAL(static_cast(2), payloadType3.getChannels()); CPPUNIT_ASSERT_EQUAL(static_cast(16000), payloadType3.getClockrate()); CPPUNIT_ASSERT_EQUAL(static_cast(103), payloadType3.getID()); CPPUNIT_ASSERT_EQUAL(std::string("L16"), payloadType3.getName()); } // http://xmpp.org/extensions/xep-0167.html#example-48 void testParse_Xep0167_Example48() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "" "" "" "" "" "" "" "" "" "" "128" "" //"" "" "" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::ContentAccept, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); JingleContentPayload::ref content = jingle->getPayload(); CPPUNIT_ASSERT(content); CPPUNIT_ASSERT_EQUAL(std::string("webcam"), content->getName()); JingleRTPDescription::ref desc = content->getDescription(); CPPUNIT_ASSERT(desc); CPPUNIT_ASSERT_EQUAL(JingleRTPDescription::Video, desc->getMedia()); CPPUNIT_ASSERT_EQUAL(static_cast(1), desc->getPayloadTypes().size()); const RTPPayloadType& payloadType = desc->getPayloadTypes()[0]; CPPUNIT_ASSERT_EQUAL(static_cast(90000), payloadType.getClockrate()); CPPUNIT_ASSERT_EQUAL(static_cast(98), payloadType.getID()); CPPUNIT_ASSERT_EQUAL(std::string("theora"), payloadType.getName()); RTPPayloadType::ParameterMap params = payloadType.getParameters(); // Explicit copy for easy testing CPPUNIT_ASSERT_EQUAL(params["configuration"], std::string("somebase16string")); CPPUNIT_ASSERT_EQUAL(params["delivery-method"], std::string("inline")); CPPUNIT_ASSERT_EQUAL(params["height"], std::string("600")); CPPUNIT_ASSERT_EQUAL(params["sampling"], std::string("YCbCr-4:2:2")); CPPUNIT_ASSERT_EQUAL(params["width"], std::string("800")); std::string type, value; desc->getBandwidth(type, value); CPPUNIT_ASSERT_EQUAL(std::string("AS"), type); CPPUNIT_ASSERT_EQUAL(std::string("128"), value); } // http://xmpp.org/extensions/xep-0177.html#example-3 void testParse_Xep0177_Example3() { PayloadsParserTester parser; CPPUNIT_ASSERT(parser.parse( "" "" "" "" "" "" "" "" "" "" "" )); JinglePayload::ref jingle = parser.getPayload(); CPPUNIT_ASSERT(jingle); CPPUNIT_ASSERT_EQUAL(JinglePayload::SessionAccept, jingle->getAction()); CPPUNIT_ASSERT_EQUAL(JID("romeo@montague.lit/orchard"), jingle->getInitiator()); CPPUNIT_ASSERT_EQUAL(JID("juliet@capulet.lit/balcony"), jingle->getResponder()); CPPUNIT_ASSERT_EQUAL(std::string("a73sjjvkla37jfea"), jingle->getSessionID()); JingleContentPayload::ref content = jingle->getPayload(); CPPUNIT_ASSERT(content); CPPUNIT_ASSERT_EQUAL(std::string("voice"), content->getName()); JingleRTPDescription::ref desc = content->getDescription(); CPPUNIT_ASSERT(desc); CPPUNIT_ASSERT_EQUAL(JingleRTPDescription::Audio, desc->getMedia()); CPPUNIT_ASSERT_EQUAL(static_cast(1), desc->getPayloadTypes().size()); const RTPPayloadType& payloadType = desc->getPayloadTypes()[0]; CPPUNIT_ASSERT_EQUAL(static_cast(18), payloadType.getID()); CPPUNIT_ASSERT_EQUAL(std::string("G729"), payloadType.getName()); JingleRawUDPTransportPayload::ref transport = content->getTransport(); CPPUNIT_ASSERT(transport); CPPUNIT_ASSERT_EQUAL(static_cast(2), transport->getCandidates().size()); const JingleRawUDPTransportPayload::Candidate& candidate1 = transport->getCandidates()[0]; boost::uint8_t expected = 1; boost::uint8_t actual = candidate1.component; CPPUNIT_ASSERT_EQUAL(expected, actual); CPPUNIT_ASSERT_EQUAL(static_cast(0), candidate1.generation); CPPUNIT_ASSERT_EQUAL(std::string("z7sdjb01hf"), candidate1.cid); CPPUNIT_ASSERT(HostAddressPort(HostAddress("208.68.163.214"), 9876) == candidate1.hostAddressPort); const JingleRawUDPTransportPayload::Candidate& candidate2 = transport->getCandidates()[1]; CPPUNIT_ASSERT_EQUAL(static_cast(2), candidate2.component); CPPUNIT_ASSERT_EQUAL(static_cast(0), candidate2.generation); CPPUNIT_ASSERT_EQUAL(std::string("hg92lsn10b"), candidate2.cid); CPPUNIT_ASSERT(HostAddressPort(HostAddress("208.68.163.214"), 9877) == candidate2.hostAddressPort); } }; CPPUNIT_TEST_SUITE_REGISTRATION(JingleParserTest);