summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-11 15:27:08 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-11 15:27:08 (GMT)
commite1a2d258479cd915e8c30c5c996b58da3da3e55d (patch)
tree5028f999ae6d752b0c5d80752d41f4b8b26f8cae /Swiften/Parser/UnitTest
parenta7963958d9a649dd77c22e65edcf35210a1f66c1 (diff)
downloadswift-contrib-e1a2d258479cd915e8c30c5c996b58da3da3e55d.zip
swift-contrib-e1a2d258479cd915e8c30c5c996b58da3da3e55d.tar.bz2
PayloadParserFactoryCollection additions.
Added the ability to set a default PayloadParserFactory. Check factories in reverse order. Add PayloadParserFactoryCollection unit test.
Diffstat (limited to 'Swiften/Parser/UnitTest')
-rw-r--r--Swiften/Parser/UnitTest/Makefile.inc1
-rw-r--r--Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp97
2 files changed, 98 insertions, 0 deletions
diff --git a/Swiften/Parser/UnitTest/Makefile.inc b/Swiften/Parser/UnitTest/Makefile.inc
index 4f9c59e..be570d2 100644
--- a/Swiften/Parser/UnitTest/Makefile.inc
+++ b/Swiften/Parser/UnitTest/Makefile.inc
@@ -1,4 +1,5 @@
UNITTEST_SOURCES += \
+ Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp \
Swiften/Parser/UnitTest/XMPPParserTest.cpp \
Swiften/Parser/UnitTest/StanzaParserTest.cpp \
Swiften/Parser/UnitTest/MessageParserTest.cpp \
diff --git a/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp
new file mode 100644
index 0000000..bfd2c2c
--- /dev/null
+++ b/Swiften/Parser/UnitTest/PayloadParserFactoryCollectionTest.cpp
@@ -0,0 +1,97 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Parser/PayloadParserFactoryCollection.h"
+#include "Swiften/Parser/PayloadParserFactory.h"
+
+using namespace Swift;
+
+class PayloadParserFactoryCollectionTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(PayloadParserFactoryCollectionTest);
+ CPPUNIT_TEST(testGetPayloadParserFactory);
+ CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchingFactory);
+ CPPUNIT_TEST(testGetPayloadParserFactory_TwoMatchingFactories);
+ CPPUNIT_TEST(testGetPayloadParserFactory_MatchWithDefaultFactory);
+ CPPUNIT_TEST(testGetPayloadParserFactory_NoMatchWithDefaultFactory);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ PayloadParserFactoryCollectionTest() {}
+
+ void setUp() {
+ }
+
+ void tearDown() {
+ }
+
+ void testGetPayloadParserFactory() {
+ PayloadParserFactoryCollection testling;
+ DummyFactory factory1("foo");
+ testling.addFactory(&factory1);
+ DummyFactory factory2("bar");
+ testling.addFactory(&factory2);
+ DummyFactory factory3("baz");
+ testling.addFactory(&factory3);
+
+ PayloadParserFactory* factory = testling.getPayloadParserFactory("bar", "", AttributeMap());
+
+ CPPUNIT_ASSERT(factory == &factory2);
+ }
+
+ void testGetPayloadParserFactory_NoMatchingFactory() {
+ PayloadParserFactoryCollection testling;
+ DummyFactory factory("foo");
+
+ CPPUNIT_ASSERT(!testling.getPayloadParserFactory("bar", "", AttributeMap()));
+ }
+
+ void testGetPayloadParserFactory_TwoMatchingFactories() {
+ PayloadParserFactoryCollection testling;
+ DummyFactory factory1("foo");
+ testling.addFactory(&factory1);
+ DummyFactory factory2("foo");
+ testling.addFactory(&factory2);
+
+ PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap());
+
+ CPPUNIT_ASSERT(factory == &factory2);
+ }
+
+ void testGetPayloadParserFactory_MatchWithDefaultFactory() {
+ PayloadParserFactoryCollection testling;
+ DummyFactory factory1("foo");
+ testling.addFactory(&factory1);
+ DummyFactory factory2;
+ testling.setDefaultFactory(&factory2);
+
+ PayloadParserFactory* factory = testling.getPayloadParserFactory("foo", "", AttributeMap());
+
+ CPPUNIT_ASSERT(factory == &factory1);
+ }
+
+ void testGetPayloadParserFactory_NoMatchWithDefaultFactory() {
+ PayloadParserFactoryCollection testling;
+ DummyFactory factory1("foo");
+ testling.addFactory(&factory1);
+ DummyFactory factory2;
+ testling.setDefaultFactory(&factory2);
+
+ PayloadParserFactory* factory = testling.getPayloadParserFactory("baz", "", AttributeMap());
+
+ CPPUNIT_ASSERT(factory == &factory2);
+ }
+
+
+ private:
+ struct DummyFactory : public PayloadParserFactory {
+ DummyFactory(const String& element = "") : element(element) {}
+ virtual bool canParse(const String& e, const String&, const AttributeMap&) const {
+ return element.isEmpty() ? true : element == e;
+ }
+ virtual PayloadParser* createPayloadParser() { return NULL; }
+ String element;
+ };
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(PayloadParserFactoryCollectionTest);