summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/JID/UnitTest/JIDTest.cpp')
-rw-r--r--Swiften/JID/UnitTest/JIDTest.cpp69
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,11 +1,11 @@
/*
- * Copyright (c) 2010-2016 Isode Limited.
+ * Copyright (c) 2010-2018 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/JID/JID.h>
@@ -14,23 +14,31 @@ using namespace Swift;
class JIDTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(JIDTest);
CPPUNIT_TEST(testConstructorWithString);
CPPUNIT_TEST(testConstructorWithString_Empty);
CPPUNIT_TEST(testConstructorWithString_NoResource);
CPPUNIT_TEST(testConstructorWithString_NoNode);
CPPUNIT_TEST(testConstructorWithString_EmptyResource);
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);
CPPUNIT_TEST(testConstructorWithString_UpperCaseDomain);
CPPUNIT_TEST(testConstructorWithString_UpperCaseResource);
CPPUNIT_TEST(testConstructorWithString_EmptyNode);
+ CPPUNIT_TEST(testConstructorWithString_EmptyDomain);
+ CPPUNIT_TEST(testConstructorWithString_EmptyDomainWithResource);
+ CPPUNIT_TEST(testConstructorWithString_DotDomain);
+ CPPUNIT_TEST(testConstructorWithString_DotDomainWithResource);
CPPUNIT_TEST(testConstructorWithString_IllegalResource);
CPPUNIT_TEST(testConstructorWithString_SpacesInNode);
CPPUNIT_TEST(testConstructorWithStrings);
CPPUNIT_TEST(testConstructorWithStrings_EmptyDomain);
CPPUNIT_TEST(testConstructorWithStrings_EmptyResource);
CPPUNIT_TEST(testIsBare);
CPPUNIT_TEST(testIsBare_NotBare);
CPPUNIT_TEST(testToBare);
CPPUNIT_TEST(testToBare_EmptyNode);
@@ -56,18 +64,19 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_TEST(testSmallerThan_Equal);
CPPUNIT_TEST(testSmallerThan_Larger);
CPPUNIT_TEST(testHasResource);
CPPUNIT_TEST(testHasResource_NoResource);
CPPUNIT_TEST(testGetEscapedNode);
CPPUNIT_TEST(testGetEscapedNode_XEP106Examples);
CPPUNIT_TEST(testGetEscapedNode_BackslashAtEnd);
CPPUNIT_TEST(testGetUnescapedNode);
CPPUNIT_TEST(testGetUnescapedNode_XEP106Examples);
+ CPPUNIT_TEST(testStringPrepFailures);
CPPUNIT_TEST_SUITE_END();
public:
JIDTest() {}
void testConstructorWithString() {
JID testling("foo@bar/baz");
CPPUNIT_ASSERT_EQUAL(std::string("foo"), testling.getNode());
@@ -113,22 +122,50 @@ class JIDTest : public CppUnit::TestFixture
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_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() {
CPPUNIT_ASSERT(!JID("foo@bar,baz").isValid());
}
+ void testConstructorWithString_InvalidDomainEmptyLabel() {
+ CPPUNIT_ASSERT(!JID("foo@bar..").isValid());
+ }
+
void testConstructorWithString_UpperCaseNode() {
JID testling("Fo\xCE\xA9@bar");
CPPUNIT_ASSERT_EQUAL(std::string("fo\xCF\x89"), testling.getNode());
CPPUNIT_ASSERT_EQUAL(std::string("bar"), testling.getDomain());
CPPUNIT_ASSERT(testling.isValid());
}
void testConstructorWithString_UpperCaseDomain() {
@@ -145,18 +182,48 @@ class JIDTest : public CppUnit::TestFixture
CPPUNIT_ASSERT(testling.isValid());
}
void testConstructorWithString_EmptyNode() {
JID testling("@bar");
CPPUNIT_ASSERT(!testling.isValid());
}
+ 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() {
JID testling("foo@bar.com/\xd8\xb1\xd9\x85\xd9\x82\xd9\x87\x20\xd8\xaa\xd8\xb1\xd9\x86\xd8\xb3\x20");
CPPUNIT_ASSERT(!testling.isValid());
}
void testConstructorWithString_SpacesInNode() {
CPPUNIT_ASSERT(!JID(" alice@wonderland.lit").isValid());
CPPUNIT_ASSERT(!JID("alice @wonderland.lit").isValid());