diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-07-04 16:30:34 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-07-04 16:30:34 -0700 |
commit | 872905197e3dbcdf0041930fda67cbd371c240ac (patch) | |
tree | 0f3c694e2b65eea87d0e6d3403353f0ef8f9b23e /test | |
parent | 4603102722e1cc2abc3494c9446bc576d008e7fa (diff) |
Add GenerateString (incomplete)
Add methods to set scheme, host, and query elements.
Add ability to generate URI strings out of scheme,
host, and query elements.
This does not yet support userinfo, port, or fragment elements.
Diffstat (limited to 'test')
-rw-r--r-- | test/src/UriTests.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/src/UriTests.cpp b/test/src/UriTests.cpp index 7f4a1a0..e2ad7bd 100644 --- a/test/src/UriTests.cpp +++ b/test/src/UriTests.cpp @@ -755,3 +755,34 @@ TEST(UriTests, IPv6Address) { ++index; } } + +TEST(UriTests, GenerateString) { + struct TestVector { + std::string scheme; + std::string host; + std::string query; + std::string expectedUriString; + }; + const std::vector< TestVector > testVectors{ + {"http", "www.example.com", "foobar", "http://www.example.com?foobar"}, + {"", "example.com", "bar", "//example.com?bar"}, + {"", "example.com", "", "//example.com"}, + {"", "", "bar", "?bar"}, + {"http", "", "bar", "http:?bar"}, + {"http", "", "", "http:"}, + {"http", "::1", "", "http://[::1]"}, + {"http", "::1.2.3.4", "", "http://[::1.2.3.4]"}, + {"http", "1.2.3.4", "", "http://1.2.3.4"}, + {"", "", "", ""}, + }; + size_t index = 0; + for (const auto& testVector : testVectors) { + Uri::Uri uri; + uri.SetScheme(testVector.scheme); + uri.SetHost(testVector.host); + uri.SetQuery(testVector.query); + const auto actualUriString = uri.GenerateString(); + ASSERT_EQ(testVector.expectedUriString, actualUriString) << index; + ++index; + } +} |