Code format

This commit is contained in:
yhirose 2021-04-13 20:52:49 -04:00
parent 6cc2edce99
commit 63643e6386
2 changed files with 103 additions and 89 deletions

View file

@ -417,16 +417,16 @@ TEST(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver) {
cli.set_connection_timeout(2);
std::string body;
auto res =
cli.Get("/httpgallery/chunked/chunkedimage.aspx?0.4153841143030137",
[&](const Response &response) {
EXPECT_EQ(200, response.status);
return true;
},
[&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
auto res = cli.Get(
"/httpgallery/chunked/chunkedimage.aspx?0.4153841143030137",
[&](const Response &response) {
EXPECT_EQ(200, response.status);
return true;
},
[&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
ASSERT_TRUE(res);
std::string out;
@ -916,11 +916,10 @@ TEST(RedirectFromPageWithContent, Redirect) {
cli.set_follow_location(true);
std::string body;
auto res = cli.Get("/1",
[&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
auto res = cli.Get("/1", [&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
@ -931,11 +930,10 @@ TEST(RedirectFromPageWithContent, Redirect) {
Client cli("localhost", PORT);
std::string body;
auto res = cli.Get("/1",
[&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
auto res = cli.Get("/1", [&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
ASSERT_TRUE(res);
EXPECT_EQ(302, res->status);
@ -2520,13 +2518,13 @@ TEST_F(ServerTest, SlowPost) {
char buffer[64 * 1024];
memset(buffer, 0x42, sizeof(buffer));
auto res =
cli_.Post("/slowpost", 64 * 1024 * 1024,
[&](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
sink.write(buffer, sizeof(buffer));
return true;
},
"text/plain");
auto res = cli_.Post(
"/slowpost", 64 * 1024 * 1024,
[&](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
sink.write(buffer, sizeof(buffer));
return true;
},
"text/plain");
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
@ -2537,13 +2535,13 @@ TEST_F(ServerTest, SlowPostFail) {
memset(buffer, 0x42, sizeof(buffer));
cli_.set_write_timeout(std::chrono::seconds(0));
auto res =
cli_.Post("/slowpost", 64 * 1024 * 1024,
[&](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
sink.write(buffer, sizeof(buffer));
return true;
},
"text/plain");
auto res = cli_.Post(
"/slowpost", 64 * 1024 * 1024,
[&](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
sink.write(buffer, sizeof(buffer));
return true;
},
"text/plain");
ASSERT_TRUE(!res);
EXPECT_EQ(Error::Write, res.error());
@ -2557,13 +2555,14 @@ TEST_F(ServerTest, Put) {
}
TEST_F(ServerTest, PutWithContentProvider) {
auto res = cli_.Put("/put", 3,
[](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
EXPECT_TRUE(sink.is_writable());
sink.os << "PUT";
return true;
},
"text/plain");
auto res = cli_.Put(
"/put", 3,
[](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
EXPECT_TRUE(sink.is_writable());
sink.os << "PUT";
return true;
},
"text/plain");
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
@ -2571,24 +2570,27 @@ TEST_F(ServerTest, PutWithContentProvider) {
}
TEST_F(ServerTest, PostWithContentProviderAbort) {
auto res = cli_.Post("/post", 42,
[](size_t /*offset*/, size_t /*length*/,
DataSink & /*sink*/) { return false; },
"text/plain");
auto res = cli_.Post(
"/post", 42,
[](size_t /*offset*/, size_t /*length*/, DataSink & /*sink*/) {
return false;
},
"text/plain");
ASSERT_TRUE(!res);
EXPECT_EQ(Error::Canceled, res.error());
}
TEST_F(ServerTest, PutWithContentProviderWithoutLength) {
auto res = cli_.Put("/put",
[](size_t /*offset*/, DataSink &sink) {
EXPECT_TRUE(sink.is_writable());
sink.os << "PUT";
sink.done();
return true;
},
"text/plain");
auto res = cli_.Put(
"/put",
[](size_t /*offset*/, DataSink &sink) {
EXPECT_TRUE(sink.is_writable());
sink.os << "PUT";
sink.done();
return true;
},
"text/plain");
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
@ -2607,13 +2609,14 @@ TEST_F(ServerTest, PostWithContentProviderWithoutLengthAbort) {
#ifdef CPPHTTPLIB_ZLIB_SUPPORT
TEST_F(ServerTest, PutWithContentProviderWithGzip) {
cli_.set_compress(true);
auto res = cli_.Put("/put", 3,
[](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
EXPECT_TRUE(sink.is_writable());
sink.os << "PUT";
return true;
},
"text/plain");
auto res = cli_.Put(
"/put", 3,
[](size_t /*offset*/, size_t /*length*/, DataSink &sink) {
EXPECT_TRUE(sink.is_writable());
sink.os << "PUT";
return true;
},
"text/plain");
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
@ -2622,10 +2625,12 @@ TEST_F(ServerTest, PutWithContentProviderWithGzip) {
TEST_F(ServerTest, PostWithContentProviderWithGzipAbort) {
cli_.set_compress(true);
auto res = cli_.Post("/post", 42,
[](size_t /*offset*/, size_t /*length*/,
DataSink & /*sink*/) { return false; },
"text/plain");
auto res = cli_.Post(
"/post", 42,
[](size_t /*offset*/, size_t /*length*/, DataSink & /*sink*/) {
return false;
},
"text/plain");
ASSERT_TRUE(!res);
EXPECT_EQ(Error::Canceled, res.error());
@ -2633,14 +2638,15 @@ TEST_F(ServerTest, PostWithContentProviderWithGzipAbort) {
TEST_F(ServerTest, PutWithContentProviderWithoutLengthWithGzip) {
cli_.set_compress(true);
auto res = cli_.Put("/put",
[](size_t /*offset*/, DataSink &sink) {
EXPECT_TRUE(sink.is_writable());
sink.os << "PUT";
sink.done();
return true;
},
"text/plain");
auto res = cli_.Put(
"/put",
[](size_t /*offset*/, DataSink &sink) {
EXPECT_TRUE(sink.is_writable());
sink.os << "PUT";
sink.done();
return true;
},
"text/plain");
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
@ -2960,8 +2966,9 @@ TEST_F(ServerTest, KeepAlive) {
EXPECT_EQ("empty", res->body);
EXPECT_EQ("close", res->get_header_value("Connection"));
res = cli_.Post("/empty", 0, [&](size_t, size_t, DataSink &) { return true; },
"text/plain");
res = cli_.Post(
"/empty", 0, [&](size_t, size_t, DataSink &) { return true; },
"text/plain");
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);
EXPECT_EQ("text/plain", res->get_header_value("Content-Type"));
@ -3556,7 +3563,7 @@ TEST(ErrorHandlerWithContentProviderTest, ErrorHandler) {
TEST(GetWithParametersTest, GetWithParameters) {
Server svr;
svr.Get("/", [&](const Request & req, Response &res) {
svr.Get("/", [&](const Request &req, Response &res) {
auto text = req.get_param_value("hello");
res.set_content(text, "text/plain");
});
@ -3585,7 +3592,7 @@ TEST(GetWithParametersTest, GetWithParameters) {
TEST(GetWithParametersTest, GetWithParameters2) {
Server svr;
svr.Get("/", [&](const Request & req, Response &res) {
svr.Get("/", [&](const Request &req, Response &res) {
auto text = req.get_param_value("hello");
res.set_content(text, "text/plain");
});
@ -3602,10 +3609,11 @@ TEST(GetWithParametersTest, GetWithParameters2) {
params.emplace("hello", "world");
std::string body;
auto res = cli.Get("/", params, Headers{}, [&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
auto res = cli.Get("/", params, Headers{},
[&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
ASSERT_TRUE(res);
EXPECT_EQ(200, res->status);