/* * Copyright (c) 2014 Kevin Smith and Remko Tronçon * Licensed under the GNU General Public License v3. * See Documentation/Licenses/GPLv3.txt for more information. */ #include #include #include #include #include #include #include #include #include #include #include using namespace Swift; class ForwardedSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(ForwardedSerializerTest); CPPUNIT_TEST(testSerializeIQ); CPPUNIT_TEST(testSerializeMessage); CPPUNIT_TEST(testSerializeMessageNoDelay); CPPUNIT_TEST(testSerializePresence); CPPUNIT_TEST_SUITE_END(); public: void testSerializeIQ() { ForwardedSerializer serializer(&serializers); boost::shared_ptr iq = IQ::createResult(JID("juliet@capulet.lit/balcony"), JID("romeo@montague.lit/orchard"), "id0"); boost::shared_ptr forwarded(boost::make_shared()); forwarded->setStanza(iq); forwarded->setDelay(boost::make_shared(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); std::string expectedResult = "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); } void testSerializeMessage() { ForwardedSerializer serializer(&serializers); boost::shared_ptr message(boost::make_shared()); message->setType(Message::Chat); message->setTo(JID("juliet@capulet.lit/balcony")); message->setFrom(JID("romeo@montague.lit/orchard")); message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."); boost::shared_ptr forwarded(boost::make_shared()); forwarded->setStanza(message); forwarded->setDelay(boost::make_shared(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); std::string expectedResult = "" "" "" "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." "" ""; CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); } void testSerializeMessageNoDelay() { ForwardedSerializer serializer(&serializers); boost::shared_ptr message(boost::make_shared()); message->setType(Message::Chat); message->setTo(JID("juliet@capulet.lit/balcony")); message->setFrom(JID("romeo@montague.lit/orchard")); message->setBody("Call me but love, and I'll be new baptized; Henceforth I never will be Romeo."); boost::shared_ptr forwarded(boost::make_shared()); forwarded->setStanza(message); std::string expectedResult = "" "" "Call me but love, and I'll be new baptized; Henceforth I never will be Romeo." "" ""; CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); } void testSerializePresence() { ForwardedSerializer serializer(&serializers); boost::shared_ptr presence(boost::make_shared()); presence->setType(Presence::Subscribe); boost::shared_ptr forwarded(boost::make_shared()); forwarded->setStanza(presence); forwarded->setDelay(boost::make_shared(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); std::string expectedResult = "" "" "" ""; CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); } private: FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(ForwardedSerializerTest);