write_dsv.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Unit Test
  3. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  4. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  5. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  6. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  7. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  8. // Use, modification and distribution is subject to the Boost Software License,
  9. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  10. // http://www.boost.org/LICENSE_1_0.txt)
  11. #include <sstream>
  12. #include <geometry_test_common.hpp>
  13. #include <boost/geometry/io/dsv/write.hpp>
  14. #include <boost/geometry/geometries/geometries.hpp>
  15. #include <boost/geometry/io/wkt/read.hpp>
  16. template <typename G>
  17. void test_dsv(std::string const& wkt, std::string const& dsv)
  18. {
  19. G geometry;
  20. bg::read_wkt(wkt, geometry);
  21. std::ostringstream out;
  22. out << bg::dsv(geometry);
  23. BOOST_CHECK_EQUAL(out.str(), dsv);
  24. }
  25. #ifndef GEOMETRY_TEST_MULTI
  26. template <typename T>
  27. void test_all()
  28. {
  29. using namespace boost::geometry;
  30. typedef model::point<T, 2, cs::cartesian> P;
  31. test_dsv<P >("POINT(1 2)", "(1, 2)");
  32. test_dsv<model::linestring<P> >(
  33. "LINESTRING(1 1,2 2,3 3)",
  34. "((1, 1), (2, 2), (3, 3))");
  35. test_dsv<model::polygon<P> >("POLYGON((0 0,0 4,4 4,4 0,0 0))",
  36. "(((0, 0), (0, 4), (4, 4), (4, 0), (0, 0)))");
  37. test_dsv<model::ring<P> >("POLYGON((0 0,0 4,4 4,4 0,0 0))",
  38. "((0, 0), (0, 4), (4, 4), (4, 0), (0, 0))");
  39. test_dsv<model::box<P> >("BOX(0 0,1 1)",
  40. "((0, 0), (1, 1))");
  41. }
  42. #endif
  43. int test_main(int, char* [])
  44. {
  45. test_all<double>();
  46. test_all<int>();
  47. return 0;
  48. }