Skip to content

Commit

Permalink
Merge pull request #33 from GIScience/feat/more-tests
Browse files Browse the repository at this point in the history
feat: improve test setup
  • Loading branch information
takb committed Mar 11, 2024
2 parents 63ee4af + 538f85e commit 2c2d6fd
Show file tree
Hide file tree
Showing 8 changed files with 475 additions and 55 deletions.
13 changes: 10 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@ cmake_minimum_required(VERSION 3.22)
find_package(Boost REQUIRED COMPONENTS unit_test_framework regex)
find_package(GDAL REQUIRED)

file(GLOB sources CONFIGURE_DEPENDS *.h *.cpp)

add_executable(test-osm-transform test-osm-transform.cpp ../location_area_service.cpp)
add_executable(test-osm-transform test-osm-transform.cpp
../location_area_service.cpp
../location_elevation_service.cpp
../rewrite_handler.cpp
test_utils.cpp
test_location_area.cpp
test_location_elevation.cpp
test_firstpass_handler.cpp
test_rewrite_handler.cpp
)
target_link_libraries(test-osm-transform PRIVATE Boost::unit_test_framework Boost::regex GDAL::GDAL)

enable_testing()
Expand Down
54 changes: 2 additions & 52 deletions test/test-osm-transform.cpp
Original file line number Diff line number Diff line change
@@ -1,52 +1,2 @@
#define BOOST_TEST_MODULE FirstPassHandler Test
#include <boost/test/included/unit_test.hpp>
#include <boost/regex.hpp>

#include <osmium/osm/tag.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/builder/osm_object_builder.hpp>

#define private public
#include "../firstpass_handler.h"
#include "../location_area_service.h"


BOOST_AUTO_TEST_CASE(test_has_no_relevant_tags)
{
boost::regex remove_tags(
"(.*:)?remove_1(:.*)?|remove_2",
boost::regex::icase
);
osmium::nwr_array<osmium::index::IdSetDense<osmium::unsigned_object_id_type>> valid_ids;
osmium::nwr_array<osmium::index::IdSetSmall<osmium::unsigned_object_id_type>> no_elevation;
FirstPassHandler fph(remove_tags, valid_ids, no_elevation);

// Create tag list with relevant and irrelevant tags
osmium::memory::Buffer buf1{1024, osmium::memory::Buffer::auto_grow::yes};
osmium::builder::TagListBuilder tlb(buf1);
tlb.add_tag("landuse","forest");
tlb.add_tag("railway", "platform");
osmium::TagList &tags_with_relevant_tags = buf1.get<osmium::TagList>(0);
BOOST_TEST(fph.has_no_relevant_tags(tags_with_relevant_tags) == false);

// Create tag list with only irrelevant tags
osmium::memory::Buffer buf2{1024, osmium::memory::Buffer::auto_grow::yes};
osmium::builder::TagListBuilder tlb2(buf2);
tlb2.add_tag("landuse","forest");
osmium::TagList &tags_without_relevant_tags = buf2.get<osmium::TagList>(0);
BOOST_TEST(fph.has_no_relevant_tags(tags_without_relevant_tags) == true);
}

BOOST_AUTO_TEST_CASE(test_location_area_service)
{
std::string geo_type("wkt");
std::string prefix("mapping_");
LocationAreaService location_area_service(true, 0, 2, geo_type, true, prefix);
location_area_service.load("test/mapping_test.csv");

osmium::Location location = osmium::Location(6.306152343750001, 50.05713877598692);
std::vector<std::string> areas = location_area_service.get_area(location);

BOOST_TEST(areas.size() == 1);
BOOST_TEST(areas[0] == "DEU");
}
#define BOOST_TEST_MODULE OSM-Transform Test
#include <boost/test/included/unit_test.hpp>
61 changes: 61 additions & 0 deletions test/test_firstpass_handler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <boost/test/unit_test.hpp>

#include <boost/regex.hpp>

#include <osmium/osm/tag.hpp>
#include <osmium/builder/osm_object_builder.hpp>
#include <osmium/memory/buffer.hpp>
#include <osmium/visitor.hpp>

#define private public
#include "../firstpass_handler.h"
#include "test_utils.h"

BOOST_AUTO_TEST_SUITE( test_first_pass )

