blob: 378323133cf944bcb44d2757dd32176d813ada55 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
* Copyright (c) 2015 Tarun Gupta.
* Licensed under the simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
/*
* Copyright (c) 2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/Base/DateTime.h>
#include <Swiften/Elements/UserTune.h>
#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
#include <Swiften/Parser/PayloadParsers/UserTuneParser.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);
|