Permalink
Browse files

Add ut-allocator testing that std::deque uses the tpie::allocator pro…

…perly. Closes #25.
  • Loading branch information...
1 parent 8cee7dc commit 34d800588514732713c1bb0c486a18a8a8e6a21d @Mortal Mortal committed Aug 2, 2012
Showing with 51 additions and 0 deletions.
  1. +1 −0 test/unit/CMakeLists.txt
  2. +50 −0 test/unit/test_allocator.cpp
View
1 test/unit/CMakeLists.txt
@@ -17,6 +17,7 @@ macro(add_fulltest NAME)
endforeach(TEST)
endmacro(add_fulltest)
+add_unittest(allocator deque)
add_unittest(ami_stream basic truncate)
add_unittest(array basic iterators auto_ptr memory segmented memory_segmented bit_basic bit_iterators bit_memory copyempty arrayarray frontback)
add_unittest(disjoint_set basic memory)
View
50 test/unit/test_allocator.cpp
@@ -0,0 +1,50 @@
+// -*- mode: c++; tab-width: 4; indent-tabs-mode: t; c-file-style: "stroustrup"; -*-
+// vi:set ts=4 sts=4 sw=4 noet :
+// Copyright 2012, The TPIE development team
+//
+// This file is part of TPIE.
+//
+// TPIE is free software: you can redistribute it and/or modify it under
+// the terms of the GNU Lesser General Public License as published by the
+// Free Software Foundation, either version 3 of the License, or (at your
+// option) any later version.
+//
+// TPIE is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+// License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with TPIE. If not, see <http://www.gnu.org/licenses/>
+#include "../app_config.h"
+#include "common.h"
+#include <queue>
+#include <tpie/memory.h>
+
+using namespace tpie;
+
+bool allocator_deque_test() {
+ memory_size_type m1, m2, m3;
+ m1 = get_memory_manager().used();
+ typedef int test_t;
+ const test_t N = 100;
+ {
+ std::deque<test_t, allocator<test_t> > d;
+ for (test_t i = 0; i < N; ++i) {
+ d.push_back(i);
+ }
+ m2 = get_memory_manager().used();
+ }
+ m3 = get_memory_manager().used();
+ if (m1 != m3) {
+ log_error() << "Memory leak" << std::endl;
+ }
+ log_info() << "Pushing " << N << " numbers of size " << sizeof(test_t) << " uses " << m2-m1 << std::endl;
+ return m1 != m2;
+}
+
+int main(int argc, char ** argv) {
+ return tests(argc, argv)
+ .test(allocator_deque_test, "deque")
+ ;
+}

0 comments on commit 34d8005

Please sign in to comment.