aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2018-06-30 21:20:37 -0700
committerRichard Walters <rwalters@digitalstirling.com>2018-06-30 21:20:37 -0700
commita43820d0b4014878e4bbfede6acde25f5830faa7 (patch)
tree58892b88fe5927b04b060af1501741c4766b7bee /test
parent58e2beb7717cf724ae37e03f2e5bf3afbfc23a35 (diff)
Add support for port and hasPort elements
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"));
+}