summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/JID/UnitTest/JIDTest.cpp')
-rw-r--r--Swiften/JID/UnitTest/JIDTest.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/Swiften/JID/UnitTest/JIDTest.cpp b/Swiften/JID/UnitTest/JIDTest.cpp
index 0753fb5..fc7583f 100644
--- a/Swiften/JID/UnitTest/JIDTest.cpp
+++ b/Swiften/JID/UnitTest/JIDTest.cpp
@@ -24,6 +24,7 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_TEST(testConstructorWithString_OnlyDomainDotStrippedOff);
CPPUNIT_TEST(testConstructorWithString_InvalidOnlyDomainSingleDot);
CPPUNIT_TEST(testConstructorWithString_InvalidDomain);
+ CPPUNIT_TEST(testConstructorWithString_InvalidDomainOnlyDigits);
CPPUNIT_TEST(testConstructorWithString_InvalidDomainEmptyLabel);
CPPUNIT_TEST(testConstructorWithString_UpperCaseNode);
CPPUNIT_TEST(testConstructorWithString_UpperCaseDomain);
@@ -71,6 +72,12 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_TEST(testGetUnescapedNode);
CPPUNIT_TEST(testGetUnescapedNode_XEP106Examples);
CPPUNIT_TEST(testStringPrepFailures);
+ CPPUNIT_TEST(testConstructorWithString_DomainIPv4);
+ CPPUNIT_TEST(testConstructorWithString_DomainNOTIPv4);
+ CPPUNIT_TEST(testConstructorWithString_ValidDomainNOTIPv4);
+ CPPUNIT_TEST(testConstructorWithString_DomainIPv6);
+ CPPUNIT_TEST(testConstructorWithString_DomainInvalidIPv6);
+ CPPUNIT_TEST(testConstructorWithString_DomainIPv6NoBrackets);
CPPUNIT_TEST_SUITE_END();
public:
@@ -156,6 +163,10 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_ASSERT(!JID("foo@bar,baz").isValid());
}
+ void testConstructorWithString_InvalidDomainOnlyDigits() {
+ CPPUNIT_ASSERT(!JID("1234").isValid());
+ }
+
void testConstructorWithString_InvalidDomainEmptyLabel() {
CPPUNIT_ASSERT(!JID("foo@bar..").isValid());
}
@@ -492,6 +503,46 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_ASSERT_EQUAL(std::string("c:\\cool stuff"), JID("c\\3a\\cool\\20stuff@example.com").getUnescapedNode());
CPPUNIT_ASSERT_EQUAL(std::string("c:\\5commas"), JID("c\\3a\\5c5commas@example.com").getUnescapedNode());
}
+
+ void testConstructorWithString_DomainIPv4() {
+ JID testling("foo@192.34.12.1/resource");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), testling.getNode());
+ CPPUNIT_ASSERT_EQUAL(std::string("192.34.12.1"), testling.getDomain());
+ CPPUNIT_ASSERT_EQUAL(std::string("resource"), testling.getResource());
+ CPPUNIT_ASSERT(!testling.isBare());
+ CPPUNIT_ASSERT(testling.isValid());
+ }
+
+ void testConstructorWithString_DomainNOTIPv4() {
+ JID testling("foo@500.34.12.1/resource");
+ CPPUNIT_ASSERT(!testling.isValid());
+ }
+
+ void testConstructorWithString_ValidDomainNOTIPv4() {
+ JID testling("foo@500.34.12.1a/resource");
+ CPPUNIT_ASSERT(testling.isValid());
+ }
+
+ void testConstructorWithString_DomainIPv6() {
+ JID testling("foo@[fe80::a857:33ff:febd:3580]/resource");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("foo"), testling.getNode());
+ CPPUNIT_ASSERT_EQUAL(std::string("[fe80::a857:33ff:febd:3580]"), testling.getDomain());
+ CPPUNIT_ASSERT_EQUAL(std::string("resource"), testling.getResource());
+ CPPUNIT_ASSERT(!testling.isBare());
+ CPPUNIT_ASSERT(testling.isValid());
+ }
+
+ void testConstructorWithString_DomainInvalidIPv6() {
+ JID testling("foo@[1111::a1111:1111:111!:!!!!]/resource");
+ CPPUNIT_ASSERT(!testling.isValid());
+ }
+
+ void testConstructorWithString_DomainIPv6NoBrackets() {
+ JID testling("foo@fe80::a857:33ff:febd:3580/resource");
+ CPPUNIT_ASSERT(!testling.isValid());
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(JIDTest);