From 27322abb7ec40f46020f93b3814c19f77ea2ccfb Mon Sep 17 00:00:00 2001 From: Francois Rousseau Date: Tue, 5 Nov 2019 14:31:17 -0800 Subject: [PATCH] [net] specify parameter name in parameterized test suite * this renders as "HTTPTransport/HTTPTransport.ValidFormData_Gzip/http" instead of the default "HTTPTransport/HTTPTransport.ValidFormData_Gzip/0" * switch the parameter type from a base::FilePath::StringType to a string Change-Id: I19743966406f92176c566827d74a79aef5a87bb5 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/1900324 Reviewed-by: Scott Graham Commit-Queue: Francois Rousseau --- util/net/http_transport_test.cc | 44 +++++++++++++++++---------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/util/net/http_transport_test.cc b/util/net/http_transport_test.cc index 7c5ca2f2..d6a7675f 100644 --- a/util/net/http_transport_test.cc +++ b/util/net/http_transport_test.cc @@ -54,10 +54,10 @@ std::string ToUTF8IfWin(const std::string& x) { class HTTPTransportTestFixture : public MultiprocessExec { public: - using RequestValidator = - void(*)(HTTPTransportTestFixture*, const std::string&); + using RequestValidator = void (*)(HTTPTransportTestFixture*, + const std::string&); - HTTPTransportTestFixture(const base::FilePath::StringType& scheme, + HTTPTransportTestFixture(const std::string& scheme, const HTTPHeaders& headers, std::unique_ptr body_stream, uint16_t http_response_code, @@ -74,9 +74,9 @@ class HTTPTransportTestFixture : public MultiprocessExec { #if defined(OS_WIN) FILE_PATH_LITERAL(".exe") #endif - ); + ); - if (ToUTF8IfWin(scheme) == "http") { + if (scheme == "http") { scheme_and_host_ = "http://localhost"; SetChildCommand(server_path, nullptr); } else { @@ -116,9 +116,8 @@ class HTTPTransportTestFixture : public MultiprocessExec { // 200. const std::string random_string = RandomString(); - ASSERT_TRUE(LoggingWriteFile(WritePipeHandle(), - random_string.c_str(), - random_string.size())); + ASSERT_TRUE(LoggingWriteFile( + WritePipeHandle(), random_string.c_str(), random_string.size())); // Now execute the HTTP request. std::unique_ptr transport(HTTPTransport::Create()); @@ -245,8 +244,7 @@ void ValidFormData(HTTPTransportTestFixture* fixture, EXPECT_EQ(request.substr(body_start), expected); } -class HTTPTransport - : public testing::TestWithParam {}; +class HTTPTransport : public testing::TestWithParam {}; TEST_P(HTTPTransport, ValidFormData) { HTTPMultipartBuilder builder; @@ -256,8 +254,8 @@ TEST_P(HTTPTransport, ValidFormData) { HTTPHeaders headers; builder.PopulateContentHeaders(&headers); - HTTPTransportTestFixture test(GetParam(), - headers, builder.GetBodyStream(), 200, &ValidFormData); + HTTPTransportTestFixture test( + GetParam(), headers, builder.GetBodyStream(), 200, &ValidFormData); test.Run(); } @@ -288,8 +286,8 @@ TEST_P(HTTPTransport, ErrorResponse) { HTTPMultipartBuilder builder; HTTPHeaders headers; headers[kContentType] = kTextPlain; - HTTPTransportTestFixture test(GetParam(), headers, builder.GetBodyStream(), - 404, &ErrorResponse); + HTTPTransportTestFixture test( + GetParam(), headers, builder.GetBodyStream(), 404, &ErrorResponse); test.Run(); } @@ -320,13 +318,12 @@ TEST_P(HTTPTransport, UnchunkedPlainText) { headers[kContentType] = kTextPlain; headers[kContentLength] = base::StringPrintf("%" PRIuS, strlen(kTextBody)); - HTTPTransportTestFixture test(GetParam(), - headers, std::move(body_stream), 200, &UnchunkedPlainText); + HTTPTransportTestFixture test( + GetParam(), headers, std::move(body_stream), 200, &UnchunkedPlainText); test.Run(); } -void RunUpload33k(const base::FilePath::StringType& scheme, - bool has_content_length) { +void RunUpload33k(const std::string& scheme, bool has_content_length) { // On macOS, NSMutableURLRequest winds up calling into a CFReadStream’s Read() // callback with a 32kB buffer. Make sure that it’s able to get everything // when enough is available to fill this buffer, requiring more than one @@ -375,12 +372,17 @@ TEST_P(HTTPTransport, Upload33k_LengthUnknown) { // re-running generate_test_server_key.py. INSTANTIATE_TEST_SUITE_P(HTTPTransport, HTTPTransport, - testing::Values(FILE_PATH_LITERAL("http"), - FILE_PATH_LITERAL("https"))); + testing::Values("http", "https"), + [](const testing::TestParamInfo& info) { + return info.param; + }); #else INSTANTIATE_TEST_SUITE_P(HTTPTransport, HTTPTransport, - testing::Values(FILE_PATH_LITERAL("http"))); + testing::Values("http"), + [](const testing::TestParamInfo& info) { + return info.param; + }); #endif } // namespace