Skip to content

Commit

Permalink
Refactored some SECTIONs from test cases into TEST_CASEs.
Browse files Browse the repository at this point in the history
  • Loading branch information
joto committed Jul 22, 2018
1 parent 3af83c6 commit 7489178
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 140 deletions.
15 changes: 6 additions & 9 deletions test/t/geom/test_geojson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@

TEST_CASE("GeoJSON point geometry") {
osmium::geom::GeoJSONFactory<> factory;
const std::string json{factory.create_point(osmium::Location{3.2, 4.2})};
REQUIRE(std::string{"{\"type\":\"Point\",\"coordinates\":[3.2,4.2]}"} == json);
}

SECTION("point") {
const std::string json{factory.create_point(osmium::Location{3.2, 4.2})};
REQUIRE(std::string{"{\"type\":\"Point\",\"coordinates\":[3.2,4.2]}"} == json);
}

SECTION("empty_point") {
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), const osmium::invalid_location&);
}

TEST_CASE("GeoJSON empty point geometry") {
osmium::geom::GeoJSONFactory<> factory;
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), const osmium::invalid_location&);
}

TEST_CASE("GeoJSON linestring geometry") {
Expand Down
17 changes: 7 additions & 10 deletions test/t/geom/test_ogr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,14 @@

TEST_CASE("OGR point geometry") {
osmium::geom::OGRFactory<> factory;
std::unique_ptr<OGRPoint> point{factory.create_point(osmium::Location{3.2, 4.2})};
REQUIRE(3.2 == point->getX());
REQUIRE(4.2 == point->getY());
}

SECTION("point") {
std::unique_ptr<OGRPoint> point{factory.create_point(osmium::Location{3.2, 4.2})};
REQUIRE(3.2 == point->getX());
REQUIRE(4.2 == point->getY());
}

SECTION("empty_point") {
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), const osmium::invalid_location&);
}

TEST_CASE("OGR empty point geometry") {
osmium::geom::OGRFactory<> factory;
REQUIRE_THROWS_AS(factory.create_point(osmium::Location()), const osmium::invalid_location&);
}

TEST_CASE("OGR linestring geometry") {
Expand Down
52 changes: 26 additions & 26 deletions test/t/geom/test_projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,35 +76,35 @@ TEST_CASE("Projection 3857") {
}
}

TEST_CASE("MercatorProjection") {
TEST_CASE("MercatorProjection: Zero coordinates") {
osmium::geom::MercatorProjection projection;
const osmium::Location loc{0.0, 0.0};
const osmium::geom::Coordinates c{0.0, 0.0};
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
}

SECTION("Zero coordinates") {
const osmium::Location loc{0.0, 0.0};
const osmium::geom::Coordinates c{0.0, 0.0};
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
}

SECTION("Max longitude") {
const osmium::Location loc{180.0, 0.0};
const osmium::geom::Coordinates c{20037508.34, 0.0};
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
}
TEST_CASE("MercatorProjection: Max longitude") {
osmium::geom::MercatorProjection projection;
const osmium::Location loc{180.0, 0.0};
const osmium::geom::Coordinates c{20037508.34, 0.0};
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
}

SECTION("Min longitude") {
const osmium::Location loc{-180.0, 0.0};
const osmium::geom::Coordinates c{-20037508.34, 0.0};
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
}
TEST_CASE("MercatorProjection: Min longitude") {
osmium::geom::MercatorProjection projection;
const osmium::Location loc{-180.0, 0.0};
const osmium::geom::Coordinates c{-20037508.34, 0.0};
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
}

SECTION("Max latitude") {
const osmium::Location loc{0.0, 85.0511288};
const osmium::geom::Coordinates c{0.0, 20037508.34};
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
}
TEST_CASE("MercatorProjection: Max latitude") {
osmium::geom::MercatorProjection projection;
const osmium::Location loc{0.0, 85.0511288};
const osmium::geom::Coordinates c{0.0, 20037508.34};
REQUIRE(projection(loc).x == Approx(c.x).epsilon(0.00001));
REQUIRE(projection(loc).y == Approx(c.y).epsilon(0.00001));
}

183 changes: 88 additions & 95 deletions test/t/geom/test_wkb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,137 +10,130 @@

#if __BYTE_ORDER == __LITTLE_ENDIAN

TEST_CASE("WKB geometry factory (byte-order-dependant), points") {
TEST_CASE("WKB geometry factory (byte-order-dependent), point in WKB") {
const osmium::Location loc{3.2, 4.2};
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};

SECTION("point") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};

const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb == "01010000009A99999999990940CDCCCCCCCCCC1040");
}
const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb == "01010000009A99999999990940CDCCCCCCCCCC1040");
}

