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
|
// Test Suite for C-API GEOSGeom_createRectangle
#include <tut/tut.hpp>
// geos
#include <geos_c.h>
#include "capi_test_utils.h"
namespace tut {
struct test_capiGEOSGeom_createRectangle : public capitest::utility {};
typedef test_group<test_capiGEOSGeom_createRectangle> group;
typedef group::object object;
group test_capiGEOSGeom_createRectangle_group("capi::GEOSGeom_createRectangle");
template <>
template <>
void object::test<1>() {
GEOSGeometry* expected = GEOSGeomFromWKT("POLYGON ((0 0, 1 0, 1 2, 0 2, 0 0))");
GEOSGeometry* geom = GEOSGeom_createRectangle(0, 0, 1, 2);
ensure(geom != nullptr);
ensure_equals(GEOSEqualsExact(geom, expected, 0), 1);
GEOSGeom_destroy(expected);
GEOSGeom_destroy(geom);
}
// verify that bounds with width and height of 0 returns point
template <>
template <>
void object::test<2>() {
GEOSGeometry* expected = GEOSGeomFromWKT("POINT (1 1)");
GEOSGeometry* geom = GEOSGeom_createRectangle(1,1,1,1);
ensure(geom != nullptr);
ensure_equals(GEOSEqualsExact(geom, expected, 0), 1);
GEOSGeom_destroy(expected);
GEOSGeom_destroy(geom);
}
// verify that a rectangle is returned if either but not both width and height are 0
template <>
template <>
void object::test<3>() {
// no height
GEOSGeometry* expected = GEOSGeomFromWKT("POLYGON ((0 0, 1 0, 1 0, 0 0, 0 0))");
GEOSGeometry* geom = GEOSGeom_createRectangle(0,0,1,0);
ensure(geom != nullptr);
ensure_equals(GEOSEqualsExact(geom, expected, 0), 1);
GEOSGeom_destroy(expected);
GEOSGeom_destroy(geom);
// no width
expected = GEOSGeomFromWKT("POLYGON ((0 0, 0 0, 0 1, 0 1, 0 0))");
geom = GEOSGeom_createRectangle(0,0,0,1);
ensure(geom != nullptr);
ensure_equals(GEOSEqualsExact(geom, expected, 0), 1);
GEOSGeom_destroy(expected);
GEOSGeom_destroy(geom);
}
// verify that mismatched bounds are reversed correctly
template <>
template <>
void object::test<4>() {
GEOSGeometry* expected = GEOSGeomFromWKT("POLYGON ((0 0, 1 0, 1 2, 0 2, 0 0))");
GEOSGeometry* geom = GEOSGeom_createRectangle(1, 2, 0, 0);
ensure(geom != nullptr);
ensure_equals(GEOSEqualsExact(geom, expected, 0), 1);
GEOSGeom_destroy(expected);
GEOSGeom_destroy(geom);
}
} // namespace tut
|