diff --git a/tests/unit/algorithm/AreaTest.cpp b/tests/unit/algorithm/AreaTest.cpp index f40de57337..e46fa5dae3 100644 --- a/tests/unit/algorithm/AreaTest.cpp +++ b/tests/unit/algorithm/AreaTest.cpp @@ -70,8 +70,7 @@ struct test_area_data { void checkAreaOfRingSigned(std::string wkt, double expectedArea) { - std::unique_ptr lineGeom(reader_.read(wkt)); - std::unique_ptr line(dynamic_cast(lineGeom.release())); + auto line = reader_.read(wkt); ensure(nullptr != line.get()); const CoordinateSequence* ringSeq = line->getCoordinatesRO(); diff --git a/tests/unit/algorithm/CGAlgorithms/OrientationIsCCWTest.cpp b/tests/unit/algorithm/CGAlgorithms/OrientationIsCCWTest.cpp index b56e11c16b..a8054f5294 100644 --- a/tests/unit/algorithm/CGAlgorithms/OrientationIsCCWTest.cpp +++ b/tests/unit/algorithm/CGAlgorithms/OrientationIsCCWTest.cpp @@ -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(geom.get()); + auto poly = reader_.read(wkt); ensure("WKT must be POLYGON)", poly != nullptr); const geos::geom::CoordinateSequence* cs = poly->getExteriorRing()->getCoordinatesRO(); bool actualCCW = Orientation::isCCW(cs); @@ -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(geom.get()); + auto poly = reader_.read(wkt); ensure("WKT must be POLYGON)", poly != nullptr); const geos::geom::CoordinateSequence* cs = poly->getExteriorRing()->getCoordinatesRO(); bool actualCCWArea = Orientation::isCCWArea(cs); diff --git a/tests/unit/algorithm/LengthTest.cpp b/tests/unit/algorithm/LengthTest.cpp index e70cb87aab..598cd60de8 100644 --- a/tests/unit/algorithm/LengthTest.cpp +++ b/tests/unit/algorithm/LengthTest.cpp @@ -48,8 +48,7 @@ struct test_length_data { void checkLengthOfLine(std::string wkt, double expectedLength) { - std::unique_ptr lineGeom(reader_.read(wkt)); - std::unique_ptr line(dynamic_cast(lineGeom.release())); + auto line = reader_.read(wkt); ensure(nullptr != line.get()); const CoordinateSequence* lineSeq = line->getCoordinatesRO(); double actual = algorithm::Length::ofLine(lineSeq); diff --git a/tests/unit/algorithm/LocatePointInRingTest.cpp b/tests/unit/algorithm/LocatePointInRingTest.cpp index 0dfacdff27..b527683801 100644 --- a/tests/unit/algorithm/LocatePointInRingTest.cpp +++ b/tests/unit/algorithm/LocatePointInRingTest.cpp @@ -59,7 +59,7 @@ struct test_locatepointinring_data { } if (checkReverse) { - runPtLocator(expected, pt, geom->reverse()->toString(), false); + runPtLocator(expected, pt, poly->reverse()->toString(), false); } } }; diff --git a/tests/unit/algorithm/PointLocationTest.cpp b/tests/unit/algorithm/PointLocationTest.cpp index bed1a1b0bc..f580c3ee9b 100644 --- a/tests/unit/algorithm/PointLocationTest.cpp +++ b/tests/unit/algorithm/PointLocationTest.cpp @@ -49,8 +49,7 @@ struct test_PointLocation_data { std::unique_ptr readPts(const std::string& wkt) { - std::unique_ptr geom = r_.read(wkt); - const LineString* line = dynamic_cast(geom.get()); + auto line = r_.read(wkt); if (line) return line->getCoordinatesRO()->clone(); else diff --git a/tests/unit/algorithm/PolygonNodeTopologyTest.cpp b/tests/unit/algorithm/PolygonNodeTopologyTest.cpp index 720349164d..1b6dfdef2d 100644 --- a/tests/unit/algorithm/PolygonNodeTopologyTest.cpp +++ b/tests/unit/algorithm/PolygonNodeTopologyTest.cpp @@ -74,8 +74,7 @@ struct test_polygonnodetopology_data { std::unique_ptr readPts(const std::string& wkt) { - std::unique_ptr geom = r_.read(wkt); - const LineString* line = dynamic_cast(geom.get()); + auto line = r_.read(wkt); if (line) return line->getCoordinatesRO()->clone(); else diff --git a/tests/unit/algorithm/RectangleTest.cpp b/tests/unit/algorithm/RectangleTest.cpp index c68810eb8b..9035fb6041 100644 --- a/tests/unit/algorithm/RectangleTest.cpp +++ b/tests/unit/algorithm/RectangleTest.cpp @@ -35,9 +35,7 @@ struct test_rectangle_data { void checkRectangle(const std::string& wkt, const std::string& wktExpected) { - - std::unique_ptr geom = reader_.read(wkt); - const LineString *line = static_cast(geom.get()); + auto line = reader_.read(wkt); const Coordinate& baseRightPt = line->getCoordinateN(0); const Coordinate& baseLeftPt = line->getCoordinateN(1); diff --git a/tests/unit/algorithm/RobustLineIntersectionTest.cpp b/tests/unit/algorithm/RobustLineIntersectionTest.cpp index 595dbd79f3..aaeea3e89c 100644 --- a/tests/unit/algorithm/RobustLineIntersectionTest.cpp +++ b/tests/unit/algorithm/RobustLineIntersectionTest.cpp @@ -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(g1.get()); - LineString* l2ptr = dynamic_cast(g2.get()); + auto l1ptr = reader.read(wkt1); + auto l2ptr = reader.read(wkt2); ensure(nullptr != l1ptr); ensure(nullptr != l2ptr); @@ -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(g1.get()); - LineString* l2ptr = dynamic_cast(g2.get()); + auto l1ptr = reader.read(wkt1); + auto l2ptr = reader.read(wkt2); ensure(nullptr != l1ptr); ensure(nullptr != l2ptr); @@ -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(g1.get()); - LineString* l2ptr = dynamic_cast(g2.get()); + auto l1ptr = reader.read(wkt1); + auto l2ptr = reader.read(wkt2); ensure(nullptr != l1ptr); ensure(nullptr != l2ptr); @@ -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(g1.get()); - LineString* l2ptr = dynamic_cast(g2.get()); + auto l1ptr = reader.read(wkt1); + auto l2ptr = reader.read(wkt2); ensure(nullptr != l1ptr); ensure(nullptr != l2ptr); diff --git a/tests/unit/coverage/TPVWSimplifierTest.cpp b/tests/unit/coverage/TPVWSimplifierTest.cpp index de8d0beac5..ce55c99656 100644 --- a/tests/unit/coverage/TPVWSimplifierTest.cpp +++ b/tests/unit/coverage/TPVWSimplifierTest.cpp @@ -41,9 +41,8 @@ struct test_tpvwsimplifier_data { double tolerance, const std::string& wktExpected) { - std::unique_ptr geom = r.read(wkt); - const MultiLineString* mls = static_cast(geom.get()); - std::unique_ptr actual = TPVWSimplifier::simplify(mls, tolerance); + auto mls = r.read(wkt); + std::unique_ptr actual = TPVWSimplifier::simplify(mls.get(), tolerance); std::unique_ptr expected = r.read(wktExpected); ensure_equals_geometry(actual.get(), expected.get()); } @@ -66,19 +65,18 @@ struct test_tpvwsimplifier_data { double tolerance, const std::string& wktExpected) { - auto geom = r.read(wkt); - const MultiLineString* lines = static_cast(geom.get()); + auto lines = r.read(wkt); std::vector freeRings(lines->getNumGeometries(), false); for (std::size_t index : freeRingIndex) { freeRings[index] = true; } - std::unique_ptr constraintsPtr(nullptr); + std::unique_ptr constraints(nullptr); if (wktConstraints.length() > 0) { - constraintsPtr = r.read(wktConstraints); + constraints = r.read(wktConstraints); } - const MultiLineString* constraints = static_cast(constraintsPtr.get()); - std::unique_ptr actual = TPVWSimplifier::simplify(lines, freeRings, constraints, tolerance); + + std::unique_ptr actual = TPVWSimplifier::simplify(lines.get(), freeRings, constraints.get(), tolerance); std::unique_ptr expected = r.read(wktExpected); // std::cout << "-- actual" << std::endl; diff --git a/tests/unit/edgegraph/EdgeGraphTest.cpp b/tests/unit/edgegraph/EdgeGraphTest.cpp index 731dceb36d..9d96139e34 100644 --- a/tests/unit/edgegraph/EdgeGraphTest.cpp +++ b/tests/unit/edgegraph/EdgeGraphTest.cpp @@ -21,10 +21,9 @@ struct test_edgegraph_data { } std::unique_ptr build(std::string wkt) { - auto geo = reader_.read(wkt); - auto geocol = dynamic_cast(geo.get()); - ensure("could not cast input geometry to collection", geocol); - return EdgeGraphBuilder::build(geocol); + auto geocol = reader_.read(wkt); + ensure("could not cast input geometry to collection", geocol.get()); + return EdgeGraphBuilder::build(geocol.get()); } void checkNodeValid(HalfEdge* e) { diff --git a/tests/unit/geom/Geometry/isRectangleTest.cpp b/tests/unit/geom/Geometry/isRectangleTest.cpp index c191b3f014..c2daa21b2f 100644 --- a/tests/unit/geom/Geometry/isRectangleTest.cpp +++ b/tests/unit/geom/Geometry/isRectangleTest.cpp @@ -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(g.get()); + auto poly = reader.read(wkt); ensure("Geometry is not a Polygon: " + wkt, poly != nullptr); ensure(poly->isRectangle()); } @@ -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(g.get()); + auto poly = reader.read(wkt); ensure("Geometry is not a Polygon: " + wkt, poly != nullptr); ensure(poly->isRectangle()); } @@ -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(g.get()); + auto poly = reader.read(wkt); ensure("Geometry is not a Polygon: " + wkt, poly != nullptr); ensure(!poly->isRectangle()); } @@ -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(g.get()); + auto poly = reader.read(wkt); ensure("Geometry is not a Polygon: " + wkt, poly != nullptr); ensure(!poly->isRectangle()); } @@ -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(g.get()); + auto poly = reader.read(wkt); ensure("Geometry is not a Polygon: " + wkt, poly != nullptr); ensure(!poly->isRectangle()); } @@ -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(g.get()); + auto poly = reader.read(wkt); ensure("Geometry is not a Polygon: " + wkt, poly != nullptr); ensure(!poly->isRectangle()); } @@ -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(g.get()); + auto poly = reader.read(wkt); ensure("Geometry is not a Polygon: " + wkt, poly != nullptr); ensure(!poly->isRectangle()); } diff --git a/tests/unit/geom/LineStringTest.cpp b/tests/unit/geom/LineStringTest.cpp index 06e1dfa0cf..930f8885ae 100644 --- a/tests/unit/geom/LineStringTest.cpp +++ b/tests/unit/geom/LineStringTest.cpp @@ -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(geom.get()); + auto line = reader_.read("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); @@ -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(geom.get()); + auto line = reader_.read("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); @@ -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(geom.get()); + auto line = reader_.read("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); diff --git a/tests/unit/geom/MultiPointTest.cpp b/tests/unit/geom/MultiPointTest.cpp index 5899f1cfeb..21881b6175 100644 --- a/tests/unit/geom/MultiPointTest.cpp +++ b/tests/unit/geom/MultiPointTest.cpp @@ -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 empty_mp_; + std::unique_ptr 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(geo.release()); - } + , empty_mp_(factory_->createMultiPoint()) + , mp_(reader_.read("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 diff --git a/tests/unit/geom/PointTest.cpp b/tests/unit/geom/PointTest.cpp index b19de45fe5..fc13bf9bc2 100644 --- a/tests/unit/geom/PointTest.cpp +++ b/tests/unit/geom/PointTest.cpp @@ -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 empty_point_; + std::unique_ptr 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(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("POINT(1.234 5.678)")) + {}; + + ~test_point_data() {}; }; typedef test_group group; diff --git a/tests/unit/operation/overlayng/OverlayGraphTest.cpp b/tests/unit/operation/overlayng/OverlayGraphTest.cpp index 46db88b5a8..e179702fef 100644 --- a/tests/unit/operation/overlayng/OverlayGraphTest.cpp +++ b/tests/unit/operation/overlayng/OverlayGraphTest.cpp @@ -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 geom = r.read(std::string(wktLine)); - LineString* line = dynamic_cast(geom.get()); + auto line = r.read(wktLine); std::unique_ptr cs = line->getCoordinates(); EdgeSourceInfo esi(0); diff --git a/tests/unit/triangulate/polygon/PolygonHoleJoinerTest.cpp b/tests/unit/triangulate/polygon/PolygonHoleJoinerTest.cpp index 3a61c17825..afe0f6fa34 100644 --- a/tests/unit/triangulate/polygon/PolygonHoleJoinerTest.cpp +++ b/tests/unit/triangulate/polygon/PolygonHoleJoinerTest.cpp @@ -32,13 +32,12 @@ struct test_polygonholejoiner_data { // test_polygonholejoiner_data() {} void checkJoin(const std::string& wkt, const std::string& wktExpected) { - std::unique_ptr geom = r.read(wkt); - Polygon* polyPtr = dynamic_cast(geom.get()); - ensure(polyPtr); - std::unique_ptr actual = PolygonHoleJoiner::joinAsPolygon(polyPtr); - std::unique_ptr expected = r.read(wktExpected); - Geometry* actualPtr = dynamic_cast(actual.get()); - ensure(actualPtr); + + auto poly = r.read(wkt); + + std::unique_ptr actual = PolygonHoleJoiner::joinAsPolygon(poly.get()); + auto actualPtr = dynamic_cast(actual.get()); + std::unique_ptr expected = r.read(wktExpected); // std::cout << std::endl << "geom" << std::endl << *geom << std::endl; // std::cout << std::endl << "actual" << std::endl << *actual << std::endl;