summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordknn <yoann.blein@free.fr>2012-06-02 18:31:08 (GMT)
committerdknn <yoann.blein@free.fr>2012-09-22 08:39:46 (GMT)
commited95bc3cb17285a16a201f8ffe26ac38a4403f47 (patch)
tree86694b0145cbc956afb97d879331e9e2f2a41556 /Swiften/Serializer
parent8e2195fce7f7905ae63525239428a3634d3c4de1 (diff)
downloadswift-contrib-ed95bc3cb17285a16a201f8ffe26ac38a4403f47.zip
swift-contrib-ed95bc3cb17285a16a201f8ffe26ac38a4403f47.tar.bz2
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
Diffstat (limited to 'Swiften/Serializer')
-rw-r--r--Swiften/Serializer/PayloadSerializers/JinglePayloadSerializer.cpp10
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp22
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