58 out <<
"Test Teuchos::Details::Allocator for T = "
59 << TypeNameTraits<T>::name () << endl;
60 AllocationLogger::resetAllocationCounts ();
65 typedef typename alloc_type::size_type size_type;
72 size_type oldMaxAlloc = 0;
78 const size_type numEntries = 10;
80 typedef std::vector<T, alloc_type> vec_type;
88 T val =
static_cast<T
> (22);
89 vec_type vec (numEntries, val, alloc);
94 oldMaxAlloc = alloc.maxAllocInBytes ();
95 const size_type curAlloc = alloc.curAllocInBytes ();
96 const size_type expectedCurAlloc = numEntries *
sizeof (T);
107 for (size_type k = 0; k < numEntries; ++k) {
114 const size_type newMaxAlloc = alloc.maxAllocInBytes ();
118 out <<
"Done with test!" << endl;
131 out <<
"Test Teuchos::Details::Allocator for T = "
132 << TypeNameTraits<T>::name () <<
", with verbose logging on" << endl;
133 AllocationLogger::resetAllocationCounts ();
137 alloc_type alloc (
true,
true);
139 typedef typename alloc_type::size_type size_type;
146 size_type oldMaxAlloc = 0;
152 const size_type numEntries = 10;
154 typedef std::vector<T, alloc_type> vec_type;
162 T val =
static_cast<T
> (22);
163 vec_type vec (numEntries, val, alloc);
168 oldMaxAlloc = alloc.maxAllocInBytes ();
169 const size_type curAlloc = alloc.curAllocInBytes ();
170 const size_type expectedCurAlloc = numEntries *
sizeof (T);
181 for (size_type k = 0; k < numEntries; ++k) {
188 const size_type newMaxAlloc = alloc.maxAllocInBytes ();
192 out <<
"Done with test!" << endl;
205 out <<
"Test Teuchos::Details::Allocator<T> for mixed T" << endl;
206 AllocationLogger::resetAllocationCounts ();
209 typedef int_alloc_type::size_type size_type;
210 const size_type numEntries = 10;
211 const size_type expectedMaxAlloc = numEntries *
sizeof (int) + numEntries *
sizeof (
double);
217 std::vector<int, int_alloc_type> intVec (numEntries);
220 std::vector<double, double_alloc_type> dblVec (numEntries);
224 TEST_EQUALITY( intVec.get_allocator ().curAllocInBytes (), dblVec.get_allocator ().curAllocInBytes () );
225 TEST_EQUALITY( intVec.get_allocator ().maxAllocInBytes (), dblVec.get_allocator ().maxAllocInBytes () );
228 TEST_EQUALITY_CONST( intVec.get_allocator ().curAllocInBytes () >= expectedMaxAlloc, true );
229 TEST_EQUALITY_CONST( intVec.get_allocator ().maxAllocInBytes () >= expectedMaxAlloc, true );
235 out <<
"Done with test!" << endl;
253 out <<
"Test Teuchos::Details::Allocator<std::string>" << endl;
254 AllocationLogger::resetAllocationCounts ();
257 typedef string_alloc_type::size_type size_type;
258 const size_type numEntries = 10;
262 const size_type expectedMaxAlloc = numEntries *
sizeof (std::string);
269 std::vector<std::string, string_alloc_type> vec (numEntries);
281 string_alloc_type alloc;
282 std::string val (
"I'm a little teapot, short and stout.");
283 std::vector<std::string, string_alloc_type> vec (numEntries, val, alloc);
297 string_alloc_type alloc;
298 std::vector<std::string, string_alloc_type> vec (numEntries);
300 for (size_type k = 0; k < numEntries; ++k) {
301 std::ostringstream os;
302 os <<
"Current index: " << k;
313 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...