/* * Copyright (c) 2011 Tobias Markmann * Licensed under the simplified BSD license. * See Documentation/Licenses/BSD-simplified.txt for more information. */ /* * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Swift; class JingleSerializersTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(JingleSerializersTest); CPPUNIT_TEST(testSerialize_StreamInitiationFileInfo); CPPUNIT_TEST(testSerialize_StreamInitiationFileInfoRange); CPPUNIT_TEST(testSerialize_Xep0261_Example1); CPPUNIT_TEST(testSerialize_Xep0261_Example9); CPPUNIT_TEST(testSerialize_Xep0261_Example13); CPPUNIT_TEST(testSerialize_Xep0234_Example1); CPPUNIT_TEST(testSerialize_Xep0234_Example3); CPPUNIT_TEST(testSerialize_Xep0234_Example5); CPPUNIT_TEST(testSerialize_Xep0234_Example8); CPPUNIT_TEST(testSerialize_Xep0260_Example1); CPPUNIT_TEST_SUITE_END(); boost::shared_ptr createTestling() { return boost::make_shared(&collection); } public: void testSerialize_StreamInitiationFileInfo() { std::string expected = "" "This is a test. If this were a real file..." "" ""; StreamInitiationFileInfo::ref fileInfo = boost::make_shared(); fileInfo->setDate(stringToDateTime("1969-07-21T02:56:15Z")); fileInfo->setHash("552da749930852c69ae5d2141d3766b1"); fileInfo->setSize(1022); fileInfo->setName("test.txt"); fileInfo->setDescription("This is a test. If this were a real file..."); fileInfo->setSupportsRangeRequests(true); boost::shared_ptr serializer = boost::make_shared(); CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); } void testSerialize_StreamInitiationFileInfoRange() { std::string expected = "" "" ""; StreamInitiationFileInfo::ref fileInfo = boost::make_shared(); fileInfo->setHash("552da749930852c69ae5d2141d3766b1"); fileInfo->setSupportsRangeRequests(true); fileInfo->setRangeOffset(270336); boost::shared_ptr serializer = boost::make_shared(); CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); } // IBB Transport Method Examples // http://xmpp.org/extensions/xep-0261.html#example-1 void testSerialize_Xep0261_Example1() { std::string expected = "" "" "" "" ""; JinglePayload::ref payload = boost::make_shared(); payload->setAction(JinglePayload::SessionInitiate); payload->setSessionID("a73sjjvkla37jfea"); payload->setInitiator(JID("romeo@montague.lit/orchard")); JingleIBBTransportPayload::ref transport = boost::make_shared(); transport->setBlockSize(4096); transport->setSessionID("ch3d9s71"); JingleContentPayload::ref content = boost::make_shared(); content->setCreator(JingleContentPayload::InitiatorCreator); content->setName("ex"); content->addTransport(transport); payload->addPayload(content); CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); } // http://xmpp.org/extensions/xep-0261.html#example-9 void testSerialize_Xep0261_Example9() { std::string expected = "" "" "" "" ""; JinglePayload::ref payload = boost::make_shared(); payload->setAction(JinglePayload::TransportInfo); payload->setInitiator(JID("romeo@montague.lit/orchard")); payload->setSessionID("a73sjjvkla37jfea"); JingleContentPayload::ref content = boost::make_shared(); content->setCreator(JingleContentPayload::InitiatorCreator); content->setName("ex"); JingleIBBTransportPayload::ref transport = boost::make_shared(); transport->setBlockSize(2048); transport->setSessionID("bt8a71h6"); content->addTransport(transport); payload->addPayload(content); CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); } // http://xmpp.org/extensions/xep-0261.html#example-13 void testSerialize_Xep0261_Example13() { std::string expected = "" "" ""; JinglePayload::ref payload = boost::make_shared(); payload->setAction(JinglePayload::SessionTerminate); payload->setInitiator(JID("romeo@montague.lit/orchard")); payload->setSessionID("a73sjjvkla37jfea"); payload->setReason(JinglePayload::Reason(JinglePayload::Reason::Success)); CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); } // http://xmpp.org/extensions/xep-0234.html#example-1 void testSerialize_Xep0234_Example1() { std::string expected = "" "" "1969-07-21T02:56:15Z" "This is a test. If this were a real file..." "test.txt" "" "1022" "VS2nSZMIUsaa5dIUHTdmsQ==" "" ""; JingleFileTransferDescription::ref desc = boost::make_shared(); JingleFileTransferFileInfo fileInfo; fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z")); fileInfo.addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); fileInfo.setSize(1022); fileInfo.setName("test.txt"); fileInfo.setDescription("This is a test. If this were a real file..."); fileInfo.setSupportsRangeRequests(true); desc->setFileInfo(fileInfo); CPPUNIT_ASSERT_EQUAL(expected, boost::make_shared()->serialize(desc)); } // http://xmpp.org/extensions/xep-0234.html#example-3 void testSerialize_Xep0234_Example3() { std::string expected = "" "" "" "" "1969-07-21T02:56:15Z" "This is a test. If this were a real file..." "test.txt" "" "1022" "VS2nSZMIUsaa5dIUHTdmsQ==" "" "" /*"" "" "" "" ""*/ "" ""; JinglePayload::ref payload = boost::make_shared(); payload->setAction(JinglePayload::SessionAccept); payload->setInitiator(JID("romeo@montague.lit/orchard")); payload->setSessionID("851ba2"); JingleContentPayload::ref content = boost::make_shared(); content->setCreator(JingleContentPayload::InitiatorCreator); content->setName("a-file-offer"); JingleFileTransferDescription::ref description = boost::make_shared(); JingleFileTransferFileInfo fileInfo; fileInfo.setName("test.txt"); fileInfo.setSize(1022); fileInfo.addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z")); fileInfo.setDescription("This is a test. If this were a real file..."); fileInfo.setSupportsRangeRequests(true); description->setFileInfo(fileInfo); content->addDescription(description); payload->addPayload(content); CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); } // http://xmpp.org/extensions/xep-0234.html#example-5 void testSerialize_Xep0234_Example5() { std::string expected = "" "" /*"" "" ""*/ //"" ""; JinglePayload::ref payload = boost::make_shared(); payload->setAction(JinglePayload::TransportInfo); payload->setInitiator(JID("romeo@montague.lit/orchard")); payload->setSessionID("a73sjjvkla37jfea"); JingleContentPayload::ref content = boost::make_shared(); content->setCreator(JingleContentPayload::InitiatorCreator); content->setName("ex"); payload->addPayload(content); CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); } // http://xmpp.org/extensions/xep-0234.html#example-8 void testSerialize_Xep0234_Example8() { std::string expected = "" "" "" "VS2nSZMIUsaa5dIUHTdmsQ==" "" "" ""; JinglePayload::ref payload = boost::make_shared(); payload->setAction(JinglePayload::SessionInfo); payload->setInitiator(JID("romeo@montague.lit/orchard")); payload->setSessionID("a73sjjvkla37jfea"); JingleFileTransferHash::ref hash = boost::make_shared(); hash->getFileInfo().addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); payload->addPayload(hash); CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); } // http://xmpp.org/extensions/xep-0260.html#example-1 void testSerialize_Xep0260_Example1() { std::string expected = "" "" "" "" "" "" "" ""; JinglePayload::ref payload = boost::make_shared(); payload->setAction(JinglePayload::SessionInitiate); payload->setInitiator(JID("romeo@montague.lit/orchard")); payload->setSessionID("a73sjjvkla37jfea"); JingleContentPayload::ref content = boost::make_shared(); content->setCreator(JingleContentPayload::InitiatorCreator); content->setName("ex"); JingleS5BTransportPayload::ref transport = boost::make_shared(); transport->setMode(JingleS5BTransportPayload::TCPMode); transport->setDstAddr("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba"); transport->setSessionID("vj3hs98y"); JingleS5BTransportPayload::Candidate candidate1; candidate1.cid = "hft54dqy"; candidate1.hostPort = HostAddressPort(HostAddress("192.168.4.1"), 5086); candidate1.jid = JID("romeo@montague.lit/orchard"); candidate1.priority = 8257636; candidate1.type = JingleS5BTransportPayload::Candidate::DirectType; transport->addCandidate(candidate1); JingleS5BTransportPayload::Candidate candidate2; candidate2.cid = "hutr46fe"; candidate2.hostPort = HostAddressPort(HostAddress("24.24.24.1"), 5087); candidate2.jid = JID("romeo@montague.lit/orchard"); candidate2.priority = 8258636; candidate2.type = JingleS5BTransportPayload::Candidate::DirectType; transport->addCandidate(candidate2); content->addTransport(transport); payload->addPayload(content); CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); } private: FullPayloadSerializerCollection collection; }; CPPUNIT_TEST_SUITE_REGISTRATION(JingleSerializersTest);