1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
|
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
#include "capi_test_utils.h"
namespace tut {
//
// Test Group
//
struct test_geoswktwriter_data : public capitest::utility {
test_geoswktwriter_data() :
wktwriter_(GEOSWKTWriter_create()),
wkt_(nullptr)
{}
~test_geoswktwriter_data() {
GEOSWKTWriter_destroy(wktwriter_);
GEOSFree(wkt_);
}
void
test_writer_wkt(std::string const& wkt)
{
GEOSGeometry* geom1 = GEOSGeomFromWKT(wkt.c_str());
ensure(nullptr != geom1);
char* wkt_c = GEOSWKTWriter_write(wktwriter_, geom1);
std::string out(wkt_c);
free(wkt_c);
GEOSGeom_destroy(geom1);
ensure_equals(out, wkt);
}
void
test_writer_wkt(std::string const& wkt, std::string const& expected)
{
GEOSGeometry* geom1 = GEOSGeomFromWKT(wkt.c_str());
ensure(nullptr != geom1);
char* wkt_c = GEOSWKTWriter_write(wktwriter_, geom1);
std::string out(wkt_c);
free(wkt_c);
GEOSGeom_destroy(geom1);
ensure_equals(out, expected);
}
GEOSWKTWriter* wktwriter_;
char* wkt_;
};
typedef test_group<test_geoswktwriter_data> group;
typedef group::object object;
group test_geoswktwriter("capi::GEOSWKTWriter");
// Check default output dimension 4
template<>
template<>
void object::test<1>()
{
ensure_equals(GEOSWKTWriter_getOutputDimension(wktwriter_), 4);
test_writer_wkt("POINT (10 13)");
test_writer_wkt("POINT Z (10 13 3)");
test_writer_wkt("POINT M (10 13 5)");
test_writer_wkt("POINT ZM (10 13 3 5)");
}
// Check writer with output dimension 2
template<>
template<>
void object::test<2>()
{
GEOSWKTWriter_setOutputDimension(wktwriter_, 2);
ensure_equals("getOutputDimension_2", GEOSWKTWriter_getOutputDimension(wktwriter_), 2);
test_writer_wkt("POINT (10 13)");
test_writer_wkt("POINT Z (10 13 3)", "POINT (10 13)");
test_writer_wkt("POINT M (10 13 5)", "POINT (10 13)");
test_writer_wkt("POINT ZM (10 13 3 5)", "POINT (10 13)");
}
// Check writer with output dimension 3
template<>
template<>
void object::test<3>()
{
GEOSWKTWriter_setTrim(wktwriter_, 1); // redundant, but keep to ensure it stays trim
GEOSWKTWriter_setOutputDimension(wktwriter_, 3);
ensure_equals("getOutputDimension_3", GEOSWKTWriter_getOutputDimension(wktwriter_), 3);
test_writer_wkt("POINT (10 13)");
test_writer_wkt("POINT Z (10 13 3)");
test_writer_wkt("POINT M (10 13 3)");
test_writer_wkt("POINT ZM (10 13 3 5)", "POINT Z (10 13 3)");
}
// Check Old3D with output dimension 3
template<>
template<>
void object::test<4>()
{
GEOSWKTWriter_setOld3D(wktwriter_, 1);
GEOSWKTWriter_setOutputDimension(wktwriter_, 3);
test_writer_wkt("POINT (10 13)");
test_writer_wkt("POINT (10 13 3)");
test_writer_wkt("POINT M (10 13 5)");
test_writer_wkt("POINT ZM (10 13 3 5)", "POINT (10 13 3)");
}
// Check Old3D with default output dimension 4
template<>
template<>
void object::test<5>()
{
GEOSWKTWriter_setOld3D(wktwriter_, 1);
ensure_equals(GEOSWKTWriter_getOutputDimension(wktwriter_), 4);
test_writer_wkt("POINT (10 13)");
test_writer_wkt("POINT (10 13 3)");
test_writer_wkt("POINT M (10 13 5)");
test_writer_wkt("POINT (10 13 3 5)");
}
// Check to get legacy default output before GEOS 3.12, showing untrimmed 2D WKT
template<>
template<>
void object::test<6>()
{
GEOSWKTWriter_setTrim(wktwriter_, 0);
GEOSWKTWriter_setOutputDimension(wktwriter_, 2);
std::string expected("POINT (10.0000000000000000 13.0000000000000000)");
test_writer_wkt("POINT (10 13)", expected);
test_writer_wkt("POINT Z (10 13 3)", expected);
test_writer_wkt("POINT M (10 13 5)", expected);
test_writer_wkt("POINT ZM (10 13 3 5)", expected);
}
// Check untrimmed WKT with a fixed precision
template<>
template<>
void object::test<7>()
{
GEOSWKTWriter_setTrim(wktwriter_, 0);
GEOSWKTWriter_setRoundingPrecision(wktwriter_, 2);
test_writer_wkt("POINT (10 13)", "POINT (10.00 13.00)");
test_writer_wkt("POINT Z (10 13 3)", "POINT Z (10.00 13.00 3.00)");
test_writer_wkt("POINT M (10 13 5)", "POINT M (10.00 13.00 5.00)");
test_writer_wkt("POINT ZM (10 13 3 5)", "POINT ZM (10.00 13.00 3.00 5.00)");
}
} // namespace tut
|