diff options
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/UnitTest')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp index a89c91c..4a74a24 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp @@ -16,6 +16,7 @@ #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> #include <Swiften/Serializer/PayloadSerializers/RTPPayloadTypeSerializer.h> #include <Swiften/Serializer/PayloadSerializers/JingleRTPDescriptionSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/JingleRawUDPTransportPayloadSerializer.h> #include <Swiften/Elements/JingleFileTransferDescription.h> #include <Swiften/Elements/StreamInitiationFileInfo.h> #include <Swiften/Elements/JingleIBBTransportPayload.h> @@ -25,6 +26,7 @@ #include <Swiften/Elements/JingleFileTransferReceived.h> #include <Swiften/Elements/RTPPayloadType.h> #include <Swiften/Elements/JingleRTPDescription.h> +#include <Swiften/Elements/JingleRawUDPTransportPayload.h> #include <Swiften/Base/DateTime.h> using namespace Swift; @@ -56,6 +58,10 @@ class JingleSerializersTest : public CppUnit::TestFixture { CPPUNIT_TEST(testSerialize_Xep0167_Example1); CPPUNIT_TEST(testSerialize_Xep0167_Example48); + CPPUNIT_TEST(testSerialize_RawUDPTransportPayload); + + CPPUNIT_TEST(testSerialize_Xep0177_Example3); + CPPUNIT_TEST_SUITE_END(); boost::shared_ptr<JinglePayloadSerializer> createTestling() { @@ -660,6 +666,95 @@ class JingleSerializersTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); } + void testSerialize_RawUDPTransportPayload() { + std::string expected = + "<transport xmlns=\"urn:xmpp:jingle:transports:raw-udp:1\">" + "<candidate component=\"1\"" + " generation=\"0\"" + " id=\"a9j3mnbtu1\"" + " ip=\"10.1.1.104\"" + " port=\"13540\"" + " type=\"srflx\"/>" + "</transport>"; + + JingleRawUDPTransportPayload::ref transport = boost::make_shared<JingleRawUDPTransportPayload>(); + + JingleRawUDPTransportPayload::Candidate candidate; + candidate.component = 1; + candidate.generation = 0; + candidate.cid = "a9j3mnbtu1"; + candidate.hostAddressPort = HostAddressPort(HostAddress("10.1.1.104"), 13540); + candidate.type = JingleRawUDPTransportPayload::Candidate::ServerReflected; + transport->addCandidate(candidate); + + boost::shared_ptr<JingleRawUDPTransportPayloadSerializer> serializer = boost::make_shared<JingleRawUDPTransportPayloadSerializer>(); + CPPUNIT_ASSERT_EQUAL(expected, serializer->serialize(transport)); + } + + // http://xmpp.org/extensions/xep-0177.html#example-3 + void testSerialize_Xep0177_Example3() { + std::string expected = + "<jingle action=\"session-accept\"" + " initiator=\"romeo@montague.lit/orchard\"" + " responder=\"juliet@capulet.lit/balcony\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"voice\">" + "<description media=\"audio\" xmlns=\"urn:xmpp:jingle:apps:rtp:1\">" + "<payload-type id=\"18\" name=\"G729\"/>" + "</description>" + "<transport xmlns=\"urn:xmpp:jingle:transports:raw-udp:1\">" + "<candidate component=\"1\"" + " generation=\"0\"" + " id=\"z7sdjb01hf\"" + " ip=\"208.68.163.214\"" + " port=\"9876\"/>" + "<candidate component=\"2\"" + " generation=\"0\"" + " id=\"hg92lsn10b\"" + " ip=\"208.68.163.214\"" + " port=\"9877\"/>" + "</transport>" + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionAccept); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setResponder(JID("juliet@capulet.lit/balcony")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleRTPDescription::ref desc = boost::make_shared<JingleRTPDescription>(JingleRTPDescription::Audio); + RTPPayloadType payloadType(18, "G729"); + desc->addPayloadType(payloadType); + + JingleRawUDPTransportPayload::ref transport = boost::make_shared<JingleRawUDPTransportPayload>(); + + JingleRawUDPTransportPayload::Candidate candidate1; + candidate1.component = 1; + candidate1.generation = 0; + candidate1.cid = "z7sdjb01hf"; + candidate1.hostAddressPort = HostAddressPort(HostAddress("208.68.163.214"), 9876); + transport->addCandidate(candidate1); + + JingleRawUDPTransportPayload::Candidate candidate2; + candidate2.component = 2; + candidate2.generation = 0; + candidate2.cid = "hg92lsn10b"; + candidate2.hostAddressPort = HostAddressPort(HostAddress("208.68.163.214"), 9877); + transport->addCandidate(candidate2); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("voice"); + content->addDescription(desc); + content->addTransport(transport); + + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + private: FullPayloadSerializerCollection collection; }; |