diff options
Diffstat (limited to 'Swiften/SASL/UnitTest/PLAINMessageTest.cpp')
-rw-r--r-- | Swiften/SASL/UnitTest/PLAINMessageTest.cpp | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/Swiften/SASL/UnitTest/PLAINMessageTest.cpp b/Swiften/SASL/UnitTest/PLAINMessageTest.cpp new file mode 100644 index 0000000..6493bd5 --- /dev/null +++ b/Swiften/SASL/UnitTest/PLAINMessageTest.cpp @@ -0,0 +1,61 @@ +#include <cppunit/extensions/HelperMacros.h> +#include <cppunit/extensions/TestFactoryRegistry.h> + +#include "Swiften/SASL/PLAINMessage.h" + +using namespace Swift; + +class PLAINMessageTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE(PLAINMessageTest); + CPPUNIT_TEST(testGetValue_WithoutAuthzID); + CPPUNIT_TEST(testGetValue_WithAuthzID); + CPPUNIT_TEST(testConstructor_WithoutAuthzID); + CPPUNIT_TEST(testConstructor_WithAuthzID); + CPPUNIT_TEST(testConstructor_NoAuthcid); + CPPUNIT_TEST(testConstructor_NoPassword); + CPPUNIT_TEST_SUITE_END(); + + public: + PLAINMessageTest() {} + + void testGetValue_WithoutAuthzID() { + PLAINMessage message("user", "pass"); + CPPUNIT_ASSERT_EQUAL(message.getValue(), ByteArray("\0user\0pass", 10)); + } + + void testGetValue_WithAuthzID() { + PLAINMessage message("user", "pass", "authz"); + CPPUNIT_ASSERT_EQUAL(message.getValue(), ByteArray("authz\0user\0pass", 15)); + } + + void testConstructor_WithoutAuthzID() { + PLAINMessage message(ByteArray("\0user\0pass", 10)); + + CPPUNIT_ASSERT_EQUAL(String(""), message.getAuthorizationID()); + CPPUNIT_ASSERT_EQUAL(String("user"), message.getAuthenticationID()); + CPPUNIT_ASSERT_EQUAL(String("pass"), message.getPassword()); + } + + void testConstructor_WithAuthzID() { + PLAINMessage message(ByteArray("authz\0user\0pass", 15)); + + CPPUNIT_ASSERT_EQUAL(String("authz"), message.getAuthorizationID()); + CPPUNIT_ASSERT_EQUAL(String("user"), message.getAuthenticationID()); + CPPUNIT_ASSERT_EQUAL(String("pass"), message.getPassword()); + } + + void testConstructor_NoAuthcid() { + PLAINMessage message(ByteArray("authzid", 7)); + + CPPUNIT_ASSERT_EQUAL(String(""), message.getAuthenticationID()); + } + + void testConstructor_NoPassword() { + PLAINMessage message(ByteArray("authzid\0authcid", 15)); + + CPPUNIT_ASSERT_EQUAL(String(""), message.getAuthenticationID()); + } +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(PLAINMessageTest); |