// Boost.Geometry (aka GGL, Generic Geometry Library) test file // // Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands // 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 #include #include #include #include #include template void test_option(Range const& range, std::string const& expected) { typedef typename boost::range_iterator::type iterator; View view(range); bool first = true; std::ostringstream out; iterator end = boost::end(view); for (iterator it = boost::begin(view); it != end; ++it, first = false) { out << (first ? "" : " ") << bg::dsv(*it); } BOOST_CHECK_EQUAL(out.str(), expected); } template void test_close_reverse(Range const& range, std::string const& expected) { test_option < bg::closeable_view < bg::reversible_view const, Close > >(range, expected); } /* This should NOT compile, or at least not instantiate Use the code as above, so reversible_view should be nested inside closeable_view template void test_reverse_close(Range const& range, std::string const& expected) { test_option < bg::reversible_view < bg::closeable_view const, Direction > >(range, expected); } */ template < bg::iterate_direction Direction1, bg::iterate_direction Direction2, typename Range > void test_reverse_reverse(Range const& range, std::string const& expected) { test_option < bg::reversible_view < bg::reversible_view const, Direction1 > >(range, expected); } template < bool Close1, bool Close2, typename Range > void test_close_close(Range const& range, std::string const& expected) { test_option < bg::closeable_view < bg::closeable_view const, Close1 > >(range, expected); } template void test_geometry(std::string const& wkt, std::string const& expected_1, std::string const& expected_2, std::string const& expected_3, std::string const& expected_4, std::string const& expected_cc ) { Geometry geo; bg::read_wkt(wkt, geo); test_close_reverse(geo, expected_1); test_close_reverse(geo, expected_2); test_close_reverse(geo, expected_3); test_close_reverse(geo, expected_4); /* This should NOT compile on purpose Because the closing_iterator can only be used forward test_reverse_close(geo, expected_1); test_reverse_close(geo, expected_2); test_reverse_close(geo, expected_3); test_reverse_close(geo, expected_4); */ test_reverse_reverse(geo, expected_1); test_reverse_reverse(geo, expected_1); test_close_close(geo, expected_1); test_close_close(geo, expected_2); test_close_close(geo, expected_2); // Does not compile - no assignment operator // Ranges basically support nesting, but the closing iterator does not. // It is not necessary for the closing iterator to do so. //test_close_close(geo, expected_cc); } template void test_all() { test_geometry >( "POLYGON((1 1,1 4,4 4,4 1))", "(1, 1) (1, 4) (4, 4) (4, 1)", "(1, 1) (1, 4) (4, 4) (4, 1) (1, 1)", "(4, 1) (4, 4) (1, 4) (1, 1)", "(4, 1) (4, 4) (1, 4) (1, 1) (4, 1)", "(1, 1) (1, 4) (4, 4) (4, 1) (1, 1) (1, 1)" // closed twice, not used ); } int test_main(int, char* []) { test_all(); test_all >(); test_all >(); return 0; }