summaryrefslogtreecommitdiffstats
blob: 4c2121fe9af0032781f7e15ded0478a4b7eeb95f (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
 * 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 <memory>

#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>

#include <Swiften/Base/DateTime.h>
#include <Swiften/Elements/UserLocation.h>
#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h>
#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.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);
            std::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);
            std::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);