Toolbox snapshot
The Reactive C++ Toolbox
Loading...
Searching...
No Matches
Allocator.ut.cpp
Go to the documentation of this file.
1// The Reactive C++ Toolbox.
2// Copyright (C) 2013-2019 Swirly Cloud Limited
3// Copyright (C) 2021 Reactive Markets Limited
4//
5// Licensed under the Apache License, Version 2.0 (the "License");
6// you may not use this file except in compliance with the License.
7// You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing, software
12// distributed under the License is distributed on an "AS IS" BASIS,
13// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14// See the License for the specific language governing permissions and
15// limitations under the License.
16
17#include "Allocator.hpp"
18
20
21#include <boost/test/unit_test.hpp>
22
23using namespace std;
24using namespace toolbox;
25
26namespace {
27
28std::size_t size_{};
29std::align_val_t al_{};
30
31struct alignas(64) Foo : RefCount<Foo, ThreadUnsafePolicy> {
32
33 static void* operator new(std::size_t size, std::align_val_t al)
34 {
35 size_ = size;
36 al_ = al;
37 return ::operator new(size, al);
38 }
39 static void operator delete(void* ptr, std::size_t size, std::align_val_t al) noexcept
40 {
41 size_ = size;
42 al_ = al;
43#if __cpp_sized_deallocation
44 ::operator delete(ptr, size, al);
45#else
46 ::operator delete(ptr, al);
47#endif
48 }
49 char data[64 + 1];
50};
51
52} // namespace
53
55
57{
58 {
59 auto h = make_intrusive<Foo>();
60 BOOST_CHECK_EQUAL(size_, 128);
61 BOOST_CHECK_EQUAL(static_cast<int>(al_), 64);
62 size_ = {};
63 al_ = {};
64 }
65 BOOST_CHECK_EQUAL(size_, 128);
66 BOOST_CHECK_EQUAL(static_cast<int>(al_), 64);
67}
68
BOOST_AUTO_TEST_CASE(AllocatorCase)
BOOST_CHECK_EQUAL(v.size(), 10U)
Base class for atomic referenced counted objects.
Definition RefCount.hpp:61
STL namespace.
const DataT & data(const MsgEvent &ev) noexcept
Definition Event.hpp:54
constexpr std::size_t size(const detail::Struct< detail::Member< TagsT, ValuesT >... > &s)
Definition Struct.hpp:98
constexpr auto bind() noexcept
Definition Slot.hpp:92