SECTION("point in ewkb") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};
TEST_CASE("WKB geometry factory (byte-order-dependent), point in EWKB") {
const osmium::Location loc{3.2, 4.2};
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};

const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb == "0101000020E61000009A99999999990940CDCCCCCCCCCC1040");
}
const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb == "0101000020E61000009A99999999990940CDCCCCCCCCCC1040");
}

#ifndef OSMIUM_USE_SLOW_MERCATOR_PROJECTION
SECTION("point in web mercator") {
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};

const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb.substr(0, 10) == "0101000000"); // little endian, point type
REQUIRE(wkb.substr(10 + 2, 16 - 2) == "706E7BF9BD1541"); // x coordinate (without first (least significant) byte)
REQUIRE(wkb.substr(26 + 2, 16 - 2) == "A90093E48F1C41"); // y coordinate (without first (least significant) byte)
}
TEST_CASE("WKB geometry factory (byte-order-dependent), point in web mercator WKB") {
const osmium::Location loc{3.2, 4.2};
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};

SECTION("point in ewkb in web mercator") {
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};
const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb.substr(0, 10) == "0101000000"); // little endian, point type
REQUIRE(wkb.substr(10 + 2, 16 - 2) == "706E7BF9BD1541"); // x coordinate (without first (least significant) byte)
REQUIRE(wkb.substr(26 + 2, 16 - 2) == "A90093E48F1C41"); // y coordinate (without first (least significant) byte)
}

const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb.substr(0, 10) == "0101000020"); // little endian, point type (extended)
REQUIRE(wkb.substr(10, 8) == "110F0000"); // SRID 3857
REQUIRE(wkb.substr(18 + 2, 16 - 2) == "706E7BF9BD1541"); // x coordinate (without first (least significant) byte)
REQUIRE(wkb.substr(34 + 2, 16 - 2) == "A90093E48F1C41"); // y coordinate (without first (least significant) byte)
}
#endif
TEST_CASE("WKB geometry factory (byte-order-dependent), point in web mercator EWKB") {
const osmium::Location loc{3.2, 4.2};
osmium::geom::WKBFactory<osmium::geom::MercatorProjection> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};

const std::string wkb{factory.create_point(loc)};
REQUIRE(wkb.substr(0, 10) == "0101000020"); // little endian, point type (extended)
REQUIRE(wkb.substr(10, 8) == "110F0000"); // SRID 3857
REQUIRE(wkb.substr(18 + 2, 16 - 2) == "706E7BF9BD1541"); // x coordinate (without first (least significant) byte)
REQUIRE(wkb.substr(34 + 2, 16 - 2) == "A90093E48F1C41"); // y coordinate (without first (least significant) byte)
}
#endif

