summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Robbings <tim.robbings@isode.com>2015-01-26 17:33:20 (GMT)
committerKevin Smith <kevin.smith@isode.com>2015-02-17 12:17:35 (GMT)
commit55461d1b5f97591b4ab9510896ca1bc5b5e2a71f (patch)
tree17c79419d06c6740bb6ff04f6e17a13e7c4533a5 /Swiften/Parser/PayloadParsers/UnitTest
parent265b779d6766130afa8f2f166733dc172ba22dca (diff)
downloadswift-55461d1b5f97591b4ab9510896ca1bc5b5e2a71f.zip
swift-55461d1b5f97591b4ab9510896ca1bc5b5e2a71f.tar.bz2
Swiften XEP-0141 support
Classes to support XEP-0141 data forms layout. This includes <page/>, <section/>, <reportedref/> and <text/> elements. The form parser and serializer classes have also been updated to handle these new elements, with added CPPUnit tests. Test-information: Tested using updated CPPUnit tests to check the parsing and serializing of new elements. All tests complete successfully. Change-Id: Ibeab22d2834512d06c7f656acd1ef24eea39d650
Diffstat (limited to 'Swiften/Parser/PayloadParsers/UnitTest')
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
index 83fca83..c9e685e 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
+++ b/Swiften/Parser/PayloadParsers/UnitTest/FormParserTest.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2013 Isode Limited.
+ * Copyright (c) 2010-2015 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
@@ -15,6 +15,7 @@ using namespace Swift;
class FormParserTest : public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(FormParserTest);
CPPUNIT_TEST(testParse_FormInformation);
+ CPPUNIT_TEST(testParse_FormLayout);
CPPUNIT_TEST(testParse);
CPPUNIT_TEST(testParse_FormItems);
CPPUNIT_TEST_SUITE_END();
@@ -37,6 +38,49 @@ class FormParserTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(Form::SubmitType, payload->getType());
}
+ void testParse_FormLayout() {
+ PayloadsParserTester parser;
+
+ // P1 = page one, S1 = section one, F1 = field one, T1 = text one
+ CPPUNIT_ASSERT(parser.parse(
+ "<x type=\"form\" xmlns=\"jabber:x:data\">"
+ "<page label=\"P1\" xmlns=\"http://jabber.org/protocol/xdata-layout\">"
+ "<reportedref/>"
+ "<text>P1T1</text>"
+ "<fieldref var=\"P1F1\"/>"
+ "<section label=\"P1S1\">"
+ "<text>P1S1T1</text>"
+ "<fieldref var=\"P1S1F1\"/>"
+ "</section>"
+ "</page>"
+ "<page label=\"P2\" xmlns=\"http://jabber.org/protocol/xdata-layout\">"
+ "<section label=\"P2S1\">"
+ "<section label=\"P2S2\">"
+ "<section label=\"P2S3\"/>"
+ "</section>"
+ "</section>"
+ "</page>"
+ "<field label=\"field one\" type=\"text-single\" var=\"P1F1\"/>"
+ "<field label=\"field two\" type=\"text-single\" var=\"P1S1F1\"/>"
+ "</x>"));
+
+ Form* payload = dynamic_cast<Form*>(parser.getPayload().get());
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(payload->getFields().size()));
+ // PAGE ONE - parsing of element types
+ CPPUNIT_ASSERT_EQUAL(std::string("P1"), payload->getPages()[0]->getLabel());
+ CPPUNIT_ASSERT(payload->getPages()[0]->getReportedRefs()[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("P1T1"), payload->getPages()[0]->getTextElements()[0]->getTextString());
+ CPPUNIT_ASSERT_EQUAL(std::string("P1F1"), payload->getPages()[0]->getFields()[0]->getName());
+ CPPUNIT_ASSERT_EQUAL(std::string("P1S1"), payload->getPages()[0]->getChildSections()[0]->getLabel());
+ CPPUNIT_ASSERT_EQUAL(std::string("P1S1T1"), payload->getPages()[0]->getChildSections()[0]->getTextElements()[0]->getTextString());
+ CPPUNIT_ASSERT_EQUAL(std::string("P1S1F1"), payload->getPages()[0]->getChildSections()[0]->getFields()[0]->getName());
+ // PAGE TWO - parsing of nested elements
+ CPPUNIT_ASSERT_EQUAL(std::string("P2"), payload->getPages()[1]->getLabel());
+ CPPUNIT_ASSERT_EQUAL(std::string("P2S1"), payload->getPages()[1]->getChildSections()[0]->getLabel());
+ CPPUNIT_ASSERT_EQUAL(std::string("P2S2"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getLabel());
+ CPPUNIT_ASSERT_EQUAL(std::string("P2S3"), payload->getPages()[1]->getChildSections()[0]->getChildSections()[0]->getChildSections()[0]->getLabel());
+ }
+
void testParse() {
PayloadsParserTester parser;