BOOST_AUTO_TEST_CASE(test_has_no_relevant_tags) {
boost::regex remove_tags(
"(.*:)?remove_1(:.*)?|remove_2",
boost::regex::icase);
osmium::nwr_array<osmium::index::IdSetDense<osmium::unsigned_object_id_type>> valid_ids;
osmium::nwr_array<osmium::index::IdSetSmall<osmium::unsigned_object_id_type>> no_elevation;
FirstPassHandler handler(remove_tags, valid_ids, no_elevation);

// Create tag list with relevant and irrelevant tags
osmium::memory::Buffer buf1{1024, osmium::memory::Buffer::auto_grow::yes};
osmium::builder::TagListBuilder tlb(buf1);
tlb.add_tag("landuse", "forest");
tlb.add_tag("railway", "platform");
auto &tags_with_relevant_tags = buf1.get<osmium::TagList>(0);
BOOST_TEST(handler.has_no_relevant_tags(tags_with_relevant_tags) == false);

// Create tag list with only irrelevant tags
osmium::memory::Buffer buf2{1024, osmium::memory::Buffer::auto_grow::yes};
osmium::builder::TagListBuilder tlb2(buf2);
tlb2.add_tag("landuse", "forest");
auto &tags_without_relevant_tags = buf2.get<osmium::TagList>(0);
BOOST_TEST(handler.has_no_relevant_tags(tags_without_relevant_tags) == true);
}

BOOST_AUTO_TEST_CASE(bla) {
boost::regex remove_tags("(.*:)?source(:.*)?|(.*:)?note(:.*)?|url|created_by|fixme|wikipedia", boost::regex::icase);
osmium::nwr_array<osmium::index::IdSetDense<osmium::unsigned_object_id_type>> valid_ids;
osmium::nwr_array<osmium::index::IdSetSmall<osmium::unsigned_object_id_type>> no_elevation;
FirstPassHandler handler(remove_tags, valid_ids, no_elevation);

osmium::memory::Buffer buffer{1024, osmium::memory::Buffer::auto_grow::yes};
// add_node(buffer, 123, {{"troilo", "rafael"}, {"highway", "yes"}}, 8.6756824, 49.4184793);
// add_node(buffer, 234, {{"troilo", "rafael"}, {"building", "bla"}}, 8.6756824, 49.4184793);
add_way(buffer, 12, {{"highway","yes"}}, {123, 234});
buffer.commit();

osmium::apply(buffer, handler);
BOOST_TEST(valid_ids.nodes().size() == 2);
BOOST_TEST(valid_ids.ways().size() == 1);
BOOST_TEST(valid_ids.nodes().get(123));
BOOST_TEST(valid_ids.nodes().get(234));
BOOST_TEST(valid_ids.ways().get(12));

}

BOOST_AUTO_TEST_SUITE_END()
33 changes: 33 additions & 0 deletions test/test_location_area.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <boost/test/unit_test.hpp>

#include "../location_area_service.h"

BOOST_AUTO_TEST_SUITE( test_locacion_area )
BOOST_AUTO_TEST_CASE( test_location_area_service )
{
std::string geo_type("wkt");
std::string prefix("mapping_");
LocationAreaService location_area_service(true, 0, 2, geo_type, true, prefix);
location_area_service.load("test/mapping_test.csv");

{
const auto areas = location_area_service.get_area(osmium::Location(6.306152343750001, 50.05713877598692));
BOOST_CHECK_EQUAL(areas.size(), 1);
BOOST_CHECK_EQUAL(areas[0], "DEU");
}

{
const auto areas = location_area_service.get_area(osmium::Location(6.0900938, 50.7225850));
BOOST_CHECK_EQUAL(areas.size(), 1);
BOOST_CHECK_EQUAL(areas[0], "DEU");
}

{
const auto areas = location_area_service.get_area(osmium::Location(6.0902180, 50.7220057));
BOOST_CHECK_EQUAL(areas.size(), 1);
BOOST_CHECK_EQUAL(areas[0], "BEL");
}


}
BOOST_AUTO_TEST_SUITE_END()
31 changes: 31 additions & 0 deletions test/test_location_elevation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <boost/test/unit_test.hpp>

#include "../location_elevation_service.h"

BOOST_AUTO_TEST_SUITE( test_locacion_elevation )
BOOST_AUTO_TEST_CASE( test_lookup ) {

LocationElevationService location_elevation_service(1 << 20, false);
location_elevation_service.load({"files/limburg_an_der_lahn.tif"});

double ele = ((int)(location_elevation_service.elevation(osmium::Location(8.0513629, 50.3876977), false)*100))/100.0;
BOOST_CHECK_EQUAL(ele, 163.81);

}

BOOST_AUTO_TEST_CASE( test_interpolate ) {

LocationElevationService location_elevation_service(1 << 20, false);
location_elevation_service.load({"files/limburg_an_der_lahn.tif"});

auto interpolated = location_elevation_service.interpolate(osmium::Location(8.0515393,50.3873984), osmium::Location(8.0505023, 50.3868868));
BOOST_CHECK_EQUAL(interpolated.size(), 14);
for (const auto& le : interpolated) {
auto location = le.location;
auto ele = le.ele;
std::cout << std::setprecision (8) << location.lon() << "," << location.lat() << "," << ele << "\n";
}


}
BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 2c2d6fd

Please sign in to comment.