From abbfb6f8c410104c883c54e6f483c8c37f954d56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Mon, 22 Jun 2009 18:48:19 +0200 Subject: Added VCard-Update serializer. diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp index f9a0789..0f66b35 100644 --- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp +++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp @@ -16,6 +16,7 @@ #include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h" #include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h" #include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h" +#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" namespace Swift { @@ -35,6 +36,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() { serializers_.push_back(new SecurityLabelSerializer()); serializers_.push_back(new SecurityLabelsCatalogSerializer()); serializers_.push_back(new VCardSerializer()); + serializers_.push_back(new VCardUpdateSerializer()); foreach(PayloadSerializer* serializer, serializers_) { addSerializer(serializer); } diff --git a/Swiften/Serializer/PayloadSerializers/Makefile.inc b/Swiften/Serializer/PayloadSerializers/Makefile.inc index 893da6c..9bfbeee 100644 --- a/Swiften/Serializer/PayloadSerializers/Makefile.inc +++ b/Swiften/Serializer/PayloadSerializers/Makefile.inc @@ -9,6 +9,7 @@ SWIFTEN_SOURCES += \ Swiften/Serializer/PayloadSerializers/ResourceBindSerializer.cpp \ Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.cpp \ Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.cpp \ - Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp + Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp \ + Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp include Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc b/Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc index fce7ab9..73887a1 100644 --- a/Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/Makefile.inc @@ -9,4 +9,5 @@ UNITTEST_SOURCES += \ Swiften/Serializer/PayloadSerializers/UnitTest/StatusShowSerializerTest.cpp \ Swiften/Serializer/PayloadSerializers/UnitTest/SoftwareVersionSerializerTest.cpp \ Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelSerializerTest.cpp \ - Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp + Swiften/Serializer/PayloadSerializers/UnitTest/SecurityLabelsCatalogSerializerTest.cpp \ + Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp new file mode 100644 index 0000000..fc7e442 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/UnitTest/VCardUpdateSerializerTest.cpp @@ -0,0 +1,31 @@ +#include +#include + +#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" + +using namespace Swift; + +class VCardUpdateSerializerTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(VCardUpdateSerializerTest); + CPPUNIT_TEST(testSerialize); + CPPUNIT_TEST_SUITE_END(); + + public: + VCardUpdateSerializerTest() {} + + void testSerialize() { + VCardUpdateSerializer testling; + boost::shared_ptr update(new VCardUpdate()); + update->setPhotoHash("sha1-hash-of-image"); + + String expectedResult = + "" + "sha1-hash-of-image" + ""; + + CPPUNIT_ASSERT_EQUAL(expectedResult, testling.serialize(update)); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(VCardUpdateSerializerTest); diff --git a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp index ce4e399..4e1a762 100644 --- a/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp +++ b/Swiften/Serializer/PayloadSerializers/VCardSerializer.cpp @@ -9,7 +9,7 @@ namespace Swift { VCardSerializer::VCardSerializer() : GenericPayloadSerializer() { } -String VCardSerializer::serializePayload(boost::shared_ptr discoInfo) const { +String VCardSerializer::serializePayload(boost::shared_ptr) const { XMLElement queryElement("vCard", "vcard-temp"); // TODO return queryElement.serialize(); diff --git a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp new file mode 100644 index 0000000..540b48d --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.cpp @@ -0,0 +1,21 @@ +#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h" + +#include + +#include "Swiften/Serializer/XML/XMLElement.h" +#include "Swiften/Serializer/XML/XMLTextNode.h" + +namespace Swift { + +VCardUpdateSerializer::VCardUpdateSerializer() : GenericPayloadSerializer() { +} + +String VCardUpdateSerializer::serializePayload(boost::shared_ptr vcardUpdate) const { + XMLElement updateElement("x", "vcard-temp:x:update"); + boost::shared_ptr photoElement(new XMLElement("photo")); + photoElement->addNode(boost::shared_ptr(new XMLTextNode(vcardUpdate->getPhotoHash()))); + updateElement.addNode(photoElement); + return updateElement.serialize(); +} + +} diff --git a/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h new file mode 100644 index 0000000..e1373a9 --- /dev/null +++ b/Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h @@ -0,0 +1,13 @@ +#pragma once + +#include "Swiften/Serializer/GenericPayloadSerializer.h" +#include "Swiften/Elements/VCardUpdate.h" + +namespace Swift { + class VCardUpdateSerializer : public GenericPayloadSerializer { + public: + VCardUpdateSerializer(); + + virtual String serializePayload(boost::shared_ptr) const; + }; +} -- cgit v0.10.2-6-g49f6