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/Parser/PayloadParsers | |
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/Parser/PayloadParsers')
3 files changed, 236 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); |