diff options
Diffstat (limited to 'Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp')
| -rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/UserTuneParserTest.cpp | 64 |
1 files changed, 64 insertions, 0 deletions
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); | ||
Swift