diff options
author | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2016-03-31 14:57:35 (GMT) |
commit | cfbdb43d2cadd40aa87338d41548e4bf89e146e6 (patch) | |
tree | 18d94153a302445196fc0c18586abf44a1ce4a38 /Swiften/Serializer/PayloadSerializers/UnitTest | |
parent | 1d545a4a7fb877f021508094b88c1f17b30d8b4e (diff) | |
download | swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.zip swift-cfbdb43d2cadd40aa87338d41548e4bf89e146e6.tar.bz2 |
Convert tabs to 4 spaces for all source files
Removed trailing spaces and whitespace on empty lines
in the process.
Changed CheckTabs.py tool to disallow hard tabs in source
files.
Test-Information:
Manually checked 30 random files that the conversion worked
as expected.
Change-Id: I874f99d617bd3d2bb55f02d58f22f58f9b094480
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/UnitTest')
41 files changed, 2339 insertions, 2339 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/BlockSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/BlockSerializerTest.cpp index d130577..1dc97f8 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/BlockSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/BlockSerializerTest.cpp @@ -23,39 +23,39 @@ using namespace Swift; class BlockSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(BlockSerializerTest); - CPPUNIT_TEST(testExample4); - CPPUNIT_TEST(testExample6); - CPPUNIT_TEST(testExample10); - CPPUNIT_TEST_SUITE_END(); - - public: - BlockSerializerTest() {} - - void testExample4() { - BlockSerializer<BlockListPayload> testling("blocklist"); - boost::shared_ptr<BlockListPayload> blocklist = boost::make_shared<BlockListPayload>(); - blocklist->addItem(JID("romeo@montague.net")); - blocklist->addItem(JID("iago@shakespeare.lit")); - - CPPUNIT_ASSERT_EQUAL(std::string("<blocklist xmlns=\"urn:xmpp:blocking\"><item jid=\"romeo@montague.net\"/><item jid=\"iago@shakespeare.lit\"/></blocklist>"), testling.serialize(blocklist)); - } - - void testExample6() { - BlockSerializer<BlockPayload> testling("block"); - boost::shared_ptr<BlockPayload> block = boost::make_shared<BlockPayload>(); - block->addItem(JID("romeo@montague.net")); - - CPPUNIT_ASSERT_EQUAL(std::string("<block xmlns=\"urn:xmpp:blocking\"><item jid=\"romeo@montague.net\"/></block>"), testling.serialize(block)); - } - - void testExample10() { - BlockSerializer<UnblockPayload> testling("unblock"); - boost::shared_ptr<UnblockPayload> unblock = boost::make_shared<UnblockPayload>(); - unblock->addItem(JID("romeo@montague.net")); - - CPPUNIT_ASSERT_EQUAL(std::string("<unblock xmlns=\"urn:xmpp:blocking\"><item jid=\"romeo@montague.net\"/></unblock>"), testling.serialize(unblock)); - } + CPPUNIT_TEST_SUITE(BlockSerializerTest); + CPPUNIT_TEST(testExample4); + CPPUNIT_TEST(testExample6); + CPPUNIT_TEST(testExample10); + CPPUNIT_TEST_SUITE_END(); + + public: + BlockSerializerTest() {} + + void testExample4() { + BlockSerializer<BlockListPayload> testling("blocklist"); + boost::shared_ptr<BlockListPayload> blocklist = boost::make_shared<BlockListPayload>(); + blocklist->addItem(JID("romeo@montague.net")); + blocklist->addItem(JID("iago@shakespeare.lit")); + + CPPUNIT_ASSERT_EQUAL(std::string("<blocklist xmlns=\"urn:xmpp:blocking\"><item jid=\"romeo@montague.net\"/><item jid=\"iago@shakespeare.lit\"/></blocklist>"), testling.serialize(blocklist)); + } + + void testExample6() { + BlockSerializer<BlockPayload> testling("block"); + boost::shared_ptr<BlockPayload> block = boost::make_shared<BlockPayload>(); + block->addItem(JID("romeo@montague.net")); + + CPPUNIT_ASSERT_EQUAL(std::string("<block xmlns=\"urn:xmpp:blocking\"><item jid=\"romeo@montague.net\"/></block>"), testling.serialize(block)); + } + + void testExample10() { + BlockSerializer<UnblockPayload> testling("unblock"); + boost::shared_ptr<UnblockPayload> unblock = boost::make_shared<UnblockPayload>(); + unblock->addItem(JID("romeo@montague.net")); + + CPPUNIT_ASSERT_EQUAL(std::string("<unblock xmlns=\"urn:xmpp:blocking\"><item jid=\"romeo@montague.net\"/></unblock>"), testling.serialize(unblock)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(BlockSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp index bdf5cbc..517e98b 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/CapsInfoSerializerTest.cpp @@ -13,19 +13,19 @@ using namespace Swift; class CapsInfoSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(CapsInfoSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(CapsInfoSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); - public: - CapsInfoSerializerTest() {} + public: + CapsInfoSerializerTest() {} - void testSerialize() { - CapsInfoSerializer testling; - boost::shared_ptr<CapsInfo> priority(new CapsInfo("http://swift.im", "myversion", "sha-1")); + void testSerialize() { + CapsInfoSerializer testling; + boost::shared_ptr<CapsInfo> priority(new CapsInfo("http://swift.im", "myversion", "sha-1")); - CPPUNIT_ASSERT_EQUAL(std::string("<c hash=\"sha-1\" node=\"http://swift.im\" ver=\"myversion\" xmlns=\"http://jabber.org/protocol/caps\"/>"), testling.serialize(priority)); - } + CPPUNIT_ASSERT_EQUAL(std::string("<c hash=\"sha-1\" node=\"http://swift.im\" ver=\"myversion\" xmlns=\"http://jabber.org/protocol/caps\"/>"), testling.serialize(priority)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(CapsInfoSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/CarbonsSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/CarbonsSerializerTest.cpp index b4dadf8..a0c49a6 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/CarbonsSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/CarbonsSerializerTest.cpp @@ -20,117 +20,117 @@ #include <Swiften/Serializer/PayloadSerializers/CarbonsEnableSerializer.h> #include <Swiften/Serializer/PayloadSerializers/CarbonsPrivateSerializer.h> #include <Swiften/Serializer/PayloadSerializers/CarbonsReceivedSerializer.h> -#include <Swiften/Serializer/PayloadSerializers/CarbonsSentSerializer.h> +#include <Swiften/Serializer/PayloadSerializers/CarbonsSentSerializer.h> #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> 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("<enable xmlns=\"urn:xmpp:carbons:2\"/>"), testling.serialize(boost::make_shared<CarbonsEnable>())); - } - - /* - * Test serializing of example 6 in XEP-0280. - */ - void testSerializeExample6() { - CarbonsDisableSerializer testling; - - CPPUNIT_ASSERT_EQUAL(std::string("<disable xmlns=\"urn:xmpp:carbons:2\"/>"), testling.serialize(boost::make_shared<CarbonsDisable>())); - } - - /* - * Test serializing of example 12 in XEP-0280. - */ - void testSerializeExample12() { - CarbonsReceivedSerializer testling(&serializers); - - CarbonsReceived::ref received = boost::make_shared<CarbonsReceived>(); - - boost::shared_ptr<Forwarded> forwarded = boost::make_shared<Forwarded>(); - - Message::ref message = boost::make_shared<Message>(); - 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(boost::make_shared<Thread>("0e3141cd80894871a68e6fe6b1ec56fa")); - - forwarded->setStanza(message); - received->setForwarded(forwarded); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<received xmlns=\"urn:xmpp:carbons:2\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<message from=\"juliet@capulet.example/balcony\"" - " to=\"romeo@montague.example/garden\"" - " type=\"chat\"" - " xmlns=\"jabber:client\">" - "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" - "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" - "</message>" - "</forwarded>" - "</received>"), testling.serialize(received)); - } - - /* - * Test serializing of example 14 in XEP-0280. - */ - void testSerializeExample14() { - CarbonsSentSerializer testling(&serializers); - - CarbonsSent::ref sent = boost::make_shared<CarbonsSent>(); - - boost::shared_ptr<Forwarded> forwarded = boost::make_shared<Forwarded>(); - - Message::ref message = boost::make_shared<Message>(); - 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(boost::make_shared<Thread>("0e3141cd80894871a68e6fe6b1ec56fa")); - - forwarded->setStanza(message); - sent->setForwarded(forwarded); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<sent xmlns=\"urn:xmpp:carbons:2\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<message from=\"romeo@montague.example/home\"" - " to=\"juliet@capulet.example/balcony\"" - " type=\"chat\"" - " xmlns=\"jabber:client\">" - "<body>Neither, fair saint, if either thee dislike.</body>" - "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" - "</message>" - "</forwarded>" - "</sent>"), testling.serialize(sent)); - } - - /* - * Test serializing of example 15 in XEP-0280. - */ - void testSerializeExample15() { - CarbonsPrivateSerializer testling; - - CPPUNIT_ASSERT_EQUAL(std::string("<private xmlns=\"urn:xmpp:carbons:2\"/>"), testling.serialize(boost::make_shared<CarbonsPrivate>())); - } - private: - FullPayloadSerializerCollection serializers; + 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("<enable xmlns=\"urn:xmpp:carbons:2\"/>"), testling.serialize(boost::make_shared<CarbonsEnable>())); + } + + /* + * Test serializing of example 6 in XEP-0280. + */ + void testSerializeExample6() { + CarbonsDisableSerializer testling; + + CPPUNIT_ASSERT_EQUAL(std::string("<disable xmlns=\"urn:xmpp:carbons:2\"/>"), testling.serialize(boost::make_shared<CarbonsDisable>())); + } + + /* + * Test serializing of example 12 in XEP-0280. + */ + void testSerializeExample12() { + CarbonsReceivedSerializer testling(&serializers); + + CarbonsReceived::ref received = boost::make_shared<CarbonsReceived>(); + + boost::shared_ptr<Forwarded> forwarded = boost::make_shared<Forwarded>(); + + Message::ref message = boost::make_shared<Message>(); + 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(boost::make_shared<Thread>("0e3141cd80894871a68e6fe6b1ec56fa")); + + forwarded->setStanza(message); + received->setForwarded(forwarded); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<received xmlns=\"urn:xmpp:carbons:2\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<message from=\"juliet@capulet.example/balcony\"" + " to=\"romeo@montague.example/garden\"" + " type=\"chat\"" + " xmlns=\"jabber:client\">" + "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" + "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" + "</message>" + "</forwarded>" + "</received>"), testling.serialize(received)); + } + + /* + * Test serializing of example 14 in XEP-0280. + */ + void testSerializeExample14() { + CarbonsSentSerializer testling(&serializers); + + CarbonsSent::ref sent = boost::make_shared<CarbonsSent>(); + + boost::shared_ptr<Forwarded> forwarded = boost::make_shared<Forwarded>(); + + Message::ref message = boost::make_shared<Message>(); + 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(boost::make_shared<Thread>("0e3141cd80894871a68e6fe6b1ec56fa")); + + forwarded->setStanza(message); + sent->setForwarded(forwarded); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<sent xmlns=\"urn:xmpp:carbons:2\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<message from=\"romeo@montague.example/home\"" + " to=\"juliet@capulet.example/balcony\"" + " type=\"chat\"" + " xmlns=\"jabber:client\">" + "<body>Neither, fair saint, if either thee dislike.</body>" + "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" + "</message>" + "</forwarded>" + "</sent>"), testling.serialize(sent)); + } + + /* + * Test serializing of example 15 in XEP-0280. + */ + void testSerializeExample15() { + CarbonsPrivateSerializer testling; + + CPPUNIT_ASSERT_EQUAL(std::string("<private xmlns=\"urn:xmpp:carbons:2\"/>"), testling.serialize(boost::make_shared<CarbonsPrivate>())); + } + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(CarbonsSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ChatStateSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ChatStateSerializerTest.cpp index 36a01d3..85b067f 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ChatStateSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ChatStateSerializerTest.cpp @@ -13,42 +13,42 @@ using namespace Swift; class ChatStateSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ChatStateSerializerTest); - CPPUNIT_TEST(testSerialize_ActiveState); - CPPUNIT_TEST(testSerialize_GoneState); - CPPUNIT_TEST(testSerialize_ComposingState); - CPPUNIT_TEST(testSerialize_PausedState); - CPPUNIT_TEST(testSerialize_InacativeState); - CPPUNIT_TEST_SUITE_END(); - - public: - ChatStateSerializerTest() {} - ChatStateSerializer testling; - - void testSerialize_ActiveState() { - boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Active)); - CPPUNIT_ASSERT_EQUAL(std::string("<active xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); - } - - void testSerialize_GoneState() { - boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Gone)); - CPPUNIT_ASSERT_EQUAL(std::string("<gone xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); - } - - void testSerialize_ComposingState() { - boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Composing)); - CPPUNIT_ASSERT_EQUAL(std::string("<composing xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); - } - - void testSerialize_PausedState() { - boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Paused)); - CPPUNIT_ASSERT_EQUAL(std::string("<paused xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); - } - - void testSerialize_InacativeState() { - boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Inactive)); - CPPUNIT_ASSERT_EQUAL(std::string("<inactive xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); - } + CPPUNIT_TEST_SUITE(ChatStateSerializerTest); + CPPUNIT_TEST(testSerialize_ActiveState); + CPPUNIT_TEST(testSerialize_GoneState); + CPPUNIT_TEST(testSerialize_ComposingState); + CPPUNIT_TEST(testSerialize_PausedState); + CPPUNIT_TEST(testSerialize_InacativeState); + CPPUNIT_TEST_SUITE_END(); + + public: + ChatStateSerializerTest() {} + ChatStateSerializer testling; + + void testSerialize_ActiveState() { + boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Active)); + CPPUNIT_ASSERT_EQUAL(std::string("<active xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); + } + + void testSerialize_GoneState() { + boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Gone)); + CPPUNIT_ASSERT_EQUAL(std::string("<gone xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); + } + + void testSerialize_ComposingState() { + boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Composing)); + CPPUNIT_ASSERT_EQUAL(std::string("<composing xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); + } + + void testSerialize_PausedState() { + boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Paused)); + CPPUNIT_ASSERT_EQUAL(std::string("<paused xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); + } + + void testSerialize_InacativeState() { + boost::shared_ptr<ChatState> priority(new ChatState(ChatState::Inactive)); + CPPUNIT_ASSERT_EQUAL(std::string("<inactive xmlns=\"http://jabber.org/protocol/chatstates\"/>"), testling.serialize(priority)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ChatStateSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp index 0c39e14..bda9ab7 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DeliveryReceiptSerializerTest.cpp @@ -22,29 +22,29 @@ using namespace Swift; class DeliveryReceiptSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DeliveryReceiptSerializerTest); - CPPUNIT_TEST(testSerialize_XEP0184Example3); - CPPUNIT_TEST(testSerialize_XEP0184Example4); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(DeliveryReceiptSerializerTest); + CPPUNIT_TEST(testSerialize_XEP0184Example3); + CPPUNIT_TEST(testSerialize_XEP0184Example4); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerialize_XEP0184Example3() { - std::string expected = "<request xmlns=\"urn:xmpp:receipts\"/>"; + public: + void testSerialize_XEP0184Example3() { + std::string expected = "<request xmlns=\"urn:xmpp:receipts\"/>"; - DeliveryReceiptRequest::ref receipt = boost::make_shared<DeliveryReceiptRequest>(); + DeliveryReceiptRequest::ref receipt = boost::make_shared<DeliveryReceiptRequest>(); - boost::shared_ptr<DeliveryReceiptRequestSerializer> serializer = boost::make_shared<DeliveryReceiptRequestSerializer>(); - CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(receipt)); - } + boost::shared_ptr<DeliveryReceiptRequestSerializer> serializer = boost::make_shared<DeliveryReceiptRequestSerializer>(); + CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(receipt)); + } - void testSerialize_XEP0184Example4() { - std::string expected = "<received id=\"richard2-4.1.247\" xmlns=\"urn:xmpp:receipts\"/>"; + void testSerialize_XEP0184Example4() { + std::string expected = "<received id=\"richard2-4.1.247\" xmlns=\"urn:xmpp:receipts\"/>"; - DeliveryReceipt::ref receipt = boost::make_shared<DeliveryReceipt>("richard2-4.1.247"); + DeliveryReceipt::ref receipt = boost::make_shared<DeliveryReceipt>("richard2-4.1.247"); - boost::shared_ptr<DeliveryReceiptSerializer> serializer = boost::make_shared<DeliveryReceiptSerializer>(); - CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(receipt)); - } + boost::shared_ptr<DeliveryReceiptSerializer> serializer = boost::make_shared<DeliveryReceiptSerializer>(); + CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(receipt)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(DeliveryReceiptSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp index 9aff6d2..14b1a34 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/DiscoInfoSerializerTest.cpp @@ -13,54 +13,54 @@ using namespace Swift; class DiscoInfoSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(DiscoInfoSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerialize_Form); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(DiscoInfoSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_Form); + CPPUNIT_TEST_SUITE_END(); - public: - DiscoInfoSerializerTest() {} + public: + DiscoInfoSerializerTest() {} - void testSerialize() { - DiscoInfoSerializer testling; - boost::shared_ptr<DiscoInfo> discoInfo(new DiscoInfo()); - discoInfo->addIdentity(DiscoInfo::Identity("Swift", "client", "pc")); - discoInfo->addIdentity(DiscoInfo::Identity("Vlug", "client", "pc", "nl")); - discoInfo->addFeature("http://jabber.org/protocol/caps"); - discoInfo->addFeature("http://jabber.org/protocol/disco#info"); - discoInfo->setNode("http://swift.im#bla"); + void testSerialize() { + DiscoInfoSerializer testling; + boost::shared_ptr<DiscoInfo> discoInfo(new DiscoInfo()); + discoInfo->addIdentity(DiscoInfo::Identity("Swift", "client", "pc")); + discoInfo->addIdentity(DiscoInfo::Identity("Vlug", "client", "pc", "nl")); + discoInfo->addFeature("http://jabber.org/protocol/caps"); + discoInfo->addFeature("http://jabber.org/protocol/disco#info"); + discoInfo->setNode("http://swift.im#bla"); - std::string expectedResult = - "<query node=\"http://swift.im#bla\" xmlns=\"http://jabber.org/protocol/disco#info\">" - "<identity category=\"client\" name=\"Swift\" type=\"pc\"/>" - "<identity category=\"client\" name=\"Vlug\" type=\"pc\" xml:lang=\"nl\"/>" - "<feature var=\"http://jabber.org/protocol/caps\"/>" - "<feature var=\"http://jabber.org/protocol/disco#info\"/>" - "</query>"; + std::string expectedResult = + "<query node=\"http://swift.im#bla\" xmlns=\"http://jabber.org/protocol/disco#info\">" + "<identity category=\"client\" name=\"Swift\" type=\"pc\"/>" + "<identity category=\"client\" name=\"Vlug\" type=\"pc\" xml:lang=\"nl\"/>" + "<feature var=\"http://jabber.org/protocol/caps\"/>" + "<feature var=\"http://jabber.org/protocol/disco#info\"/>" + "</query>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(discoInfo)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(discoInfo)); + } - void testSerialize_Form() { - DiscoInfoSerializer testling; - boost::shared_ptr<DiscoInfo> discoInfo(new DiscoInfo()); - discoInfo->addFeature("http://jabber.org/protocol/caps"); - discoInfo->addFeature("http://jabber.org/protocol/disco#info"); - boost::shared_ptr<Form> form(new Form(Form::FormType)); - form->setTitle("Bot Configuration"); - discoInfo->addExtension(form); + void testSerialize_Form() { + DiscoInfoSerializer testling; + boost::shared_ptr<DiscoInfo> discoInfo(new DiscoInfo()); + discoInfo->addFeature("http://jabber.org/protocol/caps"); + discoInfo->addFeature("http://jabber.org/protocol/disco#info"); + boost::shared_ptr<Form> form(new Form(Form::FormType)); + form->setTitle("Bot Configuration"); + discoInfo->addExtension(form); - std::string expectedResult = - "<query xmlns=\"http://jabber.org/protocol/disco#info\">" - "<feature var=\"http://jabber.org/protocol/caps\"/>" - "<feature var=\"http://jabber.org/protocol/disco#info\"/>" - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<title>Bot Configuration</title>" - "</x>" - "</query>"; + std::string expectedResult = + "<query xmlns=\"http://jabber.org/protocol/disco#info\">" + "<feature var=\"http://jabber.org/protocol/caps\"/>" + "<feature var=\"http://jabber.org/protocol/disco#info\"/>" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "</x>" + "</query>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(discoInfo)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(discoInfo)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(DiscoInfoSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp index c4d3e29..13d9e3c 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ErrorSerializerTest.cpp @@ -16,31 +16,31 @@ using namespace Swift; class ErrorSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ErrorSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerialize_Payload); - CPPUNIT_TEST_SUITE_END(); - - public: - void testSerialize() { - ErrorSerializer testling(&serializers); - boost::shared_ptr<ErrorPayload> error(new ErrorPayload(ErrorPayload::BadRequest, ErrorPayload::Cancel, "My Error")); - - CPPUNIT_ASSERT_EQUAL(std::string("<error type=\"cancel\"><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">My Error</text></error>"), testling.serialize(error)); - } - - void testSerialize_Payload() { - ErrorSerializer testling(&serializers); - boost::shared_ptr<ErrorPayload> error = boost::make_shared<ErrorPayload>(); - error->setPayload(boost::make_shared<Delay>()); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<error type=\"cancel\"><undefined-condition xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><delay stamp=\"not-a-date-timeZ\" xmlns=\"urn:xmpp:delay\"/></error>" - ), testling.serialize(error)); - } - - private: - FullPayloadSerializerCollection serializers; + CPPUNIT_TEST_SUITE(ErrorSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_Payload); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + ErrorSerializer testling(&serializers); + boost::shared_ptr<ErrorPayload> error(new ErrorPayload(ErrorPayload::BadRequest, ErrorPayload::Cancel, "My Error")); + + CPPUNIT_ASSERT_EQUAL(std::string("<error type=\"cancel\"><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><text xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\">My Error</text></error>"), testling.serialize(error)); + } + + void testSerialize_Payload() { + ErrorSerializer testling(&serializers); + boost::shared_ptr<ErrorPayload> error = boost::make_shared<ErrorPayload>(); + error->setPayload(boost::make_shared<Delay>()); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<error type=\"cancel\"><undefined-condition xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><delay stamp=\"not-a-date-timeZ\" xmlns=\"urn:xmpp:delay\"/></error>" + ), testling.serialize(error)); + } + + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(ErrorSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp index 967bc0e..8bd16cd 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/FormSerializerTest.cpp @@ -12,287 +12,287 @@ using namespace Swift; class FormSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(FormSerializerTest); - CPPUNIT_TEST(testSerializeFormInformation); - CPPUNIT_TEST(testSerializeLayout); - CPPUNIT_TEST(testSerializeFields); - CPPUNIT_TEST(testSerializeFormItems); - CPPUNIT_TEST_SUITE_END(); - - public: - void testSerializeFormInformation() { - FormSerializer testling; - boost::shared_ptr<Form> form(new Form(Form::FormType)); - form->setTitle("Bot Configuration"); - form->setInstructions("Hello!\nFill out this form to configure your new bot!"); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<title>Bot Configuration</title>" - "<instructions>Hello!</instructions>" - "<instructions>Fill out this form to configure your new bot!</instructions>" - "</x>"), testling.serialize(form)); - } - - void testSerializeLayout() { - FormSerializer testling; - boost::shared_ptr<Form> form(new Form(Form::FormType)); - - FormPage::page page = boost::make_shared<FormPage>(); - page->setLabel("P1"); - FormReportedRef::ref reportedRef = boost::make_shared<FormReportedRef>(); - page->addReportedRef(reportedRef); - FormText::text formText = boost::make_shared<FormText>(); - formText->setTextString("P1T1"); - page->addTextElement(formText); - FormField::ref field = boost::make_shared<FormField>(FormField::TextSingleType); - field->setName("P1F1"); - field->setLabel("field one"); - page->addField(field); - - FormSection::section section = boost::make_shared<FormSection>(); - section->setLabel("P1S1"); - formText = boost::make_shared<FormText>(); - formText->setTextString("P1S1T1"); - section->addTextElement(formText); - field = boost::make_shared<FormField>(FormField::TextSingleType); - field->setName("P1S1F1"); - field->setLabel("field two"); - section->addField(field); - page->addChildSection(section); - form->addPage(page); - - page = boost::make_shared<FormPage>(); - page->setLabel("P2"); - section = boost::make_shared<FormSection>(); - section->setLabel("P2S1"); - FormSection::section subSection = boost::make_shared<FormSection>(); - subSection->setLabel("P2S2"); - FormSection::section subSection2 = boost::make_shared<FormSection>(); - subSection2->setLabel("P2S3"); - subSection->addChildSection(subSection2); - section->addChildSection(subSection); - page->addChildSection(section); - form->addPage(page); - - // P1 = page one, S1 = section one, F1 = field one, T1 = text one - CPPUNIT_ASSERT_EQUAL(std::string( - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<page label=\"P1\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" - "<text>P1T1</text>" - "<fieldref var=\"P1F1\"/>" - "<reportedref/>" - "<section label=\"P1S1\">" - "<text>P1S1T1</text>" - "<fieldref var=\"P1S1F1\"/>" - "</section>" - "</page>" - "<page label=\"P2\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" - "<section label=\"P2S1\">" - "<section label=\"P2S2\">" - "<section label=\"P2S3\"/>" - "</section>" - "</section>" - "</page>" - "<field label=\"field one\" type=\"text-single\" var=\"P1F1\"/>" - "<field label=\"field two\" type=\"text-single\" var=\"P1S1F1\"/>" - "</x>"), testling.serialize(form)); - } - - void testSerializeFields() { - FormSerializer testling; - boost::shared_ptr<Form> form(new Form(Form::FormType)); - - FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:bot"); - field->setName("FORM_TYPE"); - form->addField(field); - - form->addField(boost::make_shared<FormField>(FormField::FixedType, "Section 1: Bot Info")); - - field = boost::make_shared<FormField>(FormField::TextSingleType); - field->setName("botname"); - field->setLabel("The name of your bot"); - form->addField(field); - - field = boost::make_shared<FormField>(FormField::TextMultiType); - field->setTextMultiValue("This is a bot.\nA quite good one actually"); - field->setName("description"); - field->setLabel("Helpful description of your bot"); - form->addField(field); - - field = boost::make_shared<FormField>(FormField::BooleanType, "1"); - field->setName("public"); - field->setLabel("Public bot?"); - field->setRequired(true); - form->addField(field); - - field = boost::make_shared<FormField>(FormField::TextPrivateType); - field->setName("password"); - field->setLabel("Password for special access"); - form->addField(field); - - field = boost::make_shared<FormField>(FormField::ListMultiType); - field->addValue("news"); - field->addValue("search"); - field->setName("features"); - field->setLabel("What features will the bot support?"); - field->addOption(FormField::Option("Contests", "contests")); - field->addOption(FormField::Option("News", "news")); - field->addOption(FormField::Option("Polls", "polls")); - field->addOption(FormField::Option("Reminders", "reminders")); - field->addOption(FormField::Option("Search", "search")); - form->addField(field); - - field = boost::make_shared<FormField>(FormField::ListSingleType, "20"); - field->setName("maxsubs"); - field->setLabel("Maximum number of subscribers"); - field->addOption(FormField::Option("10", "10")); - field->addOption(FormField::Option("20", "20")); - field->addOption(FormField::Option("30", "30")); - field->addOption(FormField::Option("50", "50")); - field->addOption(FormField::Option("100", "100")); - field->addOption(FormField::Option("", "none")); - form->addField(field); - - std::vector<JID> jids; - field = boost::make_shared<FormField>(FormField::JIDMultiType); - field->addValue("foo@bar.com"); - field->addValue("baz@fum.org"); - field->setName("invitelist"); - field->setLabel("People to invite"); - field->setDescription("Tell all your friends about your new bot!"); - form->addField(field); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<field type=\"hidden\" var=\"FORM_TYPE\">" - "<value>jabber:bot</value>" - "</field>" - "<field type=\"fixed\"><value>Section 1: Bot Info</value></field>" - "<field label=\"The name of your bot\" type=\"text-single\" var=\"botname\"/>" - "<field label=\"Helpful description of your bot\" type=\"text-multi\" var=\"description\"><value>This is a bot.</value><value>A quite good one actually</value></field>" - "<field label=\"Public bot?\" type=\"boolean\" var=\"public\">" - "<required/>" - "<value>1</value>" - "</field>" - "<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>" - "<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">" - "<value>news</value>" - "<value>search</value>" - "<option label=\"Contests\"><value>contests</value></option>" - "<option label=\"News\"><value>news</value></option>" - "<option label=\"Polls\"><value>polls</value></option>" - "<option label=\"Reminders\"><value>reminders</value></option>" - "<option label=\"Search\"><value>search</value></option>" - "</field>" - "<field label=\"Maximum number of subscribers\" type=\"list-single\" var=\"maxsubs\">" - "<value>20</value>" - "<option label=\"10\"><value>10</value></option>" - "<option label=\"20\"><value>20</value></option>" - "<option label=\"30\"><value>30</value></option>" - "<option label=\"50\"><value>50</value></option>" - "<option label=\"100\"><value>100</value></option>" - "<option><value>none</value></option>" - "</field>" - "<field label=\"People to invite\" type=\"jid-multi\" var=\"invitelist\">" - "<desc>Tell all your friends about your new bot!</desc>" - "<value>foo@bar.com</value>" - "<value>baz@fum.org</value>" - "</field>" - "</x>"), testling.serialize(form)); - } - - void testSerializeFormItems() { - FormSerializer testling; - boost::shared_ptr<Form> form(new Form(Form::ResultType)); - - FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:search"); - field->setName("FORM_TYPE"); - form->addField(field); - - // reported fields - field = boost::make_shared<FormField>(FormField::TextSingleType); - field->setName("first"); - field->setLabel("Given Name"); - form->addReportedField(field); - - field = boost::make_shared<FormField>(FormField::TextSingleType); - field->setName("last"); - field->setLabel("Family Name"); - form->addReportedField(field); - - field = boost::make_shared<FormField>(FormField::JIDSingleType); - field->setName("jid"); - field->setLabel("Jabber ID"); - form->addReportedField(field); - - field = boost::make_shared<FormField>(FormField::ListSingleType); - field->setName("x-gender"); - field->setLabel("Gender"); - form->addReportedField(field); - - Form::FormItem firstItem; - field = boost::make_shared<FormField>(FormField::TextSingleType, "Benvolio"); - field->setName("first"); - firstItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague"); - field->setName("last"); - firstItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::JIDSingleType, JID("benvolio@montague.net")); - field->setName("jid"); - firstItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::ListSingleType, "male"); - field->setName("x-gender"); - firstItem.push_back(field); - - Form::FormItem secondItem; - field = boost::make_shared<FormField>(FormField::TextSingleType, "Romeo"); - field->setName("first"); - secondItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague"); - field->setName("last"); - secondItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::JIDSingleType, JID("romeo@montague.net")); - field->setName("jid"); - secondItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::ListSingleType, "male"); - field->setName("x-gender"); - secondItem.push_back(field); - - form->addItem(firstItem); - form->addItem(secondItem); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<x type=\"result\" xmlns=\"jabber:x:data\">" - "<field type=\"hidden\" var=\"FORM_TYPE\">" - "<value>jabber:iq:search</value>" - "</field>" - "<reported>" - "<field label=\"Given Name\" type=\"text-single\" var=\"first\"/>" - "<field label=\"Family Name\" type=\"text-single\" var=\"last\"/>" - "<field label=\"Jabber ID\" type=\"jid-single\" var=\"jid\"/>" - "<field label=\"Gender\" type=\"list-single\" var=\"x-gender\"/>" - "</reported>" - "<item>" - "<field var=\"first\"><value>Benvolio</value></field>" - "<field var=\"last\"><value>Montague</value></field>" - "<field var=\"jid\"><value>benvolio@montague.net</value></field>" - "<field var=\"x-gender\"><value>male</value></field>" - "</item>" - "<item>" - "<field var=\"first\"><value>Romeo</value></field>" - "<field var=\"last\"><value>Montague</value></field>" - "<field var=\"jid\"><value>romeo@montague.net</value></field>" - "<field var=\"x-gender\"><value>male</value></field>" - "</item>" - "</x>"), testling.serialize(form)); - } + CPPUNIT_TEST_SUITE(FormSerializerTest); + CPPUNIT_TEST(testSerializeFormInformation); + CPPUNIT_TEST(testSerializeLayout); + CPPUNIT_TEST(testSerializeFields); + CPPUNIT_TEST(testSerializeFormItems); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerializeFormInformation() { + FormSerializer testling; + boost::shared_ptr<Form> form(new Form(Form::FormType)); + form->setTitle("Bot Configuration"); + form->setInstructions("Hello!\nFill out this form to configure your new bot!"); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<title>Bot Configuration</title>" + "<instructions>Hello!</instructions>" + "<instructions>Fill out this form to configure your new bot!</instructions>" + "</x>"), testling.serialize(form)); + } + + void testSerializeLayout() { + FormSerializer testling; + boost::shared_ptr<Form> form(new Form(Form::FormType)); + + FormPage::page page = boost::make_shared<FormPage>(); + page->setLabel("P1"); + FormReportedRef::ref reportedRef = boost::make_shared<FormReportedRef>(); + page->addReportedRef(reportedRef); + FormText::text formText = boost::make_shared<FormText>(); + formText->setTextString("P1T1"); + page->addTextElement(formText); + FormField::ref field = boost::make_shared<FormField>(FormField::TextSingleType); + field->setName("P1F1"); + field->setLabel("field one"); + page->addField(field); + + FormSection::section section = boost::make_shared<FormSection>(); + section->setLabel("P1S1"); + formText = boost::make_shared<FormText>(); + formText->setTextString("P1S1T1"); + section->addTextElement(formText); + field = boost::make_shared<FormField>(FormField::TextSingleType); + field->setName("P1S1F1"); + field->setLabel("field two"); + section->addField(field); + page->addChildSection(section); + form->addPage(page); + + page = boost::make_shared<FormPage>(); + page->setLabel("P2"); + section = boost::make_shared<FormSection>(); + section->setLabel("P2S1"); + FormSection::section subSection = boost::make_shared<FormSection>(); + subSection->setLabel("P2S2"); + FormSection::section subSection2 = boost::make_shared<FormSection>(); + subSection2->setLabel("P2S3"); + subSection->addChildSection(subSection2); + section->addChildSection(subSection); + page->addChildSection(section); + form->addPage(page); + + // P1 = page one, S1 = section one, F1 = field one, T1 = text one + CPPUNIT_ASSERT_EQUAL(std::string( + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<page label=\"P1\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" + "<text>P1T1</text>" + "<fieldref var=\"P1F1\"/>" + "<reportedref/>" + "<section label=\"P1S1\">" + "<text>P1S1T1</text>" + "<fieldref var=\"P1S1F1\"/>" + "</section>" + "</page>" + "<page label=\"P2\" xmlns=\"http://jabber.org/protocol/xdata-layout\">" + "<section label=\"P2S1\">" + "<section label=\"P2S2\">" + "<section label=\"P2S3\"/>" + "</section>" + "</section>" + "</page>" + "<field label=\"field one\" type=\"text-single\" var=\"P1F1\"/>" + "<field label=\"field two\" type=\"text-single\" var=\"P1S1F1\"/>" + "</x>"), testling.serialize(form)); + } + + void testSerializeFields() { + FormSerializer testling; + boost::shared_ptr<Form> form(new Form(Form::FormType)); + + FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:bot"); + field->setName("FORM_TYPE"); + form->addField(field); + + form->addField(boost::make_shared<FormField>(FormField::FixedType, "Section 1: Bot Info")); + + field = boost::make_shared<FormField>(FormField::TextSingleType); + field->setName("botname"); + field->setLabel("The name of your bot"); + form->addField(field); + + field = boost::make_shared<FormField>(FormField::TextMultiType); + field->setTextMultiValue("This is a bot.\nA quite good one actually"); + field->setName("description"); + field->setLabel("Helpful description of your bot"); + form->addField(field); + + field = boost::make_shared<FormField>(FormField::BooleanType, "1"); + field->setName("public"); + field->setLabel("Public bot?"); + field->setRequired(true); + form->addField(field); + + field = boost::make_shared<FormField>(FormField::TextPrivateType); + field->setName("password"); + field->setLabel("Password for special access"); + form->addField(field); + + field = boost::make_shared<FormField>(FormField::ListMultiType); + field->addValue("news"); + field->addValue("search"); + field->setName("features"); + field->setLabel("What features will the bot support?"); + field->addOption(FormField::Option("Contests", "contests")); + field->addOption(FormField::Option("News", "news")); + field->addOption(FormField::Option("Polls", "polls")); + field->addOption(FormField::Option("Reminders", "reminders")); + field->addOption(FormField::Option("Search", "search")); + form->addField(field); + + field = boost::make_shared<FormField>(FormField::ListSingleType, "20"); + field->setName("maxsubs"); + field->setLabel("Maximum number of subscribers"); + field->addOption(FormField::Option("10", "10")); + field->addOption(FormField::Option("20", "20")); + field->addOption(FormField::Option("30", "30")); + field->addOption(FormField::Option("50", "50")); + field->addOption(FormField::Option("100", "100")); + field->addOption(FormField::Option("", "none")); + form->addField(field); + + std::vector<JID> jids; + field = boost::make_shared<FormField>(FormField::JIDMultiType); + field->addValue("foo@bar.com"); + field->addValue("baz@fum.org"); + field->setName("invitelist"); + field->setLabel("People to invite"); + field->setDescription("Tell all your friends about your new bot!"); + form->addField(field); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:bot</value>" + "</field>" + "<field type=\"fixed\"><value>Section 1: Bot Info</value></field>" + "<field label=\"The name of your bot\" type=\"text-single\" var=\"botname\"/>" + "<field label=\"Helpful description of your bot\" type=\"text-multi\" var=\"description\"><value>This is a bot.</value><value>A quite good one actually</value></field>" + "<field label=\"Public bot?\" type=\"boolean\" var=\"public\">" + "<required/>" + "<value>1</value>" + "</field>" + "<field label=\"Password for special access\" type=\"text-private\" var=\"password\"/>" + "<field label=\"What features will the bot support?\" type=\"list-multi\" var=\"features\">" + "<value>news</value>" + "<value>search</value>" + "<option label=\"Contests\"><value>contests</value></option>" + "<option label=\"News\"><value>news</value></option>" + "<option label=\"Polls\"><value>polls</value></option>" + "<option label=\"Reminders\"><value>reminders</value></option>" + "<option label=\"Search\"><value>search</value></option>" + "</field>" + "<field label=\"Maximum number of subscribers\" type=\"list-single\" var=\"maxsubs\">" + "<value>20</value>" + "<option label=\"10\"><value>10</value></option>" + "<option label=\"20\"><value>20</value></option>" + "<option label=\"30\"><value>30</value></option>" + "<option label=\"50\"><value>50</value></option>" + "<option label=\"100\"><value>100</value></option>" + "<option><value>none</value></option>" + "</field>" + "<field label=\"People to invite\" type=\"jid-multi\" var=\"invitelist\">" + "<desc>Tell all your friends about your new bot!</desc>" + "<value>foo@bar.com</value>" + "<value>baz@fum.org</value>" + "</field>" + "</x>"), testling.serialize(form)); + } + + void testSerializeFormItems() { + FormSerializer testling; + boost::shared_ptr<Form> form(new Form(Form::ResultType)); + + FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:search"); + field->setName("FORM_TYPE"); + form->addField(field); + + // reported fields + field = boost::make_shared<FormField>(FormField::TextSingleType); + field->setName("first"); + field->setLabel("Given Name"); + form->addReportedField(field); + + field = boost::make_shared<FormField>(FormField::TextSingleType); + field->setName("last"); + field->setLabel("Family Name"); + form->addReportedField(field); + + field = boost::make_shared<FormField>(FormField::JIDSingleType); + field->setName("jid"); + field->setLabel("Jabber ID"); + form->addReportedField(field); + + field = boost::make_shared<FormField>(FormField::ListSingleType); + field->setName("x-gender"); + field->setLabel("Gender"); + form->addReportedField(field); + + Form::FormItem firstItem; + field = boost::make_shared<FormField>(FormField::TextSingleType, "Benvolio"); + field->setName("first"); + firstItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague"); + field->setName("last"); + firstItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::JIDSingleType, JID("benvolio@montague.net")); + field->setName("jid"); + firstItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::ListSingleType, "male"); + field->setName("x-gender"); + firstItem.push_back(field); + + Form::FormItem secondItem; + field = boost::make_shared<FormField>(FormField::TextSingleType, "Romeo"); + field->setName("first"); + secondItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague"); + field->setName("last"); + secondItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::JIDSingleType, JID("romeo@montague.net")); + field->setName("jid"); + secondItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::ListSingleType, "male"); + field->setName("x-gender"); + secondItem.push_back(field); + + form->addItem(firstItem); + form->addItem(secondItem); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<x type=\"result\" xmlns=\"jabber:x:data\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:search</value>" + "</field>" + "<reported>" + "<field label=\"Given Name\" type=\"text-single\" var=\"first\"/>" + "<field label=\"Family Name\" type=\"text-single\" var=\"last\"/>" + "<field label=\"Jabber ID\" type=\"jid-single\" var=\"jid\"/>" + "<field label=\"Gender\" type=\"list-single\" var=\"x-gender\"/>" + "</reported>" + "<item>" + "<field var=\"first\"><value>Benvolio</value></field>" + "<field var=\"last\"><value>Montague</value></field>" + "<field var=\"jid\"><value>benvolio@montague.net</value></field>" + "<field var=\"x-gender\"><value>male</value></field>" + "</item>" + "<item>" + "<field var=\"first\"><value>Romeo</value></field>" + "<field var=\"last\"><value>Montague</value></field>" + "<field var=\"jid\"><value>romeo@montague.net</value></field>" + "<field var=\"x-gender\"><value>male</value></field>" + "</item>" + "</x>"), testling.serialize(form)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(FormSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp index 9e986d3..d7aed26 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ForwardedSerializerTest.cpp @@ -21,99 +21,99 @@ 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 = IQ::createResult(JID("juliet@capulet.lit/balcony"), JID("romeo@montague.lit/orchard"), "id0"); - - boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(iq); - forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); - - std::string expectedResult = - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<iq from=\"romeo@montague.lit/orchard\" id=\"id0\" to=\"juliet@capulet.lit/balcony\" type=\"result\" xmlns=\"jabber:client\"/>" - "</forwarded>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); - } - - void testSerializeMessage() { - ForwardedSerializer serializer(&serializers); - - boost::shared_ptr<Message> message(boost::make_shared<Message>()); - 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> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(message); - forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); - - std::string expectedResult = - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); - } - - void testSerializeMessageNoDelay() { - ForwardedSerializer serializer(&serializers); - - boost::shared_ptr<Message> message(boost::make_shared<Message>()); - 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> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(message); - - std::string expectedResult = - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); - } - - void testSerializePresence() { - ForwardedSerializer serializer(&serializers); - - boost::shared_ptr<Presence> presence(boost::make_shared<Presence>()); - presence->setType(Presence::Subscribe); - - boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(presence); - forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); - - std::string expectedResult = - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<presence type=\"subscribe\" xmlns=\"jabber:client\"/>" - "</forwarded>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); - } - - private: - FullPayloadSerializerCollection serializers; + 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 = IQ::createResult(JID("juliet@capulet.lit/balcony"), JID("romeo@montague.lit/orchard"), "id0"); + + boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(iq); + forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + std::string expectedResult = + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<iq from=\"romeo@montague.lit/orchard\" id=\"id0\" to=\"juliet@capulet.lit/balcony\" type=\"result\" xmlns=\"jabber:client\"/>" + "</forwarded>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); + } + + void testSerializeMessage() { + ForwardedSerializer serializer(&serializers); + + boost::shared_ptr<Message> message(boost::make_shared<Message>()); + 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> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(message); + forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + std::string expectedResult = + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); + } + + void testSerializeMessageNoDelay() { + ForwardedSerializer serializer(&serializers); + + boost::shared_ptr<Message> message(boost::make_shared<Message>()); + 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> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(message); + + std::string expectedResult = + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); + } + + void testSerializePresence() { + ForwardedSerializer serializer(&serializers); + + boost::shared_ptr<Presence> presence(boost::make_shared<Presence>()); + presence->setType(Presence::Subscribe); + + boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(presence); + forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + std::string expectedResult = + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<presence type=\"subscribe\" xmlns=\"jabber:client\"/>" + "</forwarded>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(forwarded)); + } + + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(ForwardedSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp index 311ade3..45badea 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/IBBSerializerTest.cpp @@ -21,24 +21,24 @@ using namespace Swift; class IBBSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IBBSerializerTest); - CPPUNIT_TEST(testSerialize_data); - CPPUNIT_TEST_SUITE_END(); - - public: - IBBSerializerTest() {} - - void testSerialize_data() { - IBBSerializer testling; - boost::shared_ptr<IBB> ibb = boost::make_shared<IBB>(); - ibb->setAction(IBB::Data); - ibb->setData(createByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a")); - ibb->setSequenceNumber(4); - CPPUNIT_ASSERT_EQUAL(std::string("<data seq=\"4\" sid=\"\" xmlns=\"http://jabber.org/protocol/ibb\">" - "YWJjZGVmZ2loamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1" - "Njc4OTAK" - "</data>"), testling.serialize(ibb)); - } + CPPUNIT_TEST_SUITE(IBBSerializerTest); + CPPUNIT_TEST(testSerialize_data); + CPPUNIT_TEST_SUITE_END(); + + public: + IBBSerializerTest() {} + + void testSerialize_data() { + IBBSerializer testling; + boost::shared_ptr<IBB> ibb = boost::make_shared<IBB>(); + ibb->setAction(IBB::Data); + ibb->setData(createByteArray("abcdefgihjklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890\x0a")); + ibb->setSequenceNumber(4); + CPPUNIT_ASSERT_EQUAL(std::string("<data seq=\"4\" sid=\"\" xmlns=\"http://jabber.org/protocol/ibb\">" + "YWJjZGVmZ2loamtsbW5vcHFyc3R1dnd4eXpBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWjEyMzQ1" + "Njc4OTAK" + "</data>"), testling.serialize(ibb)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(IBBSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp index e00a929..147c7be 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/IdleSerializerTest.cpp @@ -20,19 +20,19 @@ using namespace Swift; class IdleSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IdleSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(IdleSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); - public: - IdleSerializerTest() {} + public: + IdleSerializerTest() {} - void testSerialize() { - IdleSerializer testling; - Idle::ref idle = boost::make_shared<Idle>(stringToDateTime("1969-07-21T02:56:15Z")); + void testSerialize() { + IdleSerializer testling; + Idle::ref idle = boost::make_shared<Idle>(stringToDateTime("1969-07-21T02:56:15Z")); - CPPUNIT_ASSERT_EQUAL(std::string("<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>"), testling.serialize(idle)); - } + CPPUNIT_ASSERT_EQUAL(std::string("<idle xmlns='urn:xmpp:idle:1' since='1969-07-21T02:56:15Z'/>"), testling.serialize(idle)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(IdleSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp index 9320eff..b1b0c45 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/InBandRegistrationPayloadSerializerTest.cpp @@ -14,50 +14,50 @@ using namespace Swift; class InBandRegistrationPayloadSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(InBandRegistrationPayloadSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerialize_Form); - CPPUNIT_TEST_SUITE_END(); - - public: - void testSerialize() { - InBandRegistrationPayloadSerializer testling; - boost::shared_ptr<InBandRegistrationPayload> registration(new InBandRegistrationPayload()); - registration->setRegistered(true); - - std::string expectedResult = - "<query xmlns=\"jabber:iq:register\">" - "<registered/>" - "</query>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(registration)); - } - void testSerialize_Form() { - InBandRegistrationPayloadSerializer testling; - boost::shared_ptr<InBandRegistrationPayload> registration(new InBandRegistrationPayload()); - registration->setInstructions("Use the enclosed form to register."); - - boost::shared_ptr<Form> form(new Form(Form::FormType)); - form->setTitle("Contest Registration"); - - FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:register"); - field->setName("FORM_TYPE"); - form->addField(field); - registration->setForm(form); - - std::string expectedResult = - "<query xmlns=\"jabber:iq:register\">" - "<instructions>Use the enclosed form to register.</instructions>" - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<title>Contest Registration</title>" - "<field type=\"hidden\" var=\"FORM_TYPE\">" - "<value>jabber:iq:register</value>" - "</field>" - "</x>" - "</query>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(registration)); - } + CPPUNIT_TEST_SUITE(InBandRegistrationPayloadSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_Form); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + InBandRegistrationPayloadSerializer testling; + boost::shared_ptr<InBandRegistrationPayload> registration(new InBandRegistrationPayload()); + registration->setRegistered(true); + + std::string expectedResult = + "<query xmlns=\"jabber:iq:register\">" + "<registered/>" + "</query>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(registration)); + } + void testSerialize_Form() { + InBandRegistrationPayloadSerializer testling; + boost::shared_ptr<InBandRegistrationPayload> registration(new InBandRegistrationPayload()); + registration->setInstructions("Use the enclosed form to register."); + + boost::shared_ptr<Form> form(new Form(Form::FormType)); + form->setTitle("Contest Registration"); + + FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:register"); + field->setName("FORM_TYPE"); + form->addField(field); + registration->setForm(form); + + std::string expectedResult = + "<query xmlns=\"jabber:iq:register\">" + "<instructions>Use the enclosed form to register.</instructions>" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<title>Contest Registration</title>" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:register</value>" + "</field>" + "</x>" + "</query>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(registration)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(InBandRegistrationPayloadSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp index 4e84648..8f46ca8 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/IsodeIQDelegationSerializerTest.cpp @@ -29,104 +29,104 @@ using namespace Swift; class IsodeIQDelegationSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(IsodeIQDelegationSerializerTest); - CPPUNIT_TEST(testSerialize_Forwarded_IQ); - CPPUNIT_TEST(testSerialize_Forwarded_Message); - CPPUNIT_TEST(testSerialize_Forwarded_MessageNoDelay); - CPPUNIT_TEST(testSerialize_Forwarded_Presence); - CPPUNIT_TEST_SUITE_END(); - - public: - IsodeIQDelegationSerializerTest() {} - - void testSerialize_Forwarded_IQ() { - IsodeIQDelegationSerializer testling(&serializers); - boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); - - boost::shared_ptr<IQ> iq = IQ::createResult(JID("juliet@capulet.lit/balcony"), JID("romeo@montague.lit/orchard"), "id0", boost::make_shared<Subject>("text")); - - boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(iq); - forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); - isodeIQDelegation->setForward(forwarded); - - CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<iq from=\"romeo@montague.lit/orchard\" id=\"id0\" to=\"juliet@capulet.lit/balcony\" type=\"result\" xmlns=\"jabber:client\"><subject>text</subject></iq>" - "</forwarded>" - "</delegate>"), testling.serialize(isodeIQDelegation)); - } - - void testSerialize_Forwarded_Message() { - IsodeIQDelegationSerializer testling(&serializers); - boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); - - boost::shared_ptr<Message> message(boost::make_shared<Message>()); - 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> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(message); - forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); - - isodeIQDelegation->setForward(forwarded); - CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>" - "</delegate>"), testling.serialize(isodeIQDelegation)); - } - - void testSerialize_Forwarded_MessageNoDelay() { - IsodeIQDelegationSerializer testling(&serializers); - boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); - - boost::shared_ptr<Message> message(boost::make_shared<Message>()); - 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> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(message); - isodeIQDelegation->setForward(forwarded); - - CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>" - "</delegate>"), testling.serialize(isodeIQDelegation)); - } - - void testSerialize_Forwarded_Presence() { - IsodeIQDelegationSerializer testling(&serializers); - boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); - - boost::shared_ptr<Presence> presence(boost::make_shared<Presence>()); - presence->setType(Presence::Subscribe); - - boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(presence); - forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); - isodeIQDelegation->setForward(forwarded); - - CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<presence type=\"subscribe\" xmlns=\"jabber:client\"/>" - "</forwarded>" - "</delegate>"), testling.serialize(isodeIQDelegation)); - } - private: - FullPayloadSerializerCollection serializers; + CPPUNIT_TEST_SUITE(IsodeIQDelegationSerializerTest); + CPPUNIT_TEST(testSerialize_Forwarded_IQ); + CPPUNIT_TEST(testSerialize_Forwarded_Message); + CPPUNIT_TEST(testSerialize_Forwarded_MessageNoDelay); + CPPUNIT_TEST(testSerialize_Forwarded_Presence); + CPPUNIT_TEST_SUITE_END(); + + public: + IsodeIQDelegationSerializerTest() {} + + void testSerialize_Forwarded_IQ() { + IsodeIQDelegationSerializer testling(&serializers); + boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); + + boost::shared_ptr<IQ> iq = IQ::createResult(JID("juliet@capulet.lit/balcony"), JID("romeo@montague.lit/orchard"), "id0", boost::make_shared<Subject>("text")); + + boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(iq); + forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + isodeIQDelegation->setForward(forwarded); + + CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<iq from=\"romeo@montague.lit/orchard\" id=\"id0\" to=\"juliet@capulet.lit/balcony\" type=\"result\" xmlns=\"jabber:client\"><subject>text</subject></iq>" + "</forwarded>" + "</delegate>"), testling.serialize(isodeIQDelegation)); + } + + void testSerialize_Forwarded_Message() { + IsodeIQDelegationSerializer testling(&serializers); + boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); + + boost::shared_ptr<Message> message(boost::make_shared<Message>()); + 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> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(message); + forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + isodeIQDelegation->setForward(forwarded); + CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>" + "</delegate>"), testling.serialize(isodeIQDelegation)); + } + + void testSerialize_Forwarded_MessageNoDelay() { + IsodeIQDelegationSerializer testling(&serializers); + boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); + + boost::shared_ptr<Message> message(boost::make_shared<Message>()); + 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> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(message); + isodeIQDelegation->setForward(forwarded); + + CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>" + "</delegate>"), testling.serialize(isodeIQDelegation)); + } + + void testSerialize_Forwarded_Presence() { + IsodeIQDelegationSerializer testling(&serializers); + boost::shared_ptr<IsodeIQDelegation> isodeIQDelegation = boost::make_shared<IsodeIQDelegation>(); + + boost::shared_ptr<Presence> presence(boost::make_shared<Presence>()); + presence->setType(Presence::Subscribe); + + boost::shared_ptr<Forwarded> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(presence); + forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + isodeIQDelegation->setForward(forwarded); + + CPPUNIT_ASSERT_EQUAL(std::string("<delegate xmlns=\"http://isode.com/iq_delegation\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<presence type=\"subscribe\" xmlns=\"jabber:client\"/>" + "</forwarded>" + "</delegate>"), testling.serialize(isodeIQDelegation)); + } + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(IsodeIQDelegationSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp index d0e469f..ecb68cd 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/JingleSerializersTest.cpp @@ -32,377 +32,377 @@ using namespace Swift; class JingleSerializersTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(JingleSerializersTest); - CPPUNIT_TEST(testSerialize_StreamInitiationFileInfo); - CPPUNIT_TEST(testSerialize_StreamInitiationFileInfoRange); - - CPPUNIT_TEST(testSerialize_Xep0261_Example1); - CPPUNIT_TEST(testSerialize_Xep0261_Example9); - CPPUNIT_TEST(testSerialize_Xep0261_Example13); - - CPPUNIT_TEST(testSerialize_Xep0234_Example1); - CPPUNIT_TEST(testSerialize_Xep0234_Example3); - CPPUNIT_TEST(testSerialize_Xep0234_Example5); - CPPUNIT_TEST(testSerialize_Xep0234_Example8); - - CPPUNIT_TEST(testSerialize_Xep0260_Example1); - - CPPUNIT_TEST_SUITE_END(); - - boost::shared_ptr<JinglePayloadSerializer> createTestling() { - return boost::make_shared<JinglePayloadSerializer>(&collection); - } - - - public: - void testSerialize_StreamInitiationFileInfo() { - std::string expected = "<file" - " date=\"1969-07-21T02:56:15Z\"" - " hash=\"552da749930852c69ae5d2141d3766b1\"" - " name=\"test.txt\"" - " size=\"1022\"" - " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" - "<desc>This is a test. If this were a real file...</desc>" - "<range/>" - "</file>"; - - StreamInitiationFileInfo::ref fileInfo = boost::make_shared<StreamInitiationFileInfo>(); - fileInfo->setDate(stringToDateTime("1969-07-21T02:56:15Z")); - fileInfo->setHash("552da749930852c69ae5d2141d3766b1"); - fileInfo->setSize(1022); - fileInfo->setName("test.txt"); - fileInfo->setDescription("This is a test. If this were a real file..."); - fileInfo->setSupportsRangeRequests(true); - - boost::shared_ptr<StreamInitiationFileInfoSerializer> serializer = boost::make_shared<StreamInitiationFileInfoSerializer>(); - CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); - } - - void testSerialize_StreamInitiationFileInfoRange() { - std::string expected = "<file hash=\"552da749930852c69ae5d2141d3766b1\"" - " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" - "<range offset=\"270336\"/>" - "</file>"; - - StreamInitiationFileInfo::ref fileInfo = boost::make_shared<StreamInitiationFileInfo>(); - fileInfo->setHash("552da749930852c69ae5d2141d3766b1"); - fileInfo->setSupportsRangeRequests(true); - fileInfo->setRangeOffset(270336); - - boost::shared_ptr<StreamInitiationFileInfoSerializer> serializer = boost::make_shared<StreamInitiationFileInfoSerializer>(); - CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); - } - - - // IBB Transport Method Examples - - // http://xmpp.org/extensions/xep-0261.html#example-1 - void testSerialize_Xep0261_Example1() { - std::string expected = - "<jingle action=\"session-initiate\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"a73sjjvkla37jfea\"" - " xmlns=\"urn:xmpp:jingle:1\">" - "<content creator=\"initiator\" name=\"ex\">" - "<transport block-size=\"4096\"" - " sid=\"ch3d9s71\"" - " xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" - "</content>" - "</jingle>"; - - JinglePayload::ref payload = boost::make_shared<JinglePayload>(); - payload->setAction(JinglePayload::SessionInitiate); - payload->setSessionID("a73sjjvkla37jfea"); - payload->setInitiator(JID("romeo@montague.lit/orchard")); - - JingleIBBTransportPayload::ref transport = boost::make_shared<JingleIBBTransportPayload>(); - transport->setBlockSize(4096); - transport->setSessionID("ch3d9s71"); - - JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); - content->setCreator(JingleContentPayload::InitiatorCreator); - content->setName("ex"); - content->addTransport(transport); - - payload->addPayload(content); - - CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); - } - - // http://xmpp.org/extensions/xep-0261.html#example-9 - void testSerialize_Xep0261_Example9() { - std::string expected = - "<jingle action=\"transport-info\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"a73sjjvkla37jfea\"" - " xmlns=\"urn:xmpp:jingle:1\">" - "<content creator=\"initiator\" name=\"ex\">" - "<transport block-size=\"2048\"" - " sid=\"bt8a71h6\"" - " xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" - "</content>" - "</jingle>"; - - JinglePayload::ref payload = boost::make_shared<JinglePayload>(); - payload->setAction(JinglePayload::TransportInfo); - payload->setInitiator(JID("romeo@montague.lit/orchard")); - payload->setSessionID("a73sjjvkla37jfea"); - - JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); - content->setCreator(JingleContentPayload::InitiatorCreator); - content->setName("ex"); - - JingleIBBTransportPayload::ref transport = boost::make_shared<JingleIBBTransportPayload>(); - transport->setBlockSize(2048); - transport->setSessionID("bt8a71h6"); - - content->addTransport(transport); - payload->addPayload(content); - - CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); - } - - // http://xmpp.org/extensions/xep-0261.html#example-13 - void testSerialize_Xep0261_Example13() { - std::string expected = - "<jingle action=\"session-terminate\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"a73sjjvkla37jfea\"" - " xmlns=\"urn:xmpp:jingle:1\">" - "<reason><success/></reason>" - "</jingle>"; - - JinglePayload::ref payload = boost::make_shared<JinglePayload>(); - payload->setAction(JinglePayload::SessionTerminate); - payload->setInitiator(JID("romeo@montague.lit/orchard")); - payload->setSessionID("a73sjjvkla37jfea"); - payload->setReason(JinglePayload::Reason(JinglePayload::Reason::Success)); - - CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); - } - - // http://xmpp.org/extensions/xep-0234.html#example-1 - void testSerialize_Xep0234_Example1() { - std::string expected = "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" - "<file>" - "<date>1969-07-21T02:56:15Z</date>" - "<desc>This is a test. If this were a real file...</desc>" - "<name>test.txt</name>" - "<range/>" - "<size>1022</size>" - "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash>" - "</file>" - "</description>"; - JingleFileTransferDescription::ref desc = boost::make_shared<JingleFileTransferDescription>(); - JingleFileTransferFileInfo fileInfo; - - fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z")); - fileInfo.addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); - fileInfo.setSize(1022); - fileInfo.setName("test.txt"); - fileInfo.setDescription("This is a test. If this were a real file..."); - fileInfo.setSupportsRangeRequests(true); - - desc->setFileInfo(fileInfo); - - CPPUNIT_ASSERT_EQUAL(expected, boost::make_shared<JingleFileTransferDescriptionSerializer>()->serialize(desc)); - } - - // http://xmpp.org/extensions/xep-0234.html#example-3 - void testSerialize_Xep0234_Example3() { - std::string expected = - "<jingle action=\"session-accept\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"851ba2\"" - " xmlns=\"urn:xmpp:jingle:1\">" - "<content creator=\"initiator\" name=\"a-file-offer\">" - "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" - "<file>" - "<date>1969-07-21T02:56:15Z</date>" - "<desc>This is a test. If this were a real file...</desc>" - "<name>test.txt</name>" - "<range/>" - "<size>1022</size>" - "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash>" - "</file>" - "</description>" - /*"<transport xmlns=\"urn:xmpp:jingle:transports:s5b:1\"" - " mode=\"tcp\"" - " sid=\"vj3hs98y\">" - "<candidate cid=\"ht567dq\"" - " host=\"192.169.1.10\"" - " jid=\"juliet@capulet.lit/balcony\"" - " port=\"6539\"" - " priority=\"8257636\"" - " type=\"direct\"/>" - "<candidate cid=\"hr65dqyd\"" - " host=\"134.102.201.180\"" - " jid=\"juliet@capulet.lit/balcony\"" - " port=\"16453\"" - " priority=\"7929856\"" - " type=\"assisted\"/>" - "<candidate cid=\"grt654q2\"" - " host=\"2001:638:708:30c9:219:d1ff:fea4:a17d\"" - " jid=\"juliet@capulet.lit/balcony\"" - " port=\"6539\"" - " priority=\"8257606\"" - " type=\"direct\"/>" - "</transport>"*/ - "</content>" - "</jingle>"; - - JinglePayload::ref payload = boost::make_shared<JinglePayload>(); - payload->setAction(JinglePayload::SessionAccept); - payload->setInitiator(JID("romeo@montague.lit/orchard")); - payload->setSessionID("851ba2"); - - JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); - content->setCreator(JingleContentPayload::InitiatorCreator); - content->setName("a-file-offer"); - - JingleFileTransferDescription::ref description = boost::make_shared<JingleFileTransferDescription>(); - JingleFileTransferFileInfo fileInfo; - fileInfo.setName("test.txt"); - fileInfo.setSize(1022); - fileInfo.addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); - fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z")); - fileInfo.setDescription("This is a test. If this were a real file..."); - fileInfo.setSupportsRangeRequests(true); - - description->setFileInfo(fileInfo); - content->addDescription(description); - payload->addPayload(content); - - CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); - } - - // http://xmpp.org/extensions/xep-0234.html#example-5 - void testSerialize_Xep0234_Example5() { - std::string expected = - "<jingle" - " action=\"transport-info\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"a73sjjvkla37jfea\"" - " xmlns=\"urn:xmpp:jingle:1\">" - "<content creator=\"initiator\" name=\"ex\"/>" - /*"<transport" - " sid=\"vj3hs98y\"" - " xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" - "<candidate-used cid=\"hr65dqyd\"/>" - "</transport>"*/ - //"</content>" - "</jingle>"; - - JinglePayload::ref payload = boost::make_shared<JinglePayload>(); - payload->setAction(JinglePayload::TransportInfo); - payload->setInitiator(JID("romeo@montague.lit/orchard")); - payload->setSessionID("a73sjjvkla37jfea"); - - JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); - content->setCreator(JingleContentPayload::InitiatorCreator); - content->setName("ex"); - payload->addPayload(content); - - CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); - } - - // http://xmpp.org/extensions/xep-0234.html#example-8 - void testSerialize_Xep0234_Example8() { - std::string expected = - "<jingle" - " action=\"session-info\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"a73sjjvkla37jfea\"" - " xmlns=\"urn:xmpp:jingle:1\">" - "<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" - "<file>" - "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash>" - "</file>" - "</checksum>" - "</jingle>"; - - JinglePayload::ref payload = boost::make_shared<JinglePayload>(); - payload->setAction(JinglePayload::SessionInfo); - payload->setInitiator(JID("romeo@montague.lit/orchard")); - payload->setSessionID("a73sjjvkla37jfea"); - - JingleFileTransferHash::ref hash = boost::make_shared<JingleFileTransferHash>(); - hash->getFileInfo().addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); - - payload->addPayload(hash); - - CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); - } - - // http://xmpp.org/extensions/xep-0260.html#example-1 - void testSerialize_Xep0260_Example1() { - std::string expected = - "<jingle" - " action=\"session-initiate\"" - " initiator=\"romeo@montague.lit/orchard\"" - " sid=\"a73sjjvkla37jfea\"" - " xmlns=\"urn:xmpp:jingle:1\">" - "<content creator=\"initiator\" name=\"ex\">" - "<transport" - " dstaddr=\"1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba\"" - " mode=\"tcp\"" - " sid=\"vj3hs98y\"" - " xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" - "<candidate cid=\"hft54dqy\"" - " host=\"192.168.4.1\"" - " jid=\"romeo@montague.lit/orchard\"" - " port=\"5086\"" - " priority=\"8257636\"" - " type=\"direct\"/>" - "<candidate cid=\"hutr46fe\"" - " host=\"24.24.24.1\"" - " jid=\"romeo@montague.lit/orchard\"" - " port=\"5087\"" - " priority=\"8258636\"" - " type=\"direct\"/>" - "</transport>" - "</content>" - "</jingle>"; - - JinglePayload::ref payload = boost::make_shared<JinglePayload>(); - payload->setAction(JinglePayload::SessionInitiate); - payload->setInitiator(JID("romeo@montague.lit/orchard")); - payload->setSessionID("a73sjjvkla37jfea"); - - JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); - content->setCreator(JingleContentPayload::InitiatorCreator); - content->setName("ex"); - - JingleS5BTransportPayload::ref transport = boost::make_shared<JingleS5BTransportPayload>(); - transport->setMode(JingleS5BTransportPayload::TCPMode); - transport->setDstAddr("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba"); - transport->setSessionID("vj3hs98y"); - - JingleS5BTransportPayload::Candidate candidate1; - candidate1.cid = "hft54dqy"; - candidate1.hostPort = HostAddressPort(HostAddress("192.168.4.1"), 5086); - candidate1.jid = JID("romeo@montague.lit/orchard"); - candidate1.priority = 8257636; - candidate1.type = JingleS5BTransportPayload::Candidate::DirectType; - transport->addCandidate(candidate1); - - JingleS5BTransportPayload::Candidate candidate2; - candidate2.cid = "hutr46fe"; - candidate2.hostPort = HostAddressPort(HostAddress("24.24.24.1"), 5087); - candidate2.jid = JID("romeo@montague.lit/orchard"); - candidate2.priority = 8258636; - candidate2.type = JingleS5BTransportPayload::Candidate::DirectType; - transport->addCandidate(candidate2); - - content->addTransport(transport); - - payload->addPayload(content); - - CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); - } - - private: - FullPayloadSerializerCollection collection; + CPPUNIT_TEST_SUITE(JingleSerializersTest); + CPPUNIT_TEST(testSerialize_StreamInitiationFileInfo); + CPPUNIT_TEST(testSerialize_StreamInitiationFileInfoRange); + + CPPUNIT_TEST(testSerialize_Xep0261_Example1); + CPPUNIT_TEST(testSerialize_Xep0261_Example9); + CPPUNIT_TEST(testSerialize_Xep0261_Example13); + + CPPUNIT_TEST(testSerialize_Xep0234_Example1); + CPPUNIT_TEST(testSerialize_Xep0234_Example3); + CPPUNIT_TEST(testSerialize_Xep0234_Example5); + CPPUNIT_TEST(testSerialize_Xep0234_Example8); + + CPPUNIT_TEST(testSerialize_Xep0260_Example1); + + CPPUNIT_TEST_SUITE_END(); + + boost::shared_ptr<JinglePayloadSerializer> createTestling() { + return boost::make_shared<JinglePayloadSerializer>(&collection); + } + + + public: + void testSerialize_StreamInitiationFileInfo() { + std::string expected = "<file" + " date=\"1969-07-21T02:56:15Z\"" + " hash=\"552da749930852c69ae5d2141d3766b1\"" + " name=\"test.txt\"" + " size=\"1022\"" + " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<desc>This is a test. If this were a real file...</desc>" + "<range/>" + "</file>"; + + StreamInitiationFileInfo::ref fileInfo = boost::make_shared<StreamInitiationFileInfo>(); + fileInfo->setDate(stringToDateTime("1969-07-21T02:56:15Z")); + fileInfo->setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo->setSize(1022); + fileInfo->setName("test.txt"); + fileInfo->setDescription("This is a test. If this were a real file..."); + fileInfo->setSupportsRangeRequests(true); + + boost::shared_ptr<StreamInitiationFileInfoSerializer> serializer = boost::make_shared<StreamInitiationFileInfoSerializer>(); + CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); + } + + void testSerialize_StreamInitiationFileInfoRange() { + std::string expected = "<file hash=\"552da749930852c69ae5d2141d3766b1\"" + " xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<range offset=\"270336\"/>" + "</file>"; + + StreamInitiationFileInfo::ref fileInfo = boost::make_shared<StreamInitiationFileInfo>(); + fileInfo->setHash("552da749930852c69ae5d2141d3766b1"); + fileInfo->setSupportsRangeRequests(true); + fileInfo->setRangeOffset(270336); + + boost::shared_ptr<StreamInitiationFileInfoSerializer> serializer = boost::make_shared<StreamInitiationFileInfoSerializer>(); + CPPUNIT_ASSERT_EQUAL(expected, serializer->serializePayload(fileInfo)); + } + + + // IBB Transport Method Examples + + // http://xmpp.org/extensions/xep-0261.html#example-1 + void testSerialize_Xep0261_Example1() { + std::string expected = + "<jingle action=\"session-initiate\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"ex\">" + "<transport block-size=\"4096\"" + " sid=\"ch3d9s71\"" + " xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionInitiate); + payload->setSessionID("a73sjjvkla37jfea"); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + + JingleIBBTransportPayload::ref transport = boost::make_shared<JingleIBBTransportPayload>(); + transport->setBlockSize(4096); + transport->setSessionID("ch3d9s71"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("ex"); + content->addTransport(transport); + + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0261.html#example-9 + void testSerialize_Xep0261_Example9() { + std::string expected = + "<jingle action=\"transport-info\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"ex\">" + "<transport block-size=\"2048\"" + " sid=\"bt8a71h6\"" + " xmlns=\"urn:xmpp:jingle:transports:ibb:1\"/>" + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::TransportInfo); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("ex"); + + JingleIBBTransportPayload::ref transport = boost::make_shared<JingleIBBTransportPayload>(); + transport->setBlockSize(2048); + transport->setSessionID("bt8a71h6"); + + content->addTransport(transport); + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0261.html#example-13 + void testSerialize_Xep0261_Example13() { + std::string expected = + "<jingle action=\"session-terminate\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<reason><success/></reason>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionTerminate); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + payload->setReason(JinglePayload::Reason(JinglePayload::Reason::Success)); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-1 + void testSerialize_Xep0234_Example1() { + std::string expected = "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" + "<file>" + "<date>1969-07-21T02:56:15Z</date>" + "<desc>This is a test. If this were a real file...</desc>" + "<name>test.txt</name>" + "<range/>" + "<size>1022</size>" + "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash>" + "</file>" + "</description>"; + JingleFileTransferDescription::ref desc = boost::make_shared<JingleFileTransferDescription>(); + JingleFileTransferFileInfo fileInfo; + + fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z")); + fileInfo.addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); + fileInfo.setSize(1022); + fileInfo.setName("test.txt"); + fileInfo.setDescription("This is a test. If this were a real file..."); + fileInfo.setSupportsRangeRequests(true); + + desc->setFileInfo(fileInfo); + + CPPUNIT_ASSERT_EQUAL(expected, boost::make_shared<JingleFileTransferDescriptionSerializer>()->serialize(desc)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-3 + void testSerialize_Xep0234_Example3() { + std::string expected = + "<jingle action=\"session-accept\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"851ba2\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"a-file-offer\">" + "<description xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" + "<file>" + "<date>1969-07-21T02:56:15Z</date>" + "<desc>This is a test. If this were a real file...</desc>" + "<name>test.txt</name>" + "<range/>" + "<size>1022</size>" + "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash>" + "</file>" + "</description>" + /*"<transport xmlns=\"urn:xmpp:jingle:transports:s5b:1\"" + " mode=\"tcp\"" + " sid=\"vj3hs98y\">" + "<candidate cid=\"ht567dq\"" + " host=\"192.169.1.10\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"6539\"" + " priority=\"8257636\"" + " type=\"direct\"/>" + "<candidate cid=\"hr65dqyd\"" + " host=\"134.102.201.180\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"16453\"" + " priority=\"7929856\"" + " type=\"assisted\"/>" + "<candidate cid=\"grt654q2\"" + " host=\"2001:638:708:30c9:219:d1ff:fea4:a17d\"" + " jid=\"juliet@capulet.lit/balcony\"" + " port=\"6539\"" + " priority=\"8257606\"" + " type=\"direct\"/>" + "</transport>"*/ + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionAccept); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("851ba2"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("a-file-offer"); + + JingleFileTransferDescription::ref description = boost::make_shared<JingleFileTransferDescription>(); + JingleFileTransferFileInfo fileInfo; + fileInfo.setName("test.txt"); + fileInfo.setSize(1022); + fileInfo.addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); + fileInfo.setDate(stringToDateTime("1969-07-21T02:56:15Z")); + fileInfo.setDescription("This is a test. If this were a real file..."); + fileInfo.setSupportsRangeRequests(true); + + description->setFileInfo(fileInfo); + content->addDescription(description); + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-5 + void testSerialize_Xep0234_Example5() { + std::string expected = + "<jingle" + " action=\"transport-info\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"ex\"/>" + /*"<transport" + " sid=\"vj3hs98y\"" + " xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" + "<candidate-used cid=\"hr65dqyd\"/>" + "</transport>"*/ + //"</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::TransportInfo); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("ex"); + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0234.html#example-8 + void testSerialize_Xep0234_Example8() { + std::string expected = + "<jingle" + " action=\"session-info\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<checksum xmlns=\"urn:xmpp:jingle:apps:file-transfer:4\">" + "<file>" + "<hash algo=\"sha-1\" xmlns=\"urn:xmpp:hashes:1\">VS2nSZMIUsaa5dIUHTdmsQ==</hash>" + "</file>" + "</checksum>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionInfo); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleFileTransferHash::ref hash = boost::make_shared<JingleFileTransferHash>(); + hash->getFileInfo().addHash(HashElement("sha-1", Base64::decode("VS2nSZMIUsaa5dIUHTdmsQ=="))); + + payload->addPayload(hash); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + // http://xmpp.org/extensions/xep-0260.html#example-1 + void testSerialize_Xep0260_Example1() { + std::string expected = + "<jingle" + " action=\"session-initiate\"" + " initiator=\"romeo@montague.lit/orchard\"" + " sid=\"a73sjjvkla37jfea\"" + " xmlns=\"urn:xmpp:jingle:1\">" + "<content creator=\"initiator\" name=\"ex\">" + "<transport" + " dstaddr=\"1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba\"" + " mode=\"tcp\"" + " sid=\"vj3hs98y\"" + " xmlns=\"urn:xmpp:jingle:transports:s5b:1\">" + "<candidate cid=\"hft54dqy\"" + " host=\"192.168.4.1\"" + " jid=\"romeo@montague.lit/orchard\"" + " port=\"5086\"" + " priority=\"8257636\"" + " type=\"direct\"/>" + "<candidate cid=\"hutr46fe\"" + " host=\"24.24.24.1\"" + " jid=\"romeo@montague.lit/orchard\"" + " port=\"5087\"" + " priority=\"8258636\"" + " type=\"direct\"/>" + "</transport>" + "</content>" + "</jingle>"; + + JinglePayload::ref payload = boost::make_shared<JinglePayload>(); + payload->setAction(JinglePayload::SessionInitiate); + payload->setInitiator(JID("romeo@montague.lit/orchard")); + payload->setSessionID("a73sjjvkla37jfea"); + + JingleContentPayload::ref content = boost::make_shared<JingleContentPayload>(); + content->setCreator(JingleContentPayload::InitiatorCreator); + content->setName("ex"); + + JingleS5BTransportPayload::ref transport = boost::make_shared<JingleS5BTransportPayload>(); + transport->setMode(JingleS5BTransportPayload::TCPMode); + transport->setDstAddr("1a12fb7bc625e55f3ed5b29a53dbe0e4aa7d80ba"); + transport->setSessionID("vj3hs98y"); + + JingleS5BTransportPayload::Candidate candidate1; + candidate1.cid = "hft54dqy"; + candidate1.hostPort = HostAddressPort(HostAddress("192.168.4.1"), 5086); + candidate1.jid = JID("romeo@montague.lit/orchard"); + candidate1.priority = 8257636; + candidate1.type = JingleS5BTransportPayload::Candidate::DirectType; + transport->addCandidate(candidate1); + + JingleS5BTransportPayload::Candidate candidate2; + candidate2.cid = "hutr46fe"; + candidate2.hostPort = HostAddressPort(HostAddress("24.24.24.1"), 5087); + candidate2.jid = JID("romeo@montague.lit/orchard"); + candidate2.priority = 8258636; + candidate2.type = JingleS5BTransportPayload::Candidate::DirectType; + transport->addCandidate(candidate2); + + content->addTransport(transport); + + payload->addPayload(content); + + CPPUNIT_ASSERT_EQUAL(expected, createTestling()->serialize(payload)); + } + + private: + FullPayloadSerializerCollection collection; }; CPPUNIT_TEST_SUITE_REGISTRATION(JingleSerializersTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp index caa904e..0eda01c 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMFinSerializerTest.cpp @@ -15,50 +15,50 @@ using namespace Swift; class MAMFinSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMFinSerializerTest); - CPPUNIT_TEST(testSerialize_XEP0313_Exmaple1); - CPPUNIT_TEST(testSerialize_XEP0313_Exmaple9); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(MAMFinSerializerTest); + CPPUNIT_TEST(testSerialize_XEP0313_Exmaple1); + CPPUNIT_TEST(testSerialize_XEP0313_Exmaple9); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerialize_XEP0313_Exmaple1() { - MAMFinSerializer serializer; + public: + void testSerialize_XEP0313_Exmaple1() { + MAMFinSerializer serializer; - boost::shared_ptr<MAMFin> fin = boost::make_shared<MAMFin>(); - fin->setQueryID("f27"); + boost::shared_ptr<MAMFin> fin = boost::make_shared<MAMFin>(); + fin->setQueryID("f27"); - std::string expectedResult = - "<fin queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\"/>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(fin)); - } + std::string expectedResult = + "<fin queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\"/>"; + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(fin)); + } - void testSerialize_XEP0313_Exmaple9() { - MAMFinSerializer serializer; + void testSerialize_XEP0313_Exmaple9() { + MAMFinSerializer serializer; - boost::shared_ptr<MAMFin> fin = boost::make_shared<MAMFin>(); - fin->setComplete(true); + boost::shared_ptr<MAMFin> fin = boost::make_shared<MAMFin>(); + fin->setComplete(true); - boost::shared_ptr<ResultSet> set = boost::make_shared<ResultSet>(); - set->setFirstID(std::string("23452-4534-1")); - set->setFirstIDIndex(0); - set->setLastID(std::string("390-2342-22")); - set->setCount(16); + boost::shared_ptr<ResultSet> set = boost::make_shared<ResultSet>(); + set->setFirstID(std::string("23452-4534-1")); + set->setFirstIDIndex(0); + set->setLastID(std::string("390-2342-22")); + set->setCount(16); - fin->setResultSet(set); + fin->setResultSet(set); - std::string expectedResult = - "<fin complete=\"true\" xmlns=\"urn:xmpp:mam:0\">" - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<count>16</count>" - "<first index=\"0\">23452-4534-1</first>" - "<last>390-2342-22</last>" - "</set>" - "</fin>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(fin)); - } + std::string expectedResult = + "<fin complete=\"true\" xmlns=\"urn:xmpp:mam:0\">" + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<count>16</count>" + "<first index=\"0\">23452-4534-1</first>" + "<last>390-2342-22</last>" + "</set>" + "</fin>"; + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(fin)); + } - private: - FullPayloadSerializerCollection serializers; + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(MAMFinSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp index d9f7f12..faf788d 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMQuerySerializerTest.cpp @@ -19,55 +19,55 @@ using namespace Swift; class MAMQuerySerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMQuerySerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(MAMQuerySerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerialize() { - MAMQuerySerializer serializer; + public: + void testSerialize() { + MAMQuerySerializer serializer; - boost::shared_ptr<Form> parameters(boost::make_shared<Form>()); + boost::shared_ptr<Form> parameters(boost::make_shared<Form>()); - boost::shared_ptr<FormField> fieldType = boost::make_shared<FormField>(FormField::TextSingleType); - fieldType->setName("FORM_TYPE"); - fieldType->addValue("urn:xmpp:mam:0"); - parameters->addField(fieldType); + boost::shared_ptr<FormField> fieldType = boost::make_shared<FormField>(FormField::TextSingleType); + fieldType->setName("FORM_TYPE"); + fieldType->addValue("urn:xmpp:mam:0"); + parameters->addField(fieldType); - boost::shared_ptr<FormField> fieldStart = boost::make_shared<FormField>(FormField::TextSingleType); - fieldStart->setName("start"); - fieldStart->addValue("2010-08-07T00:00:00Z"); - parameters->addField(fieldStart); + boost::shared_ptr<FormField> fieldStart = boost::make_shared<FormField>(FormField::TextSingleType); + fieldStart->setName("start"); + fieldStart->addValue("2010-08-07T00:00:00Z"); + parameters->addField(fieldStart); - boost::shared_ptr<ResultSet> set = boost::make_shared<ResultSet>(); - set->setMaxItems(10); + boost::shared_ptr<ResultSet> set = boost::make_shared<ResultSet>(); + set->setMaxItems(10); - boost::shared_ptr<MAMQuery> query(boost::make_shared<MAMQuery>()); - query->setQueryID(std::string("id0")); - query->setNode(std::string("node1")); - query->setForm(parameters); - query->setResultSet(set); + boost::shared_ptr<MAMQuery> query(boost::make_shared<MAMQuery>()); + query->setQueryID(std::string("id0")); + query->setNode(std::string("node1")); + query->setForm(parameters); + query->setResultSet(set); - std::string expectedResult = - "<query node=\"node1\" queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<field type=\"text-single\" var=\"FORM_TYPE\">" - "<value>urn:xmpp:mam:0</value>" - "</field>" - "<field type=\"text-single\" var=\"start\">" - "<value>2010-08-07T00:00:00Z</value>" - "</field>" - "</x>" - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<max>10</max>" - "</set>" - "</query>"; + std::string expectedResult = + "<query node=\"node1\" queryid=\"id0\" xmlns=\"urn:xmpp:mam:0\">" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<field type=\"text-single\" var=\"FORM_TYPE\">" + "<value>urn:xmpp:mam:0</value>" + "</field>" + "<field type=\"text-single\" var=\"start\">" + "<value>2010-08-07T00:00:00Z</value>" + "</field>" + "</x>" + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>10</max>" + "</set>" + "</query>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(query)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(query)); + } - private: - FullPayloadSerializerCollection serializers; + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(MAMQuerySerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp index c829f3d..40ca27d 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MAMResultSerializerTest.cpp @@ -19,44 +19,44 @@ using namespace Swift; class MAMResultSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MAMResultSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); - - public: - void testSerialize() { - MAMResultSerializer serializer(&serializers); - - boost::shared_ptr<Message> message(boost::make_shared<Message>()); - 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> forwarded(boost::make_shared<Forwarded>()); - forwarded->setStanza(message); - forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); - - boost::shared_ptr<MAMResult> result(boost::make_shared<MAMResult>()); - result->setID("28482-98726-73623"); - result->setQueryID(std::string("f27")); - result->setPayload(forwarded); - - std::string expectedResult = - "<result id=\"28482-98726-73623\" queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\">" - "<forwarded xmlns=\"urn:xmpp:forward:0\">" - "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" - "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" - "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" - "</message>" - "</forwarded>" - "</result>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(result)); - } - - private: - FullPayloadSerializerCollection serializers; + CPPUNIT_TEST_SUITE(MAMResultSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + MAMResultSerializer serializer(&serializers); + + boost::shared_ptr<Message> message(boost::make_shared<Message>()); + 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> forwarded(boost::make_shared<Forwarded>()); + forwarded->setStanza(message); + forwarded->setDelay(boost::make_shared<Delay>(stringToDateTime(std::string("2010-07-10T23:08:25Z")))); + + boost::shared_ptr<MAMResult> result(boost::make_shared<MAMResult>()); + result->setID("28482-98726-73623"); + result->setQueryID(std::string("f27")); + result->setPayload(forwarded); + + std::string expectedResult = + "<result id=\"28482-98726-73623\" queryid=\"f27\" xmlns=\"urn:xmpp:mam:0\">" + "<forwarded xmlns=\"urn:xmpp:forward:0\">" + "<delay stamp=\"2010-07-10T23:08:25Z\" xmlns=\"urn:xmpp:delay\"/>" + "<message from=\"romeo@montague.lit/orchard\" to=\"juliet@capulet.lit/balcony\" type=\"chat\" xmlns=\"jabber:client\">" + "<body>Call me but love, and I'll be new baptized; Henceforth I never will be Romeo.</body>" + "</message>" + "</forwarded>" + "</result>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(result)); + } + + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(MAMResultSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp index 2c0baff..fc6b346 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MUCAdminPayloadSerializerTest.cpp @@ -15,25 +15,25 @@ using namespace Swift; class MUCAdminPayloadSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(MUCAdminPayloadSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); - - public: - MUCAdminPayloadSerializerTest() {} - - void testSerialize() { - MUCAdminPayloadSerializer testling; - boost::shared_ptr<MUCAdminPayload> admin = boost::make_shared<MUCAdminPayload>(); - MUCItem item; - item.affiliation = MUCOccupant::Owner; - item.role = MUCOccupant::Visitor; - item.reason = "malice"; - item.actor = JID("kev@tester.lit"); - admin->addItem(item); - - CPPUNIT_ASSERT_EQUAL(std::string("<query xmlns=\"http://jabber.org/protocol/muc#admin\"><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item></query>"), testling.serialize(admin)); - } + CPPUNIT_TEST_SUITE(MUCAdminPayloadSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + MUCAdminPayloadSerializerTest() {} + + void testSerialize() { + MUCAdminPayloadSerializer testling; + boost::shared_ptr<MUCAdminPayload> admin = boost::make_shared<MUCAdminPayload>(); + MUCItem item; + item.affiliation = MUCOccupant::Owner; + item.role = MUCOccupant::Visitor; + item.reason = "malice"; + item.actor = JID("kev@tester.lit"); + admin->addItem(item); + + CPPUNIT_ASSERT_EQUAL(std::string("<query xmlns=\"http://jabber.org/protocol/muc#admin\"><item affiliation=\"owner\" role=\"visitor\"><actor jid=\"kev@tester.lit\"/><reason>malice</reason></item></query>"), testling.serialize(admin)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(MUCAdminPayloadSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp index 7bd729d..223e7d9 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.cpp @@ -13,14 +13,14 @@ namespace Swift { std::string PayloadsSerializer::serialize(boost::shared_ptr<Payload> payload) { - PayloadSerializer* serializer = serializers.getPayloadSerializer(payload); - if (serializer) { - return serializer->serialize(payload); - } - else { - CPPUNIT_ASSERT(false); - return ""; - } + PayloadSerializer* serializer = serializers.getPayloadSerializer(payload); + if (serializer) { + return serializer->serialize(payload); + } + else { + CPPUNIT_ASSERT(false); + return ""; + } } diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h index 6abe396..827e9da 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PayloadsSerializer.h @@ -14,11 +14,11 @@ #include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> namespace Swift { - class PayloadsSerializer { - public: - std::string serialize(boost::shared_ptr<Payload> payload); + class PayloadsSerializer { + public: + std::string serialize(boost::shared_ptr<Payload> payload); - private: - FullPayloadSerializerCollection serializers; - }; + private: + FullPayloadSerializerCollection serializers; + }; } diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp index 272c25f..19971c2 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrioritySerializerTest.cpp @@ -13,19 +13,19 @@ using namespace Swift; class PrioritySerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PrioritySerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(PrioritySerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); - public: - PrioritySerializerTest() {} + public: + PrioritySerializerTest() {} - void testSerialize() { - PrioritySerializer testling; - boost::shared_ptr<Priority> priority(new Priority(-113)); + void testSerialize() { + PrioritySerializer testling; + boost::shared_ptr<Priority> priority(new Priority(-113)); - CPPUNIT_ASSERT_EQUAL(std::string("<priority>-113</priority>"), testling.serialize(priority)); - } + CPPUNIT_ASSERT_EQUAL(std::string("<priority>-113</priority>"), testling.serialize(priority)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(PrioritySerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp index 5236821..3b115b3 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PrivateStorageSerializerTest.cpp @@ -14,37 +14,37 @@ using namespace Swift; class PrivateStorageSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PrivateStorageSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); - - public: - PrivateStorageSerializerTest() {} - - void testSerialize() { - PayloadsSerializer serializer; - - boost::shared_ptr<PrivateStorage> privateStorage(new PrivateStorage()); - boost::shared_ptr<Storage> storage(new Storage()); - Storage::Room room; - room.name = "Swift"; - room.jid = JID("swift@rooms.swift.im"); - room.nick = "Alice"; - storage->addRoom(room); - privateStorage->setPayload(storage); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<query xmlns=\"jabber:iq:private\">" - "<storage xmlns=\"storage:bookmarks\">" - "<conference " - "autojoin=\"0\" " - "jid=\"swift@rooms.swift.im\" " - "name=\"Swift\">" - "<nick>Alice</nick>" - "</conference>" - "</storage>" - "</query>"), serializer.serialize(privateStorage)); - } + CPPUNIT_TEST_SUITE(PrivateStorageSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + PrivateStorageSerializerTest() {} + + void testSerialize() { + PayloadsSerializer serializer; + + boost::shared_ptr<PrivateStorage> privateStorage(new PrivateStorage()); + boost::shared_ptr<Storage> storage(new Storage()); + Storage::Room room; + room.name = "Swift"; + room.jid = JID("swift@rooms.swift.im"); + room.nick = "Alice"; + storage->addRoom(room); + privateStorage->setPayload(storage); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<query xmlns=\"jabber:iq:private\">" + "<storage xmlns=\"storage:bookmarks\">" + "<conference " + "autojoin=\"0\" " + "jid=\"swift@rooms.swift.im\" " + "name=\"Swift\">" + "<nick>Alice</nick>" + "</conference>" + "</storage>" + "</query>"), serializer.serialize(privateStorage)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(PrivateStorageSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp index c871a4e..b835421 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemSerializerTest.cpp @@ -17,43 +17,43 @@ using namespace Swift; class PubSubItemSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PubSubItemSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerializeEmptyID); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(PubSubItemSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerializeEmptyID); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerialize() { - PubSubItemSerializer serializer(&serializers); + public: + void testSerialize() { + PubSubItemSerializer serializer(&serializers); - boost::shared_ptr<RawXMLPayload> payload(boost::make_shared<RawXMLPayload>()); - payload->setRawXML("<payload xmlns=\"tmp\"/>"); + boost::shared_ptr<RawXMLPayload> payload(boost::make_shared<RawXMLPayload>()); + payload->setRawXML("<payload xmlns=\"tmp\"/>"); - boost::shared_ptr<PubSubItem> item(boost::make_shared<PubSubItem>()); - item->addData(payload); - item->setID("pubsub-item-1"); + boost::shared_ptr<PubSubItem> item(boost::make_shared<PubSubItem>()); + item->addData(payload); + item->setID("pubsub-item-1"); - std::string expectedResult = - "<item id=\"pubsub-item-1\" xmlns=\"http://jabber.org/protocol/pubsub\">" - "<payload xmlns=\"tmp\"/>" - "</item>"; + std::string expectedResult = + "<item id=\"pubsub-item-1\" xmlns=\"http://jabber.org/protocol/pubsub\">" + "<payload xmlns=\"tmp\"/>" + "</item>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(item)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(item)); + } - void testSerializeEmptyID() { - PubSubItemSerializer serializer(&serializers); + void testSerializeEmptyID() { + PubSubItemSerializer serializer(&serializers); - boost::shared_ptr<PubSubItem> item(boost::make_shared<PubSubItem>()); + boost::shared_ptr<PubSubItem> item(boost::make_shared<PubSubItem>()); - std::string expectedResult = - "<item xmlns=\"http://jabber.org/protocol/pubsub\"/>"; + std::string expectedResult = + "<item xmlns=\"http://jabber.org/protocol/pubsub\"/>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(item)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(item)); + } - private: - FullPayloadSerializerCollection serializers; + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(PubSubItemSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp index d557a89..fa99202 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/PubSubItemsSerializerTest.cpp @@ -17,61 +17,61 @@ using namespace Swift; class PubSubItemsSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(PubSubItemsSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerializeEmptyItems); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(PubSubItemsSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerializeEmptyItems); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerialize() { - PubSubItemsSerializer serializer(&serializers); + public: + void testSerialize() { + PubSubItemsSerializer serializer(&serializers); - boost::shared_ptr<RawXMLPayload> payload1(boost::make_shared<RawXMLPayload>()); - payload1->setRawXML("<payload xmlns=\"tmp\"/>"); + boost::shared_ptr<RawXMLPayload> payload1(boost::make_shared<RawXMLPayload>()); + payload1->setRawXML("<payload xmlns=\"tmp\"/>"); - boost::shared_ptr<PubSubItem> item1(boost::make_shared<PubSubItem>()); - item1->addData(payload1); - item1->setID("pubsub-item-1"); + boost::shared_ptr<PubSubItem> item1(boost::make_shared<PubSubItem>()); + item1->addData(payload1); + item1->setID("pubsub-item-1"); - boost::shared_ptr<RawXMLPayload> payload2(boost::make_shared<RawXMLPayload>()); - payload2->setRawXML("<payload xmlns=\"other-tmp\"/>"); + boost::shared_ptr<RawXMLPayload> payload2(boost::make_shared<RawXMLPayload>()); + payload2->setRawXML("<payload xmlns=\"other-tmp\"/>"); - boost::shared_ptr<PubSubItem> item2(boost::make_shared<PubSubItem>()); - item2->addData(payload2); - item2->setID("pubsub-item-2"); + boost::shared_ptr<PubSubItem> item2(boost::make_shared<PubSubItem>()); + item2->addData(payload2); + item2->setID("pubsub-item-2"); - boost::shared_ptr<PubSubItems> items(boost::make_shared<PubSubItems>()); - items->setNode("test-node"); - items->setSubscriptionID(std::string("sub-id")); - items->addItem(item1); - items->addItem(item2); + boost::shared_ptr<PubSubItems> items(boost::make_shared<PubSubItems>()); + items->setNode("test-node"); + items->setSubscriptionID(std::string("sub-id")); + items->addItem(item1); + items->addItem(item2); - std::string expectedResult = - "<items node=\"test-node\" subid=\"sub-id\" xmlns=\"http://jabber.org/protocol/pubsub\">" - "<item id=\"pubsub-item-1\" xmlns=\"http://jabber.org/protocol/pubsub\">" - "<payload xmlns=\"tmp\"/>" - "</item>" - "<item id=\"pubsub-item-2\" xmlns=\"http://jabber.org/protocol/pubsub\">" - "<payload xmlns=\"other-tmp\"/>" - "</item>" - "</items>"; + std::string expectedResult = + "<items node=\"test-node\" subid=\"sub-id\" xmlns=\"http://jabber.org/protocol/pubsub\">" + "<item id=\"pubsub-item-1\" xmlns=\"http://jabber.org/protocol/pubsub\">" + "<payload xmlns=\"tmp\"/>" + "</item>" + "<item id=\"pubsub-item-2\" xmlns=\"http://jabber.org/protocol/pubsub\">" + "<payload xmlns=\"other-tmp\"/>" + "</item>" + "</items>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(items)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(items)); + } - void testSerializeEmptyItems() { - PubSubItemsSerializer serializer(&serializers); + void testSerializeEmptyItems() { + PubSubItemsSerializer serializer(&serializers); - boost::shared_ptr<PubSubItems> items(boost::make_shared<PubSubItems>()); + boost::shared_ptr<PubSubItems> items(boost::make_shared<PubSubItems>()); - std::string expectedResult = - "<items node=\"\" xmlns=\"http://jabber.org/protocol/pubsub\"/>"; + std::string expectedResult = + "<items node=\"\" xmlns=\"http://jabber.org/protocol/pubsub\"/>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(items)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(items)); + } - private: - FullPayloadSerializerCollection serializers; + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(PubSubItemsSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp index 6a51182..1f40b26 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ReplaceSerializerTest.cpp @@ -18,19 +18,19 @@ using namespace Swift; class ReplaceSerializerTest: public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ReplaceSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); - - public: - ReplaceSerializerTest() {} - - void testSerialize() { - ReplaceSerializer testling; - boost::shared_ptr<Replace> replace(new Replace()); - replace->setID("bad1"); - CPPUNIT_ASSERT_EQUAL(std::string("<replace id = 'bad1' xmlns='urn:xmpp:message-correct:0'/>"), testling.serialize(replace)); - } + CPPUNIT_TEST_SUITE(ReplaceSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + ReplaceSerializerTest() {} + + void testSerialize() { + ReplaceSerializer testling; + boost::shared_ptr<Replace> replace(new Replace()); + replace->setID("bad1"); + CPPUNIT_ASSERT_EQUAL(std::string("<replace id = 'bad1' xmlns='urn:xmpp:message-correct:0'/>"), testling.serialize(replace)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ReplaceSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp index 718370f..9bc637f 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResourceBindSerializerTest.cpp @@ -13,43 +13,43 @@ using namespace Swift; class ResourceBindSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ResourceBindSerializerTest); - CPPUNIT_TEST(testSerialize_JID); - CPPUNIT_TEST(testSerialize_Resource); - CPPUNIT_TEST(testSerialize_Empty); - CPPUNIT_TEST_SUITE_END(); - - public: - ResourceBindSerializerTest() {} - - void testSerialize_JID() { - ResourceBindSerializer testling; - boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); - resourceBind->setJID(JID("somenode@example.com/someresource")); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" - "<jid>somenode@example.com/someresource</jid>" - "</bind>"), testling.serialize(resourceBind)); - } - - void testSerialize_Resource() { - ResourceBindSerializer testling; - boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); - resourceBind->setResource("someresource"); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" - "<resource>someresource</resource>" - "</bind>"), testling.serialize(resourceBind)); - } - - void testSerialize_Empty() { - ResourceBindSerializer testling; - boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); - - CPPUNIT_ASSERT_EQUAL(std::string("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"), testling.serialize(resourceBind)); - } + CPPUNIT_TEST_SUITE(ResourceBindSerializerTest); + CPPUNIT_TEST(testSerialize_JID); + CPPUNIT_TEST(testSerialize_Resource); + CPPUNIT_TEST(testSerialize_Empty); + CPPUNIT_TEST_SUITE_END(); + + public: + ResourceBindSerializerTest() {} + + void testSerialize_JID() { + ResourceBindSerializer testling; + boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); + resourceBind->setJID(JID("somenode@example.com/someresource")); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<jid>somenode@example.com/someresource</jid>" + "</bind>"), testling.serialize(resourceBind)); + } + + void testSerialize_Resource() { + ResourceBindSerializer testling; + boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); + resourceBind->setResource("someresource"); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\">" + "<resource>someresource</resource>" + "</bind>"), testling.serialize(resourceBind)); + } + + void testSerialize_Empty() { + ResourceBindSerializer testling; + boost::shared_ptr<ResourceBind> resourceBind(new ResourceBind()); + + CPPUNIT_ASSERT_EQUAL(std::string("<bind xmlns=\"urn:ietf:params:xml:ns:xmpp-bind\"/>"), testling.serialize(resourceBind)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ResourceBindSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp index b44ac0b..0b0163e 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/ResultSetSerializerTest.cpp @@ -16,103 +16,103 @@ using namespace Swift; class ResultSetSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(ResultSetSerializerTest); - CPPUNIT_TEST(testSerializeFull); - CPPUNIT_TEST(testSerializeMaxItems); - CPPUNIT_TEST(testSerializeEmptyBefore); - CPPUNIT_TEST(testSerializeFirst); - CPPUNIT_TEST(testSerializeFirstWithIndex); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(ResultSetSerializerTest); + CPPUNIT_TEST(testSerializeFull); + CPPUNIT_TEST(testSerializeMaxItems); + CPPUNIT_TEST(testSerializeEmptyBefore); + CPPUNIT_TEST(testSerializeFirst); + CPPUNIT_TEST(testSerializeFirstWithIndex); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerializeFull() { - ResultSetSerializer serializer; + public: + void testSerializeFull() { + ResultSetSerializer serializer; - boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); + boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); - resultSet->setMaxItems(100); - resultSet->setCount(800); - resultSet->setIndex(0); - resultSet->setFirstIDIndex(123); - resultSet->setFirstID(std::string("stpeter@jabber.org")); - resultSet->setLastID(std::string("peterpan@neverland.lit")); - resultSet->setAfter(std::string("09af3-cc343-b409f")); - resultSet->setBefore(std::string("decaf-badba-dbad1")); + resultSet->setMaxItems(100); + resultSet->setCount(800); + resultSet->setIndex(0); + resultSet->setFirstIDIndex(123); + resultSet->setFirstID(std::string("stpeter@jabber.org")); + resultSet->setLastID(std::string("peterpan@neverland.lit")); + resultSet->setAfter(std::string("09af3-cc343-b409f")); + resultSet->setBefore(std::string("decaf-badba-dbad1")); - std::string expectedResult = - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<max>100</max>" - "<count>800</count>" - "<index>0</index>" - "<first index=\"123\">stpeter@jabber.org</first>" - "<last>peterpan@neverland.lit</last>" - "<before>decaf-badba-dbad1</before>" - "<after>09af3-cc343-b409f</after>" - "</set>"; + std::string expectedResult = + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>100</max>" + "<count>800</count>" + "<index>0</index>" + "<first index=\"123\">stpeter@jabber.org</first>" + "<last>peterpan@neverland.lit</last>" + "<before>decaf-badba-dbad1</before>" + "<after>09af3-cc343-b409f</after>" + "</set>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } - void testSerializeMaxItems() { - ResultSetSerializer serializer; + void testSerializeMaxItems() { + ResultSetSerializer serializer; - boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); + boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); - resultSet->setMaxItems(100); + resultSet->setMaxItems(100); - std::string expectedResult = - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<max>100</max>" - "</set>"; + std::string expectedResult = + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<max>100</max>" + "</set>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } - void testSerializeEmptyBefore() { - ResultSetSerializer serializer; + void testSerializeEmptyBefore() { + ResultSetSerializer serializer; - boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); + boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); - resultSet->setBefore(std::string()); + resultSet->setBefore(std::string()); - std::string expectedResult = - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<before/>" - "</set>"; + std::string expectedResult = + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<before/>" + "</set>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } - void testSerializeFirst() { - ResultSetSerializer serializer; + void testSerializeFirst() { + ResultSetSerializer serializer; - boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); + boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); - resultSet->setFirstID(std::string("stpeter@jabber.org")); + resultSet->setFirstID(std::string("stpeter@jabber.org")); - std::string expectedResult = - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<first>stpeter@jabber.org</first>" - "</set>"; + std::string expectedResult = + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<first>stpeter@jabber.org</first>" + "</set>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } - void testSerializeFirstWithIndex() { - ResultSetSerializer serializer; + void testSerializeFirstWithIndex() { + ResultSetSerializer serializer; - boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); + boost::shared_ptr<ResultSet> resultSet(boost::make_shared<ResultSet>()); - resultSet->setFirstID(std::string("stpeter@jabber.org")); - resultSet->setFirstIDIndex(123); + resultSet->setFirstID(std::string("stpeter@jabber.org")); + resultSet->setFirstIDIndex(123); - std::string expectedResult = - "<set xmlns=\"http://jabber.org/protocol/rsm\">" - "<first index=\"123\">stpeter@jabber.org</first>" - "</set>"; + std::string expectedResult = + "<set xmlns=\"http://jabber.org/protocol/rsm\">" + "<first index=\"123\">stpeter@jabber.org</first>" + "</set>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, serializer.serialize(resultSet)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(ResultSetSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp index b6a90d9..65922f7 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterItemExchangeSerializerTest.cpp @@ -13,42 +13,42 @@ using namespace Swift; class RosterItemExchangeSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RosterItemExchangeSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); - - public: - RosterItemExchangeSerializerTest() {} - - void testSerialize() { - RosterItemExchangeSerializer testling; - boost::shared_ptr<RosterItemExchangePayload> roster(new RosterItemExchangePayload()); - - RosterItemExchangePayload::Item item1; - item1.setJID("foo@bar.com"); - item1.setName("Foo @ Bar"); - item1.setAction(RosterItemExchangePayload::Item::Add); - item1.addGroup("Group 1"); - item1.addGroup("Group 2"); - roster->addItem(item1); - - RosterItemExchangePayload::Item item2; - item2.setJID("baz@blo.com"); - item2.setName("Baz"); - item2.setAction(RosterItemExchangePayload::Item::Modify); - roster->addItem(item2); - - std::string expectedResult = - "<x xmlns=\"http://jabber.org/protocol/rosterx\">" - "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" - "<group>Group 1</group>" - "<group>Group 2</group>" - "</item>" - "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" - "</x>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); - } + CPPUNIT_TEST_SUITE(RosterItemExchangeSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + RosterItemExchangeSerializerTest() {} + + void testSerialize() { + RosterItemExchangeSerializer testling; + boost::shared_ptr<RosterItemExchangePayload> roster(new RosterItemExchangePayload()); + + RosterItemExchangePayload::Item item1; + item1.setJID("foo@bar.com"); + item1.setName("Foo @ Bar"); + item1.setAction(RosterItemExchangePayload::Item::Add); + item1.addGroup("Group 1"); + item1.addGroup("Group 2"); + roster->addItem(item1); + + RosterItemExchangePayload::Item item2; + item2.setJID("baz@blo.com"); + item2.setName("Baz"); + item2.setAction(RosterItemExchangePayload::Item::Modify); + roster->addItem(item2); + + std::string expectedResult = + "<x xmlns=\"http://jabber.org/protocol/rosterx\">" + "<item action=\"add\" jid=\"foo@bar.com\" name=\"Foo @ Bar\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "</item>" + "<item action=\"modify\" jid=\"baz@blo.com\" name=\"Baz\"/>" + "</x>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterItemExchangeSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp index b75b0a0..6670bb8 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/RosterSerializerTest.cpp @@ -12,90 +12,90 @@ using namespace Swift; class RosterSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(RosterSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerialize_ItemWithUnknownContent); - CPPUNIT_TEST(testSerialize_WithVersion); - CPPUNIT_TEST(testSerialize_WithEmptyVersion); - CPPUNIT_TEST_SUITE_END(); - - public: - void testSerialize() { - RosterSerializer testling; - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - - RosterItemPayload item1; - item1.setJID(JID("foo@bar.com")); - item1.setName("Foo @ Bar"); - item1.setSubscription(RosterItemPayload::From); - item1.addGroup("Group 1"); - item1.addGroup("Group 2"); - item1.setSubscriptionRequested(); - roster->addItem(item1); - - RosterItemPayload item2; - item2.setJID(JID("baz@blo.com")); - item2.setName("Baz"); - roster->addItem(item2); - - std::string expectedResult = - "<query xmlns=\"jabber:iq:roster\">" - "<item ask=\"subscribe\" jid=\"foo@bar.com\" name=\"Foo @ Bar\" subscription=\"from\">" - "<group>Group 1</group>" - "<group>Group 2</group>" - "</item>" - "<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\"/>" - "</query>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); - } - - void testSerialize_ItemWithUnknownContent() { - RosterSerializer testling; - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - - RosterItemPayload item; - item.setJID(JID("baz@blo.com")); - item.setName("Baz"); - item.addGroup("Group 1"); - item.addGroup("Group 2"); - item.addUnknownContent(std::string( - "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" - "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>")); - roster->addItem(item); - - std::string expectedResult = - "<query xmlns=\"jabber:iq:roster\">" - "<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\">" - "<group>Group 1</group>" - "<group>Group 2</group>" - "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" - "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" - "</item>" - "</query>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); - } - - void testSerialize_WithVersion() { - RosterSerializer testling; - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - roster->setVersion("ver20"); - - std::string expectedResult = "<query ver=\"ver20\" xmlns=\"jabber:iq:roster\"/>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); - } - - void testSerialize_WithEmptyVersion() { - RosterSerializer testling; - boost::shared_ptr<RosterPayload> roster(new RosterPayload()); - roster->setVersion(""); - - std::string expectedResult = "<query ver=\"\" xmlns=\"jabber:iq:roster\"/>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); - } + CPPUNIT_TEST_SUITE(RosterSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_ItemWithUnknownContent); + CPPUNIT_TEST(testSerialize_WithVersion); + CPPUNIT_TEST(testSerialize_WithEmptyVersion); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + + RosterItemPayload item1; + item1.setJID(JID("foo@bar.com")); + item1.setName("Foo @ Bar"); + item1.setSubscription(RosterItemPayload::From); + item1.addGroup("Group 1"); + item1.addGroup("Group 2"); + item1.setSubscriptionRequested(); + roster->addItem(item1); + + RosterItemPayload item2; + item2.setJID(JID("baz@blo.com")); + item2.setName("Baz"); + roster->addItem(item2); + + std::string expectedResult = + "<query xmlns=\"jabber:iq:roster\">" + "<item ask=\"subscribe\" jid=\"foo@bar.com\" name=\"Foo @ Bar\" subscription=\"from\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "</item>" + "<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\"/>" + "</query>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } + + void testSerialize_ItemWithUnknownContent() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + + RosterItemPayload item; + item.setJID(JID("baz@blo.com")); + item.setName("Baz"); + item.addGroup("Group 1"); + item.addGroup("Group 2"); + item.addUnknownContent(std::string( + "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" + "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>")); + roster->addItem(item); + + std::string expectedResult = + "<query xmlns=\"jabber:iq:roster\">" + "<item jid=\"baz@blo.com\" name=\"Baz\" subscription=\"none\">" + "<group>Group 1</group>" + "<group>Group 2</group>" + "<foo xmlns=\"http://example.com\"><bar xmlns=\"http://example.com\">Baz</bar></foo>" + "<baz xmlns=\"jabber:iq:roster\"><fum xmlns=\"jabber:iq:roster\">foo</fum></baz>" + "</item>" + "</query>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } + + void testSerialize_WithVersion() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->setVersion("ver20"); + + std::string expectedResult = "<query ver=\"ver20\" xmlns=\"jabber:iq:roster\"/>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } + + void testSerialize_WithEmptyVersion() { + RosterSerializer testling; + boost::shared_ptr<RosterPayload> roster(new RosterPayload()); + roster->setVersion(""); + + std::string expectedResult = "<query ver=\"\" xmlns=\"jabber:iq:roster\"/>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(roster)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(RosterSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp index 54da0bc..0dfe0b0 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SearchPayloadSerializerTest.cpp @@ -14,164 +14,164 @@ using namespace Swift; class SearchPayloadSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SearchPayloadSerializerTest); - CPPUNIT_TEST(testSerialize_Request); - CPPUNIT_TEST(testSerialize_Items); - CPPUNIT_TEST(testSerialize_DataForm); - CPPUNIT_TEST_SUITE_END(); - - public: - void testSerialize_Request() { - SearchPayloadSerializer testling; - - SearchPayload::ref payload(new SearchPayload()); - payload->setFirst("Juliet"); - payload->setLast("Capulet"); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<query xmlns=\"jabber:iq:search\">" - "<first>Juliet</first>" - "<last>Capulet</last>" - "</query>" - ), testling.serialize(payload)); - } - - void testSerialize_Items() { - SearchPayloadSerializer testling; - - SearchPayload::ref payload(new SearchPayload()); - SearchPayload::Item item1; - item1.jid = JID("juliet@capulet.com"); - item1.first = "Juliet"; - item1.last = "Capulet"; - item1.nick = "JuliC"; - item1.email = "juliet@shakespeare.lit"; - payload->addItem(item1); - - SearchPayload::Item item2; - item2.jid = JID("tybalt@shakespeare.lit"); - item2.first = "Tybalt"; - item2.last = "Capulet"; - item2.nick = "ty"; - item2.email = "tybalt@shakespeare.lit"; - payload->addItem(item2); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<query xmlns=\"jabber:iq:search\">" - "<item jid=\"juliet@capulet.com\">" - "<first>Juliet</first>" - "<last>Capulet</last>" - "<nick>JuliC</nick>" - "<email>juliet@shakespeare.lit</email>" - "</item>" - "<item jid=\"tybalt@shakespeare.lit\">" - "<first>Tybalt</first>" - "<last>Capulet</last>" - "<nick>ty</nick>" - "<email>tybalt@shakespeare.lit</email>" - "</item>" - "</query>" - ), testling.serialize(payload)); - } - - void testSerialize_DataForm() { - SearchPayloadSerializer testling; - - SearchPayload::ref payload(new SearchPayload()); - boost::shared_ptr<Form> form(new Form(Form::ResultType)); - - FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:search"); - field->setName("FORM_TYPE"); - form->addField(field); - - // reported fields - field = boost::make_shared<FormField>(FormField::TextSingleType); - field->setName("first"); - field->setLabel("Given Name"); - form->addReportedField(field); - - field = boost::make_shared<FormField>(FormField::TextSingleType); - field->setName("last"); - field->setLabel("Family Name"); - form->addReportedField(field); - - field = boost::make_shared<FormField>(FormField::JIDSingleType); - field->setName("jid"); - field->setLabel("Jabber ID"); - form->addReportedField(field); - - field = boost::make_shared<FormField>(FormField::ListSingleType); - field->setName("x-gender"); - field->setLabel("Gender"); - form->addReportedField(field); - - Form::FormItem firstItem; - field = boost::make_shared<FormField>(FormField::TextSingleType, "Benvolio"); - field->setName("first"); - firstItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague"); - field->setName("last"); - firstItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::TextSingleType, "benvolio@montague.net"); - field->setName("jid"); - firstItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::ListSingleType, "male"); - field->setName("x-gender"); - firstItem.push_back(field); - - Form::FormItem secondItem; - field = boost::make_shared<FormField>(FormField::TextSingleType, "Romeo"); - field->setName("first"); - secondItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague"); - field->setName("last"); - secondItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::TextSingleType, "romeo@montague.net"); - field->setName("jid"); - secondItem.push_back(field); - - field = boost::make_shared<FormField>(FormField::ListSingleType, "male"); - field->setName("x-gender"); - secondItem.push_back(field); - - form->addItem(firstItem); - form->addItem(secondItem); - - payload->setForm(form); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<query xmlns=\"jabber:iq:search\">" - "<x type=\"result\" xmlns=\"jabber:x:data\">" - "<field type=\"hidden\" var=\"FORM_TYPE\">" - "<value>jabber:iq:search</value>" - "</field>" - "<reported>" - "<field label=\"Given Name\" type=\"text-single\" var=\"first\"/>" - "<field label=\"Family Name\" type=\"text-single\" var=\"last\"/>" - "<field label=\"Jabber ID\" type=\"jid-single\" var=\"jid\"/>" - "<field label=\"Gender\" type=\"list-single\" var=\"x-gender\"/>" - "</reported>" - "<item>" - "<field var=\"first\"><value>Benvolio</value></field>" - "<field var=\"last\"><value>Montague</value></field>" - "<field var=\"jid\"><value>benvolio@montague.net</value></field>" - "<field var=\"x-gender\"><value>male</value></field>" - "</item>" - "<item>" - "<field var=\"first\"><value>Romeo</value></field>" - "<field var=\"last\"><value>Montague</value></field>" - "<field var=\"jid\"><value>romeo@montague.net</value></field>" - "<field var=\"x-gender\"><value>male</value></field>" - "</item>" - "</x>" - "</query>"), testling.serialize(payload)); - - } + CPPUNIT_TEST_SUITE(SearchPayloadSerializerTest); + CPPUNIT_TEST(testSerialize_Request); + CPPUNIT_TEST(testSerialize_Items); + CPPUNIT_TEST(testSerialize_DataForm); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize_Request() { + SearchPayloadSerializer testling; + + SearchPayload::ref payload(new SearchPayload()); + payload->setFirst("Juliet"); + payload->setLast("Capulet"); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<query xmlns=\"jabber:iq:search\">" + "<first>Juliet</first>" + "<last>Capulet</last>" + "</query>" + ), testling.serialize(payload)); + } + + void testSerialize_Items() { + SearchPayloadSerializer testling; + + SearchPayload::ref payload(new SearchPayload()); + SearchPayload::Item item1; + item1.jid = JID("juliet@capulet.com"); + item1.first = "Juliet"; + item1.last = "Capulet"; + item1.nick = "JuliC"; + item1.email = "juliet@shakespeare.lit"; + payload->addItem(item1); + + SearchPayload::Item item2; + item2.jid = JID("tybalt@shakespeare.lit"); + item2.first = "Tybalt"; + item2.last = "Capulet"; + item2.nick = "ty"; + item2.email = "tybalt@shakespeare.lit"; + payload->addItem(item2); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<query xmlns=\"jabber:iq:search\">" + "<item jid=\"juliet@capulet.com\">" + "<first>Juliet</first>" + "<last>Capulet</last>" + "<nick>JuliC</nick>" + "<email>juliet@shakespeare.lit</email>" + "</item>" + "<item jid=\"tybalt@shakespeare.lit\">" + "<first>Tybalt</first>" + "<last>Capulet</last>" + "<nick>ty</nick>" + "<email>tybalt@shakespeare.lit</email>" + "</item>" + "</query>" + ), testling.serialize(payload)); + } + + void testSerialize_DataForm() { + SearchPayloadSerializer testling; + + SearchPayload::ref payload(new SearchPayload()); + boost::shared_ptr<Form> form(new Form(Form::ResultType)); + + FormField::ref field = boost::make_shared<FormField>(FormField::HiddenType, "jabber:iq:search"); + field->setName("FORM_TYPE"); + form->addField(field); + + // reported fields + field = boost::make_shared<FormField>(FormField::TextSingleType); + field->setName("first"); + field->setLabel("Given Name"); + form->addReportedField(field); + + field = boost::make_shared<FormField>(FormField::TextSingleType); + field->setName("last"); + field->setLabel("Family Name"); + form->addReportedField(field); + + field = boost::make_shared<FormField>(FormField::JIDSingleType); + field->setName("jid"); + field->setLabel("Jabber ID"); + form->addReportedField(field); + + field = boost::make_shared<FormField>(FormField::ListSingleType); + field->setName("x-gender"); + field->setLabel("Gender"); + form->addReportedField(field); + + Form::FormItem firstItem; + field = boost::make_shared<FormField>(FormField::TextSingleType, "Benvolio"); + field->setName("first"); + firstItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague"); + field->setName("last"); + firstItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::TextSingleType, "benvolio@montague.net"); + field->setName("jid"); + firstItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::ListSingleType, "male"); + field->setName("x-gender"); + firstItem.push_back(field); + + Form::FormItem secondItem; + field = boost::make_shared<FormField>(FormField::TextSingleType, "Romeo"); + field->setName("first"); + secondItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::TextSingleType, "Montague"); + field->setName("last"); + secondItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::TextSingleType, "romeo@montague.net"); + field->setName("jid"); + secondItem.push_back(field); + + field = boost::make_shared<FormField>(FormField::ListSingleType, "male"); + field->setName("x-gender"); + secondItem.push_back(field); + + form->addItem(firstItem); + form->addItem(secondItem); + + payload->setForm(form); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<query xmlns=\"jabber:iq:search\">" + "<x type=\"result\" xmlns=\"jabber:x:data\">" + "<field type=\"hidden\" var=\"FORM_TYPE\">" + "<value>jabber:iq:search</value>" + "</field>" + "<reported>" + "<field label=\"Given Name\" type=\"text-single\" var=\"first\"/>" + "<field label=\"Family Name\" type=\"text-single\" var=\"last\"/>" + "<field label=\"Jabber ID\" type=\"jid-single\" var=\"jid\"/>" + "<field label=\"Gender\" type=\"list-single\" var=\"x-gender\"/>" + "</reported>" + "<item>" + "<field var=\"first\"><value>Benvolio</value></field>" + "<field var=\"last\"><value>Montague</value></field>" + "<field var=\"jid\"><value>benvolio@montague.net</value></field>" + "<field var=\"x-gender\"><value>male</value></field>" + "</item>" + "<item>" + "<field var=\"first\"><value>Romeo</value></field>" + "<field var=\"last\"><value>Montague</value></field>" + "<field var=\"jid\"><value>romeo@montague.net</value></field>" + "<field var=\"x-gender\"><value>male</value></field>" + "</item>" + "</x>" + "</query>"), testling.serialize(payload)); + + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SearchPayloadSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp index 9ad9ea6..db482ff 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp @@ -12,49 +12,49 @@ using namespace Swift; class SecurityLabelSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SecurityLabelSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerialize_EmptyLabel); - CPPUNIT_TEST_SUITE_END(); - - public: - void testSerialize() { - SecurityLabelSerializer testling; - boost::shared_ptr<SecurityLabel> securityLabel(new SecurityLabel()); - securityLabel->setDisplayMarking("SECRET"); - securityLabel->setForegroundColor("black"); - securityLabel->setBackgroundColor("red"); - securityLabel->setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"); - securityLabel->addEquivalentLabel("<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>"); - securityLabel->addEquivalentLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" - "<label>" - "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" - "</label>" - "<equivalentlabel>" - "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" - "</equivalentlabel>" - "<equivalentlabel>" - "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" - "</equivalentlabel>" - "</securitylabel>"), testling.serialize(securityLabel)); - } - - void testSerialize_EmptyLabel() { - SecurityLabelSerializer testling; - boost::shared_ptr<SecurityLabel> securityLabel(new SecurityLabel()); - securityLabel->setDisplayMarking("SECRET"); - securityLabel->setLabel(""); - - CPPUNIT_ASSERT_EQUAL(std::string( - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking>SECRET</displaymarking>" - "<label></label>" - "</securitylabel>"), testling.serialize(securityLabel)); - } + CPPUNIT_TEST_SUITE(SecurityLabelSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_EmptyLabel); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + SecurityLabelSerializer testling; + boost::shared_ptr<SecurityLabel> securityLabel(new SecurityLabel()); + securityLabel->setDisplayMarking("SECRET"); + securityLabel->setForegroundColor("black"); + securityLabel->setBackgroundColor("red"); + securityLabel->setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"); + securityLabel->addEquivalentLabel("<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>"); + securityLabel->addEquivalentLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>"); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + "<label>" + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>" + "</label>" + "<equivalentlabel>" + "<icismlabel xmlns=\"http://example.gov/IC-ISM/0\" classification=\"S\" ownerProducer=\"USA\" disseminationControls=\"FOUO\"/>" + "</equivalentlabel>" + "<equivalentlabel>" + "<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MRUCAgD9DA9BcXVhIChvYnNvbGV0ZSk=</esssecuritylabel>" + "</equivalentlabel>" + "</securitylabel>"), testling.serialize(securityLabel)); + } + + void testSerialize_EmptyLabel() { + SecurityLabelSerializer testling; + boost::shared_ptr<SecurityLabel> securityLabel(new SecurityLabel()); + securityLabel->setDisplayMarking("SECRET"); + securityLabel->setLabel(""); + + CPPUNIT_ASSERT_EQUAL(std::string( + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking>SECRET</displaymarking>" + "<label></label>" + "</securitylabel>"), testling.serialize(securityLabel)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp index e18b4d7..51c98c1 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp @@ -13,63 +13,63 @@ using namespace Swift; class SecurityLabelsCatalogSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SecurityLabelsCatalogSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(SecurityLabelsCatalogSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); - public: - SecurityLabelsCatalogSerializerTest() {} + public: + SecurityLabelsCatalogSerializerTest() {} - void testSerialize() { - SecurityLabelsCatalogSerializer testling; - boost::shared_ptr<SecurityLabelsCatalog> catalog(new SecurityLabelsCatalog()); - catalog->setTo(JID("example.com")); - catalog->setName("Default"); - catalog->setDescription("an example set of labels"); + void testSerialize() { + SecurityLabelsCatalogSerializer testling; + boost::shared_ptr<SecurityLabelsCatalog> catalog(new SecurityLabelsCatalog()); + catalog->setTo(JID("example.com")); + catalog->setName("Default"); + catalog->setDescription("an example set of labels"); - SecurityLabelsCatalog::Item item1; - boost::shared_ptr<SecurityLabel> securityLabel1(new SecurityLabel()); - item1.setLabel(securityLabel1); - securityLabel1->setDisplayMarking("SECRET"); - securityLabel1->setForegroundColor("black"); - securityLabel1->setBackgroundColor("red"); - item1.setIsDefault(false); - item1.setSelector("Classified|SECRET"); - securityLabel1->setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"); - catalog->addItem(item1); + SecurityLabelsCatalog::Item item1; + boost::shared_ptr<SecurityLabel> securityLabel1(new SecurityLabel()); + item1.setLabel(securityLabel1); + securityLabel1->setDisplayMarking("SECRET"); + securityLabel1->setForegroundColor("black"); + securityLabel1->setBackgroundColor("red"); + item1.setIsDefault(false); + item1.setSelector("Classified|SECRET"); + securityLabel1->setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel>"); + catalog->addItem(item1); - SecurityLabelsCatalog::Item item2; - boost::shared_ptr<SecurityLabel> securityLabel2(new SecurityLabel()); - item2.setLabel(securityLabel2); - securityLabel2->setDisplayMarking("CONFIDENTIAL"); - securityLabel2->setForegroundColor("black"); - securityLabel2->setBackgroundColor("navy"); - item2.setIsDefault(true); - item2.setSelector("Classified|CONFIDENTIAL"); - securityLabel2->setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"); - catalog->addItem(item2); + SecurityLabelsCatalog::Item item2; + boost::shared_ptr<SecurityLabel> securityLabel2(new SecurityLabel()); + item2.setLabel(securityLabel2); + securityLabel2->setDisplayMarking("CONFIDENTIAL"); + securityLabel2->setForegroundColor("black"); + securityLabel2->setBackgroundColor("navy"); + item2.setIsDefault(true); + item2.setSelector("Classified|CONFIDENTIAL"); + securityLabel2->setLabel("<esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel>"); + catalog->addItem(item2); - SecurityLabelsCatalog::Item item3; - item3.setSelector("Unclassified|UNCLASSIFIED"); - catalog->addItem(item3); + SecurityLabelsCatalog::Item item3; + item3.setSelector("Unclassified|UNCLASSIFIED"); + catalog->addItem(item3); - CPPUNIT_ASSERT_EQUAL(std::string( - "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:2\">" - "<item selector=\"Classified|SECRET\">" - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" - "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" - "</securitylabel>" - "</item>" - "<item default=\"true\" selector=\"Classified|CONFIDENTIAL\">" - "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" - "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" - "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" - "</securitylabel>" - "</item>" - "<item selector=\"Unclassified|UNCLASSIFIED\"/>" - "</catalog>"), testling.serialize(catalog)); - } + CPPUNIT_ASSERT_EQUAL(std::string( + "<catalog desc=\"an example set of labels\" name=\"Default\" to=\"example.com\" xmlns=\"urn:xmpp:sec-label:catalog:2\">" + "<item selector=\"Classified|SECRET\">" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"red\" fgcolor=\"black\">SECRET</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQYCAQQGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</item>" + "<item default=\"true\" selector=\"Classified|CONFIDENTIAL\">" + "<securitylabel xmlns=\"urn:xmpp:sec-label:0\">" + "<displaymarking bgcolor=\"navy\" fgcolor=\"black\">CONFIDENTIAL</displaymarking>" + "<label><esssecuritylabel xmlns=\"urn:xmpp:sec-label:ess:0\">MQMGASk=</esssecuritylabel></label>" + "</securitylabel>" + "</item>" + "<item selector=\"Unclassified|UNCLASSIFIED\"/>" + "</catalog>"), testling.serialize(catalog)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SecurityLabelsCatalogSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp index 52e64b6..5643e1e 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp @@ -13,19 +13,19 @@ using namespace Swift; class SoftwareVersionSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(SoftwareVersionSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(SoftwareVersionSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); - public: - SoftwareVersionSerializerTest() {} + public: + SoftwareVersionSerializerTest() {} - void testSerialize() { - SoftwareVersionSerializer testling; - boost::shared_ptr<SoftwareVersion> softwareVersion(new SoftwareVersion("Swift", "0.1", "Mac OS X")); + void testSerialize() { + SoftwareVersionSerializer testling; + boost::shared_ptr<SoftwareVersion> softwareVersion(new SoftwareVersion("Swift", "0.1", "Mac OS X")); - CPPUNIT_ASSERT_EQUAL(std::string("<query xmlns=\"jabber:iq:version\"><name>Swift</name><version>0.1</version><os>Mac OS X</os></query>"), testling.serialize(softwareVersion)); - } + CPPUNIT_ASSERT_EQUAL(std::string("<query xmlns=\"jabber:iq:version\"><name>Swift</name><version>0.1</version><os>Mac OS X</os></query>"), testling.serialize(softwareVersion)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(SoftwareVersionSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp index cb3ab7e..c8c2156 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusSerializerTest.cpp @@ -13,19 +13,19 @@ using namespace Swift; class StatusSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StatusSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StatusSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); - public: - StatusSerializerTest() {} + public: + StatusSerializerTest() {} - void testSerialize() { - StatusSerializer testling; - boost::shared_ptr<Status> status(new Status("I am away")); + void testSerialize() { + StatusSerializer testling; + boost::shared_ptr<Status> status(new Status("I am away")); - CPPUNIT_ASSERT_EQUAL(std::string("<status>I am away</status>"), testling.serialize(status)); - } + CPPUNIT_ASSERT_EQUAL(std::string("<status>I am away</status>"), testling.serialize(status)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StatusSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp index 272e61a..9fda49e 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp @@ -13,52 +13,52 @@ using namespace Swift; class StatusShowSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StatusShowSerializerTest); - CPPUNIT_TEST(testSerialize_Online); - CPPUNIT_TEST(testSerialize_Away); - CPPUNIT_TEST(testSerialize_FFC); - CPPUNIT_TEST(testSerialize_XA); - CPPUNIT_TEST(testSerialize_DND); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StatusShowSerializerTest); + CPPUNIT_TEST(testSerialize_Online); + CPPUNIT_TEST(testSerialize_Away); + CPPUNIT_TEST(testSerialize_FFC); + CPPUNIT_TEST(testSerialize_XA); + CPPUNIT_TEST(testSerialize_DND); + CPPUNIT_TEST_SUITE_END(); - public: - StatusShowSerializerTest() {} + public: + StatusShowSerializerTest() {} - void testSerialize_Online() { - StatusShowSerializer testling; - boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::Online)); - CPPUNIT_ASSERT_EQUAL(std::string(""), testling.serialize(statusShow)); - } + void testSerialize_Online() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::Online)); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.serialize(statusShow)); + } - void testSerialize_Away() { - StatusShowSerializer testling; - boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::Away)); - CPPUNIT_ASSERT_EQUAL(std::string("<show>away</show>"), testling.serialize(statusShow)); - } + void testSerialize_Away() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::Away)); + CPPUNIT_ASSERT_EQUAL(std::string("<show>away</show>"), testling.serialize(statusShow)); + } - void testSerialize_FFC() { - StatusShowSerializer testling; - boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::FFC)); - CPPUNIT_ASSERT_EQUAL(std::string("<show>chat</show>"), testling.serialize(statusShow)); - } + void testSerialize_FFC() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::FFC)); + CPPUNIT_ASSERT_EQUAL(std::string("<show>chat</show>"), testling.serialize(statusShow)); + } - void testSerialize_XA() { - StatusShowSerializer testling; - boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::XA)); - CPPUNIT_ASSERT_EQUAL(std::string("<show>xa</show>"), testling.serialize(statusShow)); - } + void testSerialize_XA() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::XA)); + CPPUNIT_ASSERT_EQUAL(std::string("<show>xa</show>"), testling.serialize(statusShow)); + } - void testSerialize_DND() { - StatusShowSerializer testling; - boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::DND)); - CPPUNIT_ASSERT_EQUAL(std::string("<show>dnd</show>"), testling.serialize(statusShow)); - } + void testSerialize_DND() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::DND)); + CPPUNIT_ASSERT_EQUAL(std::string("<show>dnd</show>"), testling.serialize(statusShow)); + } - void testSerialize_None() { - StatusShowSerializer testling; - boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::None)); - CPPUNIT_ASSERT_EQUAL(std::string(""), testling.serialize(statusShow)); - } + void testSerialize_None() { + StatusShowSerializer testling; + boost::shared_ptr<StatusShow> statusShow(new StatusShow(StatusShow::None)); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.serialize(statusShow)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StatusShowSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp index 3273e4b..e98ee3a 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StorageSerializerTest.cpp @@ -13,59 +13,59 @@ using namespace Swift; class StorageSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(StorageSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerialize_NoNickOrPassword); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StorageSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST(testSerialize_NoNickOrPassword); + CPPUNIT_TEST_SUITE_END(); - public: - StorageSerializerTest() {} + public: + StorageSerializerTest() {} - void testSerialize() { - PayloadsSerializer serializer; - boost::shared_ptr<Storage> storage(new Storage()); - Storage::Room room; - room.name = "Council of Oberon"; - room.autoJoin = true; - room.jid = JID("council@conference.underhill.org"); - room.nick = "Puck"; - room.password = "MyPass"; - storage->addRoom(room); - Storage::URL url; - url.name = "Complete Works of Shakespeare"; - url.url = "http://the-tech.mit.edu/Shakespeare/"; - storage->addURL(url); + void testSerialize() { + PayloadsSerializer serializer; + boost::shared_ptr<Storage> storage(new Storage()); + Storage::Room room; + room.name = "Council of Oberon"; + room.autoJoin = true; + room.jid = JID("council@conference.underhill.org"); + room.nick = "Puck"; + room.password = "MyPass"; + storage->addRoom(room); + Storage::URL url; + url.name = "Complete Works of Shakespeare"; + url.url = "http://the-tech.mit.edu/Shakespeare/"; + storage->addURL(url); - CPPUNIT_ASSERT_EQUAL(std::string( - "<storage xmlns=\"storage:bookmarks\">" - "<conference " - "autojoin=\"1\" " - "jid=\"council@conference.underhill.org\" " - "name=\"Council of Oberon\">" - "<nick>Puck</nick>" - "<password>MyPass</password>" - "</conference>" - "<url name=\"Complete Works of Shakespeare\" url=\"http://the-tech.mit.edu/Shakespeare/\"/>" - "</storage>"), serializer.serialize(storage)); - } + CPPUNIT_ASSERT_EQUAL(std::string( + "<storage xmlns=\"storage:bookmarks\">" + "<conference " + "autojoin=\"1\" " + "jid=\"council@conference.underhill.org\" " + "name=\"Council of Oberon\">" + "<nick>Puck</nick>" + "<password>MyPass</password>" + "</conference>" + "<url name=\"Complete Works of Shakespeare\" url=\"http://the-tech.mit.edu/Shakespeare/\"/>" + "</storage>"), serializer.serialize(storage)); + } - void testSerialize_NoNickOrPassword() { - PayloadsSerializer serializer; - boost::shared_ptr<Storage> storage(new Storage()); - Storage::Room room; - room.name = "Council of Oberon"; - room.autoJoin = true; - room.jid = JID("council@conference.underhill.org"); - storage->addRoom(room); + void testSerialize_NoNickOrPassword() { + PayloadsSerializer serializer; + boost::shared_ptr<Storage> storage(new Storage()); + Storage::Room room; + room.name = "Council of Oberon"; + room.autoJoin = true; + room.jid = JID("council@conference.underhill.org"); + storage->addRoom(room); - CPPUNIT_ASSERT_EQUAL(std::string( - "<storage xmlns=\"storage:bookmarks\">" - "<conference " - "autojoin=\"1\" " - "jid=\"council@conference.underhill.org\" " - "name=\"Council of Oberon\"/>" - "</storage>"), serializer.serialize(storage)); - } + CPPUNIT_ASSERT_EQUAL(std::string( + "<storage xmlns=\"storage:bookmarks\">" + "<conference " + "autojoin=\"1\" " + "jid=\"council@conference.underhill.org\" " + "name=\"Council of Oberon\"/>" + "</storage>"), serializer.serialize(storage)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(StorageSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp index 2d11dc4..ada65a9 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/StreamInitiationSerializerTest.cpp @@ -12,57 +12,57 @@ using namespace Swift; class StreamInitiationSerializerTest : public CppUnit::TestFixture{ - CPPUNIT_TEST_SUITE(StreamInitiationSerializerTest); - CPPUNIT_TEST(testSerialize_Request); - CPPUNIT_TEST(testSerialize_Response); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(StreamInitiationSerializerTest); + CPPUNIT_TEST(testSerialize_Request); + CPPUNIT_TEST(testSerialize_Response); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerialize_Request() { - StreamInitiationSerializer testling; - boost::shared_ptr<StreamInitiation> streamInitiation(new StreamInitiation()); - StreamInitiationFileInfo fileInfo("test.txt", "This is info about the file.", 1022); - streamInitiation->setID("a0"); - streamInitiation->setFileInfo(fileInfo); - streamInitiation->addProvidedMethod("http://jabber.org/protocol/bytestreams"); - streamInitiation->addProvidedMethod("jabber:iq:oob"); - streamInitiation->addProvidedMethod("http://jabber.org/protocol/ibb"); + public: + void testSerialize_Request() { + StreamInitiationSerializer testling; + boost::shared_ptr<StreamInitiation> streamInitiation(new StreamInitiation()); + StreamInitiationFileInfo fileInfo("test.txt", "This is info about the file.", 1022); + streamInitiation->setID("a0"); + streamInitiation->setFileInfo(fileInfo); + streamInitiation->addProvidedMethod("http://jabber.org/protocol/bytestreams"); + streamInitiation->addProvidedMethod("jabber:iq:oob"); + streamInitiation->addProvidedMethod("http://jabber.org/protocol/ibb"); - CPPUNIT_ASSERT_EQUAL(std::string( - "<si id=\"a0\" profile=\"http://jabber.org/protocol/si/profile/file-transfer\" xmlns=\"http://jabber.org/protocol/si\">" - "<file name=\"test.txt\" size=\"1022\" xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" - "<desc>This is info about the file.</desc>" - "</file>" - "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">" - "<x type=\"form\" xmlns=\"jabber:x:data\">" - "<field type=\"list-single\" var=\"stream-method\">" - "<option><value>http://jabber.org/protocol/bytestreams</value></option>" - "<option><value>jabber:iq:oob</value></option>" - "<option><value>http://jabber.org/protocol/ibb</value></option>" - "</field>" - "</x>" - "</feature>" - "</si>" - ), testling.serialize(streamInitiation)); - } + CPPUNIT_ASSERT_EQUAL(std::string( + "<si id=\"a0\" profile=\"http://jabber.org/protocol/si/profile/file-transfer\" xmlns=\"http://jabber.org/protocol/si\">" + "<file name=\"test.txt\" size=\"1022\" xmlns=\"http://jabber.org/protocol/si/profile/file-transfer\">" + "<desc>This is info about the file.</desc>" + "</file>" + "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">" + "<x type=\"form\" xmlns=\"jabber:x:data\">" + "<field type=\"list-single\" var=\"stream-method\">" + "<option><value>http://jabber.org/protocol/bytestreams</value></option>" + "<option><value>jabber:iq:oob</value></option>" + "<option><value>http://jabber.org/protocol/ibb</value></option>" + "</field>" + "</x>" + "</feature>" + "</si>" + ), testling.serialize(streamInitiation)); + } - void testSerialize_Response() { - StreamInitiationSerializer testling; - boost::shared_ptr<StreamInitiation> streamInitiation(new StreamInitiation()); - streamInitiation->setRequestedMethod("http://jabber.org/protocol/bytestreams"); + void testSerialize_Response() { + StreamInitiationSerializer testling; + boost::shared_ptr<StreamInitiation> streamInitiation(new StreamInitiation()); + streamInitiation->setRequestedMethod("http://jabber.org/protocol/bytestreams"); - CPPUNIT_ASSERT_EQUAL(std::string( - "<si profile=\"http://jabber.org/protocol/si/profile/file-transfer\" xmlns=\"http://jabber.org/protocol/si\">" - "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">" - "<x type=\"submit\" xmlns=\"jabber:x:data\">" - "<field type=\"list-single\" var=\"stream-method\">" - "<value>http://jabber.org/protocol/bytestreams</value>" - "</field>" - "</x>" - "</feature>" - "</si>" - ), testling.serialize(streamInitiation)); - } + CPPUNIT_ASSERT_EQUAL(std::string( + "<si profile=\"http://jabber.org/protocol/si/profile/file-transfer\" xmlns=\"http://jabber.org/protocol/si\">" + "<feature xmlns=\"http://jabber.org/protocol/feature-neg\">" + "<x type=\"submit\" xmlns=\"jabber:x:data\">" + "<field type=\"list-single\" var=\"stream-method\">" + "<value>http://jabber.org/protocol/bytestreams</value>" + "</field>" + "</x>" + "</feature>" + "</si>" + ), testling.serialize(streamInitiation)); + } }; diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp index 565f61d..3aed450 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/UserLocationSerializerTest.cpp @@ -17,88 +17,88 @@ #include <Swiften/Base/DateTime.h> #include <Swiften/Elements/UserLocation.h> -#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.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(); + CPPUNIT_TEST_SUITE(UserLocationSerializerTest); + CPPUNIT_TEST(testSerialize_withAllVariablesSet); + CPPUNIT_TEST(testSerialize_withSomeVariablesSet); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerialize_withAllVariablesSet() { - UserLocationSerializer testling(&serializers); - boost::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); + public: + void testSerialize_withAllVariablesSet() { + UserLocationSerializer testling(&serializers); + boost::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>"; + 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)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userLocation)); + } - void testSerialize_withSomeVariablesSet() { - UserLocationSerializer testling(&serializers); - boost::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")); + void testSerialize_withSomeVariablesSet() { + UserLocationSerializer testling(&serializers); + boost::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>"; + 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_ASSERT_EQUAL(expectedResult, testling.serialize(userLocation)); + } + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(UserLocationSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp index 6e2fc8b..50f2a54 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/UserTuneSerializerTest.cpp @@ -17,53 +17,53 @@ #include <Swiften/Base/DateTime.h> #include <Swiften/Elements/UserTune.h> -#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> +#include <Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.h> #include <Swiften/Serializer/PayloadSerializers/UserTuneSerializer.h> using namespace Swift; class UserTuneSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(UserTuneSerializerTest); - CPPUNIT_TEST(testSerialize_withAllVariablesSet); - CPPUNIT_TEST(testSerialize_withSomeVariablesSet); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(UserTuneSerializerTest); + CPPUNIT_TEST(testSerialize_withAllVariablesSet); + CPPUNIT_TEST(testSerialize_withSomeVariablesSet); + CPPUNIT_TEST_SUITE_END(); - public: - void testSerialize_withAllVariablesSet() { - UserTuneSerializer testling(&serializers); - boost::shared_ptr<UserTune> userTune(new UserTune()); - userTune->setRating(5); - userTune->setTitle(boost::optional<std::string>("Minion")); - userTune->setTrack(boost::optional<std::string>("Yellow")); - userTune->setArtist(boost::optional<std::string>("Ice")); - userTune->setURI(boost::optional<std::string>("Fire")); - userTune->setSource(boost::optional<std::string>("Origin")); - userTune->setLength(226); + public: + void testSerialize_withAllVariablesSet() { + UserTuneSerializer testling(&serializers); + boost::shared_ptr<UserTune> userTune(new UserTune()); + userTune->setRating(5); + userTune->setTitle(boost::optional<std::string>("Minion")); + userTune->setTrack(boost::optional<std::string>("Yellow")); + userTune->setArtist(boost::optional<std::string>("Ice")); + userTune->setURI(boost::optional<std::string>("Fire")); + userTune->setSource(boost::optional<std::string>("Origin")); + userTune->setLength(226); - std::string expectedResult = - "<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>"; + std::string expectedResult = + "<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>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune)); + } - void testSerialize_withSomeVariablesSet() { - UserTuneSerializer testling(&serializers); - boost::shared_ptr<UserTune> userTune(new UserTune()); - userTune->setTitle(boost::optional<std::string>("Minion")); - userTune->setTrack(boost::optional<std::string>("Yellow")); - userTune->setArtist(boost::optional<std::string>("Ice")); - userTune->setSource(boost::optional<std::string>("Origin")); - userTune->setLength(226); + void testSerialize_withSomeVariablesSet() { + UserTuneSerializer testling(&serializers); + boost::shared_ptr<UserTune> userTune(new UserTune()); + userTune->setTitle(boost::optional<std::string>("Minion")); + userTune->setTrack(boost::optional<std::string>("Yellow")); + userTune->setArtist(boost::optional<std::string>("Ice")); + userTune->setSource(boost::optional<std::string>("Origin")); + userTune->setLength(226); - std::string expectedResult = - "<tune xmlns=\"http://jabber.org/protocol/tune\">" - "<title>Minion</title><track>Yellow</track><artist>Ice</artist><source>Origin</source><length>226</length></tune>"; + std::string expectedResult = + "<tune xmlns=\"http://jabber.org/protocol/tune\">" + "<title>Minion</title><track>Yellow</track><artist>Ice</artist><source>Origin</source><length>226</length></tune>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune)); - } - private: - FullPayloadSerializerCollection serializers; + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(userTune)); + } + private: + FullPayloadSerializerCollection serializers; }; CPPUNIT_TEST_SUITE_REGISTRATION(UserTuneSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp index d0385d3..c4a8156 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardSerializerTest.cpp @@ -13,136 +13,136 @@ using namespace Swift; class VCardSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(VCardSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); - - public: - void testSerialize() { - VCardSerializer testling; - boost::shared_ptr<VCard> vcard(new VCard()); - vcard->setVersion("2.0"); - vcard->setFullName("Alice In Wonderland"); - vcard->setPrefix("Mrs"); - vcard->setGivenName("Alice"); - vcard->setMiddleName("In"); - vcard->setFamilyName("Wonderland"); - vcard->setSuffix("PhD"); - vcard->setNickname("DreamGirl"); - vcard->setPhoto(createByteArray("abcdef")); - vcard->setPhotoType("image/png"); - vcard->setBirthday(boost::posix_time::ptime(boost::gregorian::date(1865, 5, 4))); - vcard->addUnknownContent("<MAILER>mutt</MAILER>"); - - VCard::EMailAddress emailAddress1; - emailAddress1.address = "alice@wonderland.lit"; - emailAddress1.isHome = true; - emailAddress1.isPreferred = true; - emailAddress1.isInternet = true; - vcard->addEMailAddress(emailAddress1); - - VCard::EMailAddress address2; - address2.address = "alice@teaparty.lit"; - address2.isWork = true; - address2.isX400 = true; - vcard->addEMailAddress(address2); - - VCard::Telephone telephone1; - telephone1.number = "555-6273"; - telephone1.isHome = true; - telephone1.isVoice = true; - vcard->addTelephone(telephone1); - - VCard::Address address1; - address1.locality = "Any Town"; - address1.street = "Fake Street 123"; - address1.postalCode = "12345"; - address1.country = "USA"; - address1.isHome = true; - vcard->addAddress(address1); - - VCard::AddressLabel label1; - label1.lines.push_back("Fake Street 123"); - label1.lines.push_back("12345 Any Town"); - label1.lines.push_back("USA"); - label1.isHome = true; - vcard->addAddressLabel(label1); - - vcard->addJID(JID("alice@teaparty.lit")); - vcard->addJID(JID("alice@wonderland.lit")); - - vcard->setDescription("I once fell down a rabbit hole."); - - VCard::Organization org1; - org1.name = "Alice In Wonderland Inc."; - vcard->addOrganization(org1); - - vcard->addTitle("Some Title"); - vcard->addRole("Main Character"); - vcard->addURL("http://wonderland.lit/~alice"); - vcard->addURL("http://teaparty.lit/~alice2"); - - std::string expectedResult = - "<vCard xmlns=\"vcard-temp\">" - "<VERSION>2.0</VERSION>" - "<FN>Alice In Wonderland</FN>" - "<N>" - "<FAMILY>Wonderland</FAMILY>" - "<GIVEN>Alice</GIVEN>" - "<MIDDLE>In</MIDDLE>" - "<PREFIX>Mrs</PREFIX>" - "<SUFFIX>PhD</SUFFIX>" - "</N>" - "<EMAIL>" - "<USERID>alice@wonderland.lit</USERID>" - "<HOME/>" - "<INTERNET/>" - "<PREF/>" - "</EMAIL>" - "<EMAIL>" - "<USERID>alice@teaparty.lit</USERID>" - "<WORK/>" - "<X400/>" - "</EMAIL>" - "<NICKNAME>DreamGirl</NICKNAME>" - "<PHOTO>" - "<TYPE>image/png</TYPE>" - "<BINVAL>YWJjZGVm</BINVAL>" - "</PHOTO>" - "<BDAY>1865-05-04T00:00:00Z</BDAY>" - "<TEL>" - "<NUMBER>555-6273</NUMBER>" - "<HOME/>" - "<VOICE/>" - "</TEL>" - "<ADR>" - "<STREET>Fake Street 123</STREET>" - "<LOCALITY>Any Town</LOCALITY>" - "<PCODE>12345</PCODE>" - "<CTRY>USA</CTRY>" - "<HOME/>" - "</ADR>" - "<LABEL>" - "<LINE>Fake Street 123</LINE>" - "<LINE>12345 Any Town</LINE>" - "<LINE>USA</LINE>" - "<HOME/>" - "</LABEL>" - "<JID>alice@teaparty.lit</JID>" - "<JID>alice@wonderland.lit</JID>" - "<DESC>I once fell down a rabbit hole.</DESC>" - "<ORG>" - "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>" - "</ORG>" - "<TITLE>Some Title</TITLE>" - "<ROLE>Main Character</ROLE>" - "<URL>http://wonderland.lit/~alice</URL>" - "<URL>http://teaparty.lit/~alice2</URL>" - "<MAILER>mutt</MAILER>" - "</vCard>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(vcard)); - } + CPPUNIT_TEST_SUITE(VCardSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + void testSerialize() { + VCardSerializer testling; + boost::shared_ptr<VCard> vcard(new VCard()); + vcard->setVersion("2.0"); + vcard->setFullName("Alice In Wonderland"); + vcard->setPrefix("Mrs"); + vcard->setGivenName("Alice"); + vcard->setMiddleName("In"); + vcard->setFamilyName("Wonderland"); + vcard->setSuffix("PhD"); + vcard->setNickname("DreamGirl"); + vcard->setPhoto(createByteArray("abcdef")); + vcard->setPhotoType("image/png"); + vcard->setBirthday(boost::posix_time::ptime(boost::gregorian::date(1865, 5, 4))); + vcard->addUnknownContent("<MAILER>mutt</MAILER>"); + + VCard::EMailAddress emailAddress1; + emailAddress1.address = "alice@wonderland.lit"; + emailAddress1.isHome = true; + emailAddress1.isPreferred = true; + emailAddress1.isInternet = true; + vcard->addEMailAddress(emailAddress1); + + VCard::EMailAddress address2; + address2.address = "alice@teaparty.lit"; + address2.isWork = true; + address2.isX400 = true; + vcard->addEMailAddress(address2); + + VCard::Telephone telephone1; + telephone1.number = "555-6273"; + telephone1.isHome = true; + telephone1.isVoice = true; + vcard->addTelephone(telephone1); + + VCard::Address address1; + address1.locality = "Any Town"; + address1.street = "Fake Street 123"; + address1.postalCode = "12345"; + address1.country = "USA"; + address1.isHome = true; + vcard->addAddress(address1); + + VCard::AddressLabel label1; + label1.lines.push_back("Fake Street 123"); + label1.lines.push_back("12345 Any Town"); + label1.lines.push_back("USA"); + label1.isHome = true; + vcard->addAddressLabel(label1); + + vcard->addJID(JID("alice@teaparty.lit")); + vcard->addJID(JID("alice@wonderland.lit")); + + vcard->setDescription("I once fell down a rabbit hole."); + + VCard::Organization org1; + org1.name = "Alice In Wonderland Inc."; + vcard->addOrganization(org1); + + vcard->addTitle("Some Title"); + vcard->addRole("Main Character"); + vcard->addURL("http://wonderland.lit/~alice"); + vcard->addURL("http://teaparty.lit/~alice2"); + + std::string expectedResult = + "<vCard xmlns=\"vcard-temp\">" + "<VERSION>2.0</VERSION>" + "<FN>Alice In Wonderland</FN>" + "<N>" + "<FAMILY>Wonderland</FAMILY>" + "<GIVEN>Alice</GIVEN>" + "<MIDDLE>In</MIDDLE>" + "<PREFIX>Mrs</PREFIX>" + "<SUFFIX>PhD</SUFFIX>" + "</N>" + "<EMAIL>" + "<USERID>alice@wonderland.lit</USERID>" + "<HOME/>" + "<INTERNET/>" + "<PREF/>" + "</EMAIL>" + "<EMAIL>" + "<USERID>alice@teaparty.lit</USERID>" + "<WORK/>" + "<X400/>" + "</EMAIL>" + "<NICKNAME>DreamGirl</NICKNAME>" + "<PHOTO>" + "<TYPE>image/png</TYPE>" + "<BINVAL>YWJjZGVm</BINVAL>" + "</PHOTO>" + "<BDAY>1865-05-04T00:00:00Z</BDAY>" + "<TEL>" + "<NUMBER>555-6273</NUMBER>" + "<HOME/>" + "<VOICE/>" + "</TEL>" + "<ADR>" + "<STREET>Fake Street 123</STREET>" + "<LOCALITY>Any Town</LOCALITY>" + "<PCODE>12345</PCODE>" + "<CTRY>USA</CTRY>" + "<HOME/>" + "</ADR>" + "<LABEL>" + "<LINE>Fake Street 123</LINE>" + "<LINE>12345 Any Town</LINE>" + "<LINE>USA</LINE>" + "<HOME/>" + "</LABEL>" + "<JID>alice@teaparty.lit</JID>" + "<JID>alice@wonderland.lit</JID>" + "<DESC>I once fell down a rabbit hole.</DESC>" + "<ORG>" + "<ORGNAME>Alice In Wonderland Inc.</ORGNAME>" + "</ORG>" + "<TITLE>Some Title</TITLE>" + "<ROLE>Main Character</ROLE>" + "<URL>http://wonderland.lit/~alice</URL>" + "<URL>http://teaparty.lit/~alice2</URL>" + "<MAILER>mutt</MAILER>" + "</vCard>"; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(vcard)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(VCardSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp index fd2bb42..ed0500a 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp @@ -13,25 +13,25 @@ using namespace Swift; class VCardUpdateSerializerTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE(VCardUpdateSerializerTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST_SUITE_END(); + CPPUNIT_TEST_SUITE(VCardUpdateSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); - public: - VCardUpdateSerializerTest() {} + public: + VCardUpdateSerializerTest() {} - void testSerialize() { - VCardUpdateSerializer testling; - boost::shared_ptr<VCardUpdate> update(new VCardUpdate()); - update->setPhotoHash("sha1-hash-of-image"); + void testSerialize() { + VCardUpdateSerializer testling; + boost::shared_ptr<VCardUpdate> update(new VCardUpdate()); + update->setPhotoHash("sha1-hash-of-image"); - std::string expectedResult = - "<x xmlns=\"vcard-temp:x:update\">" - "<photo>sha1-hash-of-image</photo>" - "</x>"; + std::string expectedResult = + "<x xmlns=\"vcard-temp:x:update\">" + "<photo>sha1-hash-of-image</photo>" + "</x>"; - CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(update)); - } + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(update)); + } }; CPPUNIT_TEST_SUITE_REGISTRATION(VCardUpdateSerializerTest); |