diff options
author | Tobias Markmann <tm@ayena.de> | 2013-03-08 15:17:30 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2013-03-27 14:12:26 (GMT) |
commit | 497b647fe034a3d2cdc6d75ce0ff70e3df3aaf04 (patch) | |
tree | dc81e56199f54cf20f834c78bda7fc26ffbc38f9 /Swiften/Serializer/PayloadSerializers | |
parent | 20ead0a84fdd8c9e870e98ee6a2712bfa263d7fb (diff) | |
download | swift-contrib-497b647fe034a3d2cdc6d75ce0ff70e3df3aaf04.zip swift-contrib-497b647fe034a3d2cdc6d75ce0ff70e3df3aaf04.tar.bz2 |
Adding support for Blocking Command (XEP-0191) to Swift(-en).
Change-Id: I7c92518dc389474d520d4cf96f96a11459f73d26
License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers')
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/BlockSerializer.h | 2 | ||||
-rw-r--r-- | Swiften/Serializer/PayloadSerializers/UnitTest/BlockSerializerTest.cpp | 55 |
2 files changed, 57 insertions, 0 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/BlockSerializer.h b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h index 10ae8b0..fc628c2 100644 --- a/Swiften/Serializer/PayloadSerializers/BlockSerializer.h +++ b/Swiften/Serializer/PayloadSerializers/BlockSerializer.h @@ -8,6 +8,7 @@ #include <boost/smart_ptr/make_shared.hpp> +#include <Swiften/JID/JID.h> #include <Swiften/Serializer/GenericPayloadSerializer.h> #include <Swiften/Serializer/XML/XMLElement.h> @@ -24,6 +25,7 @@ namespace Swift { for (std::vector<JID>::const_iterator i = items.begin(); i != items.end(); ++i) { boost::shared_ptr<XMLElement> item = boost::make_shared<XMLElement>("item"); item->setAttribute("jid", *i); + element.addNode(item); } return element.serialize(); } diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/BlockSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/BlockSerializerTest.cpp new file mode 100644 index 0000000..7772381 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/BlockSerializerTest.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2013 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include <Swiften/Serializer/PayloadSerializers/BlockSerializer.h> +#include <Swiften/Elements/BlockListPayload.h> +#include <Swiften/Elements/BlockPayload.h> +#include <Swiften/Elements/UnblockPayload.h> +#include <Swiften/JID/JID.h> + +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_REGISTRATION(BlockSerializerTest); |