diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2017-06-24 16:09:39 (GMT) |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2017-07-03 19:02:35 (GMT) |
commit | 4f61e116c83be5e38a8406ac3285a07b84712ec1 (patch) | |
tree | 1e7b2c908b1bc8e59b675ff940c32f2b505ccb55 /Swiften/Parser/PayloadParsers/UnitTest | |
parent | e142d11c3fa6ae2bdfc95ee9cea54bb0000917c9 (diff) | |
download | swift-4f61e116c83be5e38a8406ac3285a07b84712ec1.zip swift-4f61e116c83be5e38a8406ac3285a07b84712ec1.tar.bz2 |
Adds MIX Create Element, its Parser and Serializer
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Added tests for MIX Create Parser and Serializer based on
examples in XEP 0369, which passes.
Change-Id: I33b85c8243d55cd293c886f2607bdd9dec6c7bdb
Diffstat (limited to 'Swiften/Parser/PayloadParsers/UnitTest')
-rw-r--r-- | Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp new file mode 100644 index 0000000..85c79c6 --- /dev/null +++ b/Swiften/Parser/PayloadParsers/UnitTest/MIXCreateParserTest.cpp @@ -0,0 +1,89 @@ +/* + * 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/MIXCreate.h> +#include <Swiften/Parser/PayloadParsers/UnitTest/PayloadsParserTester.h> + +using namespace Swift; + +TEST(MIXCreateParserTest, XEP0369_Example68) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<create xmlns=\"urn:xmpp:mix:1\"/>" + )); + + auto payload = parser.getPayload<MIXCreate>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getData()); + ASSERT_FALSE(payload->getChannel()); +} + +TEST(MIXCreateParserTest, XEP0369_Example66) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<create channel=\"coven\" xmlns=\"urn:xmpp:mix:1\"/>" + )); + + auto payload = parser.getPayload<MIXCreate>(); + ASSERT_TRUE(payload); + + ASSERT_FALSE(payload->getData()); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(std::string("coven"), *payload->getChannel()); +} + +TEST(MIXCreateParserTest, XEP0369_Example67) { + PayloadsParserTester parser; + ASSERT_TRUE(parser.parse( + "<create channel=\"coven\" xmlns=\"urn:xmpp:mix:1\">" + "<x xmlns=\"jabber:x:data\" type=\"result\">" + "<field var=\"FORM_TYPE\" type=\"hidden\">" + "<value>urn:xmpp:mix:1</value>" + "</field>" + "<field var=\"Owner\">" + "<value>hecate@shakespeare.lit</value>" + "<value>greymalkin@shakespeare.lit</value>" + "</field>" + "<field var=\"Messages Node Subscription\">" + "<value>allowed</value>" + "</field>" + "<field var=\"JID Visibility\">" + "<value>jid-mandatory-visible</value>" + "</field>" + "<field var=\"No Private Messages\">" + "<value>true</value>" + "</field>" + "</x>" + "</create>" + )); + + auto payload = parser.getPayload<MIXCreate>(); + ASSERT_TRUE(payload); + + ASSERT_TRUE(payload->getData()); + ASSERT_EQ(Form::Type::ResultType, payload->getData()->getType()); + std::shared_ptr<FormField> fieldType = payload->getData()->getField("FORM_TYPE"); + ASSERT_TRUE(fieldType); + + std::shared_ptr<FormField> fieldJIDVisibility = payload->getData()->getField("JID Visibility"); + ASSERT_TRUE(fieldJIDVisibility); + ASSERT_EQ(std::string("jid-mandatory-visible"), fieldJIDVisibility->getTextSingleValue()); + + std::shared_ptr<FormField> fieldprivateMessages = payload->getData()->getField("No Private Messages"); + ASSERT_TRUE(fieldprivateMessages); + ASSERT_EQ(std::string("true"), fieldprivateMessages->getTextSingleValue()); + + std::shared_ptr<FormField> nodeSubs = payload->getData()->getField("Messages Node Subscription"); + ASSERT_TRUE(nodeSubs); + ASSERT_EQ(std::string("allowed"), nodeSubs->getTextSingleValue()); + + ASSERT_TRUE(payload->getChannel()); + ASSERT_EQ(std::string("coven"), *payload->getChannel()); +} |