diff options
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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Tarun Gupta. | ||
| 3 | * Licensed under the simplified BSD license. | ||
| 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <cppunit/extensions/HelperMacros.h> | ||
| 8 | #include <cppunit/extensions/TestFactoryRegistry.h> | ||
| 9 | |||
| 10 | #include <Swiften/Parser/PayloadParsers/InBandRegistrationPayloadParser.h> | ||
| 11 | #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> | ||
| 12 | #include <Swiften/Elements/Form.h> | ||
| 13 | #include <Swiften/Elements/InBandRegistrationPayload.h> | ||
| 14 | |||
| 15 | using namespace Swift; | ||
| 16 | |||
| 17 | class InBandRegistrationPayloadParserTest : public CppUnit::TestFixture | ||
| 18 | { | ||
| 19 | CPPUNIT_TEST_SUITE(InBandRegistrationPayloadParserTest); | ||
| 20 | CPPUNIT_TEST(testParse); | ||
| 21 | CPPUNIT_TEST(testParse_Form); | ||
| 22 | CPPUNIT_TEST_SUITE_END(); | ||
| 23 | |||
| 24 | public: | ||
| 25 | InBandRegistrationPayloadParserTest() {} | ||
| 26 | |||
| 27 | void testParse() { | ||
| 28 | PayloadsParserTester parser; | ||
| 29 | |||
| 30 | CPPUNIT_ASSERT(parser.parse( | ||
| 31 | "<query xmlns=\"jabber:iq:register\">" | ||
| 32 | "<registered/>" | ||
| 33 | "</query>")); | ||
| 34 | |||
| 35 | InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); | ||
| 36 | CPPUNIT_ASSERT(payload); | ||
| 37 | CPPUNIT_ASSERT(payload->isRegistered()); | ||
| 38 | } | ||
| 39 | |||
| 40 | void testParse_Form() { | ||
| 41 | PayloadsParserTester parser; | ||
| 42 | |||
| 43 | CPPUNIT_ASSERT(parser.parse( | ||
| 44 | "<query xmlns=\"jabber:iq:register\">" | ||
| 45 | "<instructions>Use the enclosed form to register.</instructions>" | ||
| 46 | "<x type=\"form\" xmlns=\"jabber:x:data\">" | ||
| 47 | "<title>Contest Registration</title>" | ||
| 48 | "<field type=\"hidden\" var=\"FORM_TYPE\">" | ||
| 49 | "<value>jabber:iq:register</value>" | ||
| 50 | "</field>" | ||
| 51 | "</x>" | ||
| 52 | "</query>")); | ||
| 53 | |||
| 54 | InBandRegistrationPayload* payload = dynamic_cast<InBandRegistrationPayload*>(parser.getPayload().get()); | ||
| 55 | CPPUNIT_ASSERT(payload); | ||
| 56 | boost::optional<std::string> instruction = payload->getInstructions(); | ||
| 57 | CPPUNIT_ASSERT(instruction); | ||
| 58 | CPPUNIT_ASSERT_EQUAL(std::string("Use the enclosed form to register."), instruction.get()); | ||
| 59 | |||
| 60 | Form::ref form = payload->getForm(); | ||
| 61 | CPPUNIT_ASSERT(form); | ||
| 62 | CPPUNIT_ASSERT_EQUAL(std::string("Contest Registration"), form->getTitle()); | ||
| 63 | CPPUNIT_ASSERT_EQUAL(Form::FormType, form->getType()); | ||
| 64 | CPPUNIT_ASSERT_EQUAL(std::string("jabber:iq:register"), form->getFormType()); | ||
| 65 | } | ||
| 66 | }; | ||
| 67 | |||
| 68 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Tarun Gupta. | ||
| 3 | * Licensed under the simplified BSD license. | ||
| 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <cppunit/extensions/HelperMacros.h> | ||
| 8 | #include <cppunit/extensions/TestFactoryRegistry.h> | ||
| 9 | |||
| 10 | #include <Swiften/Parser/PayloadParsers/UserLocationParser.h> | ||
| 11 | #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> | ||
| 12 | #include <Swiften/Elements/UserLocation.h> | ||
| 13 | #include <Swiften/Base/DateTime.h> | ||
| 14 | |||
| 15 | using namespace Swift; | ||
| 16 | |||
| 17 | class UserLocationParserTest : public CppUnit::TestFixture | ||
| 18 | { | ||
| 19 | CPPUNIT_TEST_SUITE(UserLocationParserTest); | ||
| 20 | CPPUNIT_TEST(testParse_with_all_variables); | ||
| 21 | CPPUNIT_TEST(testParse_with_Some_variables); | ||
| 22 | CPPUNIT_TEST_SUITE_END(); | ||
| 23 | |||
| 24 | public: | ||
| 25 | UserLocationParserTest() {} | ||
| 26 | |||
| 27 | void testParse_with_all_variables() { | ||
| 28 | PayloadsParserTester parser; | ||
| 29 | |||
| 30 | CPPUNIT_ASSERT(parser.parse( | ||
| 31 | "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" | ||
| 32 | "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" | ||
| 33 | "<lat>1.67</lat><accuracy>0.95</accuracy><description>Nice</description>" | ||
| 34 | "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" | ||
| 35 | "<building>First</building><room>E315</room><country>USA</country>" | ||
| 36 | "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" | ||
| 37 | "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text>" | ||
| 38 | "<datum>Datee</datum><street>Highway</street><speed>56.77</speed></geoloc>")); | ||
| 39 | |||
| 40 | UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); | ||
| 41 | CPPUNIT_ASSERT(payload); | ||
| 42 | CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); | ||
| 43 | CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get()); | ||
| 44 | CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); | ||
| 45 | CPPUNIT_ASSERT_EQUAL(1.670F, payload->getLatitude().get()); | ||
| 46 | CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get()); | ||
| 47 | CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); | ||
| 48 | CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); | ||
| 49 | CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); | ||
| 50 | CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); | ||
| 51 | CPPUNIT_ASSERT_EQUAL(std::string("First"), payload->getBuilding().get()); | ||
| 52 | CPPUNIT_ASSERT_EQUAL(std::string("E315"), payload->getRoom().get()); | ||
| 53 | CPPUNIT_ASSERT_EQUAL(std::string("USA"), payload->getCountry().get()); | ||
| 54 | CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); | ||
| 55 | CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); | ||
| 56 | CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get()); | ||
| 57 | CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get()); | ||
| 58 | CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); | ||
| 59 | CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get()); | ||
| 60 | CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); | ||
| 61 | CPPUNIT_ASSERT_EQUAL(std::string("Datee"), payload->getDatum().get()); | ||
| 62 | CPPUNIT_ASSERT_EQUAL(std::string("Highway"), payload->getStreet().get()); | ||
| 63 | CPPUNIT_ASSERT_EQUAL(56.77F, payload->getSpeed().get()); | ||
| 64 | } | ||
| 65 | |||
| 66 | void testParse_with_Some_variables() { | ||
| 67 | PayloadsParserTester parser; | ||
| 68 | |||
| 69 | CPPUNIT_ASSERT(parser.parse( | ||
| 70 | "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" | ||
| 71 | "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" | ||
| 72 | "<accuracy>0.95</accuracy><description>Nice</description>" | ||
| 73 | "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" | ||
| 74 | "<region>NewSode</region><uri>URIs</uri><lon>6.7578</lon><error>5.66</error>" | ||
| 75 | "<postalcode>67</postalcode><bearing>12.89</bearing><text>Hello</text></geoloc>")); | ||
| 76 | |||
| 77 | UserLocation* payload = dynamic_cast<UserLocation*>(parser.getPayload().get()); | ||
| 78 | CPPUNIT_ASSERT(payload); | ||
| 79 | CPPUNIT_ASSERT_EQUAL(std::string("Barbaric"), payload->getArea().get()); | ||
| 80 | CPPUNIT_ASSERT_EQUAL(5.75F, payload->getAltitude().get()); | ||
| 81 | CPPUNIT_ASSERT_EQUAL(std::string("Near"), payload->getLocality().get()); | ||
| 82 | CPPUNIT_ASSERT(!payload->getLatitude()); | ||
| 83 | CPPUNIT_ASSERT_EQUAL(0.95F, payload->getAccuracy().get()); | ||
| 84 | CPPUNIT_ASSERT_EQUAL(std::string("Nice"), payload->getDescription().get()); | ||
| 85 | CPPUNIT_ASSERT_EQUAL(std::string("+91"), payload->getCountryCode().get()); | ||
| 86 | CPPUNIT_ASSERT_EQUAL(std::string("2015-06-11T20:55:50Z"), dateTimeToString(payload->getTimestamp().get())); | ||
| 87 | CPPUNIT_ASSERT_EQUAL(std::string("3"), payload->getFloor().get()); | ||
| 88 | CPPUNIT_ASSERT(!payload->getBuilding()); | ||
| 89 | CPPUNIT_ASSERT(!payload->getRoom()); | ||
| 90 | CPPUNIT_ASSERT(!payload->getCountry()); | ||
| 91 | CPPUNIT_ASSERT_EQUAL(std::string("NewSode"), payload->getRegion().get()); | ||
| 92 | CPPUNIT_ASSERT_EQUAL(std::string("URIs"), payload->getURI().get()); | ||
| 93 | CPPUNIT_ASSERT_EQUAL(6.7578F, payload->getLongitude().get()); | ||
| 94 | CPPUNIT_ASSERT_EQUAL(5.66F, payload->getError().get()); | ||
| 95 | CPPUNIT_ASSERT_EQUAL(std::string("67"), payload->getPostalCode().get()); | ||
| 96 | CPPUNIT_ASSERT_EQUAL(12.89F, payload->getBearing().get()); | ||
| 97 | CPPUNIT_ASSERT_EQUAL(std::string("Hello"), payload->getText().get()); | ||
| 98 | CPPUNIT_ASSERT(!payload->getDatum()); | ||
| 99 | CPPUNIT_ASSERT(!payload->getStreet()); | ||
| 100 | CPPUNIT_ASSERT(!payload->getSpeed()); | ||
| 101 | } | ||
| 102 | }; | ||
| 103 | |||
| 104 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Tarun Gupta. | ||
| 3 | * Licensed under the simplified BSD license. | ||
| 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <cppunit/extensions/HelperMacros.h> | ||
| 8 | #include <cppunit/extensions/TestFactoryRegistry.h> | ||
| 9 | |||
| 10 | #include <Swiften/Parser/PayloadParsers/UserTuneParser.h> | ||
| 11 | #include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> | ||
| 12 | #include <Swiften/Elements/UserTune.h> | ||
| 13 | #include <Swiften/Base/DateTime.h> | ||
| 14 | |||
| 15 | using namespace Swift; | ||
| 16 | |||
| 17 | class UserTuneParserTest : public CppUnit::TestFixture | ||
| 18 | { | ||
| 19 | CPPUNIT_TEST_SUITE(UserTuneParserTest); | ||
| 20 | CPPUNIT_TEST(testParse_with_all_variables); | ||
| 21 | CPPUNIT_TEST(testParse_with_Some_variables); | ||
| 22 | CPPUNIT_TEST_SUITE_END(); | ||
| 23 | |||
| 24 | public: | ||
| 25 | UserTuneParserTest() {} | ||
| 26 | |||
| 27 | void testParse_with_all_variables() { | ||
| 28 | PayloadsParserTester parser; | ||
| 29 | |||
| 30 | CPPUNIT_ASSERT(parser.parse( | ||
| 31 | "<tune xmlns=\"http://jabber.org/protocol/tune\">" | ||
| 32 | "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><URI>Fire</URI><source>Origin</source><length>226</length></tune>")); | ||
| 33 | |||
| 34 | UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); | ||
| 35 | CPPUNIT_ASSERT(payload); | ||
| 36 | CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(5), payload->getRating().get()); | ||
| 37 | CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); | ||
| 38 | CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); | ||
| 39 | CPPUNIT_ASSERT_EQUAL(std::string("Ice"), payload->getArtist().get()); | ||
| 40 | CPPUNIT_ASSERT_EQUAL(std::string("Fire"), payload->getURI().get()); | ||
| 41 | CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); | ||
| 42 | CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); | ||
| 43 | } | ||
| 44 | |||
| 45 | void testParse_with_Some_variables() { | ||
| 46 | PayloadsParserTester parser; | ||
| 47 | |||
| 48 | CPPUNIT_ASSERT(parser.parse( | ||
| 49 | "<tune xmlns=\"http://jabber.org/protocol/tune\">" | ||
| 50 | "<title>Minion</title><track>Yellow</track><source>Origin</source><length>226</length></tune>")); | ||
| 51 | |||
| 52 | UserTune* payload = dynamic_cast<UserTune*>(parser.getPayload().get()); | ||
| 53 | CPPUNIT_ASSERT(payload); | ||
| 54 | CPPUNIT_ASSERT(!payload->getRating()); | ||
| 55 | CPPUNIT_ASSERT_EQUAL(std::string("Minion"), payload->getTitle().get()); | ||
| 56 | CPPUNIT_ASSERT_EQUAL(std::string("Yellow"), payload->getTrack().get()); | ||
| 57 | CPPUNIT_ASSERT(!payload->getArtist()); | ||
| 58 | CPPUNIT_ASSERT(!payload->getURI()); | ||
| 59 | CPPUNIT_ASSERT_EQUAL(std::string("Origin"), payload->getSource().get()); | ||
| 60 | CPPUNIT_ASSERT_EQUAL(static_cast<unsigned int>(226), payload->getLength().get()); | ||
| 61 | } | ||
| 62 | }; | ||
| 63 | |||
| 64 | CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneParserTest); | ||
diff --git a/Swiften/SConscript b/Swiften/SConscript index ad380ff..de71849 100644 --- a/Swiften/SConscript +++ b/Swiften/SConscript | |||
| @@ -421,10 +421,11 @@ if env["SCONS_STAGE"] == "build" : | |||
| 421 | File("Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp"), | 421 | File("Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp"), |
| 422 | File("Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp"), | 422 | File("Parser/PayloadParsers/UnitTest/ResourceBindParserTest.cpp"), |
| 423 | File("Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp"), | 423 | File("Parser/PayloadParsers/UnitTest/RosterItemExchangeParserTest.cpp"), |
| 424 | File("Parser/PayloadParsers/UnitTest/RosterParserTest.cpp"), | 424 | File("Parser/PayloadParsers/UnitTest/RosterParserTest.cpp"), |
| 425 | File("Parser/PayloadParsers/UnitTest/IBBParserTest.cpp"), | 425 | File("Parser/PayloadParsers/UnitTest/IBBParserTest.cpp"), |
| 426 | File("Parser/PayloadParsers/UnitTest/InBandRegistrationPayloadParserTest.cpp"), | ||
| 426 | File("Parser/PayloadParsers/UnitTest/JingleParserTest.cpp"), | 427 | File("Parser/PayloadParsers/UnitTest/JingleParserTest.cpp"), |
| 427 | File("Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp"), | 428 | File("Parser/PayloadParsers/UnitTest/SearchPayloadParserTest.cpp"), |
| 428 | File("Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp"), | 429 | File("Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp"), |
| 429 | File("Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp"), | 430 | File("Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp"), |
| 430 | File("Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp"), | 431 | File("Parser/PayloadParsers/UnitTest/SoftwareVersionParserTest.cpp"), |
| @@ -444,10 +445,12 @@ if env["SCONS_STAGE"] == "build" : | |||
| 444 | File("Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp"), | 445 | File("Parser/PayloadParsers/UnitTest/ForwardedParserTest.cpp"), |
| 445 | File("Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp"), | 446 | File("Parser/PayloadParsers/UnitTest/MAMFinParserTest.cpp"), |
| 446 | File("Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp"), | 447 | File("Parser/PayloadParsers/UnitTest/MAMResultParserTest.cpp"), |
| 447 | File("Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp"), | 448 | File("Parser/PayloadParsers/UnitTest/MAMQueryParserTest.cpp"), |
| 448 | File("Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp"), | 449 | File("Parser/PayloadParsers/UnitTest/CarbonsParserTest.cpp"), |
| 450 | File("Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp"), | ||
| 451 | File("Parser/PayloadParsers/UnitTest/UserLocationParserTest.cpp"), | ||
| 449 | File("Parser/UnitTest/BOSHBodyExtractorTest.cpp"), | 452 | File("Parser/UnitTest/BOSHBodyExtractorTest.cpp"), |
| 450 | File("Parser/UnitTest/AttributeMapTest.cpp"), | 453 | File("Parser/UnitTest/AttributeMapTest.cpp"), |
| 451 | File("Parser/UnitTest/EnumParserTest.cpp"), | 454 | File("Parser/UnitTest/EnumParserTest.cpp"), |
| 452 | File("Parser/UnitTest/IQParserTest.cpp"), | 455 | File("Parser/UnitTest/IQParserTest.cpp"), |
| 453 | File("Parser/UnitTest/GenericPayloadTreeParserTest.cpp"), | 456 | File("Parser/UnitTest/GenericPayloadTreeParserTest.cpp"), |
| @@ -477,10 +480,11 @@ if env["SCONS_STAGE"] == "build" : | |||
| 477 | File("Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp"), | 480 | File("Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp"), |
| 478 | File("Serializer/PayloadSerializers/UnitTest/ChatStateSerializerTest.cpp"), | 481 | File("Serializer/PayloadSerializers/UnitTest/ChatStateSerializerTest.cpp"), |
| 479 | File("Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp"), | 482 | File("Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp"), |
| 480 | File("Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp"), | 483 | File("Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp"), |
| 481 | File("Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp"), | 484 | File("Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp"), |
| 485 | File("Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp"), | ||
| 482 | File("Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp"), | 486 | File("Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp"), |
| 483 | File("Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp"), | 487 | File("Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp"), |
| 484 | File("Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp"), | 488 | File("Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp"), |
| 485 | File("Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp"), | 489 | File("Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp"), |
| 486 | File("Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp"), | 490 | File("Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp"), |
| @@ -489,10 +493,11 @@ if env["SCONS_STAGE"] == "build" : | |||
| 489 | File("Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp"), | 493 | File("Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp"), |
| 490 | File("Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp"), | 494 | File("Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp"), |
| 491 | File("Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp"), | 495 | File("Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp"), |
| 492 | File("Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp"), | 496 | File("Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp"), |
| 493 | File("Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp"), | 497 | File("Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp"), |
| 498 | File("Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp"), | ||
| 494 | File("Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp"), | 499 | File("Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp"), |
| 495 | File("Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp"), | 500 | File("Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp"), |
| 496 | File("Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp"), | 501 | File("Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp"), |
| 497 | File("Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp"), | 502 | File("Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp"), |
| 498 | File("Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp"), | 503 | File("Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp"), |
| @@ -505,10 +510,12 @@ if env["SCONS_STAGE"] == "build" : | |||
| 505 | File("Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp"), | 510 | File("Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp"), |
| 506 | File("Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp"), | 511 | File("Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp"), |
| 507 | File("Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp"), | 512 | File("Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp"), |
| 508 | File("Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp"), | 513 | File("Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp"), |
| 509 | File("Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp"), | 514 | File("Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp"), |
| 515 | File("Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp"), | ||
| 516 | File("Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp"), | ||
| 510 | File("Serializer/UnitTest/StreamFeaturesSerializerTest.cpp"), | 517 | File("Serializer/UnitTest/StreamFeaturesSerializerTest.cpp"), |
| 511 | File("Serializer/UnitTest/AuthSuccessSerializerTest.cpp"), | 518 | File("Serializer/UnitTest/AuthSuccessSerializerTest.cpp"), |
| 512 | File("Serializer/UnitTest/AuthChallengeSerializerTest.cpp"), | 519 | File("Serializer/UnitTest/AuthChallengeSerializerTest.cpp"), |
| 513 | File("Serializer/UnitTest/AuthRequestSerializerTest.cpp"), | 520 | File("Serializer/UnitTest/AuthRequestSerializerTest.cpp"), |
| 514 | File("Serializer/UnitTest/AuthResponseSerializerTest.cpp"), | 521 | File("Serializer/UnitTest/AuthResponseSerializerTest.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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Tarun Gupta. | ||
| 3 | * Licensed under the simplified BSD license. | ||
| 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <cppunit/extensions/HelperMacros.h> | ||
| 8 | #include <cppunit/extensions/TestFactoryRegistry.h> | ||
| 9 | |||
| 10 | #include <Swiften/Serializer/PayloadSerializers/IBBSerializer.h> | ||
| 11 | #include <Swiften/Elements/IBB.h> | ||
| 12 | #include <Swiften/Base/ByteArray.h> | ||
| 13 | |||
| 14 | using namespace Swift; | ||
| 15 | |||
| 16 | class IBBSerializerTest : public CppUnit::TestFixture | ||
| 17 | { | ||
| 18 | CPPUNIT_TEST_SUITE(IBBSerializerTest); | ||
| 19 | CPPUNIT_TEST(testSerialize_data); | ||
| 20 | CPPUNIT_TEST_SUITE_END(); | ||
| 21 | |||
| 22 | public: | ||
| 23 | IBBSerializerTest() {} | ||
| 24 | |||
| 25 | void testSerialize_data() { | ||
| 26 | IBBSerializer testling; | ||
| 27 | boost::shared_ptr<IBB> ibb = boost::make_shared<IBB>(); | ||
| 28 | ibb->setAction(IBB::Data); | ||
| 29 | ibb->setData(createByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a")); | ||
| 30 | ibb->setSequenceNumber(4); | ||
| 31 | CPPUNIT_ASSERT_EQUAL(std::string("<data seq=\"4\" sid=\"\" xmlns=\"http://jabber.org/protocol/ibb\">" | ||
| 32 | "YWJjZGVmZ2loamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1" | ||
| 33 | "Njc4OTAK" | ||
| 34 | "</data>"), testling.serialize(ibb)); | ||
| 35 | } | ||
| 36 | }; | ||
| 37 | |||
| 38 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Tarun Gupta | ||
| 3 | * Licensed under the simplified BSD license. | ||
| 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <cppunit/extensions/HelperMacros.h> | ||
| 8 | #include <cppunit/extensions/TestFactoryRegistry.h> | ||
| 9 | |||
| 10 | #include <Swiften/Serializer/PayloadSerializers/IsodeIQDelegationSerializer.h> | ||
| 11 | #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> | ||
| 12 | #include <Swiften/Elements/IsodeIQDelegation.h> | ||
| 13 | #include <Swiften/Elements/Delay.h> | ||
| 14 | #include <Swiften/Elements/Forwarded.h> | ||
| 15 | #include <Swiften/Elements/IQ.h> | ||
| 16 | #include <Swiften/Elements/Message.h> | ||
| 17 | #include <Swiften/Elements/Presence.h> | ||
| 18 | #include <Swiften/Elements/Subject.h> | ||
| 19 | #include <Swiften/JID/JID.h> | ||
| 20 | #include <Swiften/Base/DateTime.h> | ||
| 21 | |||
| 22 | using namespace Swift; | ||
| 23 | |||
| 24 | class IsodeIQDelegationSerializerTest : public CppUnit::TestFixture | ||
| 25 | { | ||
| 26 | CPPUNIT_TEST_SUITE(IsodeIQDelegationSerializerTest); | ||
| 27 | CPPUNIT_TEST(testSerialize_Forwarded_IQ); | ||
| 28 | CPPUNIT_TEST(testSerialize_Forwarded_Message); | ||
| 29 | CPPUNIT_TEST(testSerialize_Forwarded_MessageNoDelay); | ||
| 30 | CPPUNIT_TEST(testSerialize_Forwarded_Presence); | ||
| 31 | CPPUNIT_TEST_SUITE_END(); | ||
| 32 | |||
| 33 | public: | ||
| 34 | IsodeIQDelegationSerializerTest() {} | ||
| 35 | |||
| 36 | void testSerialize_Forwarded_IQ() { | ||
| 37 | IsodeIQDelegationSerializer testling(&serializers); | ||
| 38 | boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); | ||
| 39 | |||
| 40 | boost::shared_ptr<IQ> iq = IQ::createResult(JID("juliet@capulet.lit/balcony"), JID("romeo@montague.lit/orchard"), "id0", boost::make_shared<Subject>("text")); | ||
| 41 | |||
| 42 | boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); | ||
| 43 | forwarded->setStanza(iq); | ||
| 44 | forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); | ||
| 45 | isodeIQDelegation->setForward(forwarded); | ||
| 46 | |||
| 47 | CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" | ||
| 48 | "<forwarded xmlns=\"urn:xmpp:forward:0\">" | ||
| 49 | "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" | ||
| 50 | "<iq from=\"romeo@montague.lit/orchard\" id=\"id0\" to=\"juliet@capulet.lit/balcony\" type=\"result\" xmlns=\"jabber:client\"><subject>text</subject></iq>" | ||
| 51 | "</forwarded>" | ||
| 52 | "</delegate>"), testling.serialize(isodeIQDelegation)); | ||
| 53 | } | ||
| 54 | |||
| 55 | void testSerialize_Forwarded_Message() { | ||
| 56 | IsodeIQDelegationSerializer testling(&serializers); | ||
| 57 | boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); | ||
| 58 | |||
| 59 | boost::shared_ptr<Message> message(boost::make_shared<Message>()); | ||
| 60 | message->setType(Message::Chat); | ||
| 61 | message->setTo(JID("juliet@capulet.lit/balcony")); | ||
| 62 | message->setFrom(JID("romeo@montague.lit/orchard")); | ||
| 63 | message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."); | ||
| 64 | |||
| 65 | boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); | ||
| 66 | forwarded->setStanza(message); | ||
| 67 | forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); | ||
| 68 | |||
| 69 | isodeIQDelegation->setForward(forwarded); | ||
| 70 | CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" | ||
| 71 | "<forwarded xmlns=\"urn:xmpp:forward:0\">" | ||
| 72 | "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" | ||
| 73 | "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" | ||
| 74 | "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" | ||
| 75 | "</message>" | ||
| 76 | "</forwarded>" | ||
| 77 | "</delegate>"), testling.serialize(isodeIQDelegation)); | ||
| 78 | } | ||
| 79 | |||
| 80 | void testSerialize_Forwarded_MessageNoDelay() { | ||
| 81 | IsodeIQDelegationSerializer testling(&serializers); | ||
| 82 | boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); | ||
| 83 | |||
| 84 | boost::shared_ptr<Message> message(boost::make_shared<Message>()); | ||
| 85 | message->setType(Message::Chat); | ||
| 86 | message->setTo(JID("juliet@capulet.lit/balcony")); | ||
| 87 | message->setFrom(JID("romeo@montague.lit/orchard")); | ||
| 88 | message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."); | ||
| 89 | |||
| 90 | boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); | ||
| 91 | forwarded->setStanza(message); | ||
| 92 | isodeIQDelegation->setForward(forwarded); | ||
| 93 | |||
| 94 | CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" | ||
| 95 | "<forwarded xmlns=\"urn:xmpp:forward:0\">" | ||
| 96 | "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" | ||
| 97 | "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" | ||
| 98 | "</message>" | ||
| 99 | "</forwarded>" | ||
| 100 | "</delegate>"), testling.serialize(isodeIQDelegation)); | ||
| 101 | } | ||
| 102 | |||
| 103 | void testSerialize_Forwarded_Presence() { | ||
| 104 | IsodeIQDelegationSerializer testling(&serializers); | ||
| 105 | boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); | ||
| 106 | |||
| 107 | boost::shared_ptr<Presence> presence(boost::make_shared<Presence>()); | ||
| 108 | presence->setType(Presence::Subscribe); | ||
| 109 | |||
| 110 | boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); | ||
| 111 | forwarded->setStanza(presence); | ||
| 112 | forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); | ||
| 113 | isodeIQDelegation->setForward(forwarded); | ||
| 114 | |||
| 115 | CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" | ||
| 116 | "<forwarded xmlns=\"urn:xmpp:forward:0\">" | ||
| 117 | "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" | ||
| 118 | "<presence type=\"subscribe\" xmlns=\"jabber:client\"/>" | ||
| 119 | "</forwarded>" | ||
| 120 | "</delegate>"), testling.serialize(isodeIQDelegation)); | ||
| 121 | } | ||
| 122 | private: | ||
| 123 | FullPayloadSerializerCollection serializers; | ||
| 124 | }; | ||
| 125 | |||
| 126 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Tarun Gupta. | ||
| 3 | * Licensed under the simplified BSD license. | ||
| 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <cppunit/extensions/HelperMacros.h> | ||
| 8 | #include <cppunit/extensions/TestFactoryRegistry.h> | ||
| 9 | #include <boost/smart_ptr/make_shared.hpp> | ||
| 10 | |||
| 11 | #include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h> | ||
| 12 | #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> | ||
| 13 | #include <Swiften/Elements/UserLocation.h> | ||
| 14 | #include <Swiften/Base/DateTime.h> | ||
| 15 | |||
| 16 | using namespace Swift; | ||
| 17 | |||
| 18 | class UserLocationSerializerTest : public CppUnit::TestFixture { | ||
| 19 | CPPUNIT_TEST_SUITE(UserLocationSerializerTest); | ||
| 20 | CPPUNIT_TEST(testSerialize_withAllVariablesSet); | ||
| 21 | CPPUNIT_TEST(testSerialize_withSomeVariablesSet); | ||
| 22 | CPPUNIT_TEST_SUITE_END(); | ||
| 23 | |||
| 24 | public: | ||
| 25 | void testSerialize_withAllVariablesSet() { | ||
| 26 | UserLocationSerializer testling(&serializers); | ||
| 27 | boost::shared_ptr<UserLocation> userLocation(new UserLocation()); | ||
| 28 | userLocation->setArea(boost::optional<std::string>("Barbaric")); | ||
| 29 | userLocation->setAltitude(5.75F); | ||
| 30 | userLocation->setLocality(boost::optional<std::string>("Near")); | ||
| 31 | userLocation->setLatitude(boost::optional<float>(5.75F)); | ||
| 32 | userLocation->setAccuracy(5.75F); | ||
| 33 | userLocation->setDescription(boost::optional<std::string>("Nice")); | ||
| 34 | userLocation->setCountryCode(boost::optional<std::string>("+91")); | ||
| 35 | userLocation->setTimestamp(stringToDateTime("2015-06-11T20:55:50Z")); | ||
| 36 | userLocation->setFloor(boost::optional<std::string>("3")); | ||
| 37 | userLocation->setBuilding(boost::optional<std::string>("First")); | ||
| 38 | userLocation->setRoom(boost::optional<std::string>("E315")); | ||
| 39 | userLocation->setCountry(boost::optional<std::string>("USA")); | ||
| 40 | userLocation->setRegion(boost::optional<std::string>("NewSode")); | ||
| 41 | userLocation->setURI(boost::optional<std::string>("URIs")); | ||
| 42 | userLocation->setLongitude(5.75F); | ||
| 43 | userLocation->setError(5.75F); | ||
| 44 | userLocation->setPostalCode(boost::optional<std::string>("67")); | ||
| 45 | userLocation->setBearing(5.75F); | ||
| 46 | userLocation->setText(boost::optional<std::string>("Hello")); | ||
| 47 | userLocation->setDatum(boost::optional<std::string>("Datee")); | ||
| 48 | userLocation->setStreet(boost::optional<std::string>("Highway")); | ||
| 49 | userLocation->setSpeed(5.75F); | ||
| 50 | |||
| 51 | std::string expectedResult = | ||
| 52 | "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" | ||
| 53 | "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" | ||
| 54 | "<lat>5.75</lat><accuracy>5.75</accuracy><description>Nice</description>" | ||
| 55 | "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" | ||
| 56 | "<building>First</building><room>E315</room><country>USA</country>" | ||
| 57 | "<region>NewSode</region><uri>URIs</uri><lon>5.75</lon><error>5.75</error>" | ||
| 58 | "<postalcode>67</postalcode><bearing>5.75</bearing><text>Hello</text>" | ||
| 59 | "<datum>Datee</datum><street>Highway</street><speed>5.75</speed></geoloc>"; | ||
| 60 | |||
| 61 | CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userLocation)); | ||
| 62 | } | ||
| 63 | |||
| 64 | void testSerialize_withSomeVariablesSet() { | ||
| 65 | UserLocationSerializer testling(&serializers); | ||
| 66 | boost::shared_ptr<UserLocation> userLocation(new UserLocation()); | ||
| 67 | userLocation->setArea(boost::optional<std::string>("Barbaric")); | ||
| 68 | userLocation->setAltitude(5.75F); | ||
| 69 | userLocation->setLocality(boost::optional<std::string>("Near")); | ||
| 70 | userLocation->setAccuracy(5.75F); | ||
| 71 | userLocation->setDescription(boost::optional<std::string>("Nice")); | ||
| 72 | userLocation->setCountryCode(boost::optional<std::string>("+91")); | ||
| 73 | userLocation->setTimestamp(stringToDateTime("2015-06-11T20:55:50Z")); | ||
| 74 | userLocation->setFloor(boost::optional<std::string>("3")); | ||
| 75 | userLocation->setRegion(boost::optional<std::string>("NewSode")); | ||
| 76 | userLocation->setURI(boost::optional<std::string>("URIs")); | ||
| 77 | userLocation->setLongitude(5.75F); | ||
| 78 | userLocation->setError(5.75F); | ||
| 79 | userLocation->setPostalCode(boost::optional<std::string>("67")); | ||
| 80 | userLocation->setBearing(5.75F); | ||
| 81 | userLocation->setText(boost::optional<std::string>("Hello")); | ||
| 82 | |||
| 83 | std::string expectedResult = | ||
| 84 | "<geoloc xmlns=\"http://jabber.org/protocol/geoloc\">" | ||
| 85 | "<area>Barbaric</area><alt>5.75</alt><locality>Near</locality>" | ||
| 86 | "<accuracy>5.75</accuracy><description>Nice</description>" | ||
| 87 | "<countrycode>+91</countrycode><timestamp>2015-06-11T20:55:50Z</timestamp><floor>3</floor>" | ||
| 88 | "<region>NewSode</region><uri>URIs</uri><lon>5.75</lon><error>5.75</error>" | ||
| 89 | "<postalcode>67</postalcode><bearing>5.75</bearing><text>Hello</text></geoloc>"; | ||
| 90 | |||
| 91 | CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userLocation)); | ||
| 92 | } | ||
| 93 | private: | ||
| 94 | FullPayloadSerializerCollection serializers; | ||
| 95 | }; | ||
| 96 | |||
| 97 | 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 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 2015 Tarun Gupta. | ||
| 3 | * Licensed under the simplified BSD license. | ||
| 4 | * See Documentation/Licenses/BSD-simplified.txt for more information. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <cppunit/extensions/HelperMacros.h> | ||
| 8 | #include <cppunit/extensions/TestFactoryRegistry.h> | ||
| 9 | #include <boost/smart_ptr/make_shared.hpp> | ||
| 10 | |||
| 11 | #include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h> | ||
| 12 | #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> | ||
| 13 | #include <Swiften/Elements/UserTune.h> | ||
| 14 | #include <Swiften/Base/DateTime.h> | ||
| 15 | |||
| 16 | using namespace Swift; | ||
| 17 | |||
| 18 | class UserTuneSerializerTest : public CppUnit::TestFixture { | ||
| 19 | CPPUNIT_TEST_SUITE(UserTuneSerializerTest); | ||
| 20 | CPPUNIT_TEST(testSerialize_withAllVariablesSet); | ||
| 21 | CPPUNIT_TEST(testSerialize_withSomeVariablesSet); | ||
| 22 | CPPUNIT_TEST_SUITE_END(); | ||
| 23 | |||
| 24 | public: | ||
| 25 | void testSerialize_withAllVariablesSet() { | ||
| 26 | UserTuneSerializer testling(&serializers); | ||
| 27 | boost::shared_ptr<UserTune> userTune(new UserTune()); | ||
| 28 | userTune->setRating(5); | ||
| 29 | userTune->setTitle(boost::optional<std::string>("Minion")); | ||
| 30 | userTune->setTrack(boost::optional<std::string>("Yellow")); | ||
| 31 | userTune->setArtist(boost::optional<std::string>("Ice")); | ||
| 32 | userTune->setURI(boost::optional<std::string>("Fire")); | ||
| 33 | userTune->setSource(boost::optional<std::string>("Origin")); | ||
| 34 | userTune->setLength(226); | ||
| 35 | |||
| 36 | std::string expectedResult = | ||
| 37 | "<tune xmlns=\"http://jabber.org/protocol/tune\">" | ||
| 38 | "<rating>5</rating><title>Minion</title><track>Yellow</track><artist>Ice</artist><uri>Fire</uri><source>Origin</source><length>226</length></tune>"; | ||
| 39 | |||
| 40 | CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune)); | ||
| 41 | } | ||
| 42 | |||
| 43 | void testSerialize_withSomeVariablesSet() { | ||
| 44 | UserTuneSerializer testling(&serializers); | ||
| 45 | boost::shared_ptr<UserTune> userTune(new UserTune()); | ||
| 46 | userTune->setTitle(boost::optional<std::string>("Minion")); | ||
| 47 | userTune->setTrack(boost::optional<std::string>("Yellow")); | ||
| 48 | userTune->setArtist(boost::optional<std::string>("Ice")); | ||
| 49 | userTune->setSource(boost::optional<std::string>("Origin")); | ||
| 50 | userTune->setLength(226); | ||
| 51 | |||
| 52 | std::string expectedResult = | ||
| 53 | "<tune xmlns=\"http://jabber.org/protocol/tune\">" | ||
| 54 | "<title>Minion</title><track>Yellow</track><artist>Ice</artist><source>Origin</source><length>226</length></tune>"; | ||
| 55 | |||
| 56 | CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune)); | ||
| 57 | } | ||
| 58 | private: | ||
| 59 | FullPayloadSerializerCollection serializers; | ||
| 60 | }; | ||
| 61 | |||
| 62 | CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneSerializerTest); | ||
Swift