From 3847f1d45580e2e62990088d236d10d5f36cb2f1 Mon Sep 17 00:00:00 2001 From: Raoul Gough Date: Wed, 15 Oct 2003 16:17:51 +0000 Subject: [PATCH] Tests for vector of shared pointers [SVN r20390] --- test/test_vector_shared.py | 46 ++++++++++++++++++++++ test/test_vector_shared_ext.cpp | 67 +++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 test/test_vector_shared.py create mode 100755 test/test_vector_shared_ext.cpp diff --git a/test/test_vector_shared.py b/test/test_vector_shared.py new file mode 100644 index 00000000..0d97b08a --- /dev/null +++ b/test/test_vector_shared.py @@ -0,0 +1,46 @@ +#!/usr/bin/python +# -*- mode:python -*- +# +# Python module test_vector_proxy.py +# +# Copyright (c) 2003 Raoul M. Gough +# +# Use, modification and distribution is subject to the Boost Software +# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy +# at http://www.boost.org/LICENSE_1_0.txt) +# +# History +# ======= +# 2003/ 9/29 rmg File creation +# +# $Id$ +# + +'''>>> from test_vector_shared_ext import * +>>> element_type = int_wrapper +>>> def increment(wrapper, change = 1): +... wrapper.increment (change) +... +>>> setTrace(False) +>>> v = Vector_shared() +>>> #### NOTE: test_python_ref, test_vector_common included after this #### +''' + +def run(args = None): + import sys + import doctest + + if args is not None: + sys.argv = args + return doctest.testmod(sys.modules.get(__name__)) + +if __name__ == '__main__': + import test_python_ref_common # Checks for python reference semantics + import test_vector_common + __doc__ += test_python_ref_common.extended_doctest_string + __doc__ += test_vector_common.common_doctest_string + print 'running...' + import sys + status = run()[0] + if (status == 0): print "Done." + sys.exit(status) diff --git a/test/test_vector_shared_ext.cpp b/test/test_vector_shared_ext.cpp new file mode 100755 index 00000000..65181f83 --- /dev/null +++ b/test/test_vector_shared_ext.cpp @@ -0,0 +1,67 @@ +// -*- mode:c++ -*- +// +// Module test_vector_shared_ext.cpp +// +// Copyright (c) 2003 Raoul M. Gough +// +// Use, modification and distribution is subject to the Boost Software +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy +// at http://www.boost.org/LICENSE_1_0.txt) +// +// History +// ======= +// 2003/10/15 rmg File creation from test_vector_ext.cpp +// +// $Id$ +// + +#include "int_wrapper.hpp" +#include + +// Declare overloads for correct sort and find of int_wrappers via +// shared pointers +typedef boost::shared_ptr int_wrapper_holder; +bool operator< (int_wrapper_holder const &, int_wrapper_holder const &); +bool operator== (int_wrapper_holder const &, int_wrapper_holder const &); + +#include +#include +#include +#include +#include +#include + +// More messiness from not having a separate int_wrapper.cpp file +bool int_wrapper::our_trace_flag = true; +unsigned int_wrapper::our_object_counter = 0; + +bool operator< (int_wrapper_holder const &lhs, int_wrapper_holder const &rhs) +{ + return (*lhs) < (*rhs); +} + +bool operator== (int_wrapper_holder const &lhs, int_wrapper_holder const &rhs) +{ + return (*lhs) == (*rhs); +} + +BOOST_PYTHON_MODULE(test_vector_shared_ext) +{ + boost::python::implicitly_convertible (); + + boost::python::def ("setTrace", &int_wrapper::setTrace); + + boost::python::class_ + ("int_wrapper", boost::python::init()) + .def ("increment", &int_wrapper::increment) + .def ("__repr__", &int_wrapper::repr) + .def ("__cmp__", compare) + ; + + typedef std::vector Container1; + + boost::python::class_("Vector_shared") + .def (boost::python::indexing::container_suite()) + .def ("reserve", &Container1::reserve) + ; +}