| 1 | // |
|---|---|
| 2 | // recycling_allocator.cpp |
| 3 | // ~~~~~~~~~~~~~~~~~~~~~~~ |
| 4 | // |
| 5 | // Copyright (c) 2003-2024 Christopher M. Kohlhoff (chris at kohlhoff dot com) |
| 6 | // |
| 7 | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 8 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 9 | // |
| 10 | |
| 11 | // Disable autolinking for unit tests. |
| 12 | #if !defined(BOOST_ALL_NO_LIB) |
| 13 | #define BOOST_ALL_NO_LIB 1 |
| 14 | #endif // !defined(BOOST_ALL_NO_LIB) |
| 15 | |
| 16 | // Test that header file is self-contained. |
| 17 | #include <boost/asio/recycling_allocator.hpp> |
| 18 | |
| 19 | #include "unit_test.hpp" |
| 20 | #include <vector> |
| 21 | #include <boost/asio/detail/type_traits.hpp> |
| 22 | |
| 23 | void recycling_allocator_test() |
| 24 | { |
| 25 | BOOST_ASIO_CHECK(( |
| 26 | boost::asio::is_same< |
| 27 | boost::asio::recycling_allocator<int>::value_type, |
| 28 | int |
| 29 | >::value)); |
| 30 | |
| 31 | BOOST_ASIO_CHECK(( |
| 32 | boost::asio::is_same< |
| 33 | boost::asio::recycling_allocator<void>::value_type, |
| 34 | void |
| 35 | >::value)); |
| 36 | |
| 37 | BOOST_ASIO_CHECK(( |
| 38 | boost::asio::is_same< |
| 39 | boost::asio::recycling_allocator<int>::rebind<char>::other, |
| 40 | boost::asio::recycling_allocator<char> |
| 41 | >::value)); |
| 42 | |
| 43 | BOOST_ASIO_CHECK(( |
| 44 | boost::asio::is_same< |
| 45 | boost::asio::recycling_allocator<void>::rebind<char>::other, |
| 46 | boost::asio::recycling_allocator<char> |
| 47 | >::value)); |
| 48 | |
| 49 | boost::asio::recycling_allocator<int> a1; |
| 50 | boost::asio::recycling_allocator<int> a2(a1); |
| 51 | |
| 52 | BOOST_ASIO_CHECK(a1 == a2); |
| 53 | BOOST_ASIO_CHECK(!(a1 != a2)); |
| 54 | |
| 55 | boost::asio::recycling_allocator<void> a3; |
| 56 | boost::asio::recycling_allocator<void> a4(a3); |
| 57 | |
| 58 | BOOST_ASIO_CHECK(a3 == a4); |
| 59 | BOOST_ASIO_CHECK(!(a3 != a4)); |
| 60 | |
| 61 | boost::asio::recycling_allocator<int> a5(a4); |
| 62 | (void)a5; |
| 63 | |
| 64 | boost::asio::recycling_allocator<void> a6(a5); |
| 65 | (void)a6; |
| 66 | |
| 67 | int* p = a1.allocate(n: 42); |
| 68 | BOOST_ASIO_CHECK(p != 0); |
| 69 | |
| 70 | a1.deallocate(p, n: 42); |
| 71 | |
| 72 | std::vector<int, boost::asio::recycling_allocator<int> > v(42); |
| 73 | BOOST_ASIO_CHECK(v.size() == 42); |
| 74 | } |
| 75 | |
| 76 | BOOST_ASIO_TEST_SUITE |
| 77 | ( |
| 78 | "recycling_allocator", |
| 79 | BOOST_ASIO_TEST_CASE(recycling_allocator_test) |
| 80 | ) |
| 81 |
