Skip to content

Commit

Permalink
Reduce code duplication in GEOSCoverageUnionTest
Browse files Browse the repository at this point in the history
References GA-1098
  • Loading branch information
strk committed May 21, 2024
1 parent 55ac2f5 commit 6043951
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions tests/unit/capi/GEOSCoverageUnionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,15 @@ namespace tut {

// Common data used in test cases.
struct test_capicoverageunion_data : public capitest::utility {
static void
notice(const char *fmt, ...) {
std::fprintf(stdout, "NOTICE: ");

va_list ap;
va_start(ap, fmt);
std::vfprintf(stdout, fmt, ap);
va_end(ap);

std::fprintf(stdout, "\n");
}

test_capicoverageunion_data() {
m_context = initGEOS_r(notice, notice);
m_reader = GEOSWKTReader_create_r(m_context);
m_reader = GEOSWKTReader_create();
}

~test_capicoverageunion_data() {
GEOSWKTReader_destroy_r(m_context, m_reader);
finishGEOS_r(m_context);
GEOSWKTReader_destroy(m_reader);
}

GEOSContextHandle_t m_context;
GEOSWKTReader* m_reader;
};

Expand All @@ -66,19 +52,19 @@ template<> void object::test<1>
"POLYGON ((1 0, 1 1, 2 1, 2 0, 1 0))"
};

auto g1 = GEOSWKTReader_read_r(m_context, m_reader, wkt[0].c_str());
auto g2 = GEOSWKTReader_read_r(m_context, m_reader, wkt[1].c_str());
auto g1 = GEOSWKTReader_read(m_reader, wkt[0].c_str());
auto g2 = GEOSWKTReader_read(m_reader, wkt[1].c_str());

GEOSGeometry* geoms[2] = { g1, g2 };

auto input = GEOSGeom_createCollection_r(m_context, GEOS_GEOMETRYCOLLECTION, geoms, 2);
auto result = GEOSCoverageUnion_r(m_context, input);
auto input = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geoms, 2);
auto result = GEOSCoverageUnion(input);

ensure( result != nullptr );
ensure( GEOSGeomTypeId_r(m_context, result) == GEOS_POLYGON );
ensure( GEOSGeomTypeId(result) == GEOS_POLYGON );

GEOSGeom_destroy_r(m_context, input);
GEOSGeom_destroy_r(m_context, result);
GEOSGeom_destroy(input);
GEOSGeom_destroy(result);
}

template<>
Expand All @@ -91,18 +77,18 @@ void object::test<2>
"POLYGON ((1 0, 0.9 1, 2 1, 2 0, 1 0))"
};

auto g1 = GEOSWKTReader_read_r(m_context, m_reader, wkt[0].c_str());
auto g2 = GEOSWKTReader_read_r(m_context, m_reader, wkt[1].c_str());
auto g1 = GEOSWKTReader_read(m_reader, wkt[0].c_str());
auto g2 = GEOSWKTReader_read(m_reader, wkt[1].c_str());

GEOSGeometry* geoms[2] = { g1, g2 };

auto input = GEOSGeom_createCollection_r(m_context, GEOS_GEOMETRYCOLLECTION, geoms, 2);
auto result = GEOSCoverageUnion_r(m_context, input);
auto input = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, geoms, 2);
auto result = GEOSCoverageUnion(input);
ensure( result != nullptr );
ensure( GEOSEquals_r(m_context, input, result) );
ensure( GEOSEquals(input, result) );

GEOSGeom_destroy_r(m_context, input);
GEOSGeom_destroy_r(m_context, result);
GEOSGeom_destroy(input);
GEOSGeom_destroy(result);
}

template<>
Expand Down

0 comments on commit 6043951

Please sign in to comment.