// 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) { View view(range); bool first = true; std::ostringstream out; typedef typename boost::range_iterator::type iterator; ////std::cout << typeid(iterator).name() << std::endl; 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 < typename bg::closeable_view < typename bg::reversible_view::type const, Closure >::type >(range, expected); } template void test_reverse_close(Range const& range, std::string const& expected) { test_option < typename bg::reversible_view < typename bg::closeable_view::type const, Direction >::type >(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 < typename bg::reversible_view < typename bg::reversible_view::type const, Direction1 >::type >(range, expected); } template < bg::closure_selector Close1, bg::closure_selector Close2, typename Range > void test_close_close(Range const& range, std::string const& expected) { test_option < typename bg::closeable_view < typename bg::closeable_view::type const, Close1 >::type >(range, expected); } template void test_geometry(std::string const& wkt, std::string const& expected_n, std::string const& expected_r, std::string const& closing, std::string const& rclosing ) { std::string expected; Geometry geo; bg::read_wkt(wkt, geo); test_close_reverse(geo, expected_n); test_close_reverse(geo, expected_n + closing); test_close_reverse(geo, expected_r); #if ! defined(_MSC_VER) // 13-12-2010, Currently problematic in MSVC test_close_reverse(geo, expected_r + rclosing); #endif test_reverse_close(geo, expected_n); test_reverse_close(geo, expected_n + closing); test_reverse_close(geo, expected_r); // first closed, then reversed: expected = boost::trim_copy(closing + " " + expected_r); test_reverse_close(geo, expected); test_reverse_reverse(geo, expected_n); test_reverse_reverse(geo, expected_n); test_reverse_reverse(geo, expected_r); test_reverse_reverse(geo, expected_r); test_close_close(geo, expected_n); test_close_close(geo, expected_n + closing); test_close_close(geo, expected_n + closing); test_close_close(geo, expected_n + closing + closing); } template void test_all() { test_geometry >( "POLYGON((1 1,1 4,4 4,4 1))", "(1, 1) (1, 4) (4, 4) (4, 1)", "(4, 1) (4, 4) (1, 4) (1, 1)", " (1, 1)", // closing " (4, 1)" // rclosing ); } int test_main(int, char* []) { test_all >(); test_all >(); test_all >(); return 0; }