You've already forked cpp-httplib
clang-format
This commit is contained in:
89
test/test.cc
89
test/test.cc
@ -5305,8 +5305,10 @@ TEST_F(ServerTest, PatchContentReceiver) {
|
||||
template <typename ClientType>
|
||||
void TestWithHeadersAndContentReceiver(
|
||||
ClientType &cli,
|
||||
std::function<Result(ClientType&, const std::string&, const Headers&, const std::string&, const std::string&,
|
||||
ContentReceiver, DownloadProgress)> request_func) {
|
||||
std::function<Result(ClientType &, const std::string &, const Headers &,
|
||||
const std::string &, const std::string &,
|
||||
ContentReceiver, DownloadProgress)>
|
||||
request_func) {
|
||||
Headers headers;
|
||||
headers.emplace("X-Custom-Header", "test-value");
|
||||
|
||||
@ -5316,7 +5318,8 @@ void TestWithHeadersAndContentReceiver(
|
||||
[&](const char *data, size_t data_length) {
|
||||
received_body.append(data, data_length);
|
||||
return true;
|
||||
}, nullptr);
|
||||
},
|
||||
nullptr);
|
||||
|
||||
ASSERT_TRUE(res);
|
||||
EXPECT_EQ(StatusCode::OK_200, res->status);
|
||||
@ -5329,9 +5332,10 @@ TEST_F(ServerTest, PostWithHeadersAndContentReceiver) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiver<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver, DownloadProgress progress) {
|
||||
TestWithHeadersAndContentReceiver<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver, DownloadProgress progress) {
|
||||
return cli.Post(path, headers, body, content_type, receiver, progress);
|
||||
});
|
||||
}
|
||||
@ -5342,9 +5346,10 @@ TEST_F(ServerTest, PutWithHeadersAndContentReceiver) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiver<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver, DownloadProgress progress) {
|
||||
TestWithHeadersAndContentReceiver<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver, DownloadProgress progress) {
|
||||
return cli.Put(path, headers, body, content_type, receiver, progress);
|
||||
});
|
||||
}
|
||||
@ -5355,9 +5360,10 @@ TEST_F(ServerTest, PatchWithHeadersAndContentReceiver) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiver<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver, DownloadProgress progress) {
|
||||
TestWithHeadersAndContentReceiver<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver, DownloadProgress progress) {
|
||||
return cli.Patch(path, headers, body, content_type, receiver, progress);
|
||||
});
|
||||
}
|
||||
@ -5365,8 +5371,10 @@ TEST_F(ServerTest, PatchWithHeadersAndContentReceiver) {
|
||||
template <typename ClientType>
|
||||
void TestWithHeadersAndContentReceiverWithProgress(
|
||||
ClientType &cli,
|
||||
std::function<Result(ClientType&, const std::string&, const Headers&, const std::string&, const std::string&,
|
||||
ContentReceiver, DownloadProgress)> request_func) {
|
||||
std::function<Result(ClientType &, const std::string &, const Headers &,
|
||||
const std::string &, const std::string &,
|
||||
ContentReceiver, DownloadProgress)>
|
||||
request_func) {
|
||||
Headers headers;
|
||||
headers.emplace("X-Test-Header", "progress-test");
|
||||
|
||||
@ -5396,9 +5404,10 @@ TEST_F(ServerTest, PostWithHeadersAndContentReceiverWithProgress) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiverWithProgress<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver, DownloadProgress progress) {
|
||||
TestWithHeadersAndContentReceiverWithProgress<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver, DownloadProgress progress) {
|
||||
return cli.Post(path, headers, body, content_type, receiver, progress);
|
||||
});
|
||||
}
|
||||
@ -5409,9 +5418,10 @@ TEST_F(ServerTest, PutWithHeadersAndContentReceiverWithProgress) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiverWithProgress<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver, DownloadProgress progress) {
|
||||
TestWithHeadersAndContentReceiverWithProgress<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver, DownloadProgress progress) {
|
||||
return cli.Put(path, headers, body, content_type, receiver, progress);
|
||||
});
|
||||
}
|
||||
@ -5422,26 +5432,28 @@ TEST_F(ServerTest, PatchWithHeadersAndContentReceiverWithProgress) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiverWithProgress<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver, DownloadProgress progress) {
|
||||
TestWithHeadersAndContentReceiverWithProgress<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver, DownloadProgress progress) {
|
||||
return cli.Patch(path, headers, body, content_type, receiver, progress);
|
||||
});
|
||||
}
|
||||
|
||||
template <typename ClientType>
|
||||
void TestWithHeadersAndContentReceiverError(
|
||||
ClientType& cli,
|
||||
std::function<Result(ClientType&, const std::string&, const Headers&, const std::string&, const std::string&,
|
||||
ContentReceiver)> request_func) {
|
||||
ClientType &cli, std::function<Result(ClientType &, const std::string &,
|
||||
const Headers &, const std::string &,
|
||||
const std::string &, ContentReceiver)>
|
||||
request_func) {
|
||||
Headers headers;
|
||||
headers.emplace("X-Error-Test", "true");
|
||||
|
||||
std::string received_body;
|
||||
auto receiver_failed = false;
|
||||
|
||||
auto res = request_func(
|
||||
cli, "/content_receiver", headers, "content", "text/plain",
|
||||
auto res =
|
||||
request_func(cli, "/content_receiver", headers, "content", "text/plain",
|
||||
[&](const char *data, size_t data_length) {
|
||||
received_body.append(data, data_length);
|
||||
receiver_failed = true;
|
||||
@ -5458,9 +5470,10 @@ TEST_F(ServerTest, PostWithHeadersAndContentReceiverError) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiverError<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver) {
|
||||
TestWithHeadersAndContentReceiverError<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver) {
|
||||
return cli.Post(path, headers, body, content_type, receiver);
|
||||
});
|
||||
}
|
||||
@ -5471,9 +5484,10 @@ TEST_F(ServerTest, PuttWithHeadersAndContentReceiverError) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiverError<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver) {
|
||||
TestWithHeadersAndContentReceiverError<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver) {
|
||||
return cli.Put(path, headers, body, content_type, receiver);
|
||||
});
|
||||
}
|
||||
@ -5484,9 +5498,10 @@ TEST_F(ServerTest, PatchWithHeadersAndContentReceiverError) {
|
||||
#else
|
||||
using ClientT = Client;
|
||||
#endif
|
||||
TestWithHeadersAndContentReceiverError<ClientT>(cli_,
|
||||
[](ClientT& cli, const std::string& path, const Headers& headers, const std::string& body,
|
||||
const std::string& content_type, ContentReceiver receiver) {
|
||||
TestWithHeadersAndContentReceiverError<ClientT>(
|
||||
cli_, [](ClientT &cli, const std::string &path, const Headers &headers,
|
||||
const std::string &body, const std::string &content_type,
|
||||
ContentReceiver receiver) {
|
||||
return cli.Patch(path, headers, body, content_type, receiver);
|
||||
});
|
||||
}
|
||||
|
Reference in New Issue
Block a user