Skip to content

Commit 3784aa0

Browse files
committed
test: add response_factory facility for body unit tests
1 parent bf34a8e commit 3784aa0

17 files changed

Lines changed: 1550 additions & 125 deletions

CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,9 @@ function(boost_burl_setup_properties target)
176176
endfunction()
177177

178178
if (BOOST_BURL_MRDOCS_BUILD)
179-
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/mrdocs.cpp" "#include <boost/burl.hpp>\n")
179+
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/mrdocs.cpp"
180+
"#include <boost/burl.hpp>\n"
181+
"#include <boost/burl/test/response_factory.hpp>\n")
180182
add_library(boost_burl_mrdocs "${CMAKE_CURRENT_BINARY_DIR}/mrdocs.cpp")
181183
boost_burl_setup_properties(boost_burl_mrdocs)
182184
target_compile_definitions(boost_burl_mrdocs PUBLIC BOOST_BURL_MRDOCS)

doc/mrdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ file-patterns:
1010
# Filters
1111
include-symbols:
1212
- 'boost::burl::**'
13+
- 'boost::burl::test::**'
1314
implementation-defined:
1415
- 'boost::burl::detail'
1516
- 'boost::burl::*::detail'

include/boost/burl/detail/connection_pool.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define BOOST_BURL_DETAIL_CONNECTION_POOL_HPP
1212

1313
#include <boost/burl/detail/config.hpp>
14+
#include <boost/burl/test/response_factory_fwd.hpp>
1415
#include <boost/capy/buffers.hpp>
1516
#include <boost/capy/detail/buffer_array.hpp>
1617
#include <boost/capy/io_task.hpp>
@@ -74,6 +75,7 @@ class connection
7475
class pooled_connection
7576
{
7677
friend class connection_pool;
78+
friend class test::response_factory;
7779

7880
using duration = std::chrono::steady_clock::duration;
7981

include/boost/burl/response.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <boost/burl/detail/config.hpp>
1515
#include <boost/burl/detail/connection_pool.hpp>
1616
#include <boost/burl/error.hpp>
17+
#include <boost/burl/test/response_factory_fwd.hpp>
1718
#include <boost/capy/io/any_buffer_source.hpp>
1819
#include <boost/capy/io/any_read_source.hpp>
1920
#include <boost/capy/io_task.hpp>
@@ -74,13 +75,15 @@ namespace burl
7475
class response
7576
{
7677
friend class client;
78+
friend class test::response_factory;
7779
using clock = std::chrono::steady_clock;
7880

7981
urls::url url_;
8082
detail::pooled_connection conn_;
8183
http::response_parser parser_;
8284
std::optional<clock::time_point> deadline_;
8385

86+
BOOST_BURL_DECL
8487
response(
8588
urls::url url,
8689
detail::pooled_connection conn,
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// Copyright (c) 2026 Mohammad Nejati
3+
//
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
// Official repository: https://github.com/cppalliance/burl
8+
//
9+
10+
#ifndef BOOST_BURL_TEST_DETAIL_BUFFER_CONNECTION_HPP
11+
#define BOOST_BURL_TEST_DETAIL_BUFFER_CONNECTION_HPP
12+
13+
#include <boost/burl/detail/connection_pool.hpp>
14+
15+
#include <boost/capy/buffers/buffer_copy.hpp>
16+
#include <boost/capy/buffers/make_buffer.hpp>
17+
#include <boost/capy/error.hpp>
18+
#include <boost/capy/io_task.hpp>
19+
#include <boost/capy/test/fuse.hpp>
20+
#include <boost/capy/buffers/buffer_slice.hpp>
21+
22+
#include <cstddef>
23+
#include <string>
24+
#include <vector>
25+
26+
namespace boost
27+
{
28+
namespace burl
29+
{
30+
namespace test
31+
{
32+
namespace detail
33+
{
34+
35+
class buffer_connection final : public burl::detail::connection
36+
{
37+
std::vector<std::string> chunks_;
38+
capy::test::fuse fuse_;
39+
std::size_t idx_ = 0;
40+
std::size_t pos_ = 0;
41+
42+
public:
43+
buffer_connection(
44+
std::vector<std::string> chunks,
45+
capy::test::fuse fuse)
46+
: chunks_(std::move(chunks))
47+
, fuse_(std::move(fuse))
48+
{
49+
}
50+
51+
bool
52+
is_open() const noexcept override
53+
{
54+
return true;
55+
}
56+
57+
capy::io_task<>
58+
shutdown() override
59+
{
60+
co_return {};
61+
}
62+
63+
private:
64+
capy::io_task<std::size_t>
65+
do_read_some(std::span<capy::mutable_buffer const> bufs) override
66+
{
67+
if(auto ec = fuse_.maybe_fail())
68+
co_return { ec, 0 };
69+
70+
if(idx_ >= chunks_.size())
71+
co_return { capy::error::eof, 0 };
72+
73+
auto const b = capy::make_buffer(chunks_[idx_]);
74+
auto const n = capy::buffer_copy(
75+
bufs, capy::buffer_slice(b, pos_).data());
76+
pos_ += n;
77+
if(pos_ == b.size())
78+
{
79+
++idx_;
80+
pos_ = 0;
81+
}
82+
co_return { {}, n };
83+
}
84+
85+
capy::io_task<std::size_t>
86+
do_write_some(std::span<capy::const_buffer const>) override
87+
{
88+
co_return { capy::error::eof, 0 };
89+
}
90+
};
91+
92+
} // namespace detail
93+
} // namespace test
94+
} // namespace burl
95+
} // namespace boost
96+
97+
#endif

0 commit comments

Comments
 (0)