|
9 | 9 |
|
10 | 10 | #include <atomic>
|
11 | 11 | #include <chrono>
|
| 12 | +#include <fstream> |
12 | 13 | #include <future>
|
13 | 14 | #include <limits>
|
14 | 15 | #include <memory>
|
@@ -59,6 +60,16 @@ MultipartFormData &get_file_value(MultipartFormDataItems &files,
|
59 | 60 | #endif
|
60 | 61 | }
|
61 | 62 |
|
| 63 | +static void read_file(const std::string &path, std::string &out) { |
| 64 | + std::ifstream fs(path, std::ios_base::binary); |
| 65 | + if (!fs) throw std::runtime_error("File not found: " + path); |
| 66 | + fs.seekg(0, std::ios_base::end); |
| 67 | + auto size = fs.tellg(); |
| 68 | + fs.seekg(0); |
| 69 | + out.resize(static_cast<size_t>(size)); |
| 70 | + fs.read(&out[0], static_cast<std::streamsize>(size)); |
| 71 | +} |
| 72 | + |
62 | 73 | #ifndef _WIN32
|
63 | 74 | class UnixSocketTest : public ::testing::Test {
|
64 | 75 | protected:
|
@@ -729,7 +740,7 @@ TEST(ChunkedEncodingTest, FromHTTPWatch_Online) {
|
729 | 740 | ASSERT_TRUE(res);
|
730 | 741 |
|
731 | 742 | std::string out;
|
732 |
| - detail::read_file("./image.jpg", out); |
| 743 | + read_file("./image.jpg", out); |
733 | 744 |
|
734 | 745 | EXPECT_EQ(StatusCode::OK_200, res->status);
|
735 | 746 | EXPECT_EQ(out, res->body);
|
@@ -782,7 +793,7 @@ TEST(ChunkedEncodingTest, WithContentReceiver_Online) {
|
782 | 793 | ASSERT_TRUE(res);
|
783 | 794 |
|
784 | 795 | std::string out;
|
785 |
| - detail::read_file("./image.jpg", out); |
| 796 | + read_file("./image.jpg", out); |
786 | 797 |
|
787 | 798 | EXPECT_EQ(StatusCode::OK_200, res->status);
|
788 | 799 | EXPECT_EQ(out, body);
|
@@ -814,7 +825,7 @@ TEST(ChunkedEncodingTest, WithResponseHandlerAndContentReceiver_Online) {
|
814 | 825 | ASSERT_TRUE(res);
|
815 | 826 |
|
816 | 827 | std::string out;
|
817 |
| - detail::read_file("./image.jpg", out); |
| 828 | + read_file("./image.jpg", out); |
818 | 829 |
|
819 | 830 | EXPECT_EQ(StatusCode::OK_200, res->status);
|
820 | 831 | EXPECT_EQ(out, body);
|
@@ -6176,7 +6187,7 @@ TEST(SSLClientTest, ServerCertificateVerification4) {
|
6176 | 6187 |
|
6177 | 6188 | TEST(SSLClientTest, ServerCertificateVerification5_Online) {
|
6178 | 6189 | std::string cert;
|
6179 |
| - detail::read_file(CA_CERT_FILE, cert); |
| 6190 | + read_file(CA_CERT_FILE, cert); |
6180 | 6191 |
|
6181 | 6192 | SSLClient cli("google.com");
|
6182 | 6193 | cli.load_ca_cert_store(cert.data(), cert.size());
|
|
0 commit comments