Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
typed-allocation-manager-test.cpp
Go to the documentation of this file.
1/*
2 TypedAllocationManager(Test) - check interface to pooled allocations
3
4 Copyright (C)
5 2009, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
19#include "lib/test/run.hpp"
21#include "lib/util.hpp"
22
23#include <memory>
24
25
26namespace lib {
27namespace test{
28
30 using std::shared_ptr;
31
32
33
34 namespace { // test data and helpers...
35
36 long checksum_ = 0;
37
41 template<uint siz>
43 {
44 char crap_[siz];
45
46 public:
48 {
49 REQUIRE (siz);
50 for (uint i=0; i<siz; ++i)
51 checksum_ += (crap_[i] = rani(128));
52 }
53
55 {
56 for (uint i=0; i<siz; ++i)
57 checksum_ -= crap_[i];
58 }
59 };
60 }
61
62
63
64 /***********************************************************************************/
74 class TypedAllocationManager_test : public Test
75 {
76
77 virtual void
78 run (Arg)
79 {
80 CHECK (0 == checksum_);
81 seedRand();
82
83 TypedAllocationManager allocator;
84
85 typedef shared_ptr<DummyObj<1>> PD1;
86 typedef shared_ptr<DummyObj<22>> PD22;
87 CHECK (sizeof(DummyObj<1>) != sizeof(DummyObj<22>));
88
89 {
90 PD1 pD11 = allocator.create<DummyObj<1> >();
91 PD1 pD12 = allocator.create<DummyObj<1> >();
92 PD22 pD21 = allocator.create<DummyObj<22>>();
93 PD22 pD22 = allocator.create<DummyObj<22>>();
94 CHECK (pD11);
95 CHECK (pD12);
96 CHECK (pD21);
97 CHECK (pD22);
98 CHECK (1 == pD11.use_count());
99 CHECK (1 == pD12.use_count());
100 CHECK (1 == pD21.use_count());
101 CHECK (1 == pD22.use_count());
102 CHECK (!isSameObject (*pD11, *pD12));
103 CHECK (!isSameObject (*pD11, *pD21));
104 CHECK (!isSameObject (*pD11, *pD22));
105 CHECK (!isSameObject (*pD12, *pD21));
106 CHECK (!isSameObject (*pD12, *pD22));
107 CHECK (!isSameObject (*pD21, *pD22));
108
109 PD22 pD2x = pD21;
110 CHECK (pD2x);
111 CHECK (2 == pD21.use_count());
112 CHECK (2 == pD2x.use_count());
113 CHECK (isSameObject (*pD21, *pD2x));
114
115 CHECK (2 == allocator.numSlots<DummyObj<1> >());
116 CHECK (2 == allocator.numSlots<DummyObj<22>>());
117
118 CHECK (0 == allocator.numSlots<long>()); // query just some unrelated type...
119 }
120
121 CHECK (0 == allocator.numSlots<DummyObj<1> >());
122 CHECK (0 == allocator.numSlots<DummyObj<22>>());
123 CHECK (0 == checksum_);
124 }
125 };
126
127
130
131
132}} // namespace lib::test
Foundation for a custom allocation manager, tracking the created objects by smart-ptrs.
shared_ptr< XX > create(ARGS &&...args)
unsigned int uint
Definition integral.hpp:29
Implementation namespace for support and library code.
int rani(uint bound=_iBOUND())
Definition random.hpp:135
Test runner and basic definitions for tests.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
Definition util.hpp:421
Simplistic test class runner.
#define LAUNCHER(_TEST_CLASS_, _GROUPS_)
Definition run.hpp:116
Abstract foundation for building custom allocation managers.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...