diff options
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp | 10 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp | 22 |
2 files changed, 28 insertions, 4 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp b/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp index a04687b..3f134c5 100644 --- a/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp @@ -35,7 +35,9 @@ JinglePayloadSerializer::JinglePayloadSerializer(PayloadSerializerCollection* se std::string JinglePayloadSerializer::serializePayload(boost::shared_ptr<JinglePayload> payload) const { XMLElement jinglePayload("jingle", "urn:xmpp:jingle:1"); jinglePayload.setAttribute("action", actionToString(payload->getAction())); - jinglePayload.setAttribute("initiator", payload->getInitiator()); + if (payload->getInitiator().isValid()) { + jinglePayload.setAttribute("initiator", payload->getInitiator()); + } jinglePayload.setAttribute("sid", payload->getSessionID()); std::vector<boost::shared_ptr<Payload> > payloads = payload->getPayloads(); @@ -47,16 +49,16 @@ std::string JinglePayloadSerializer::serializePayload(boost::shared_ptr<JinglePa } } } - + if (payload->getReason().is_initialized()) { boost::shared_ptr<XMLElement> reason = boost::make_shared<XMLElement>("reason"); reason->addNode(boost::make_shared<XMLElement>(reasonTypeToString(payload->getReason()->type))); if (!payload->getReason()->text.empty()) { - reason->addNode(boost::make_shared<XMLElement>("desc", "", payload->getReason()->text)); + reason->addNode(boost::make_shared<XMLElement>("text", "", payload->getReason()->text)); } jinglePayload.addNode(reason); } - + return jinglePayload.serialize(); } diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp index a1526fc..b773fd7 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp @@ -33,6 +33,8 @@ class JingleSerializersTest : public CppUnit::TestFixture { CPPUNIT_TEST(testSerialize_StreamInitiationFileInfo); CPPUNIT_TEST(testSerialize_StreamInitiationFileInfoRange); + CPPUNIT_TEST(testSerialize_Xep0166_Example8); + CPPUNIT_TEST(testSerialize_Xep0261_Example1); CPPUNIT_TEST(testSerialize_Xep0261_Example9); CPPUNIT_TEST(testSerialize_Xep0261_Example13); @@ -95,6 +97,26 @@ class JingleSerializersTest : public CppUnit::TestFixture { CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); } + // http://xmpp.org/extensions/xep-0166.html#example-8 + void testSerialize_Xep0166_Example8() { + std::string expected = + "<jingle action=\"session-terminate\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<reason>" + "<success/>" + "<text>Sorry, gotta go!</text>" + "</reason>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionTerminate); + payload->setSessionID("a73sjjvkla37jfea"); + payload->setReason(JinglePayload::Reason(JinglePayload::Reason::Success, "Sorry, gotta go!")); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + // IBB Transport Method Examples |