Skip to content

Commit 90a07a1

Browse files
committed
test_any_adapter
1 parent 585988b commit 90a07a1

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ make_test(test_conn_exec_cancel 20)
4747
make_test(test_conn_exec_cancel2 20)
4848
make_test(test_conn_echo_stress 20)
4949
make_test(test_conn_run_cancel 20)
50+
make_test(test_any_adapter 17)
5051
make_test(test_issue_50 20)
5152
make_test(test_issue_181 17)
5253

test/test_any_adapter.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Copyright (c) 2018-2022 Marcelo Zimbres Silva ([email protected])
2+
*
3+
* Distributed under the Boost Software License, Version 1.0. (See
4+
* accompanying file LICENSE.txt)
5+
*/
6+
7+
#include <boost/redis/ignore.hpp>
8+
#include <boost/redis/response.hpp>
9+
#include <boost/redis/adapter/any_adapter.hpp>
10+
#include <string>
11+
#define BOOST_TEST_MODULE any_adapter
12+
#include <boost/test/included/unit_test.hpp>
13+
14+
using boost::redis::generic_response;
15+
using boost::redis::response;
16+
using boost::redis::ignore;
17+
using boost::redis::any_adapter;
18+
19+
BOOST_AUTO_TEST_CASE(any_adapter_response_types)
20+
{
21+
// any_adapter can be used with any supported responses
22+
response<int> r1;
23+
response<int, std::string> r2;
24+
generic_response r3;
25+
26+
BOOST_CHECK_NO_THROW(any_adapter{r1});
27+
BOOST_CHECK_NO_THROW(any_adapter{r2});
28+
BOOST_CHECK_NO_THROW(any_adapter{r3});
29+
BOOST_CHECK_NO_THROW(any_adapter{ignore});
30+
}
31+
32+
BOOST_AUTO_TEST_CASE(any_adapter_copy_move)
33+
{
34+
// any_adapter can be copied/moved
35+
response<int, std::string> r;
36+
any_adapter ad1 {r};
37+
38+
// copy constructor
39+
any_adapter ad2 {ad1};
40+
41+
// move constructor
42+
any_adapter ad3 {std::move(ad2)};
43+
44+
// copy assignment
45+
BOOST_CHECK_NO_THROW(ad2 = ad1);
46+
47+
// move assignment
48+
BOOST_CHECK_NO_THROW(ad2 = std::move(ad1));
49+
}

0 commit comments

Comments
 (0)