From a43820d0b4014878e4bbfede6acde25f5830faa7 Mon Sep 17 00:00:00 2001 From: Richard Walters Date: Sat, 30 Jun 2018 21:20:37 -0700 Subject: Add support for port and hasPort elements --- test/src/UriTests.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test/src/UriTests.cpp') 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")); +} -- cgit v1.2.3