/* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include #include #include #include using namespace Swift; class StreamFeaturesParserTest : public CppUnit::TestFixture { CPPUNIT_TEST_SUITE(StreamFeaturesParserTest); CPPUNIT_TEST(testParse); CPPUNIT_TEST(testParse_Empty); CPPUNIT_TEST(testParse_AuthenticationHostname); CPPUNIT_TEST(testParse_AuthenticationHostnameEmpty); CPPUNIT_TEST_SUITE_END(); public: void testParse() { StreamFeaturesParser testling; ElementParserTester parser(&testling); CPPUNIT_ASSERT(parser.parse( "" "" "" "zlib" "lzw" "" "" "DIGEST-MD5" "PLAIN" "" "" "" "" "" "")); StreamFeatures::ref element = std::dynamic_pointer_cast(testling.getElement()); CPPUNIT_ASSERT(element->hasStartTLS()); CPPUNIT_ASSERT(element->hasSession()); CPPUNIT_ASSERT(element->hasResourceBind()); CPPUNIT_ASSERT(element->hasCompressionMethod("zlib")); CPPUNIT_ASSERT(element->hasCompressionMethod("lzw")); CPPUNIT_ASSERT(element->hasAuthenticationMechanisms()); CPPUNIT_ASSERT(element->hasAuthenticationMechanism("DIGEST-MD5")); CPPUNIT_ASSERT(element->hasAuthenticationMechanism("PLAIN")); CPPUNIT_ASSERT(!element->getAuthenticationHostname()); CPPUNIT_ASSERT(element->hasStreamManagement()); CPPUNIT_ASSERT(element->hasRosterVersioning()); } void testParse_Empty() { StreamFeaturesParser testling; ElementParserTester parser(&testling); CPPUNIT_ASSERT(parser.parse("")); StreamFeatures::ref element = std::dynamic_pointer_cast(testling.getElement()); CPPUNIT_ASSERT(!element->hasStartTLS()); CPPUNIT_ASSERT(!element->hasSession()); CPPUNIT_ASSERT(!element->hasResourceBind()); CPPUNIT_ASSERT(!element->hasAuthenticationMechanisms()); } void testParse_AuthenticationHostname() { StreamFeaturesParser testling; ElementParserTester parser(&testling); std::string hostname("auth42.us.example.com"); CPPUNIT_ASSERT(parser.parse( "" "" "GSSAPI" "auth42.us.example.com" "" "")); StreamFeatures::ref element = std::dynamic_pointer_cast(testling.getElement()); CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI")); CPPUNIT_ASSERT_EQUAL(*element->getAuthenticationHostname(), hostname); } void testParse_AuthenticationHostnameEmpty() { StreamFeaturesParser testling; ElementParserTester parser(&testling); CPPUNIT_ASSERT(parser.parse( "" "" "GSSAPI" "" "" "")); StreamFeatures::ref element = std::dynamic_pointer_cast(testling.getElement()); CPPUNIT_ASSERT(element->hasAuthenticationMechanism("GSSAPI")); CPPUNIT_ASSERT(element->getAuthenticationHostname()->empty()); } }; CPPUNIT_TEST_SUITE_REGISTRATION(StreamFeaturesParserTest);