TEST_CASE("WKB geometry factory (byte-order-dependant)") {

TEST_CASE("WKB geometry factory (byte-order-dependent): linestring") {
osmium::memory::Buffer buffer{10000};
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
const auto& wnl = create_test_wnl_okay(buffer);

SECTION("linestring") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
const auto& wnl = create_test_wnl_okay(buffer);

{
const std::string wkb{factory.create_linestring(wnl)};
REQUIRE(wkb == "0102000000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
}

{
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
REQUIRE(wkb == "010200000003000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
}

{
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(wkb == "0102000000040000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
}

{
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(wkb == "010200000004000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
}
{
const std::string wkb{factory.create_linestring(wnl)};
REQUIRE(wkb == "0102000000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
}

SECTION("linestring as ewkb") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};
{
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward)};
REQUIRE(wkb == "010200000003000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
}

const auto& wnl = create_test_wnl_okay(buffer);
{
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(wkb == "0102000000040000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
}

const std::string ewkb{factory.create_linestring(wnl)};
REQUIRE(ewkb == "0102000020E6100000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
{
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(wkb == "010200000004000000CDCCCCCCCCCC0C409A999999999913400000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC12409A99999999990940CDCCCCCCCCCC1040");
}
}

SECTION("linestring with two same locations") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
TEST_CASE("WKB geometry factory (byte-order-dependent): linestring as ewkb") {
osmium::memory::Buffer buffer{10000};
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::ewkb, osmium::geom::out_type::hex};

const auto& wnl = create_test_wnl_same_location(buffer);
const auto& wnl = create_test_wnl_okay(buffer);

SECTION("unique forwards (default)") {
REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::geometry_error&);
}
const std::string ewkb{factory.create_linestring(wnl)};
REQUIRE(ewkb == "0102000020E6100000030000009A99999999990940CDCCCCCCCCCC10400000000000000C40CDCCCCCCCCCC1240CDCCCCCCCCCC0C409A99999999991340");
}

SECTION("unique backwards") {
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), const osmium::geometry_error&);
}
TEST_CASE("WKB geometry factory (byte-order-dependent): linestring with two same locations") {
osmium::memory::Buffer buffer{10000};
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};

SECTION("all forwards") {
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(wkb == "0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240");
}
const auto& wnl = create_test_wnl_same_location(buffer);

SECTION("all backwards") {
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(wkb == "0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240");
}
SECTION("unique forwards (default)") {
REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::geometry_error&);
}

SECTION("linestring with undefined location") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};

const auto& wnl = create_test_wnl_undefined_location(buffer);
SECTION("unique backwards") {
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), const osmium::geometry_error&);
}

REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::invalid_location&);
SECTION("all forwards") {
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all)};
REQUIRE(wkb == "0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240");
}

SECTION("all backwards") {
const std::string wkb{factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward)};
REQUIRE(wkb == "0102000000020000000000000000000C40CDCCCCCCCCCC12400000000000000C40CDCCCCCCCCCC1240");
}
}

#endif
TEST_CASE("WKB geometry factory (byte-order-dependent): linestring with undefined location") {
osmium::memory::Buffer buffer{10000};
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};

TEST_CASE("WKB geometry (byte-order-independent)") {
const auto& wnl = create_test_wnl_undefined_location(buffer);

osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::invalid_location&);
}

SECTION("empty point") {
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), const osmium::invalid_location&);
}
#endif

SECTION("empty linestring") {
osmium::memory::Buffer buffer{10000};
const auto& wnl = create_test_wnl_empty(buffer);
TEST_CASE("WKB geometry (byte-order-independent) of empty point") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
REQUIRE_THROWS_AS(factory.create_point(osmium::Location{}), const osmium::invalid_location&);
}

REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::geometry_error&);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), const osmium::geometry_error&);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), const osmium::geometry_error&);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), const osmium::geometry_error&);
}
TEST_CASE("WKB geometry (byte-order-independent) of empty linestring") {
osmium::geom::WKBFactory<> factory{osmium::geom::wkb_type::wkb, osmium::geom::out_type::hex};
osmium::memory::Buffer buffer{10000};
const auto& wnl = create_test_wnl_empty(buffer);

REQUIRE_THROWS_AS(factory.create_linestring(wnl), const osmium::geometry_error&);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::unique, osmium::geom::direction::backward), const osmium::geometry_error&);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all), const osmium::geometry_error&);
REQUIRE_THROWS_AS(factory.create_linestring(wnl, osmium::geom::use_nodes::all, osmium::geom::direction::backward), const osmium::geometry_error&);
}

0 comments on commit 7489178

Please sign in to comment.