summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp68
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp104
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp64
-rw-r--r--Swiften/SConscript7
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp38
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp126
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp97
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp62
8 files changed, 566 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp
new file mode 100644
index 0000000..f9a9efd
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+#include <Swiften/Elements/Form.h>
+#include <Swiften/Elements/InBandRegistrationPayload.h>
+
+using namespace Swift;
+
+class InBandRegistrationPayloadParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(InBandRegistrationPayloadParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST(testParse_Form);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ InBandRegistrationPayloadParserTest() {}
+
+ void testParse() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<query xmlns=\"jabber:iq:register\">"
+ "<registered/>"
+ "</query>"));
+
+ InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT(payload->isRegistered());
+ }
+
+ void testParse_Form() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<query xmlns=\"jabber:iq:register\">"
+ "<instructions>Use the enclosed form to register.</instructions>"
+ "<x type=\"form\" xmlns=\"jabber:x:data\">"
+ "<title>Contest Registration</title>"
+ "<field type=\"hidden\" var=\"FORM_TYPE\">"
+ "<value>jabber:iq:register</value>"
+ "</field>"
+ "</x>"
+ "</query>"));
+
+ InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ boost::optional<std::string> instruction = payload->getInstructions();
+ CPPUNIT_ASSERT(instruction);
+ CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to register."), instruction.get());
+
+ Form::ref form = payload->getForm();
+ CPPUNIT_ASSERT(form);
+ CPPUNIT_ASSERT_EQUAL(std::string("Contest Registration"), form->getTitle());
+ CPPUNIT_ASSERT_EQUAL(Form::FormType, form->getType());
+ CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:register"), form->getFormType());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(InBandRegistrationPayloadParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp
new file mode 100644
index 0000000..2d5d628
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/PayloadParsers/UserLocationParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+#include <Swiften/Elements/UserLocation.h>
+#include <Swiften/Base/DateTime.h>
+
+using namespace Swift;
+
+class UserLocationParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(UserLocationParserTest);
+ CPPUNIT_TEST(testParse_with_all_variables);
+ CPPUNIT_TEST(testParse_with_Some_variables);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ UserLocationParserTest() {}
+
+ void testParse_with_all_variables() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">"
+ "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>"
+ "<lat>1.67</lat><accuracy>0.95</accuracy><description>Nice</description>"
+ "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>"
+ "<building>First</building><room>E315</room><country>USA</country>"
+ "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>"
+ "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text>"
+ "<datum>Datee</datum><street>Highway</street><speed>56.77</speed></geoloc>"));
+
+ UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get());
+ CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get());
+ CPPUNIT_ASSERT_EQUAL(1.670F, payload->getLatitude().get());
+ CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get()));
+ CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("First"), payload->getBuilding().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("E315"), payload->getRoom().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getCountry().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get());
+ CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get());
+ CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get());
+ CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Datee"), payload->getDatum().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Highway"), payload->getStreet().get());
+ CPPUNIT_ASSERT_EQUAL(56.77F, payload->getSpeed().get());
+ }
+
+ void testParse_with_Some_variables() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">"
+ "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>"
+ "<accuracy>0.95</accuracy><description>Nice</description>"
+ "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>"
+ "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>"
+ "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text></geoloc>"));
+
+ UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get());
+ CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get());
+ CPPUNIT_ASSERT(!payload->getLatitude());
+ CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get()));
+ CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get());
+ CPPUNIT_ASSERT(!payload->getBuilding());
+ CPPUNIT_ASSERT(!payload->getRoom());
+ CPPUNIT_ASSERT(!payload->getCountry());
+ CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get());
+ CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get());
+ CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get());
+ CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get());
+ CPPUNIT_ASSERT(!payload->getDatum());
+ CPPUNIT_ASSERT(!payload->getStreet());
+ CPPUNIT_ASSERT(!payload->getSpeed());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(UserLocationParserTest);
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp
new file mode 100644
index 0000000..a1b284b
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Parser/PayloadParsers/UserTuneParser.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+#include <Swiften/Elements/UserTune.h>
+#include <Swiften/Base/DateTime.h>
+
+using namespace Swift;
+
+class UserTuneParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(UserTuneParserTest);
+ CPPUNIT_TEST(testParse_with_all_variables);
+ CPPUNIT_TEST(testParse_with_Some_variables);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ UserTuneParserTest() {}
+
+ void testParse_with_all_variables() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<tune xmlns=\"http://jabber.org/protocol/tune\">"
+ "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><URI>Fire</URI><source>Origin</source><length>226</length></tune>"));
+
+ UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(5), payload->getRating().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Ice"), payload->getArtist().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Fire"), payload->getURI().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get());
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get());
+ }
+
+ void testParse_with_Some_variables() {
+ PayloadsParserTester parser;
+
+ CPPUNIT_ASSERT(parser.parse(
+ "<tune xmlns=\"http://jabber.org/protocol/tune\">"
+ "<title>Minion</title><track>Yellow</track><source>Origin</source><length>226</length></tune>"));
+
+ UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get());
+ CPPUNIT_ASSERT(payload);
+ CPPUNIT_ASSERT(!payload->getRating());
+ CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get());
+ CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get());
+ CPPUNIT_ASSERT(!payload->getArtist());
+ CPPUNIT_ASSERT(!payload->getURI());
+ CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get());
+ CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneParserTest);
diff --git a/Swiften/SConscript b/Swiften/SConscript
index ad380ff..de71849 100644
--- a/Swiften/SConscript
+++ b/Swiften/SConscript
@@ -423,6 +423,7 @@ if env["SCONS_STAGE"] == "build" :
File("Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/RosterParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/IBBParserTest.cpp"),
+ File("Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/JingleParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp"),
@@ -446,6 +447,8 @@ if env["SCONS_STAGE"] == "build" :
File("Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp"),
File("Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp"),
+ File("Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp"),
+ File("Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp"),
File("Parser/UnitTest/BOSHBodyExtractorTest.cpp"),
File("Parser/UnitTest/AttributeMapTest.cpp"),
File("Parser/UnitTest/EnumParserTest.cpp"),
@@ -479,6 +482,7 @@ if env["SCONS_STAGE"] == "build" :
File("Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp"),
+ File("Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp"),
@@ -491,6 +495,7 @@ if env["SCONS_STAGE"] == "build" :
File("Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp"),
+ File("Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp"),
@@ -507,6 +512,8 @@ if env["SCONS_STAGE"] == "build" :
File("Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp"),
File("Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp"),
+ File("Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp"),
+ File("Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp"),
File("Serializer/UnitTest/StreamFeaturesSerializerTest.cpp"),
File("Serializer/UnitTest/AuthSuccessSerializerTest.cpp"),
File("Serializer/UnitTest/AuthChallengeSerializerTest.cpp"),
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp
new file mode 100644
index 0000000..0d50101
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Serializer/PayloadSerializers/IBBSerializer.h>
+#include <Swiften/Elements/IBB.h>
+#include <Swiften/Base/ByteArray.h>
+
+using namespace Swift;
+
+class IBBSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(IBBSerializerTest);
+ CPPUNIT_TEST(testSerialize_data);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ IBBSerializerTest() {}
+
+ void testSerialize_data() {
+ IBBSerializer testling;
+ boost::shared_ptr<IBB> ibb = boost::make_shared<IBB>();
+ ibb->setAction(IBB::Data);
+ ibb->setData(createByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a"));
+ ibb->setSequenceNumber(4);
+ CPPUNIT_ASSERT_EQUAL(std::string("<data seq=\"4\" sid=\"\" xmlns=\"http://jabber.org/protocol/ibb\">"
+ "YWJjZGVmZ2loamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1"
+ "Njc4OTAK"
+ "</data>"), testling.serialize(ibb));
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(IBBSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp
new file mode 100644
index 0000000..487febf
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include <Swiften/Serializer/PayloadSerializers/IsodeIQDelegationSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+#include <Swiften/Elements/IsodeIQDelegation.h>
+#include <Swiften/Elements/Delay.h>
+#include <Swiften/Elements/Forwarded.h>
+#include <Swiften/Elements/IQ.h>
+#include <Swiften/Elements/Message.h>
+#include <Swiften/Elements/Presence.h>
+#include <Swiften/Elements/Subject.h>
+#include <Swiften/JID/JID.h>
+#include <Swiften/Base/DateTime.h>
+
+using namespace Swift;
+
+class IsodeIQDelegationSerializerTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(IsodeIQDelegationSerializerTest);
+ CPPUNIT_TEST(testSerialize_Forwarded_IQ);
+ CPPUNIT_TEST(testSerialize_Forwarded_Message);
+ CPPUNIT_TEST(testSerialize_Forwarded_MessageNoDelay);
+ CPPUNIT_TEST(testSerialize_Forwarded_Presence);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ IsodeIQDelegationSerializerTest() {}
+
+ void testSerialize_Forwarded_IQ() {
+ IsodeIQDelegationSerializer testling(&serializers);
+ boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>();
+
+ boost::shared_ptr<IQ> iq = IQ::createResult(JID("juliet@capulet.lit/balcony"), JID("romeo@montague.lit/orchard"), "id0", boost::make_shared<Subject>("text"));
+
+ boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>());
+ forwarded->setStanza(iq);
+ forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z"))));
+ isodeIQDelegation->setForward(forwarded);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">"
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>"
+ "<iq from=\"romeo@montague.lit/orchard\" id=\"id0\" to=\"juliet@capulet.lit/balcony\" type=\"result\" xmlns=\"jabber:client\"><subject>text</subject></iq>"
+ "</forwarded>"
+ "</delegate>"), testling.serialize(isodeIQDelegation));
+ }
+
+ void testSerialize_Forwarded_Message() {
+ IsodeIQDelegationSerializer testling(&serializers);
+ boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>();
+
+ boost::shared_ptr<Message> message(boost::make_shared<Message>());
+ message->setType(Message::Chat);
+ message->setTo(JID("juliet@capulet.lit/balcony"));
+ message->setFrom(JID("romeo@montague.lit/orchard"));
+ message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.");
+
+ boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>());
+ forwarded->setStanza(message);
+ forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z"))));
+
+ isodeIQDelegation->setForward(forwarded);
+ CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">"
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>"
+ "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">"
+ "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>"
+ "</message>"
+ "</forwarded>"
+ "</delegate>"), testling.serialize(isodeIQDelegation));
+ }
+
+ void testSerialize_Forwarded_MessageNoDelay() {
+ IsodeIQDelegationSerializer testling(&serializers);
+ boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>();
+
+ boost::shared_ptr<Message> message(boost::make_shared<Message>());
+ message->setType(Message::Chat);
+ message->setTo(JID("juliet@capulet.lit/balcony"));
+ message->setFrom(JID("romeo@montague.lit/orchard"));
+ message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.");
+
+ boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>());
+ forwarded->setStanza(message);
+ isodeIQDelegation->setForward(forwarded);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">"
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">"
+ "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>"
+ "</message>"
+ "</forwarded>"
+ "</delegate>"), testling.serialize(isodeIQDelegation));
+ }
+
+ void testSerialize_Forwarded_Presence() {
+ IsodeIQDelegationSerializer testling(&serializers);
+ boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>();
+
+ boost::shared_ptr<Presence> presence(boost::make_shared<Presence>());
+ presence->setType(Presence::Subscribe);
+
+ boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>());
+ forwarded->setStanza(presence);
+ forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z"))));
+ isodeIQDelegation->setForward(forwarded);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">"
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">"
+ "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>"
+ "<presence type=\"subscribe\" xmlns=\"jabber:client\"/>"
+ "</forwarded>"
+ "</delegate>"), testling.serialize(isodeIQDelegation));
+ }
+ private:
+ FullPayloadSerializerCollection serializers;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(IsodeIQDelegationSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp
new file mode 100644
index 0000000..e1e3131
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+#include <Swiften/Elements/UserLocation.h>
+#include <Swiften/Base/DateTime.h>
+
+using namespace Swift;
+
+class UserLocationSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(UserLocationSerializerTest);
+ CPPUNIT_TEST(testSerialize_withAllVariablesSet);
+ CPPUNIT_TEST(testSerialize_withSomeVariablesSet);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize_withAllVariablesSet() {
+ UserLocationSerializer testling(&serializers);
+ boost::shared_ptr<UserLocation> userLocation(new UserLocation());
+ userLocation->setArea(boost::optional<std::string>("Barbaric"));
+ userLocation->setAltitude(5.75F);
+ userLocation->setLocality(boost::optional<std::string>("Near"));
+ userLocation->setLatitude(boost::optional<float>(5.75F));
+ userLocation->setAccuracy(5.75F);
+ userLocation->setDescription(boost::optional<std::string>("Nice"));
+ userLocation->setCountryCode(boost::optional<std::string>("+91"));
+ userLocation->setTimestamp(stringToDateTime("2015-06-11T20:55:50Z"));
+ userLocation->setFloor(boost::optional<std::string>("3"));
+ userLocation->setBuilding(boost::optional<std::string>("First"));
+ userLocation->setRoom(boost::optional<std::string>("E315"));
+ userLocation->setCountry(boost::optional<std::string>("USA"));
+ userLocation->setRegion(boost::optional<std::string>("NewSode"));
+ userLocation->setURI(boost::optional<std::string>("URIs"));
+ userLocation->setLongitude(5.75F);
+ userLocation->setError(5.75F);
+ userLocation->setPostalCode(boost::optional<std::string>("67"));
+ userLocation->setBearing(5.75F);
+ userLocation->setText(boost::optional<std::string>("Hello"));
+ userLocation->setDatum(boost::optional<std::string>("Datee"));
+ userLocation->setStreet(boost::optional<std::string>("Highway"));
+ userLocation->setSpeed(5.75F);
+
+ std::string expectedResult =
+ "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">"
+ "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>"
+ "<lat>5.75</lat><accuracy>5.75</accuracy><description>Nice</description>"
+ "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>"
+ "<building>First</building><room>E315</room><country>USA</country>"
+ "<region>NewSode</region><uri>URIs</uri><lon>5.75</lon><error>5.75</error>"
+ "<postalcode>67</postalcode><bearing>5.75</bearing><text>Hello</text>"
+ "<datum>Datee</datum><street>Highway</street><speed>5.75</speed></geoloc>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userLocation));
+ }
+
+ void testSerialize_withSomeVariablesSet() {
+ UserLocationSerializer testling(&serializers);
+ boost::shared_ptr<UserLocation> userLocation(new UserLocation());
+ userLocation->setArea(boost::optional<std::string>("Barbaric"));
+ userLocation->setAltitude(5.75F);
+ userLocation->setLocality(boost::optional<std::string>("Near"));
+ userLocation->setAccuracy(5.75F);
+ userLocation->setDescription(boost::optional<std::string>("Nice"));
+ userLocation->setCountryCode(boost::optional<std::string>("+91"));
+ userLocation->setTimestamp(stringToDateTime("2015-06-11T20:55:50Z"));
+ userLocation->setFloor(boost::optional<std::string>("3"));
+ userLocation->setRegion(boost::optional<std::string>("NewSode"));
+ userLocation->setURI(boost::optional<std::string>("URIs"));
+ userLocation->setLongitude(5.75F);
+ userLocation->setError(5.75F);
+ userLocation->setPostalCode(boost::optional<std::string>("67"));
+ userLocation->setBearing(5.75F);
+ userLocation->setText(boost::optional<std::string>("Hello"));
+
+ std::string expectedResult =
+ "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">"
+ "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>"
+ "<accuracy>5.75</accuracy><description>Nice</description>"
+ "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>"
+ "<region>NewSode</region><uri>URIs</uri><lon>5.75</lon><error>5.75</error>"
+ "<postalcode>67</postalcode><bearing>5.75</bearing><text>Hello</text></geoloc>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userLocation));
+ }
+ private:
+ FullPayloadSerializerCollection serializers;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(UserLocationSerializerTest);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp
new file mode 100644
index 0000000..2306e9e
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+#include <boost/smart_ptr/make_shared.hpp>
+
+#include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h>
+#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
+#include <Swiften/Elements/UserTune.h>
+#include <Swiften/Base/DateTime.h>
+
+using namespace Swift;
+
+class UserTuneSerializerTest : public CppUnit::TestFixture {
+ CPPUNIT_TEST_SUITE(UserTuneSerializerTest);
+ CPPUNIT_TEST(testSerialize_withAllVariablesSet);
+ CPPUNIT_TEST(testSerialize_withSomeVariablesSet);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testSerialize_withAllVariablesSet() {
+ UserTuneSerializer testling(&serializers);
+ boost::shared_ptr<UserTune> userTune(new UserTune());
+ userTune->setRating(5);
+ userTune->setTitle(boost::optional<std::string>("Minion"));
+ userTune->setTrack(boost::optional<std::string>("Yellow"));
+ userTune->setArtist(boost::optional<std::string>("Ice"));
+ userTune->setURI(boost::optional<std::string>("Fire"));
+ userTune->setSource(boost::optional<std::string>("Origin"));
+ userTune->setLength(226);
+
+ std::string expectedResult =
+ "<tune xmlns=\"http://jabber.org/protocol/tune\">"
+ "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><uri>Fire</uri><source>Origin</source><length>226</length></tune>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune));
+ }
+
+ void testSerialize_withSomeVariablesSet() {
+ UserTuneSerializer testling(&serializers);
+ boost::shared_ptr<UserTune> userTune(new UserTune());
+ userTune->setTitle(boost::optional<std::string>("Minion"));
+ userTune->setTrack(boost::optional<std::string>("Yellow"));
+ userTune->setArtist(boost::optional<std::string>("Ice"));
+ userTune->setSource(boost::optional<std::string>("Origin"));
+ userTune->setLength(226);
+
+ std::string expectedResult =
+ "<tune xmlns=\"http://jabber.org/protocol/tune\">"
+ "<title>Minion</title><track>Yellow</track><artist>Ice</artist><source>Origin</source><length>226</length></tune>";
+
+ CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune));
+ }
+ private:
+ FullPayloadSerializerCollection serializers;
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneSerializerTest);