/* * Copyright (c) 2015-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace Swift; class CarbonsSerializerTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(CarbonsSerializerTest); CPPUNIT_TEST(testSerializeExample3); CPPUNIT_TEST(testSerializeExample6); CPPUNIT_TEST(testSerializeExample12); CPPUNIT_TEST(testSerializeExample14); CPPUNIT_TEST(testSerializeExample15); CPPUNIT_TEST_SUITE_END(); public: CarbonsSerializerTest() {} /* * Test serializing of example 3 in XEP-0280. */ void testSerializeExample3() { CarbonsEnableSerializer testling; CPPUNIT_ASSERT_EQUAL(std::string(""), testling.serialize(std::make_shared())); } /* * Test serializing of example 6 in XEP-0280. */ void testSerializeExample6() { CarbonsDisableSerializer testling; CPPUNIT_ASSERT_EQUAL(std::string(""), testling.serialize(std::make_shared())); } /* * Test serializing of example 12 in XEP-0280. */ void testSerializeExample12() { CarbonsReceivedSerializer testling(&serializers); CarbonsReceived::ref received = std::make_shared(); std::shared_ptr forwarded = std::make_shared(); Message::ref message = std::make_shared(); message->setFrom(JID("juliet@capulet.example/balcony")); message->setTo(JID("romeo@montague.example/garden")); message->setBody("What man art thou that, thus bescreen'd in night, so stumblest on my counsel?"); message->addPayload(std::make_shared("0e3141cd80894871a68e6fe6b1ec56fa")); forwarded->setStanza(message); received->setForwarded(forwarded); CPPUNIT_ASSERT_EQUAL(std::string( "" "" "" "What man art thou that, thus bescreen'd in night, so stumblest on my counsel?" "0e3141cd80894871a68e6fe6b1ec56fa" "" "" ""), testling.serialize(received)); } /* * Test serializing of example 14 in XEP-0280. */ void testSerializeExample14() { CarbonsSentSerializer testling(&serializers); CarbonsSent::ref sent = std::make_shared(); std::shared_ptr forwarded = std::make_shared(); Message::ref message = std::make_shared(); message->setTo(JID("juliet@capulet.example/balcony")); message->setFrom(JID("romeo@montague.example/home")); message->setBody("Neither, fair saint, if either thee dislike."); message->addPayload(std::make_shared("0e3141cd80894871a68e6fe6b1ec56fa")); forwarded->setStanza(message); sent->setForwarded(forwarded); CPPUNIT_ASSERT_EQUAL(std::string( "" "" "" "Neither, fair saint, if either thee dislike." "0e3141cd80894871a68e6fe6b1ec56fa" "" "" ""), testling.serialize(sent)); } /* * Test serializing of example 15 in XEP-0280. */ void testSerializeExample15() { CarbonsPrivateSerializer testling; CPPUNIT_ASSERT_EQUAL(std::string(""), testling.serialize(std::make_shared())); } private: FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(CarbonsSerializerTest);