From 5cd851d48a45a756868b9b7d24e7a3e842da83ba Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Thu, 19 Mar 2015 01:27:51 +0100 Subject: [PATCH] [test][index] Add test for rtree packing using move_itreator. --- index/test/rtree/Jamfile.v2 | 1 + index/test/rtree/rtree_move_pack.cpp | 134 +++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 index/test/rtree/rtree_move_pack.cpp diff --git a/index/test/rtree/Jamfile.v2 b/index/test/rtree/Jamfile.v2 index 463ccb3fa..23578b4e9 100644 --- a/index/test/rtree/Jamfile.v2 +++ b/index/test/rtree/Jamfile.v2 @@ -12,6 +12,7 @@ build-project generated ; test-suite boost-geometry-index-rtree : + [ run rtree_move_pack.cpp ] [ run rtree_values.cpp ] [ compile-fail rtree_values_invalid.cpp ] ; diff --git a/index/test/rtree/rtree_move_pack.cpp b/index/test/rtree/rtree_move_pack.cpp new file mode 100644 index 000000000..b7210772d --- /dev/null +++ b/index/test/rtree/rtree_move_pack.cpp @@ -0,0 +1,134 @@ +// Boost.Geometry Index +// Unit Test + +// Copyright (c) 2015 Adam Wulkiewicz, Lodz, Poland. + +// 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) + +#include + +#include +#include +#include +#include + +#include + +class point_cm +{ + BOOST_COPYABLE_AND_MOVABLE(point_cm) + +public: + point_cm(double xx = 0, double yy = 0) + : x(xx) + , y(yy) + , moved(false) + {} + point_cm(point_cm const& other) + : x(other.x) + , y(other.y) + , moved(false) + { + BOOST_CHECK_MESSAGE(false, "copy not allowed"); + } + point_cm & operator=(BOOST_COPY_ASSIGN_REF(point_cm) other) + { + BOOST_CHECK_MESSAGE(false, "copy not allowed"); + x = other.x; + y = other.y; + moved = false; + return *this; + } + point_cm(BOOST_RV_REF(point_cm) other) + : x(other.x) + , y(other.y) + , moved(false) + { + BOOST_CHECK_MESSAGE(!other.moved, "only one move allowed"); + other.moved = true; + } + point_cm & operator=(BOOST_RV_REF(point_cm) other) + { + BOOST_CHECK_MESSAGE(!other.moved, "only one move allowed"); + x = other.x; + y = other.y; + moved = false; + other.moved = true; + return *this; + } + + double x, y; + bool moved; +}; + +template +struct indexable +{ + typedef Point const& result_type; + result_type operator()(Point const& p) const + { + BOOST_CHECK_MESSAGE(!p.moved, "can't access indexable of moved Value"); + return p; + } +}; + +BOOST_GEOMETRY_REGISTER_POINT_2D(point_cm, double, bg::cs::cartesian, x, y) + +template +void append(Vector & vec, double x, double y) +{ + point_cm pt(x, y); + BOOST_CHECK(!pt.moved); + vec.push_back(boost::move(pt)); + BOOST_CHECK(pt.moved); +} + +struct test_moved +{ + test_moved(bool ex) + : expected(ex) + {} + template + void operator()(Point const& p) const + { + BOOST_CHECK_EQUAL(p.moved, expected); + } + bool expected; +}; + +template +void test_rtree(Params const& params = Params()) +{ + // sanity check + boost::container::vector vec; + append(vec, 0, 0); append(vec, 0, 1); append(vec, 0, 2); + append(vec, 1, 0); append(vec, 1, 1); append(vec, 1, 2); + append(vec, 2, 0); append(vec, 2, 1); append(vec, 2, 2); + + std::for_each(vec.begin(), vec.end(), test_moved(false)); + + bgi::rtree > rt( + boost::make_move_iterator(vec.begin()), + boost::make_move_iterator(vec.end()), + params); + + std::for_each(vec.begin(), vec.end(), test_moved(true)); + + BOOST_CHECK_EQUAL(rt.size(), vec.size()); +} + + +int test_main(int, char* []) +{ + test_rtree< point_cm, bgi::linear<4> >(); + test_rtree< point_cm, bgi::quadratic<4> >(); + test_rtree< point_cm, bgi::rstar<4> >(); + + test_rtree(bgi::dynamic_linear(4)); + test_rtree(bgi::dynamic_quadratic(4)); + test_rtree(bgi::dynamic_rstar(4)); + + return 0; +}