/******************************************************************************* * tests/stack_allocator_test.cpp * * Part of tlx - http://panthema.net/tlx * * Copyright (C) 2015 Timo Bingmann * * All rights reserved. Published under the Boost Software License, Version 1.0 ******************************************************************************/ #include #include #include #include #include namespace tlx { // forced instantiations template class StackArena<128>; template class StackAllocator; } // namespace tlx static void test_string_vector_deque() { using CharAlloc = tlx::StackAllocator; using IntAlloc = tlx::StackAllocator; using s_string = std::basic_string, CharAlloc>; { tlx::StackArena<128> arena; const char* text = "abcdefghijklmnopqrstuvwxyz"; { s_string str(text, CharAlloc(arena)); die_unless(arena.used() >= 27u); str = s_string("abc", CharAlloc(arena)); die_unequal("abc", str); } } { tlx::StackArena<128> arena; std::vector my_vector(0, int(), IntAlloc(arena)); // push more data than in our arena for (int i = 0; i < 100; ++i) { my_vector.push_back(i); } for (int i = 0; i < 100; ++i) { die_unequal(i, my_vector[i]); } } { tlx::StackArena<128> arena; std::deque my_deque(0, int(), IntAlloc(arena)); // push more data than in our arena for (int i = 0; i < 100; ++i) { my_deque.push_back(i); } for (int i = 0; i < 100; ++i) { die_unequal(i, my_deque[i]); } } } int main() { test_string_vector_deque(); return 0; } /******************************************************************************/