aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/src/UriTests.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp
index 2f8f28e..2be24b6 100644
--- a/test/src/UriTests.cpp
+++ b/test/src/UriTests.cpp
@@ -57,3 +57,52 @@ TEST(UriTests, ParseFromStringPathCornerCases) {
++index;
}
}
+
+TEST(UriTests, ParseFromStringHasAPortNumber) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString("http://www.example.com:8080/foo/bar"));
+ ASSERT_EQ("www.example.com", uri.GetHost());
+ ASSERT_TRUE(uri.HasPort());
+ ASSERT_EQ(8080, uri.GetPort());
+}
+
+TEST(UriTests, ParseFromStringDoesNotHaveAPortNumber) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString("http://www.example.com/foo/bar"));
+ ASSERT_EQ("www.example.com", uri.GetHost());
+ ASSERT_FALSE(uri.HasPort());
+}
+
+TEST(UriTests, ParseFromStringTwiceFirstWithPortNumberThenWithout) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString("http://www.example.com:8080/foo/bar"));
+ ASSERT_TRUE(uri.ParseFromString("http://www.example.com/foo/bar"));
+ ASSERT_FALSE(uri.HasPort());
+}
+
+TEST(UriTests, ParseFromStringBadPortNumberPurelyAlphabetic) {
+ Uri::Uri uri;
+ ASSERT_FALSE(uri.ParseFromString("http://www.example.com:spam/foo/bar"));
+}
+
+TEST(UriTests, ParseFromStringBadPortNumberStartsNumericEndsAlphabetic) {
+ Uri::Uri uri;
+ ASSERT_FALSE(uri.ParseFromString("http://www.example.com:8080spam/foo/bar"));
+}
+
+TEST(UriTests, ParseFromStringLargestValidPortNumber) {
+ Uri::Uri uri;
+ ASSERT_TRUE(uri.ParseFromString("http://www.example.com:65535/foo/bar"));
+ ASSERT_TRUE(uri.HasPort());
+ ASSERT_EQ(65535, uri.GetPort());
+}
+
+TEST(UriTests, ParseFromStringBadPortNumberTooBig) {
+ Uri::Uri uri;
+ ASSERT_FALSE(uri.ParseFromString("http://www.example.com:65536/foo/bar"));
+}
+
+TEST(UriTests, ParseFromStringBadPortNumberNegative) {
+ Uri::Uri uri;
+ ASSERT_FALSE(uri.ParseFromString("http://www.example.com:-1234/foo/bar"));
+}