summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2017-06-15 11:04:26 (GMT)
committerTobias Markmann <tm@ayena.de>2017-06-26 13:06:37 (GMT)
commite142d11c3fa6ae2bdfc95ee9cea54bb0000917c9 (patch)
tree591fce5f344a983a2c0dfd6b3affd08c68b02fc9 /Swiften/Parser/PayloadParsers/UnitTest
parentcfd0f09744c543efb52dcfeaef8a760a766a4d71 (diff)
downloadswift-e142d11c3fa6ae2bdfc95ee9cea54bb0000917c9.zip
swift-e142d11c3fa6ae2bdfc95ee9cea54bb0000917c9.tar.bz2
Adds MIX Join Element, its Parser and Serializer.
Add MIXDestroySerializer to FullPayloadSerializerCollection. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Added tests for MIX Join Parser and Serializer based on examples in XEP 0369, which passes. Tested on Ubuntu 16.04 LTS. Change-Id: Ibf7446dd65714dccdd39c485549fd9fb9faba40c
Diffstat (limited to 'Swiften/Parser/PayloadParsers/UnitTest')
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/MIXJoinParserTest.cpp180
1 files changed, 180 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXJoinParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXJoinParserTest.cpp
new file mode 100644
index 0000000..7a422f4
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXJoinParserTest.cpp
@@ -0,0 +1,180 @@
+/*
+ * 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/Elements/MIXJoin.h>
+#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h>
+
+using namespace Swift;
+
+TEST(MIXJoinParserTest, XEP0369_Example22) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<join xmlns=\"urn:xmpp:mix:1\" channel=\"coven@mix.shakespeare.example\">"
+ "<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\"/>"
+ "</join>"
+ ));
+
+ MIXJoin::ref payload = parser.getPayload<MIXJoin>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_TRUE(payload->getChannel());
+ ASSERT_EQ(JID("coven@mix.shakespeare.example"), *payload->getChannel());
+ ASSERT_FALSE(payload->getJID());
+ ASSERT_FALSE(payload->getForm());
+
+ const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
+ ASSERT_EQ(static_cast<size_t>(4), items.size());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:participants"), items[2]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:config"), items[3]->getNode());
+}
+
+TEST(MIXJoinParserTest, XEP0369_Example23) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<join xmlns=\"urn:xmpp:mix:1\">"
+ "<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\"/>"
+ "</join>"
+ ));
+
+ MIXJoin::ref payload = parser.getPayload<MIXJoin>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_FALSE(payload->getChannel());
+ ASSERT_FALSE(payload->getJID());
+ ASSERT_FALSE(payload->getForm());
+
+ const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
+ ASSERT_EQ(static_cast<size_t>(4), items.size());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:participants"), items[2]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:config"), items[3]->getNode());
+}
+
+TEST(MIXJoinParserTest, XEP0369_Example24) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<join xmlns=\"urn:xmpp:mix:1\" jid=\"123456#coven@mix.shakespeare.example\">"
+ "<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\"/>"
+ "</join>"
+ ));
+
+ MIXJoin::ref payload = parser.getPayload<MIXJoin>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_FALSE(payload->getChannel());
+ ASSERT_TRUE(payload->getJID());
+ ASSERT_EQ(JID("123456#coven@mix.shakespeare.example"), *payload->getJID());
+ ASSERT_FALSE(payload->getForm());
+
+ const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
+ ASSERT_EQ(static_cast<size_t>(4), items.size());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:participants"), items[2]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:config"), items[3]->getNode());
+}
+
+TEST(MIXJoinParserTest, XEP0369_Example29) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<join xmlns=\"urn:xmpp:mix:1\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
+ "<x xmlns=\"jabber:x:data\" type=\"submit\">"
+ "<field var=\"FORM_TYPE\" type=\"hidden\">"
+ "<value>urn:xmpp:mix:1</value>"
+ "</field>"
+ "<field var=\"JID Visibility\">"
+ "<value>never</value>"
+ "</field>"
+ "</x>"
+ "</join>"));
+
+ MIXJoin::ref payload = parser.getPayload<MIXJoin>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_FALSE(payload->getChannel());
+ ASSERT_FALSE(payload->getJID());
+ const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
+ ASSERT_EQ(static_cast<size_t>(2), items.size());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());
+
+ ASSERT_TRUE(payload->getForm());
+ ASSERT_EQ(Form::Type::SubmitType, payload->getForm()->getType());
+ std::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE");
+ ASSERT_TRUE(fieldType);
+
+ std::shared_ptr<FormField> fieldJIDVisibility = payload->getForm()->getField("JID Visibility");
+ ASSERT_TRUE(fieldJIDVisibility);
+ ASSERT_EQ(std::string("never"), fieldJIDVisibility->getTextSingleValue());
+}
+
+TEST(MIXJoinParserTest, XEP0369_Example30) {
+ PayloadsParserTester parser;
+ ASSERT_TRUE(parser.parse(
+ "<join xmlns=\"urn:xmpp:mix:1\" jid=\"hag66@shakespeare.example\">"
+ "<subscribe node=\"urn:xmpp:mix:nodes:messages\"/>"
+ "<subscribe node=\"urn:xmpp:mix:nodes:presence\"/>"
+ "<x xmlns=\"jabber:x:data\" type=\"result\">"
+ "<field var=\"FORM_TYPE\" type=\"hidden\">"
+ "<value>urn:xmpp:mix:1</value>"
+ "</field>"
+ "<field var=\"JID Visibility\">"
+ "<value>never</value>"
+ "</field>"
+ "<field var=\"Private Messages\">"
+ "<value>allow</value>"
+ "</field>"
+ "<field var=\"vCard\">"
+ "<value>block</value>"
+ "</field>"
+ "</x>"
+ "</join>"));
+
+ MIXJoin::ref payload = parser.getPayload<MIXJoin>();
+ ASSERT_TRUE(payload);
+
+ ASSERT_FALSE(payload->getChannel());
+ ASSERT_TRUE(payload->getJID());
+ ASSERT_EQ(JID("hag66@shakespeare.example"), *payload->getJID());
+
+ const std::vector<MIXSubscribe::ref> items = payload->getSubscriptions();
+ ASSERT_EQ(static_cast<size_t>(2), items.size());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:messages"), items[0]->getNode());
+ ASSERT_EQ(std::string("urn:xmpp:mix:nodes:presence"), items[1]->getNode());
+
+ ASSERT_TRUE(payload->getForm());
+ ASSERT_EQ(Form::Type::ResultType, payload->getForm()->getType());
+ std::shared_ptr<FormField> fieldType = payload->getForm()->getField("FORM_TYPE");
+ ASSERT_TRUE(fieldType);
+
+ std::shared_ptr<FormField> fieldJIDVisibility = payload->getForm()->getField("JID Visibility");
+ ASSERT_TRUE(fieldJIDVisibility);
+ ASSERT_EQ(std::string("never"), fieldJIDVisibility->getTextSingleValue());
+
+ std::shared_ptr<FormField> fieldprivateMessages = payload->getForm()->getField("Private Messages");
+ ASSERT_TRUE(fieldprivateMessages);
+ ASSERT_EQ(std::string("allow"), fieldprivateMessages->getTextSingleValue());
+
+ std::shared_ptr<FormField> vCard = payload->getForm()->getField("vCard");
+ ASSERT_TRUE(vCard);
+ ASSERT_EQ(std::string("block"), vCard->getTextSingleValue());
+}