26 out <<
"Test Teuchos::Details::Allocator for T = "
27 << TypeNameTraits<T>::name () << endl;
28 AllocationLogger::resetAllocationCounts ();
33 typedef typename alloc_type::size_type size_type;
40 size_type oldMaxAlloc = 0;
46 const size_type numEntries = 10;
48 typedef std::vector<T, alloc_type> vec_type;
56 T val =
static_cast<T
> (22);
57 vec_type vec (numEntries, val, alloc);
62 oldMaxAlloc = alloc.maxAllocInBytes ();
63 const size_type curAlloc = alloc.curAllocInBytes ();
64 const size_type expectedCurAlloc = numEntries *
sizeof (T);
75 for (size_type k = 0; k < numEntries; ++k) {
82 const size_type newMaxAlloc = alloc.maxAllocInBytes ();
86 out <<
"Done with test!" << endl;
99 out <<
"Test Teuchos::Details::Allocator for T = "
100 << TypeNameTraits<T>::name () <<
", with verbose logging on" << endl;
101 AllocationLogger::resetAllocationCounts ();
105 alloc_type alloc (
true,
true);
107 typedef typename alloc_type::size_type size_type;
114 size_type oldMaxAlloc = 0;
120 const size_type numEntries = 10;
122 typedef std::vector<T, alloc_type> vec_type;
130 T val =
static_cast<T
> (22);
131 vec_type vec (numEntries, val, alloc);
136 oldMaxAlloc = alloc.maxAllocInBytes ();
137 const size_type curAlloc = alloc.curAllocInBytes ();
138 const size_type expectedCurAlloc = numEntries *
sizeof (T);
149 for (size_type k = 0; k < numEntries; ++k) {
156 const size_type newMaxAlloc = alloc.maxAllocInBytes ();
160 out <<
"Done with test!" << endl;
173 out <<
"Test Teuchos::Details::Allocator<T> for mixed T" << endl;
174 AllocationLogger::resetAllocationCounts ();
177 typedef int_alloc_type::size_type size_type;
178 const size_type numEntries = 10;
179 const size_type expectedMaxAlloc = numEntries *
sizeof (int) + numEntries *
sizeof (
double);
185 std::vector<int, int_alloc_type> intVec (numEntries);
188 std::vector<double, double_alloc_type> dblVec (numEntries);
192 TEST_EQUALITY( intVec.get_allocator ().curAllocInBytes (), dblVec.get_allocator ().curAllocInBytes () );
193 TEST_EQUALITY( intVec.get_allocator ().maxAllocInBytes (), dblVec.get_allocator ().maxAllocInBytes () );
196 TEST_EQUALITY_CONST( intVec.get_allocator ().curAllocInBytes () >= expectedMaxAlloc, true );
197 TEST_EQUALITY_CONST( intVec.get_allocator ().maxAllocInBytes () >= expectedMaxAlloc, true );
203 out <<
"Done with test!" << endl;
221 out <<
"Test Teuchos::Details::Allocator<std::string>" << endl;
222 AllocationLogger::resetAllocationCounts ();
225 typedef string_alloc_type::size_type size_type;
226 const size_type numEntries = 10;
230 const size_type expectedMaxAlloc = numEntries *
sizeof (std::string);
237 std::vector<std::string, string_alloc_type> vec (numEntries);
249 string_alloc_type alloc;
250 std::string val (
"I'm a little teapot, short and stout.");
251 std::vector<std::string, string_alloc_type> vec (numEntries, val, alloc);
265 string_alloc_type alloc;
266 std::vector<std::string, string_alloc_type> vec (numEntries);
268 for (size_type k = 0; k < numEntries; ++k) {
269 std::ostringstream os;
270 os <<
"Current index: " << k;
281 out <<
"Done with test!" << endl;
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
Optional tracking allocator for Teuchos Memory Management classes.
Logging implementation used by Allocator (see below).
Tabbing class for helping to create formated, indented output for a basic_FancyOStream object...
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
Default traits class that just returns typeid(T).name().
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT(TEST_GROUP, TEST_NAME, TYPE)
Instantiate a templated unit test with one template parameter.
Defines basic traits returning the name of a type in a portable and readable way. ...
Declaration of Teuchos::Details::Allocator, a tracking and logging implementation of the C++ Standard...