| 1 | // |
|---|---|
| 2 | // Copyright (c) 2023 Klemens Morgenstern (klemens.morgenstern@gmx.net) |
| 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 | |
| 8 | #include <boost/cobalt/detail/monotonic_resource.hpp> |
| 9 | |
| 10 | #include <boost/test/unit_test.hpp> |
| 11 | |
| 12 | BOOST_AUTO_TEST_SUITE(monotonic_resource); |
| 13 | |
| 14 | BOOST_AUTO_TEST_CASE(basic) |
| 15 | { |
| 16 | char buf[1024]; |
| 17 | boost::cobalt::detail::monotonic_resource res{buf, sizeof(buf)}; |
| 18 | |
| 19 | { |
| 20 | std::vector<int, boost::cobalt::detail::monotonic_allocator<int>> vec{}; |
| 21 | |
| 22 | for (int i = 0u; i < 4000; i++) |
| 23 | vec.push_back(x: i); |
| 24 | } |
| 25 | { |
| 26 | std::vector<int, boost::cobalt::detail::monotonic_allocator<int>> vec{&res}; |
| 27 | |
| 28 | for (int i = 0u; i < 4000; i++) |
| 29 | vec.push_back(x: i); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | BOOST_AUTO_TEST_CASE(too_small) |
| 34 | { |
| 35 | char buf[1]; |
| 36 | boost::cobalt::detail::monotonic_resource res{buf, sizeof(buf)}; |
| 37 | |
| 38 | { |
| 39 | std::vector<int, boost::cobalt::detail::monotonic_allocator<int>> vec{}; |
| 40 | |
| 41 | for (int i = 0u; i < 4000; i++) |
| 42 | vec.push_back(x: i); |
| 43 | } |
| 44 | { |
| 45 | std::vector<int, boost::cobalt::detail::monotonic_allocator<int>> vec{&res}; |
| 46 | |
| 47 | for (int i = 0u; i < 4000; i++) |
| 48 | vec.push_back(x: i); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | BOOST_AUTO_TEST_CASE(no_buf) |
| 53 | { |
| 54 | boost::cobalt::detail::monotonic_resource res; |
| 55 | |
| 56 | { |
| 57 | std::vector<int, boost::cobalt::detail::monotonic_allocator<int>> vec{}; |
| 58 | |
| 59 | for (int i = 0u; i < 4000; i++) |
| 60 | vec.push_back(x: i); |
| 61 | } |
| 62 | { |
| 63 | std::vector<int, boost::cobalt::detail::monotonic_allocator<int>> vec{&res}; |
| 64 | |
| 65 | for (int i = 0u; i < 4000; i++) |
| 66 | vec.push_back(x: i); |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | BOOST_AUTO_TEST_SUITE_END(); |
