diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-23 20:36:59 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2015-07-14 16:06:27 (GMT) |
commit | 7aa2011c591e2ca9f31ce550b884ed1c6ad75080 (patch) | |
tree | 79dc096225544ee958d69e3b7fabaf1bd7409336 /Swiften/Serializer | |
parent | 0cfa934c4c0323cc9e8e1431f25a05977e3670a6 (diff) | |
download | swift-7aa2011c591e2ca9f31ce550b884ed1c6ad75080.zip swift-7aa2011c591e2ca9f31ce550b884ed1c6ad75080.tar.bz2 |
Add tests for Parsers and Serializers.
Adds InBandRegistrationPayloadParserTest, IBBSerializerTest, IsodeIQDelegationSerializerTest.
Adds UserTune Parser and Serializer.
Adds UserLocation Parser and Serializer.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
All tests passes.
Change-Id: Ida220574c33ca9ee6f2aa8a2f4fba4c68e3fec60
Diffstat (limited to 'Swiften/Serializer')
4 files changed, 323 insertions, 0 deletions
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); |