mirror of
https://github.com/osm2pgsql-dev/osm2pgsql.git
synced 2025-08-19 16:28:16 +00:00

Middle has three interface classes: middle_query_t, middle_t and slim_middle_t. They inherit from each other. This is problematic when one wants to supply a middle implementation that follows a similar inheritence structure. There is actualy no need that the interfaces for inserting (middle_t and slim_middle_t) inherit from middle_query_t. The code is very clear about which interface is needed by which class. This change splits off the middle_query_t interface and cleans up the code where the clear distinction was still missing. Needs some larger rework of the middle test which did rely on being able to access both interface types. There is now a template class for testing middle that also contains some more common boilerplate code.
79 lines
2.3 KiB
C++
79 lines
2.3 KiB
C++
#include <iostream>
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
#include <cassert>
|
|
#include <sstream>
|
|
#include <stdexcept>
|
|
#include <memory>
|
|
|
|
#include "middle-pgsql.hpp"
|
|
#include "options.hpp"
|
|
#include "osmdata.hpp"
|
|
#include "osmtypes.hpp"
|
|
#include "output-multi.hpp"
|
|
#include "taginfo_impl.hpp"
|
|
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include "tests/middle-tests.hpp"
|
|
#include "tests/common-pg.hpp"
|
|
#include "tests/common.hpp"
|
|
|
|
int main(int argc, char *argv[]) {
|
|
std::unique_ptr<pg::tempdb> db;
|
|
|
|
try {
|
|
db.reset(new pg::tempdb);
|
|
} catch (const std::exception &e) {
|
|
std::cerr << "Unable to setup database: " << e.what() << "\n";
|
|
return 77; // <-- code to skip this test.
|
|
}
|
|
|
|
try {
|
|
options_t options;
|
|
options.database_options = db->database_options;
|
|
options.num_procs = 1;
|
|
options.slim = true;
|
|
|
|
options.projection.reset(reprojection::create_projection(PROJ_LATLONG));
|
|
|
|
options.output_backend = "multi";
|
|
options.style = "tests/test_output_multi_line_trivial.style.json";
|
|
|
|
//setup the middle
|
|
auto middle = std::make_shared<middle_pgsql_t>();
|
|
|
|
//setup the backend (output)
|
|
std::vector<std::shared_ptr<output_t> > outputs = output_t::create_outputs(middle.get(), options);
|
|
|
|
//let osmdata orchestrate between the middle and the outs
|
|
osmdata_t osmdata(middle, outputs, options.projection);
|
|
|
|
testing::parse("tests/test_output_multi_line_storage.osm", "xml",
|
|
options, &osmdata);
|
|
|
|
db->check_count(1, "select count(*) from pg_catalog.pg_class where relname = 'test_line'");
|
|
db->check_count(3, "select count(*) from test_line");
|
|
|
|
//check that we have the number of vertexes in each linestring
|
|
db->check_count(3, "SELECT ST_NumPoints(way) FROM test_line WHERE osm_id = 1");
|
|
db->check_count(2, "SELECT ST_NumPoints(way) FROM test_line WHERE osm_id = 2");
|
|
db->check_count(2, "SELECT ST_NumPoints(way) FROM test_line WHERE osm_id = 3");
|
|
|
|
db->check_count(3, "SELECT COUNT(*) FROM test_line WHERE foo = 'bar'");
|
|
return 0;
|
|
|
|
} catch (const std::exception &e) {
|
|
std::cerr << "ERROR: " << e.what() << std::endl;
|
|
|
|
} catch (...) {
|
|
std::cerr << "UNKNOWN ERROR" << std::endl;
|
|
}
|
|
|
|
return 1;
|
|
}
|