|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r71635 - sandbox/block_ptr/libs/smart_ptr/test
From: phil_at_[hidden]
Date: 2011-04-30 18:30:45
Author: pbouchard
Date: 2011-04-30 18:30:45 EDT (Sat, 30 Apr 2011)
New Revision: 71635
URL: http://svn.boost.org/trac/boost/changeset/71635
Log:
* Added automated tests
Added:
sandbox/block_ptr/libs/smart_ptr/test/
sandbox/block_ptr/libs/smart_ptr/test/Makefile (contents, props changed)
sandbox/block_ptr/libs/smart_ptr/test/block_ptr_test1.cpp (contents, props changed)
sandbox/block_ptr/libs/smart_ptr/test/block_ptr_test3.cpp (contents, props changed)
Added: sandbox/block_ptr/libs/smart_ptr/test/Makefile
==============================================================================
--- (empty file)
+++ sandbox/block_ptr/libs/smart_ptr/test/Makefile 2011-04-30 18:30:45 EDT (Sat, 30 Apr 2011)
@@ -0,0 +1,48 @@
+CXX := g++
+CXXFLAGS := -O3
+INCPATH := -I../../.. -I../../../../../include
+LINK := g++
+LFLAGS := -L../../../../../lib -lboost_thread
+RM := rm
+HEADERS := $(wildcard *.h)
+SOURCES := $(wildcard *.cpp)
+OBJECTS := $(patsubst %.cpp,%.o,$(SOURCES))
+
+.SUFFIXES: .cpp
+
+.cpp.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.PHONY : all depend clean
+
+
+all : block_ptr_test1 block_ptr_test2 block_ptr_test3 local_pool_test1 local_pool_test2 t100_test1
+
+block_ptr_test1: block_ptr_test1.o
+ $(LINK) $(LFLAGS) -o $@ $^ -lboost_unit_test_framework
+
+block_ptr_test2: block_ptr_test2.o
+ $(LINK) $(LFLAGS) -o $@ $^
+
+block_ptr_test3: block_ptr_test3.o
+ $(LINK) $(LFLAGS) -o $@ $^ -lboost_unit_test_framework
+
+local_pool_test1: local_pool_test1.o
+ $(LINK) $(LFLAGS) -o $@ $^
+
+local_pool_test2: local_pool_test2.o
+ $(LINK) $(LFLAGS) -o $@ $^
+
+t100_test1: t100_test1.o
+ $(LINK) $(LFLAGS) -o $@ $^ -lboost_regex
+
+
+Makefile.dep: $(SOURCES)
+ $(CXX) ${INCPATH} -MM $^ > $@
+
+clean:
+ $(RM) block_ptr_test1 block_ptr_test2 block_ptr_test3 local_pool_test1 local_pool_test2 t100_test1
+ $(RM) $(OBJECTS)
+ $(RM) *~ core
+
+-include Makefile.dep
Added: sandbox/block_ptr/libs/smart_ptr/test/block_ptr_test1.cpp
==============================================================================
--- (empty file)
+++ sandbox/block_ptr/libs/smart_ptr/test/block_ptr_test1.cpp 2011-04-30 18:30:45 EDT (Sat, 30 Apr 2011)
@@ -0,0 +1,83 @@
+/**
+ @file
+ block_ptr_test2.cpp
+
+ @note
+ Memory manager handling heap deallocations in constant time.
+*/
+
+#include <list>
+#include <iostream>
+#include <algorithm>
+
+#include <boost/block_ptr.hpp>
+#include <boost/current_function.hpp>
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+
+#include <boost/test/unit_test.hpp>
+
+
+using namespace std;
+using namespace boost;
+
+
+struct A
+{
+ static int counter;
+ static list<int> order;
+
+ int i;
+ block_ptr<A> p;
+
+ A() : i(counter ++)
+ {
+ }
+
+ ~A()
+ {
+ order.push_back(i);
+ }
+};
+
+int A::counter = 0;
+list<int> A::order;
+
+BOOST_AUTO_TEST_CASE(block_ptr_test1)
+{
+ {
+ block_ptr<A> p = make_block<A>(); // 0
+ block_ptr<A> q = make_block<A>(); // 1
+ block_ptr<A> r = make_block<A>(); // 2
+
+ block_ptr<void> t = make_block<A>(); // 3
+
+ p->p = p;
+ q = r;
+
+ }
+ int order1[] = {1, 3, 2, 0};
+ BOOST_CHECK( equal(A::order.begin(), A::order.end(), order1) );
+ A::order.clear();
+
+ // The following don't work with MSVC:
+#if ! defined(_MSC_VER)
+ {
+ block_ptr<A[5]> s = make_block<A[5]>(); // 4, 5, 6, 7, 8
+ }
+ int order2[] = {8, 7, 6, 5, 4};
+ BOOST_CHECK( equal(A::order.begin(), A::order.end(), order2) );
+ A::order.clear();
+#endif
+
+ {
+ block_ptr<A> v = make_block<A>(); // 9
+ v->p = make_block<A>(); // 10
+ v->p->p = make_block<A>(); // 11
+ v->p->p->p = v;
+ }
+ int order3[] = {9, 10, 11};
+ BOOST_CHECK( equal(A::order.begin(), A::order.end(), order3) );
+ A::order.clear();
+}
Added: sandbox/block_ptr/libs/smart_ptr/test/block_ptr_test3.cpp
==============================================================================
--- (empty file)
+++ sandbox/block_ptr/libs/smart_ptr/test/block_ptr_test3.cpp 2011-04-30 18:30:45 EDT (Sat, 30 Apr 2011)
@@ -0,0 +1,129 @@
+/**
+ @file
+ block_ptr_test3.cpp
+
+ @note
+ MinGW users must link with: -Wl,--enable-runtime-pseudo-reloc
+
+ @author
+ Steven Watanabe <watanabesj_at_[hidden]>
+*/
+
+
+
+#include <boost/block_ptr.hpp>
+#include <boost/block_allocator.hpp>
+
+#include <vector>
+#include <iostream>
+
+#include <boost/mpl/range_c.hpp>
+#include <boost/mpl/for_each.hpp>
+#include <boost/array.hpp>
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MAIN
+
+#include <boost/test/unit_test.hpp>
+
+static int count;
+
+using namespace boost;
+
+struct node {
+ node() {
+ ++count;
+ }
+ ~node() {
+ --count;
+ }
+ node(const node&) {
+ ++count;
+ }
+ block_ptr<node> prior;
+ block_ptr<node> next;
+};
+
+struct list {
+public:
+ list() {}
+ void clear() {
+ front.reset();
+ back.reset();
+ }
+ void insert() {
+ if(front.get() == 0) {
+ front = back = make_block<node>();
+ } else {
+ back->next = make_block<node>();
+ back->next->prior = back;
+ back = back->next;
+ }
+ }
+private:
+ block_ptr<node> front;
+ block_ptr<node> back;
+};
+
+struct vector {
+ vector() { ++count; }
+ ~vector() { --count; }
+ vector(const vector& other) : elements(other.elements) { ++count; }
+ std::vector<block_ptr<vector>, block_allocator<block_ptr<vector> > > elements;
+};
+
+struct create_type {
+ template<class T>
+ void operator()(T) const {
+ make_block<boost::array<char, T::value> >();
+ }
+};
+
+BOOST_AUTO_TEST_CASE(test_block_ptr) {
+
+ count = 0;
+ {
+ block_ptr<vector> v = make_block<vector>();
+ v->elements.push_back(v);
+ }
+ BOOST_CHECK_EQUAL(count, 0);
+
+ count = 0;
+ {
+ list l;
+ for(int j = 0; j < 2; ++j) {
+ for(int i = 0; i < 2; ++i) {
+ l.insert();
+ }
+ l.clear();
+ }
+ }
+ BOOST_CHECK_EQUAL(count, 0);
+
+ count = 0;
+ {
+ block_ptr<int> test = make_block<int>(5);
+ test = test;
+
+ BOOST_CHECK_NE(test.get(), static_cast<int*>(0));
+ BOOST_CHECK_EQUAL(*test, 5);
+ }
+
+ for(int i = 0; i < 500; ++i) {
+ boost::mpl::for_each<boost::mpl::range_c<int, 1, 100> >(create_type());
+ }
+
+ count = 0;
+ {
+ block_ptr<vector> v = make_block<vector>();
+ v->elements.push_back(v);
+ }
+ BOOST_CHECK_EQUAL(count, 0);
+
+ {
+ vector v;
+ v.elements.push_back(make_block<vector>());
+ }
+ BOOST_CHECK_EQUAL(count, 0);
+
+}
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk