summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/Base/UnitTest')
-rw-r--r--Swiften/Base/UnitTest/ByteArrayTest.cpp61
-rw-r--r--Swiften/Base/UnitTest/DateTimeTest.cpp54
-rw-r--r--Swiften/Base/UnitTest/IDGeneratorTest.cpp47
-rw-r--r--Swiften/Base/UnitTest/PathTest.cpp24
-rw-r--r--Swiften/Base/UnitTest/SimpleIDGeneratorTest.cpp49
-rw-r--r--Swiften/Base/UnitTest/StringTest.cpp175
-rw-r--r--Swiften/Base/UnitTest/URLTest.cpp320
7 files changed, 430 insertions, 300 deletions
diff --git a/Swiften/Base/UnitTest/ByteArrayTest.cpp b/Swiften/Base/UnitTest/ByteArrayTest.cpp
index 8852b78..2eb601b 100644
--- a/Swiften/Base/UnitTest/ByteArrayTest.cpp
+++ b/Swiften/Base/UnitTest/ByteArrayTest.cpp
@@ -1,56 +1,57 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <boost/lexical_cast.hpp>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/Base/ByteArray.h>
-#include <boost/lexical_cast.hpp>
using namespace Swift;
class ByteArrayTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(ByteArrayTest);
- CPPUNIT_TEST(testGetData_NoData);
- CPPUNIT_TEST(testToString);
- CPPUNIT_TEST(testToString_NullTerminated);
- CPPUNIT_TEST(testToString_TwoNullTerminated);
- CPPUNIT_TEST(testToString_AllNull);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(ByteArrayTest);
+ CPPUNIT_TEST(testGetData_NoData);
+ CPPUNIT_TEST(testToString);
+ CPPUNIT_TEST(testToString_NullTerminated);
+ CPPUNIT_TEST(testToString_TwoNullTerminated);
+ CPPUNIT_TEST(testToString_AllNull);
+ CPPUNIT_TEST_SUITE_END();
- public:
- void testGetData_NoData() {
- ByteArray testling;
+ public:
+ void testGetData_NoData() {
+ ByteArray testling;
- CPPUNIT_ASSERT_EQUAL(reinterpret_cast<const char*>(NULL), reinterpret_cast<const char*>(vecptr(testling)));
- }
+ CPPUNIT_ASSERT_EQUAL(reinterpret_cast<const char*>(NULL), reinterpret_cast<const char*>(vecptr(testling)));
+ }
- void testToString() {
- ByteArray testling(createByteArray("abcde"));
+ void testToString() {
+ ByteArray testling(createByteArray("abcde"));
- CPPUNIT_ASSERT_EQUAL(std::string("abcde"), byteArrayToString(testling));
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("abcde"), byteArrayToString(testling));
+ }
- void testToString_NullTerminated() {
- ByteArray testling(createByteArray("abcde\0", 6));
+ void testToString_NullTerminated() {
+ ByteArray testling(createByteArray("abcde\0", 6));
- CPPUNIT_ASSERT_EQUAL(std::string("abcde"), byteArrayToString(testling));
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("abcde"), byteArrayToString(testling));
+ }
- void testToString_TwoNullTerminated() {
- ByteArray testling(createByteArray("abcde\0\0", 7));
+ void testToString_TwoNullTerminated() {
+ ByteArray testling(createByteArray("abcde\0\0", 7));
- CPPUNIT_ASSERT_EQUAL(std::string("abcde"), byteArrayToString(testling));
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("abcde"), byteArrayToString(testling));
+ }
- void testToString_AllNull() {
- ByteArray testling(createByteArray("\0\0", 2));
+ void testToString_AllNull() {
+ ByteArray testling(createByteArray("\0\0", 2));
- CPPUNIT_ASSERT_EQUAL(std::string(""), byteArrayToString(testling));
- }
+ CPPUNIT_ASSERT_EQUAL(std::string(""), byteArrayToString(testling));
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(ByteArrayTest);
diff --git a/Swiften/Base/UnitTest/DateTimeTest.cpp b/Swiften/Base/UnitTest/DateTimeTest.cpp
index a9350fa..6a82d96 100644
--- a/Swiften/Base/UnitTest/DateTimeTest.cpp
+++ b/Swiften/Base/UnitTest/DateTimeTest.cpp
@@ -1,50 +1,52 @@
/*
- * Copyright (c) 2011 Isode Limited.
+ * Copyright (c) 2011-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
-#include <cppunit/extensions/HelperMacros.h>
-#include <cppunit/extensions/TestFactoryRegistry.h>
#include <string>
+
#include <boost/date_time/posix_time/posix_time.hpp>
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
#include <Swiften/Base/DateTime.h>
using namespace Swift;
class DateTimeTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(DateTimeTest);
- CPPUNIT_TEST(testStringToDateTime_UTC);
- CPPUNIT_TEST(testStringToDateTime_WithTimezone);
- CPPUNIT_TEST(testDateTimeToString);
- CPPUNIT_TEST(testDateTimeToLocalStringNotThrowingException);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(DateTimeTest);
+ CPPUNIT_TEST(testStringToDateTime_UTC);
+ CPPUNIT_TEST(testStringToDateTime_WithTimezone);
+ CPPUNIT_TEST(testDateTimeToString);
+ CPPUNIT_TEST(testDateTimeToLocalStringNotThrowingException);
+ CPPUNIT_TEST_SUITE_END();
- public:
- void testStringToDateTime_UTC() {
- boost::posix_time::ptime time = stringToDateTime("1969-07-21T02:56:15Z");
+ public:
+ void testStringToDateTime_UTC() {
+ boost::posix_time::ptime time = stringToDateTime("1969-07-21T02:56:15Z");
- CPPUNIT_ASSERT_EQUAL(std::string("1969-07-21T02:56:15"), boost::posix_time::to_iso_extended_string(time));
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("1969-07-21T02:56:15"), boost::posix_time::to_iso_extended_string(time));
+ }
- void testStringToDateTime_WithTimezone() {
- boost::posix_time::ptime time = stringToDateTime("1969-07-20T21:56:15-05:00");
+ void testStringToDateTime_WithTimezone() {
+ boost::posix_time::ptime time = stringToDateTime("1969-07-20T21:56:15-05:00");
- CPPUNIT_ASSERT_EQUAL(std::string("1969-07-21T02:56:15"), boost::posix_time::to_iso_extended_string(time));
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("1969-07-21T02:56:15"), boost::posix_time::to_iso_extended_string(time));
+ }
- void testDateTimeToString() {
- boost::posix_time::ptime time = stringToDateTime("1969-07-20T21:56:15-05:00");
+ void testDateTimeToString() {
+ boost::posix_time::ptime time = stringToDateTime("1969-07-20T21:56:15-05:00");
- CPPUNIT_ASSERT_EQUAL(std::string("1969-07-21T02:56:15Z"), dateTimeToString(time));
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("1969-07-21T02:56:15Z"), dateTimeToString(time));
+ }
- void testDateTimeToLocalStringNotThrowingException() {
- boost::posix_time::ptime time = stringToDateTime("1954-07-20T21:56:15-05:00");
+ void testDateTimeToLocalStringNotThrowingException() {
+ boost::posix_time::ptime time = stringToDateTime("1954-07-20T21:56:15-05:00");
- CPPUNIT_ASSERT_EQUAL(std::string(""), dateTimeToLocalString(time));
- }
+ CPPUNIT_ASSERT_EQUAL(std::string(""), dateTimeToLocalString(time));
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(DateTimeTest);
diff --git a/Swiften/Base/UnitTest/IDGeneratorTest.cpp b/Swiften/Base/UnitTest/IDGeneratorTest.cpp
index 06be9ca..08bd48b 100644
--- a/Swiften/Base/UnitTest/IDGeneratorTest.cpp
+++ b/Swiften/Base/UnitTest/IDGeneratorTest.cpp
@@ -1,12 +1,13 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <set>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <set>
#include <Swiften/Base/IDGenerator.h>
@@ -14,27 +15,27 @@ using namespace Swift;
class IDGeneratorTest : public CppUnit::TestFixture
{
- CPPUNIT_TEST_SUITE(IDGeneratorTest);
- CPPUNIT_TEST(testGenerate);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- IDGeneratorTest() {}
-
- void setUp() {
- generatedIDs_.clear();
- }
-
- void testGenerate() {
- IDGenerator testling;
- for (unsigned int i = 0; i < 26*4; ++i) {
- std::string id = testling.generateID();
- CPPUNIT_ASSERT(generatedIDs_.insert(id).second);
- }
- }
-
- private:
- std::set<std::string> generatedIDs_;
+ CPPUNIT_TEST_SUITE(IDGeneratorTest);
+ CPPUNIT_TEST(testGenerate);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ IDGeneratorTest() {}
+
+ void setUp() {
+ generatedIDs_.clear();
+ }
+
+ void testGenerate() {
+ IDGenerator testling;
+ for (unsigned int i = 0; i < 26*4; ++i) {
+ std::string id = testling.generateID();
+ CPPUNIT_ASSERT(generatedIDs_.insert(id).second);
+ }
+ }
+
+ private:
+ std::set<std::string> generatedIDs_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(IDGeneratorTest);
diff --git a/Swiften/Base/UnitTest/PathTest.cpp b/Swiften/Base/UnitTest/PathTest.cpp
index b22b570..dd2233b 100644
--- a/Swiften/Base/UnitTest/PathTest.cpp
+++ b/Swiften/Base/UnitTest/PathTest.cpp
@@ -13,23 +13,23 @@
using namespace Swift;
class PathTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(PathTest);
- CPPUNIT_TEST(testStringToPath);
- CPPUNIT_TEST(testPathToString);
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE(PathTest);
+ CPPUNIT_TEST(testStringToPath);
+ CPPUNIT_TEST(testPathToString);
+ CPPUNIT_TEST_SUITE_END();
- public:
- void testStringToPath() {
+ public:
+ void testStringToPath() {
#ifdef SWIFTEN_PLATFORM_WINDOWS
- CPPUNIT_ASSERT(std::wstring(L"tron\xe7on") == stringToPath("tron\xc3\xa7on").native());
+ CPPUNIT_ASSERT(std::wstring(L"tron\xe7on") == stringToPath("tron\xc3\xa7on").native());
#else
- CPPUNIT_ASSERT_EQUAL(std::string("tron\xc3\xa7on"), stringToPath("tron\xc3\xa7on").native());
+ CPPUNIT_ASSERT_EQUAL(std::string("tron\xc3\xa7on"), stringToPath("tron\xc3\xa7on").native());
#endif
- }
+ }
- void testPathToString() {
- CPPUNIT_ASSERT_EQUAL(std::string("tron\xc3\xa7on"), pathToString(stringToPath("tron\xc3\xa7on")));
- }
+ void testPathToString() {
+ CPPUNIT_ASSERT_EQUAL(std::string("tron\xc3\xa7on"), pathToString(stringToPath("tron\xc3\xa7on")));
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(PathTest);
diff --git a/Swiften/Base/UnitTest/SimpleIDGeneratorTest.cpp b/Swiften/Base/UnitTest/SimpleIDGeneratorTest.cpp
index e9dcece..9b49c0a 100644
--- a/Swiften/Base/UnitTest/SimpleIDGeneratorTest.cpp
+++ b/Swiften/Base/UnitTest/SimpleIDGeneratorTest.cpp
@@ -1,40 +1,41 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <set>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <set>
-#include "Swiften/Base/SimpleIDGenerator.h"
+#include <Swiften/Base/SimpleIDGenerator.h>
using namespace Swift;
class SimpleIDGeneratorTest : public CppUnit::TestFixture
{
- CPPUNIT_TEST_SUITE(SimpleIDGeneratorTest);
- CPPUNIT_TEST(testGenerate);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- SimpleIDGeneratorTest() {}
-
- void setUp() {
- generatedIDs_.clear();
- }
-
- void testGenerate() {
- SimpleIDGenerator testling;
- for (unsigned int i = 0; i < 26*4; ++i) {
- std::string id = testling.generateID();
- CPPUNIT_ASSERT(generatedIDs_.insert(id).second);
- }
- }
-
- private:
- std::set<std::string> generatedIDs_;
+ CPPUNIT_TEST_SUITE(SimpleIDGeneratorTest);
+ CPPUNIT_TEST(testGenerate);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ SimpleIDGeneratorTest() {}
+
+ void setUp() {
+ generatedIDs_.clear();
+ }
+
+ void testGenerate() {
+ SimpleIDGenerator testling;
+ for (unsigned int i = 0; i < 26*4; ++i) {
+ std::string id = testling.generateID();
+ CPPUNIT_ASSERT(generatedIDs_.insert(id).second);
+ }
+ }
+
+ private:
+ std::set<std::string> generatedIDs_;
};
CPPUNIT_TEST_SUITE_REGISTRATION(SimpleIDGeneratorTest);
diff --git a/Swiften/Base/UnitTest/StringTest.cpp b/Swiften/Base/UnitTest/StringTest.cpp
index 5317326..e2e1665 100644
--- a/Swiften/Base/UnitTest/StringTest.cpp
+++ b/Swiften/Base/UnitTest/StringTest.cpp
@@ -1,128 +1,129 @@
/*
- * Copyright (c) 2010 Isode Limited.
+ * Copyright (c) 2010-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <string>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
-#include <string>
-#include <Swiften/Base/String.h>
#include <Swiften/Base/Platform.h>
+#include <Swiften/Base/String.h>
using namespace Swift;
class StringTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(StringTest);
- CPPUNIT_TEST(testGetUnicodeCodePoints);
- CPPUNIT_TEST(testGetSplittedAtFirst);
- CPPUNIT_TEST(testGetSplittedAtFirst_CharacterAtBegin);
- CPPUNIT_TEST(testGetSplittedAtFirst_CharacterAtEnd);
- CPPUNIT_TEST(testGetSplittedAtFirst_NoSuchCharacter);
- CPPUNIT_TEST(testReplaceAll);
- CPPUNIT_TEST(testReplaceAll_LastChar);
- CPPUNIT_TEST(testReplaceAll_ConsecutiveChars);
- CPPUNIT_TEST(testReplaceAll_MatchingReplace);
- CPPUNIT_TEST(testSplit);
+ CPPUNIT_TEST_SUITE(StringTest);
+ CPPUNIT_TEST(testGetUnicodeCodePoints);
+ CPPUNIT_TEST(testGetSplittedAtFirst);
+ CPPUNIT_TEST(testGetSplittedAtFirst_CharacterAtBegin);
+ CPPUNIT_TEST(testGetSplittedAtFirst_CharacterAtEnd);
+ CPPUNIT_TEST(testGetSplittedAtFirst_NoSuchCharacter);
+ CPPUNIT_TEST(testReplaceAll);
+ CPPUNIT_TEST(testReplaceAll_LastChar);
+ CPPUNIT_TEST(testReplaceAll_ConsecutiveChars);
+ CPPUNIT_TEST(testReplaceAll_MatchingReplace);
+ CPPUNIT_TEST(testSplit);
#ifdef SWIFTEN_PLATFORM_WINDOWS
- CPPUNIT_TEST(testConvertWStringToString);
- CPPUNIT_TEST(testConvertStringToWString);
+ CPPUNIT_TEST(testConvertWStringToString);
+ CPPUNIT_TEST(testConvertStringToWString);
#endif
- CPPUNIT_TEST_SUITE_END();
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testGetUnicodeCodePoints() {
+ std::string testling("$\xc2\xa2\xe2\x82\xac\xf4\x8a\xaf\x8d");
+ std::vector<unsigned int> points = String::getUnicodeCodePoints(testling);
+
+ CPPUNIT_ASSERT_EQUAL(0x24U, points[0]);
+ CPPUNIT_ASSERT_EQUAL(0xA2U, points[1]);
+ CPPUNIT_ASSERT_EQUAL(0x20ACU, points[2]);
+ CPPUNIT_ASSERT_EQUAL(0x10ABCDU, points[3]);
+ }
+
+ void testGetSplittedAtFirst() {
+ std::string testling("ab@cd@ef");
+
+ std::pair<std::string,std::string> result = String::getSplittedAtFirst(testling, '@');
+ CPPUNIT_ASSERT_EQUAL(std::string("ab"), result.first);
+ CPPUNIT_ASSERT_EQUAL(std::string("cd@ef"), result.second);
+ }
- public:
- void testGetUnicodeCodePoints() {
- std::string testling("$\xc2\xa2\xe2\x82\xac\xf4\x8a\xaf\x8d");
- std::vector<unsigned int> points = String::getUnicodeCodePoints(testling);
+ void testGetSplittedAtFirst_CharacterAtBegin() {
+ std::string testling(" ab");
- CPPUNIT_ASSERT_EQUAL(0x24U, points[0]);
- CPPUNIT_ASSERT_EQUAL(0xA2U, points[1]);
- CPPUNIT_ASSERT_EQUAL(0x20ACU, points[2]);
- CPPUNIT_ASSERT_EQUAL(0x10ABCDU, points[3]);
- }
+ std::pair<std::string,std::string> result = String::getSplittedAtFirst(testling, ' ');
+ CPPUNIT_ASSERT(result.first.empty());
+ CPPUNIT_ASSERT_EQUAL(std::string("ab"), result.second);
+ }
- void testGetSplittedAtFirst() {
- std::string testling("ab@cd@ef");
+ void testGetSplittedAtFirst_CharacterAtEnd() {
+ std::string testling("ab@");
- std::pair<std::string,std::string> result = String::getSplittedAtFirst(testling, '@');
- CPPUNIT_ASSERT_EQUAL(std::string("ab"), result.first);
- CPPUNIT_ASSERT_EQUAL(std::string("cd@ef"), result.second);
- }
+ std::pair<std::string,std::string> result = String::getSplittedAtFirst(testling, '@');
+ CPPUNIT_ASSERT_EQUAL(std::string("ab"), result.first);
+ CPPUNIT_ASSERT(result.second.empty());
+ }
- void testGetSplittedAtFirst_CharacterAtBegin() {
- std::string testling(" ab");
+ void testGetSplittedAtFirst_NoSuchCharacter() {
+ std::string testling("ab");
- std::pair<std::string,std::string> result = String::getSplittedAtFirst(testling, ' ');
- CPPUNIT_ASSERT(result.first.empty());
- CPPUNIT_ASSERT_EQUAL(std::string("ab"), result.second);
- }
+ std::pair<std::string,std::string> result = String::getSplittedAtFirst(testling, '@');
+ CPPUNIT_ASSERT_EQUAL(std::string("ab"), result.first);
+ CPPUNIT_ASSERT(result.second.empty());
+ }
- void testGetSplittedAtFirst_CharacterAtEnd() {
- std::string testling("ab@");
+ void testReplaceAll() {
+ std::string testling("abcbd");
- std::pair<std::string,std::string> result = String::getSplittedAtFirst(testling, '@');
- CPPUNIT_ASSERT_EQUAL(std::string("ab"), result.first);
- CPPUNIT_ASSERT(result.second.empty());
- }
+ String::replaceAll(testling, 'b', "xyz");
- void testGetSplittedAtFirst_NoSuchCharacter() {
- std::string testling("ab");
+ CPPUNIT_ASSERT_EQUAL(std::string("axyzcxyzd"), testling);
+ }
- std::pair<std::string,std::string> result = String::getSplittedAtFirst(testling, '@');
- CPPUNIT_ASSERT_EQUAL(std::string("ab"), result.first);
- CPPUNIT_ASSERT(result.second.empty());
- }
+ void testReplaceAll_LastChar() {
+ std::string testling("abc");
- void testReplaceAll() {
- std::string testling("abcbd");
+ String::replaceAll(testling, 'c', "xyz");
- String::replaceAll(testling, 'b', "xyz");
-
- CPPUNIT_ASSERT_EQUAL(std::string("axyzcxyzd"), testling);
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("abxyz"), testling);
+ }
- void testReplaceAll_LastChar() {
- std::string testling("abc");
+ void testReplaceAll_ConsecutiveChars() {
+ std::string testling("abbc");
- String::replaceAll(testling, 'c', "xyz");
-
- CPPUNIT_ASSERT_EQUAL(std::string("abxyz"), testling);
- }
+ String::replaceAll(testling, 'b',"xyz");
- void testReplaceAll_ConsecutiveChars() {
- std::string testling("abbc");
+ CPPUNIT_ASSERT_EQUAL(std::string("axyzxyzc"), testling);
+ }
- String::replaceAll(testling, 'b',"xyz");
-
- CPPUNIT_ASSERT_EQUAL(std::string("axyzxyzc"), testling);
- }
+ void testReplaceAll_MatchingReplace() {
+ std::string testling("abc");
- void testReplaceAll_MatchingReplace() {
- std::string testling("abc");
+ String::replaceAll(testling, 'b',"bbb");
- String::replaceAll(testling, 'b',"bbb");
-
- CPPUNIT_ASSERT_EQUAL(std::string("abbbc"), testling);
- }
+ CPPUNIT_ASSERT_EQUAL(std::string("abbbc"), testling);
+ }
- void testSplit() {
- std::vector<std::string> result = String::split("abc def ghi", ' ');
+ void testSplit() {
+ std::vector<std::string> result = String::split("abc def ghi", ' ');
- CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(result.size()));
- CPPUNIT_ASSERT_EQUAL(std::string("abc"), result[0]);
- CPPUNIT_ASSERT_EQUAL(std::string("def"), result[1]);
- CPPUNIT_ASSERT_EQUAL(std::string("ghi"), result[2]);
- }
+ CPPUNIT_ASSERT_EQUAL(3, static_cast<int>(result.size()));
+ CPPUNIT_ASSERT_EQUAL(std::string("abc"), result[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("def"), result[1]);
+ CPPUNIT_ASSERT_EQUAL(std::string("ghi"), result[2]);
+ }
#ifdef SWIFTEN_PLATFORM_WINDOWS
- void testConvertWStringToString() {
- CPPUNIT_ASSERT_EQUAL(std::string("tron\xc3\xa7on"), convertWStringToString(std::wstring(L"tron\xe7on")));
- }
+ void testConvertWStringToString() {
+ CPPUNIT_ASSERT_EQUAL(std::string("tron\xc3\xa7on"), convertWStringToString(std::wstring(L"tron\xe7on")));
+ }
- void testConvertStringToWString() {
- CPPUNIT_ASSERT(std::wstring(L"tron\xe7on") == convertStringToWString(std::string("tron\xc3\xa7on")));
- }
+ void testConvertStringToWString() {
+ CPPUNIT_ASSERT(std::wstring(L"tron\xe7on") == convertStringToWString(std::string("tron\xc3\xa7on")));
+ }
#endif
};
diff --git a/Swiften/Base/UnitTest/URLTest.cpp b/Swiften/Base/UnitTest/URLTest.cpp
index b20d21e..c38398a 100644
--- a/Swiften/Base/UnitTest/URLTest.cpp
+++ b/Swiften/Base/UnitTest/URLTest.cpp
@@ -1,114 +1,238 @@
/*
- * Copyright (c) 2012 Isode Limited.
+ * Copyright (c) 2012-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
+#include <boost/lexical_cast.hpp>
+
#include <cppunit/extensions/HelperMacros.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <Swiften/Base/URL.h>
-#include <boost/lexical_cast.hpp>
using namespace Swift;
class URLTest : public CppUnit::TestFixture {
- CPPUNIT_TEST_SUITE(URLTest);
- CPPUNIT_TEST(testFromString);
- CPPUNIT_TEST(testFromString_WithoutPath);
- CPPUNIT_TEST(testFromString_WithRootPath);
- CPPUNIT_TEST(testFromString_WithPort);
- CPPUNIT_TEST(testFromString_WithPortOnePartPath);
- CPPUNIT_TEST(testFromString_WithPortWithoutPath);
- CPPUNIT_TEST(testFromString_WithUserInfo);
- CPPUNIT_TEST(testFromString_NonASCIIHost);
- CPPUNIT_TEST(testFromString_NonASCIIPath);
- CPPUNIT_TEST(testToString);
- CPPUNIT_TEST(testToString_WithPort);
- CPPUNIT_TEST_SUITE_END();
-
- public:
- void testFromString() {
- URL url = URL::fromString("http://foo.bar/baz/bam");
-
- CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
- CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT(!url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
- }
-
- void testFromString_WithoutPath() {
- URL url = URL::fromString("http://foo.bar");
-
- CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
- CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT(!url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
- }
-
- void testFromString_WithRootPath() {
- URL url = URL::fromString("http://foo.bar/");
-
- CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
- CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT(!url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string("/"), url.getPath());
- }
-
- void testFromString_WithPort() {
- URL url = URL::fromString("http://foo.bar:1234/baz/bam");
-
- CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
- CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
- }
-
- void testFromString_WithPortOnePartPath() {
- URL url = URL::fromString("http://foo.bar:11440/http-bind/");
-
- CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
- CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(11440, *url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string("/http-bind/"), url.getPath());
- }
-
- void testFromString_WithPortWithoutPath() {
- URL url = URL::fromString("http://foo.bar:1234");
-
- CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
- CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
- CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
- }
-
- void testFromString_WithUserInfo() {
- URL url = URL::fromString("http://user:pass@foo.bar/baz/bam");
-
- CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
- CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
- CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
- }
-
- void testFromString_NonASCIIHost() {
- URL url = URL::fromString("http://www.tron%C3%A7on.be/baz/bam");
-
- CPPUNIT_ASSERT_EQUAL(std::string("www.tron\xc3\xa7on.be"), url.getHost());
- }
-
- void testFromString_NonASCIIPath() {
- URL url = URL::fromString("http://foo.bar/baz/tron%C3%A7on/bam");
-
- CPPUNIT_ASSERT_EQUAL(std::string("/baz/tron\xc3\xa7on/bam"), url.getPath());
- }
-
- void testToString() {
- CPPUNIT_ASSERT_EQUAL(std::string("http://foo.bar/baz/bam"), URL("http", "foo.bar", "/baz/bam").toString());
- }
-
- void testToString_WithPort() {
- CPPUNIT_ASSERT_EQUAL(std::string("http://foo.bar:1234/baz/bam"), URL("http", "foo.bar", 1234, "/baz/bam").toString());
- }
+ CPPUNIT_TEST_SUITE(URLTest);
+ CPPUNIT_TEST(testFromString);
+ CPPUNIT_TEST(testFromString_WithoutPath);
+ CPPUNIT_TEST(testFromString_WithRootPath);
+ CPPUNIT_TEST(testFromString_WithPort);
+ CPPUNIT_TEST(testFromString_WithPortOnePartPath);
+ CPPUNIT_TEST(testFromString_WithPortWithoutPath);
+ CPPUNIT_TEST(testFromString_WithUserInfo);
+ CPPUNIT_TEST(testFromString_NonASCIIHost);
+ CPPUNIT_TEST(testFromString_NonASCIIPath);
+ CPPUNIT_TEST(testFromString_IPv4Address);
+ CPPUNIT_TEST(testFromString_IPv4AddressWithPort);
+ CPPUNIT_TEST(testFromString_IPv6Address);
+ CPPUNIT_TEST(testFromString_IPv6AddressWithPort);
+ CPPUNIT_TEST(testToString);
+ CPPUNIT_TEST(testToString_WithPort);
+ CPPUNIT_TEST(test_FromString_ToString_IPv6RFC2732);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ void testFromString() {
+ URL url = URL::fromString("http://foo.bar/baz/bam");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+ CPPUNIT_ASSERT(!url.getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
+ }
+
+ void testFromString_WithoutPath() {
+ URL url = URL::fromString("http://foo.bar");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+ CPPUNIT_ASSERT(!url.getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
+ }
+
+ void testFromString_WithRootPath() {
+ URL url = URL::fromString("http://foo.bar/");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+ CPPUNIT_ASSERT(!url.getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string("/"), url.getPath());
+ }
+
+ void testFromString_WithPort() {
+ URL url = URL::fromString("http://foo.bar:1234/baz/bam");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
+ }
+
+ void testFromString_WithPortOnePartPath() {
+ URL url = URL::fromString("http://foo.bar:11440/http-bind/");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(11440, *url.getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string("/http-bind/"), url.getPath());
+ }
+
+ void testFromString_WithPortWithoutPath() {
+ URL url = URL::fromString("http://foo.bar:1234");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(1234, *url.getPort());
+ CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
+ }
+
+ void testFromString_WithUserInfo() {
+ URL url = URL::fromString("http://user:pass@foo.bar/baz/bam");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("foo.bar"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(std::string("/baz/bam"), url.getPath());
+ }
+
+ void testFromString_NonASCIIHost() {
+ URL url = URL::fromString("http://www.tron%C3%A7on.be/baz/bam");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("www.tron\xc3\xa7on.be"), url.getHost());
+ }
+
+ void testFromString_NonASCIIPath() {
+ URL url = URL::fromString("http://foo.bar/baz/tron%C3%A7on/bam");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("/baz/tron\xc3\xa7on/bam"), url.getPath());
+ }
+
+ void testFromString_IPv4Address() {
+ URL url = URL::fromString("http://127.0.0.1/foobar");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("127.0.0.1"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(std::string("/foobar"), url.getPath());
+ }
+
+ void testFromString_IPv4AddressWithPort() {
+ URL url = URL::fromString("http://127.0.0.1:12345/foobar");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("127.0.0.1"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(12345, url.getPort().get_value_or(0));
+ CPPUNIT_ASSERT_EQUAL(std::string("/foobar"), url.getPath());
+ }
+
+ void testFromString_IPv6Address() {
+ URL url = URL::fromString("http://[fdf8:f53b:82e4::53]/foobar");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("fdf8:f53b:82e4::53"), url.getHost());
+ }
+
+ void testFromString_IPv6AddressWithPort() {
+ URL url = URL::fromString("http://[fdf8:f53b:82e4::53]:12435/foobar");
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("fdf8:f53b:82e4::53"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(12435, url.getPort().get_value_or(0));
+ }
+
+ void test_FromString_ToString_IPv6RFC2732() {
+ {
+ const char* testVector = "http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html";
+ URL url = URL::fromString(testVector);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("FEDC:BA98:7654:3210:FEDC:BA98:7654:3210"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(80, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
+
+ CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
+ }
+
+ {
+ const char* testVector = "http://[1080:0:0:0:8:800:200C:417A]/index.html";
+ URL url = URL::fromString(testVector);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("1080:0:0:0:8:800:200C:417A"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
+
+ CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
+ }
+
+ {
+ const char* testVector = "http://[3ffe:2a00:100:7031::1]";
+ URL url = URL::fromString(testVector);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("3ffe:2a00:100:7031::1"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(std::string(""), url.getPath());
+
+ CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
+ }
+
+ {
+ const char* testVector = "http://[1080::8:800:200C:417A]/foo";
+ URL url = URL::fromString(testVector);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("1080::8:800:200C:417A"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(std::string("/foo"), url.getPath());
+
+ CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
+ }
+
+ {
+ const char* testVector = "http://[::192.9.5.5]/ipng";
+ URL url = URL::fromString(testVector);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("::192.9.5.5"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(std::string("/ipng"), url.getPath());
+
+ CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
+ }
+
+ {
+ const char* testVector = "http://[::FFFF:129.144.52.38]:80/index.html";
+ URL url = URL::fromString(testVector);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("::FFFF:129.144.52.38"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(80, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(std::string("/index.html"), url.getPath());
+
+ CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
+ }
+
+ {
+ const char* testVector = "http://[2010:836B:4179::836B:4179]";
+ URL url = URL::fromString(testVector);
+
+ CPPUNIT_ASSERT_EQUAL(std::string("http"), url.getScheme());
+ CPPUNIT_ASSERT_EQUAL(std::string("2010:836B:4179::836B:4179"), url.getHost());
+ CPPUNIT_ASSERT_EQUAL(2, url.getPort().get_value_or(2));
+ CPPUNIT_ASSERT_EQUAL(std::string(), url.getPath());
+
+ CPPUNIT_ASSERT_EQUAL(std::string(testVector), url.toString());
+ }
+ }
+
+ void testToString() {
+ CPPUNIT_ASSERT_EQUAL(std::string("http://foo.bar/baz/bam"), URL("http", "foo.bar", "/baz/bam").toString());
+ }
+
+ void testToString_WithPort() {
+ CPPUNIT_ASSERT_EQUAL(std::string("http://foo.bar:1234/baz/bam"), URL("http", "foo.bar", 1234, "/baz/bam").toString());
+ }
};
CPPUNIT_TEST_SUITE_REGISTRATION(URLTest);