summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-07-07 21:09:17 (GMT)
committerTobias Markmann <tm@ayena.de>2017-07-18 15:05:09 (GMT)
commitf0db4d39912e773208e9db2a3da3b68ac92ba17b (patch)
treecb6a455ba7b21d2218b3f9f2040af3bf30a39004 /Swiften/Serializer/PayloadSerializers/UnitTest
parentf21c9448c5187493fd08574962d88c2db1405512 (diff)
downloadswift-f0db4d39912e773208e9db2a3da3b68ac92ba17b.zip
swift-f0db4d39912e773208e9db2a3da3b68ac92ba17b.tar.bz2
Add MIXUpdateSubscription Element, its Parser and Serializer
Updates MIXJoin Element list of subscriptions to an unordered_set. Remove redundant MIXSubscribe Element. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Added tests for MIXUpdateSubscription Parser and Serializer based on examples in XEP 0369, which passes. Tested on Ubuntu 16.04 LTS. Change-Id: Ied06269cf329b4fdffdde4ace67ebffa4089fbde
Diffstat (limited to 'Swiften/Serializer/PayloadSerializers/UnitTest')
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXJoinSerializerTest.cpp76
-rw-r--r--Swiften/Serializer/PayloadSerializers/UnitTest/MIXUpdateSubscriptionSerializerTest.cpp36
2 files changed, 58 insertions, 54 deletions
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXJoinSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXJoinSerializerTest.cpp
index ff8aa70..2987a20 100644
--- a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXJoinSerializerTest.cpp
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXJoinSerializerTest.cpp
@@ -16,24 +16,16 @@ TEST(MIXJoinSerializerTest, XEP0369_Example22) {
auto join = std::make_shared<MIXJoin>();
join->setChannel(JID("coven@mix.shakespeare.example"));
- std::shared_ptr<MIXSubscribe> node1(new MIXSubscribe());
- node1->setNode(std::string("urn:xmpp:mix:nodes:messages"));
- join->addSubscription(node1);
- std::shared_ptr<MIXSubscribe> node2(new MIXSubscribe());
- node2->setNode(std::string("urn:xmpp:mix:nodes:presence"));
- join->addSubscription(node2);
- std::shared_ptr<MIXSubscribe> node3(new MIXSubscribe());
- node3->setNode(std::string("urn:xmpp:mix:nodes:participants"));
- join->addSubscription(node3);
- std::shared_ptr<MIXSubscribe> node4(new MIXSubscribe());
- node4->setNode(std::string("urn:xmpp:mix:nodes:config"));
- join->addSubscription(node4);
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:messages"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:presence"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:participants"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:config"));
std::string expectedResult = "<join channel=\"coven@mix.shakespeare.example\" xmlns=\"urn:xmpp:mix:0\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
"<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
- "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
"<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
- "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
"</join>";
ASSERT_EQ(expectedResult, testling.serialize(join));
}
@@ -43,24 +35,16 @@ TEST(MIXJoinSerializerTest, XEP0369_Example23) {
std::shared_ptr<MIXJoin> join(new MIXJoin());
- std::shared_ptr<MIXSubscribe> node1(new MIXSubscribe());
- node1->setNode(std::string("urn:xmpp:mix:nodes:messages"));
- join->addSubscription(node1);
- std::shared_ptr<MIXSubscribe> node2(new MIXSubscribe());
- node2->setNode(std::string("urn:xmpp:mix:nodes:presence"));
- join->addSubscription(node2);
- std::shared_ptr<MIXSubscribe> node3(new MIXSubscribe());
- node3->setNode(std::string("urn:xmpp:mix:nodes:participants"));
- join->addSubscription(node3);
- std::shared_ptr<MIXSubscribe> node4(new MIXSubscribe());
- node4->setNode(std::string("urn:xmpp:mix:nodes:config"));
- join->addSubscription(node4);
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:messages"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:presence"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:participants"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:config"));
std::string expectedResult = "<join xmlns=\"urn:xmpp:mix:0\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
"<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
- "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
"<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
- "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
"</join>";
ASSERT_EQ(expectedResult, testling.serialize(join));
}
@@ -71,24 +55,16 @@ TEST(MIXJoinSerializerTest, XEP0369_Example24) {
std::shared_ptr<MIXJoin> join(new MIXJoin());
join->setJID(JID("123456#coven@mix.shakespeare.example"));
- std::shared_ptr<MIXSubscribe> node1(new MIXSubscribe());
- node1->setNode(std::string("urn:xmpp:mix:nodes:messages"));
- join->addSubscription(node1);
- std::shared_ptr<MIXSubscribe> node2(new MIXSubscribe());
- node2->setNode(std::string("urn:xmpp:mix:nodes:presence"));
- join->addSubscription(node2);
- std::shared_ptr<MIXSubscribe> node3(new MIXSubscribe());
- node3->setNode(std::string("urn:xmpp:mix:nodes:participants"));
- join->addSubscription(node3);
- std::shared_ptr<MIXSubscribe> node4(new MIXSubscribe());
- node4->setNode(std::string("urn:xmpp:mix:nodes:config"));
- join->addSubscription(node4);
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:messages"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:presence"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:participants"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:config"));
std::string expectedResult = "<join jid=\"123456#coven@mix.shakespeare.example\" xmlns=\"urn:xmpp:mix:0\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
"<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
- "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
"<subscribe node=\"urn:xmpp:mix:nodes:participants\"/>"
- "<subscribe node=\"urn:xmpp:mix:nodes:config\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
"</join>";
ASSERT_EQ(expectedResult, testling.serialize(join));
}
@@ -98,12 +74,8 @@ TEST(MIXJoinSerializerTest, XEP0369_Example29) {
std::shared_ptr<MIXJoin> join(new MIXJoin());
- std::shared_ptr<MIXSubscribe> node1(new MIXSubscribe());
- node1->setNode(std::string("urn:xmpp:mix:nodes:messages"));
- join->addSubscription(node1);
- std::shared_ptr<MIXSubscribe> node2(new MIXSubscribe());
- node2->setNode(std::string("urn:xmpp:mix:nodes:presence"));
- join->addSubscription(node2);
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:messages"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:presence"));
std::shared_ptr<Form> parameters(std::make_shared<Form>());
parameters->setType(Form::Type::SubmitType);
@@ -141,12 +113,8 @@ TEST(MIXJoinSerializerTest, XEP0369_Example30) {
std::shared_ptr<MIXJoin> join(new MIXJoin());
join->setJID(JID("hag66@shakespeare.example"));
- std::shared_ptr<MIXSubscribe> node1(new MIXSubscribe());
- node1->setNode(std::string("urn:xmpp:mix:nodes:messages"));
- join->addSubscription(node1);
- std::shared_ptr<MIXSubscribe> node2(new MIXSubscribe());
- node2->setNode(std::string("urn:xmpp:mix:nodes:presence"));
- join->addSubscription(node2);
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:messages"));
+ join->addSubscription(std::string("urn:xmpp:mix:nodes:presence"));
std::shared_ptr<Form> parameters(std::make_shared<Form>());
parameters->setType(Form::Type::ResultType);
diff --git a/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUpdateSubscriptionSerializerTest.cpp b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUpdateSubscriptionSerializerTest.cpp
new file mode 100644
index 0000000..3e35a82
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/UnitTest/MIXUpdateSubscriptionSerializerTest.cpp
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Tarun Gupta
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+#include <gtest/gtest.h>
+
+#include <Swiften/Serializer/PayloadSerializers/MIXUpdateSubscriptionSerializer.h>
+
+using namespace Swift;
+
+TEST(MIXUpdateSubscriptionSerializerTest, XEP0369_Example28) {
+ MIXUpdateSubscriptionSerializer testling;
+
+ auto update = std::make_shared<MIXUpdateSubscription>();
+ update->addSubscription(std::string("urn:xmpp:mix:nodes:messages"));
+
+ std::string expectedResult = "<update-subscription xmlns=\"urn:xmpp:mix:0\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "</update-subscription>";
+ ASSERT_EQ(expectedResult, testling.serialize(update));
+}
+
+TEST(MIXUpdateSubscriptionSerializerTest, XEP0369_Example28WithJID) {
+ MIXUpdateSubscriptionSerializer testling;
+
+ auto update = std::make_shared<MIXUpdateSubscription>();
+ update->setJID(JID("hag66@shakespeare.example"));
+ update->addSubscription(std::string("urn:xmpp:mix:nodes:messages"));
+
+ std::string expectedResult = "<update-subscription jid=\"hag66@shakespeare.example\" xmlns=\"urn:xmpp:mix:0\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "</update-subscription>";
+ ASSERT_EQ(expectedResult, testling.serialize(update));
+}