From ed95bc3cb17285a16a201f8ffe26ac38a4403f47 Mon Sep 17 00:00:00 2001 From: dknn Date: Sat, 2 Jun 2012 20:31:08 +0200 Subject: Fixed 2 bugs in JinglePayloadSerializer: - Change 'desc' node to 'text' node and add a test case for it - Do not set the attribute 'initiator' if empty 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 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 > payloads = payload->getPayloads(); @@ -47,16 +49,16 @@ std::string JinglePayloadSerializer::serializePayload(boost::shared_ptrgetReason().is_initialized()) { boost::shared_ptr reason = boost::make_shared("reason"); reason->addNode(boost::make_shared(reasonTypeToString(payload->getReason()->type))); if (!payload->getReason()->text.empty()) { - reason->addNode(boost::make_shared("desc", "", payload->getReason()->text)); + reason->addNode(boost::make_shared("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 = + "" + "" + "" + "Sorry, gotta go!" + "" + ""; + + JinglePayload::ref payload = boost::make_shared(); + 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 -- cgit v0.10.2-6-g49f6