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