Skip to content

Commit

Permalink
Use typed template to read(wkt) in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pramsey committed Feb 21, 2025
1 parent 89265d6 commit 577532d
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 117 deletions.
3 changes: 1 addition & 2 deletions tests/unit/algorithm/AreaTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ struct test_area_data {
void
checkAreaOfRingSigned(std::string wkt, double expectedArea)
{
std::unique_ptr<Geometry> lineGeom(reader_.read(wkt));
std::unique_ptr<LineString> line(dynamic_cast<LineString*>(lineGeom.release()));
auto line = reader_.read<LineString>(wkt);
ensure(nullptr != line.get());
const CoordinateSequence* ringSeq = line->getCoordinatesRO();

Expand Down
6 changes: 2 additions & 4 deletions tests/unit/algorithm/CGAlgorithms/OrientationIsCCWTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ struct test_isccw_data {
void
checkCCW(bool expectedCCW, const std::string& wkt)
{
GeometryPtr geom(reader_.read(wkt));
geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(geom.get());
auto poly = reader_.read<geos::geom::Polygon>(wkt);
ensure("WKT must be POLYGON)", poly != nullptr);
const geos::geom::CoordinateSequence* cs = poly->getExteriorRing()->getCoordinatesRO();
bool actualCCW = Orientation::isCCW(cs);
Expand All @@ -53,8 +52,7 @@ struct test_isccw_data {
void
checkCCWArea(bool expectedCCWArea, const std::string& wkt)
{
GeometryPtr geom(reader_.read(wkt));
geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(geom.get());
auto poly = reader_.read<geos::geom::Polygon>(wkt);
ensure("WKT must be POLYGON)", poly != nullptr);
const geos::geom::CoordinateSequence* cs = poly->getExteriorRing()->getCoordinatesRO();
bool actualCCWArea = Orientation::isCCWArea(cs);
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/algorithm/LengthTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ struct test_length_data {
void
checkLengthOfLine(std::string wkt, double expectedLength)
{
std::unique_ptr<Geometry> lineGeom(reader_.read(wkt));
std::unique_ptr<LineString> line(dynamic_cast<LineString*>(lineGeom.release()));
auto line = reader_.read<LineString>(wkt);
ensure(nullptr != line.get());
const CoordinateSequence* lineSeq = line->getCoordinatesRO();
double actual = algorithm::Length::ofLine(lineSeq);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/algorithm/LocatePointInRingTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ struct test_locatepointinring_data {
}

if (checkReverse) {
runPtLocator(expected, pt, geom->reverse()->toString(), false);
runPtLocator(expected, pt, poly->reverse()->toString(), false);
}
}
};
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/algorithm/PointLocationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ struct test_PointLocation_data {
std::unique_ptr<CoordinateSequence>
readPts(const std::string& wkt)
{
std::unique_ptr<Geometry> geom = r_.read(wkt);
const LineString* line = dynamic_cast<LineString*>(geom.get());
auto line = r_.read<LineString>(wkt);
if (line)
return line->getCoordinatesRO()->clone();
else
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/algorithm/PolygonNodeTopologyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ struct test_polygonnodetopology_data {
std::unique_ptr<CoordinateSequence>
readPts(const std::string& wkt)
{
std::unique_ptr<Geometry> geom = r_.read(wkt);
const LineString* line = dynamic_cast<LineString*>(geom.get());
auto line = r_.read<LineString>(wkt);
if (line)
return line->getCoordinatesRO()->clone();
else
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/algorithm/RectangleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ struct test_rectangle_data {
void
checkRectangle(const std::string& wkt, const std::string& wktExpected)
{

std::unique_ptr<Geometry> geom = reader_.read(wkt);
const LineString *line = static_cast<LineString*>(geom.get());
auto line = reader_.read<LineString>(wkt);

const Coordinate& baseRightPt = line->getCoordinateN(0);
const Coordinate& baseLeftPt = line->getCoordinateN(1);
Expand Down
28 changes: 8 additions & 20 deletions tests/unit/algorithm/RobustLineIntersectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,8 @@ struct test_robustlineintersection_data {
double distanceTolerance)
//throws ParseException
{
GeomPtr g1(reader.read(wkt1));
GeomPtr g2(reader.read(wkt2));

LineString* l1ptr = dynamic_cast<LineString*>(g1.get());
LineString* l2ptr = dynamic_cast<LineString*>(g2.get());
auto l1ptr = reader.read<LineString>(wkt1);
auto l2ptr = reader.read<LineString>(wkt2);

ensure(nullptr != l1ptr);
ensure(nullptr != l2ptr);
Expand Down Expand Up @@ -155,11 +152,8 @@ struct test_robustlineintersection_data {
double distanceTolerance)
// throws ParseException
{
GeomPtr g1(reader.read(wkt1));
GeomPtr g2(reader.read(wkt2));

LineString* l1ptr = dynamic_cast<LineString*>(g1.get());
LineString* l2ptr = dynamic_cast<LineString*>(g2.get());
auto l1ptr = reader.read<LineString>(wkt1);
auto l2ptr = reader.read<LineString>(wkt2);

ensure(nullptr != l1ptr);
ensure(nullptr != l2ptr);
Expand All @@ -182,11 +176,8 @@ struct test_robustlineintersection_data {
const std::string& wkt2)
// throws ParseException
{
GeomPtr g1(reader.read(wkt1));
GeomPtr g2(reader.read(wkt2));

LineString* l1ptr = dynamic_cast<LineString*>(g1.get());
LineString* l2ptr = dynamic_cast<LineString*>(g2.get());
auto l1ptr = reader.read<LineString>(wkt1);
auto l2ptr = reader.read<LineString>(wkt2);

ensure(nullptr != l1ptr);
ensure(nullptr != l2ptr);
Expand All @@ -207,11 +198,8 @@ struct test_robustlineintersection_data {
void
checkInputNotAltered(const std::string& wkt1, const std::string& wkt2, int scaleFactor)
{
GeomPtr g1(reader.read(wkt1));
GeomPtr g2(reader.read(wkt2));

LineString* l1ptr = dynamic_cast<LineString*>(g1.get());
LineString* l2ptr = dynamic_cast<LineString*>(g2.get());
auto l1ptr = reader.read<LineString>(wkt1);
auto l2ptr = reader.read<LineString>(wkt2);

ensure(nullptr != l1ptr);
ensure(nullptr != l2ptr);
Expand Down
16 changes: 7 additions & 9 deletions tests/unit/coverage/TPVWSimplifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,8 @@ struct test_tpvwsimplifier_data {
double tolerance,
const std::string& wktExpected)
{
std::unique_ptr<Geometry> geom = r.read(wkt);
const MultiLineString* mls = static_cast<const MultiLineString*>(geom.get());
std::unique_ptr<Geometry> actual = TPVWSimplifier::simplify(mls, tolerance);
auto mls = r.read<MultiLineString>(wkt);
std::unique_ptr<Geometry> actual = TPVWSimplifier::simplify(mls.get(), tolerance);
std::unique_ptr<Geometry> expected = r.read(wktExpected);
ensure_equals_geometry(actual.get(), expected.get());
}
Expand All @@ -66,19 +65,18 @@ struct test_tpvwsimplifier_data {
double tolerance,
const std::string& wktExpected)
{
auto geom = r.read(wkt);
const MultiLineString* lines = static_cast<const MultiLineString*>(geom.get());
auto lines = r.read<MultiLineString>(wkt);

std::vector<bool> freeRings(lines->getNumGeometries(), false);
for (std::size_t index : freeRingIndex) {
freeRings[index] = true;
}
std::unique_ptr<Geometry> constraintsPtr(nullptr);
std::unique_ptr<MultiLineString> constraints(nullptr);
if (wktConstraints.length() > 0) {
constraintsPtr = r.read(wktConstraints);
constraints = r.read<MultiLineString>(wktConstraints);
}
const MultiLineString* constraints = static_cast<const MultiLineString*>(constraintsPtr.get());
std::unique_ptr<Geometry> actual = TPVWSimplifier::simplify(lines, freeRings, constraints, tolerance);

std::unique_ptr<Geometry> actual = TPVWSimplifier::simplify(lines.get(), freeRings, constraints.get(), tolerance);
std::unique_ptr<Geometry> expected = r.read(wktExpected);

// std::cout << "-- actual" << std::endl;
Expand Down
7 changes: 3 additions & 4 deletions tests/unit/edgegraph/EdgeGraphTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ struct test_edgegraph_data {
}

std::unique_ptr<EdgeGraph> build(std::string wkt) {
auto geo = reader_.read(wkt);
auto geocol = dynamic_cast<const GeometryCollection *>(geo.get());
ensure("could not cast input geometry to collection", geocol);
return EdgeGraphBuilder::build(geocol);
auto geocol = reader_.read<GeometryCollection>(wkt);
ensure("could not cast input geometry to collection", geocol.get());
return EdgeGraphBuilder::build(geocol.get());
}

void checkNodeValid(HalfEdge* e) {
Expand Down
28 changes: 7 additions & 21 deletions tests/unit/geom/Geometry/isRectangleTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ void object::test<1>
()
{
const std::string wkt("POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0))");
auto g = reader.read(wkt);

geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(g.get());
auto poly = reader.read<geos::geom::Polygon>(wkt);
ensure("Geometry is not a Polygon: " + wkt, poly != nullptr);
ensure(poly->isRectangle());
}
Expand All @@ -52,9 +50,7 @@ void object::test<2>
()
{
const std::string wkt("POLYGON ((0 0, 0 200, 100 200, 100 0, 0 0))");
auto g = reader.read(wkt);

geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(g.get());
auto poly = reader.read<geos::geom::Polygon>(wkt);
ensure("Geometry is not a Polygon: " + wkt, poly != nullptr);
ensure(poly->isRectangle());
}
Expand All @@ -67,9 +63,7 @@ void object::test<3>
{
const std::string wkt("POLYGON ((0 0, 0 100, 100 100, 100 0, 0 0), \
(10 10, 10 90, 90 90, 90 10, 10 10))");
auto g = reader.read(wkt);

geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(g.get());
auto poly = reader.read<geos::geom::Polygon>(wkt);
ensure("Geometry is not a Polygon: " + wkt, poly != nullptr);
ensure(!poly->isRectangle());
}
Expand All @@ -81,9 +75,7 @@ void object::test<4>
()
{
const std::string wkt("POLYGON ((0 0, 0 100, 99 100, 100 0, 0 0))");
auto g = reader.read(wkt);

geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(g.get());
auto poly = reader.read<geos::geom::Polygon>(wkt);
ensure("Geometry is not a Polygon: " + wkt, poly != nullptr);
ensure(!poly->isRectangle());
}
Expand All @@ -95,9 +87,7 @@ void object::test<5>
()
{
const std::string wkt("POLYGON ((0 0, 0 100, 100 50, 100 100, 100 0, 0 0))");
auto g = reader.read(wkt);

geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(g.get());
auto poly = reader.read<geos::geom::Polygon>(wkt);
ensure("Geometry is not a Polygon: " + wkt, poly != nullptr);
ensure(!poly->isRectangle());
}
Expand All @@ -109,9 +99,7 @@ void object::test<6>
()
{
const std::string wkt("POLYGON ((0 0, 0 100, 100 0, 0 0))");
auto g = reader.read(wkt);

geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(g.get());
auto poly = reader.read<geos::geom::Polygon>(wkt);
ensure("Geometry is not a Polygon: " + wkt, poly != nullptr);
ensure(!poly->isRectangle());
}
Expand All @@ -123,9 +111,7 @@ void object::test<7>
()
{
const std::string wkt("POLYGON ((0 0, 0 100, 100 0, 100 100, 0 0))");
auto g = reader.read(wkt);

geos::geom::Polygon* poly = dynamic_cast<geos::geom::Polygon*>(g.get());
auto poly = reader.read<geos::geom::Polygon>(wkt);
ensure("Geometry is not a Polygon: " + wkt, poly != nullptr);
ensure(!poly->isRectangle());
}
Expand Down
12 changes: 3 additions & 9 deletions tests/unit/geom/LineStringTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,7 @@ template<>
void object::test<33>
()
{
auto geom = reader_.read("LINESTRING M (0 1 2, 10 11 12, 20 21 22)");
ensure(geom != nullptr);
geos::geom::LineString *line = static_cast<LineString*>(geom.get());
auto line = reader_.read<LineString>("LINESTRING M (0 1 2, 10 11 12, 20 21 22)");
ensure_equals(line->getCoordinateDimension(), 3);
auto pt = line->getPointN(2);
auto out = writer_.write(*pt);
Expand All @@ -610,9 +608,7 @@ template<>
void object::test<34>
()
{
auto geom = reader_.read("LINESTRING Z (0 1 2, 10 11 12, 20 21 22)");
ensure(geom != nullptr);
geos::geom::LineString *line = static_cast<LineString*>(geom.get());
auto line = reader_.read<LineString>("LINESTRING Z (0 1 2, 10 11 12, 20 21 22)");
ensure_equals(line->getCoordinateDimension(), 3);
auto pt = line->getPointN(2);
auto out = writer_.write(*pt);
Expand All @@ -624,9 +620,7 @@ template<>
void object::test<35>
()
{
auto geom = reader_.read("LINESTRING ZM (0 1 2 3, 10 11 12 13, 20 21 22 23)");
ensure(geom != nullptr);
geos::geom::LineString *line = static_cast<LineString*>(geom.get());
auto line = reader_.read<LineString>("LINESTRING ZM (0 1 2 3, 10 11 12 13, 20 21 22 23)");
ensure_equals(line->getCoordinateDimension(), 4);
auto pt = line->getPointN(2);
auto out = writer_.write(*pt);
Expand Down
23 changes: 9 additions & 14 deletions tests/unit/geom/MultiPointTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,20 @@ struct test_multipoint_data {
geos::geom::GeometryFactory::Ptr factory_;
geos::io::WKTReader reader_;

MultiPointAutoPtr empty_mp_;
MultiPointPtr mp_;
std::unique_ptr<geos::geom::MultiPoint> empty_mp_;
std::unique_ptr<geos::geom::MultiPoint> mp_;
const std::size_t mp_size_;

test_multipoint_data()
:
pm_(1.0), factory_(GeometryFactory::create(&pm_, 0))
: pm_(1.0)
, factory_(GeometryFactory::create(&pm_, 0))
, reader_(factory_.get())
, empty_mp_(factory_->createMultiPoint()), mp_size_(5)
{
// Create non-empty MultiPoint
auto geo = reader_.read("MULTIPOINT((0 0), (5 5), (10 10), (15 15), (20 20))");
mp_ = dynamic_cast<MultiPointPtr>(geo.release());
}
, empty_mp_(factory_->createMultiPoint())
, mp_(reader_.read<geos::geom::MultiPoint>("MULTIPOINT((0 0), (5 5), (10 10), (15 15), (20 20))"))
, mp_size_(5)
{};

~test_multipoint_data()
{
factory_->destroyGeometry(mp_);
}
~test_multipoint_data() {};

private:
// Declare type as noncopyable
Expand Down
24 changes: 10 additions & 14 deletions tests/unit/geom/PointTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,18 @@ struct test_point_data {
geos::geom::PrecisionModel pm_;
GeometryFactory::Ptr factory_;
geos::io::WKTReader reader_;
PointAutoPtr empty_point_;
PointPtr point_;
std::unique_ptr<geos::geom::Point> empty_point_;
std::unique_ptr<geos::geom::Point> point_;

test_point_data()
: pm_(1000), factory_(GeometryFactory::create(&pm_, 0))
, reader_(factory_.get()), empty_point_(factory_->createPoint())
{
// Create non-empty Point
auto geo = reader_.read("POINT(1.234 5.678)");
point_ = dynamic_cast<PointPtr>(geo.release());
}

~test_point_data()
{
factory_->destroyGeometry(point_);
}
: pm_(1000)
, factory_(GeometryFactory::create(&pm_, 0))
, reader_(factory_.get())
, empty_point_(factory_->createPoint())
, point_(reader_.read<geos::geom::Point>("POINT(1.234 5.678)"))
{};

~test_point_data() {};
};

typedef test_group<test_point_data, MAX_TESTS> group;
Expand Down
5 changes: 2 additions & 3 deletions tests/unit/operation/overlayng/OverlayGraphTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ struct test_overlaygraph_data {
}

void
addEdge(OverlayGraph* graph, const char* wktLine)
addEdge(OverlayGraph* graph, const std::string& wktLine)
{
std::unique_ptr<Geometry> geom = r.read(std::string(wktLine));
LineString* line = dynamic_cast<LineString*>(geom.get());
auto line = r.read<LineString>(wktLine);
std::unique_ptr<CoordinateSequence> cs = line->getCoordinates();

EdgeSourceInfo esi(0);
Expand Down
13 changes: 6 additions & 7 deletions tests/unit/triangulate/polygon/PolygonHoleJoinerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@ struct test_polygonholejoiner_data {
// test_polygonholejoiner_data() {}

void checkJoin(const std::string& wkt, const std::string& wktExpected) {
std::unique_ptr<Geometry> geom = r.read(wkt);
Polygon* polyPtr = dynamic_cast<Polygon*>(geom.get());
ensure(polyPtr);
std::unique_ptr<Polygon> actual = PolygonHoleJoiner::joinAsPolygon(polyPtr);
std::unique_ptr<Geometry> expected = r.read(wktExpected);
Geometry* actualPtr = dynamic_cast<Geometry*>(actual.get());
ensure(actualPtr);

auto poly = r.read<Polygon>(wkt);

std::unique_ptr<Polygon> actual = PolygonHoleJoiner::joinAsPolygon(poly.get());
auto actualPtr = dynamic_cast<const Geometry*>(actual.get());
std::unique_ptr<Geometry> expected = r.read<Geometry>(wktExpected);

// std::cout << std::endl << "geom" << std::endl << *geom << std::endl;
// std::cout << std::endl << "actual" << std::endl << *actual << std::endl;
Expand Down

0 comments on commit 577532d

Please sign in to comment.