diff options
Diffstat (limited to 'Swiften/JID/UnitTest/JIDTest.cpp')
-rw-r--r-- | Swiften/JID/UnitTest/JIDTest.cpp | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp index ca3e5ae..0753fb5 100644 --- a/Swiften/JID/UnitTest/JIDTest.cpp +++ b/Swiften/JID/UnitTest/JIDTest.cpp @@ -1,3 +1,3 @@ /* - * Copyright (c) 2010-2016 Isode Limited. + * Copyright (c) 2010-2018 Isode Limited. * All rights reserved. @@ -22,3 +22,7 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_TEST(testConstructorWithString_OnlyDomain); + CPPUNIT_TEST(testConstructorWithString_OnlyDomainWithDot); + CPPUNIT_TEST(testConstructorWithString_OnlyDomainDotStrippedOff); + CPPUNIT_TEST(testConstructorWithString_InvalidOnlyDomainSingleDot); CPPUNIT_TEST(testConstructorWithString_InvalidDomain); + CPPUNIT_TEST(testConstructorWithString_InvalidDomainEmptyLabel); CPPUNIT_TEST(testConstructorWithString_UpperCaseNode); @@ -27,2 +31,6 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_TEST(testConstructorWithString_EmptyNode); + CPPUNIT_TEST(testConstructorWithString_EmptyDomain); + CPPUNIT_TEST(testConstructorWithString_EmptyDomainWithResource); + CPPUNIT_TEST(testConstructorWithString_DotDomain); + CPPUNIT_TEST(testConstructorWithString_DotDomainWithResource); CPPUNIT_TEST(testConstructorWithString_IllegalResource); @@ -64,2 +72,3 @@ class JIDTest : public CppUnit::TestFixture CPPUNIT_TEST(testGetUnescapedNode_XEP106Examples); + CPPUNIT_TEST(testStringPrepFailures); CPPUNIT_TEST_SUITE_END(); @@ -121,2 +130,26 @@ class JIDTest : public CppUnit::TestFixture + void testConstructorWithString_OnlyDomainWithDot() { + JID testling("bar."); + + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string(""), testling.getResource()); + CPPUNIT_ASSERT(testling.isBare()); + CPPUNIT_ASSERT(testling.isValid()); + } + + void testConstructorWithString_OnlyDomainDotStrippedOff() { + JID testling("foo.@bar./resource."); + + CPPUNIT_ASSERT_EQUAL(std::string("foo."), testling.getNode()); + CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain()); + CPPUNIT_ASSERT_EQUAL(std::string("resource."), testling.getResource()); + CPPUNIT_ASSERT(!testling.isBare()); + CPPUNIT_ASSERT(testling.isValid()); + } + + void testConstructorWithString_InvalidOnlyDomainSingleDot() { + CPPUNIT_ASSERT(!JID(".").isValid()); + } + void testConstructorWithString_InvalidDomain() { @@ -125,2 +158,6 @@ class JIDTest : public CppUnit::TestFixture + void testConstructorWithString_InvalidDomainEmptyLabel() { + CPPUNIT_ASSERT(!JID("foo@bar..").isValid()); + } + void testConstructorWithString_UpperCaseNode() { @@ -153,2 +190,32 @@ class JIDTest : public CppUnit::TestFixture + void testConstructorWithString_EmptyDomain() { + JID testling("bar@"); + + CPPUNIT_ASSERT(!testling.isValid()); + } + + void testStringPrepFailures() { + CPPUNIT_ASSERT_EQUAL(false, JID("foo@bar", "example.com").isValid()); + CPPUNIT_ASSERT_EQUAL(false, JID("foo^", "example*com").isValid()); + CPPUNIT_ASSERT_EQUAL(false, JID("foobar", "example^com").isValid()); + } + + void testConstructorWithString_EmptyDomainWithResource() { + JID testling("bar@/resource"); + + CPPUNIT_ASSERT(!testling.isValid()); + } + + void testConstructorWithString_DotDomain() { + JID testling("bar@."); + + CPPUNIT_ASSERT(!testling.isValid()); + } + + void testConstructorWithString_DotDomainWithResource() { + JID testling("bar@./resource"); + + CPPUNIT_ASSERT(!testling.isValid()); + } + void testConstructorWithString_IllegalResource() { |