Chromium Code Reviews| Index: url/gurl_unittest.cc |
| diff --git a/url/gurl_unittest.cc b/url/gurl_unittest.cc |
| index a20472d0aa33c284cac351f902f72ff00af34ac4..c68e7f2e6660d082e9b43006252d77a078c011ab 100644 |
| --- a/url/gurl_unittest.cc |
| +++ b/url/gurl_unittest.cc |
| @@ -561,7 +561,29 @@ TEST(GURLTest, IPAddress) { |
| } |
| } |
| -TEST(GURLTest, HostNoBrackets) { |
| +// Type-parameterized test for variants of the host returning methods. |
| +template <typename StringType> |
| +class GURLHostTest : public ::testing::Test { |
|
brettw
2017/06/30 19:33:14
This is a lot of hard-to-read complexity, when I t
Adam Rice
2017/07/03 04:51:51
Thank you! I was so fixated on the type difference
|
| + public: |
| + // The GURL methods are wrapped to deal with having different method names for |
| + // the types. |
| + StringType host(const GURL& url) { return url.host(); } |
| + StringType HostNoBrackets(const GURL& url) { return url.HostNoBrackets(); } |
| +}; |
| + |
| +template <> |
| +class GURLHostTest<base::StringPiece> : public ::testing::Test { |
| + public: |
| + base::StringPiece host(const GURL& url) { return url.host_piece(); } |
| + base::StringPiece HostNoBrackets(const GURL& url) { |
| + return url.HostNoBracketsPiece(); |
| + } |
| +}; |
| + |
| +using GURLHostTestTypes = ::testing::Types<std::string, base::StringPiece>; |
| +TYPED_TEST_CASE(GURLHostTest, GURLHostTestTypes); |
| + |
| +TYPED_TEST(GURLHostTest, HostNoBrackets) { |
| struct TestCase { |
| const char* input; |
| const char* expected_host; |
| @@ -582,8 +604,8 @@ TEST(GURLTest, HostNoBrackets) { |
| }; |
| for (size_t i = 0; i < arraysize(cases); i++) { |
| GURL url(cases[i].input); |
| - EXPECT_EQ(cases[i].expected_host, url.host()); |
| - EXPECT_EQ(cases[i].expected_plainhost, url.HostNoBrackets()); |
| + EXPECT_EQ(cases[i].expected_host, this->host(url)); |
| + EXPECT_EQ(cases[i].expected_plainhost, this->HostNoBrackets(url)); |
| } |
| } |