int main(int argc, char *argv[]) { std::string inputfile = "tests/test_multipolygon.osm"; options_t options; auto projection = std::make_shared<reprojection>(PROJ_SPHERE_MERC); options.projection = projection; auto out_test = std::make_shared<test_output_t>(options); osmdata_t osmdata(std::make_shared<test_middle_t>(), out_test); boost::optional<std::string> bbox; parse_osmium_t parser(false, bbox, projection.get(), false, &osmdata); parser.stream_file(inputfile, ""); assert_equal(out_test->sum_ids, 73514L); assert_equal(out_test->num_nodes, 353L); assert_equal(out_test->num_ways, 140L); assert_equal(out_test->num_relations, 40L); assert_equal(out_test->num_nds, 495L); assert_equal(out_test->num_members, 146L); return 0; }
int main() { std::string inputfile = "tests/008-ch.osc.gz"; options_t options; std::shared_ptr<reprojection> projection(reprojection::create_projection(PROJ_SPHERE_MERC)); options.projection = projection; auto out_test = std::make_shared<test_output_t>(options); osmdata_t osmdata(std::make_shared<dummy_slim_middle_t>(), out_test, options.projection); boost::optional<std::string> bbox; parse_osmium_t parser(bbox, true, &osmdata); parser.stream_file(inputfile, ""); assert_equal(out_test->node.added, 0); assert_equal(out_test->node.modified, 1176); assert_equal(out_test->node.deleted, 16773); assert_equal(out_test->way.added, 0); assert_equal(out_test->way.modified, 161); assert_equal(out_test->way.deleted, 4); assert_equal(out_test->rel.added, 0); assert_equal(out_test->rel.modified, 11); assert_equal(out_test->rel.deleted, 1); return 0; }
int main(int argc, char *argv[]) { char *srcdir = getenv("srcdir"); if (srcdir == NULL) { std::cerr << "$srcdir not set!\n"; return 1; } std::string inputfile = std::string(srcdir) + std::string("/tests/test_multipolygon.osm"); options_t options; boost::shared_ptr<reprojection> projection(new reprojection(PROJ_SPHERE_MERC)); options.projection = projection; boost::shared_ptr<test_output_t> out_test(new test_output_t(options)); osmdata_t osmdata(boost::make_shared<test_middle_t>(), out_test); parse_xml2_t parser(0, false, projection, 0, 0, 0, 0); int ret = parser.streamFile(inputfile.c_str(), 0, &osmdata); if (ret != 0) { return ret; } assert_equal(out_test->sum_ids, 73514L); assert_equal(out_test->num_nodes, 353L); assert_equal(out_test->num_ways, 140L); assert_equal(out_test->num_relations, 40L); assert_equal(out_test->num_nds, 495L); assert_equal(out_test->num_members, 146L); return 0; }
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(new reprojection(PROJ_LATLONG)); options.output_backend = "multi"; options.style = "tests/test_output_multi_line_trivial.style.json"; //setup the front (input) parse_delegate_t parser(options.extra_attributes, options.bbox, options.projection, options.append); //setup the middle std::shared_ptr<middle_t> middle = middle_t::create_middle(options.slim); //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); osmdata.start(); parser.stream_file("xml", "tests/test_output_multi_line_storage.osm", &osmdata); osmdata.stop(); 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; }
void run_osm2pgsql(options_t &options) { //setup the middle std::shared_ptr<middle_t> middle = middle_t::create_middle(options.slim); //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); testing::parse("tests/test_output_multi_poly_trivial.osm", "xml", options, &osmdata); }
void run_osm2pgsql(options_t &options) { //setup the front (input) parse_delegate_t parser(options.extra_attributes, options.bbox, options.projection, options.append); //setup the middle std::shared_ptr<middle_t> middle = middle_t::create_middle(options.slim); //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); osmdata.start(); parser.stream_file("libxml2", "tests/test_output_multi_poly_trivial.osm", &osmdata); osmdata.stop(); }
void run_osm2pgsql(options_t &options, char const *test_file, char const *file_format) { //setup the middle std::shared_ptr<middle_t> middle; if (options.slim) { middle = std::shared_ptr<middle_t>(new middle_pgsql_t(&options)); } else { middle = std::shared_ptr<middle_t>(new middle_ram_t(&options)); } middle->start(); //setup the backend (output) auto outputs = output_t::create_outputs( middle->get_query_instance(middle), options); //let osmdata orchestrate between the middle and the outs osmdata_t osmdata(middle, outputs); parse(test_file, file_format, options, &osmdata); }
int main(int argc, char *argv[]) { boost::scoped_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 { boost::shared_ptr<middle_pgsql_t> mid_pgsql(new middle_pgsql_t()); options_t options; options.conninfo = db->conninfo().c_str(); options.num_procs = 1; options.prefix = "osm2pgsql_test"; options.tblsslim_index = "tablespacetest"; options.tblsslim_data = "tablespacetest"; options.slim = 1; boost::shared_ptr<geometry_processor> processor = geometry_processor::create("polygon", &options); export_list columns; { taginfo info; info.name = "building"; info.type = "text"; columns.add(OSMTYPE_WAY, info); } boost::shared_ptr<output_multi_t> out_test(new output_multi_t("foobar_buildings", processor, columns, mid_pgsql.get(), options)); osmdata_t osmdata(mid_pgsql, out_test); boost::scoped_ptr<parse_delegate_t> parser(new parse_delegate_t(options.extra_attributes, options.bbox, options.projection)); osmdata.start(); if (parser->streamFile("pbf", "tests/liechtenstein-2013-08-03.osm.pbf", options.sanitize, &osmdata) != 0) { throw std::runtime_error("Unable to read input file `tests/liechtenstein-2013-08-03.osm.pbf'."); } parser.reset(NULL); osmdata.stop(); // start a new connection to run tests on pg::conn_ptr test_conn = pg::conn::connect(db->conninfo()); check_count(test_conn, 1, "select count(*) from pg_catalog.pg_class where relname = 'osm2pgsql_test_foobar_buildings'"); check_count(test_conn, 0, "select count(*) from osm2pgsql_test_foobar_buildings where building is null"); check_count(test_conn, 3723, "select count(*) from osm2pgsql_test_foobar_buildings"); //check that we have the right spread check_count(test_conn, 1, "select count(*) from osm2pgsql_test_foobar_buildings where building='barn'"); check_count(test_conn, 1, "select count(*) from osm2pgsql_test_foobar_buildings where building='chapel'"); check_count(test_conn, 5, "select count(*) from osm2pgsql_test_foobar_buildings where building='church'"); check_count(test_conn, 3, "select count(*) from osm2pgsql_test_foobar_buildings where building='commercial'"); check_count(test_conn, 6, "select count(*) from osm2pgsql_test_foobar_buildings where building='farm'"); check_count(test_conn, 1, "select count(*) from osm2pgsql_test_foobar_buildings where building='garage'"); check_count(test_conn, 2, "select count(*) from osm2pgsql_test_foobar_buildings where building='glasshouse'"); check_count(test_conn, 1, "select count(*) from osm2pgsql_test_foobar_buildings where building='greenhouse'"); check_count(test_conn, 153, "select count(*) from osm2pgsql_test_foobar_buildings where building='house'"); check_count(test_conn, 4, "select count(*) from osm2pgsql_test_foobar_buildings where building='hut'"); check_count(test_conn, 8, "select count(*) from osm2pgsql_test_foobar_buildings where building='industrial'"); check_count(test_conn, 200, "select count(*) from osm2pgsql_test_foobar_buildings where building='residential'"); check_count(test_conn, 6, "select count(*) from osm2pgsql_test_foobar_buildings where building='roof'"); check_count(test_conn, 4, "select count(*) from osm2pgsql_test_foobar_buildings where building='school'"); check_count(test_conn, 2, "select count(*) from osm2pgsql_test_foobar_buildings where building='station'"); check_count(test_conn, 3, "select count(*) from osm2pgsql_test_foobar_buildings where building='warehouse'"); check_count(test_conn, 3323, "select count(*) from osm2pgsql_test_foobar_buildings where building='yes'"); return 0; } catch (const std::exception &e) { std::cerr << "ERROR: " << e.what() << std::endl; } catch (...) { std::cerr << "UNKNOWN ERROR" << std::endl; } return 1; }
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 { std::shared_ptr<middle_pgsql_t> mid_pgsql(new middle_pgsql_t()); options_t options; options.database_options = db->database_options; options.num_procs = 1; options.prefix = "osm2pgsql_test"; options.style="tests/hstore-match-only.style"; options.hstore_match_only=1; options.hstore_mode = HSTORE_NORM; options.slim = 1; auto out_test = std::make_shared<output_pgsql_t>(mid_pgsql.get(), options); osmdata_t osmdata(mid_pgsql, out_test); std::unique_ptr<parse_delegate_t> parser(new parse_delegate_t(options.extra_attributes, options.bbox, options.projection, false)); osmdata.start(); parser->stream_file("libxml2", "tests/hstore-match-only.osm", &osmdata); parser.reset(nullptr); osmdata.stop(); // tables should not contain any tag columns db->check_count(4, "select count(column_name) from information_schema.columns where table_name='osm2pgsql_test_point'"); db->check_count(5, "select count(column_name) from information_schema.columns where table_name='osm2pgsql_test_polygon'"); db->check_count(5, "select count(column_name) from information_schema.columns where table_name='osm2pgsql_test_line'"); db->check_count(5, "select count(column_name) from information_schema.columns where table_name='osm2pgsql_test_roads'"); // the testfile contains 19 tagged ways and 7 tagged nodes // out of them 18 ways and 6 nodes are interesting as specified by hstore-match-only.style // as there is also one relation we should end up getting a database which contains: // 6 objects in osm2pgsql_test_point // 7 objects in osm2pgsql_test_polygon // 12 objects in osm2pgsql_test_line // 3 objects in osm2pgsql_test_roads db->check_count(6, "select count(*) from osm2pgsql_test_point"); db->check_count(7, "select count(*) from osm2pgsql_test_polygon"); db->check_count(12, "select count(*) from osm2pgsql_test_line"); db->check_count(3, "select count(*) from osm2pgsql_test_roads"); return 0; } catch (const std::exception &e) { std::cerr << "ERROR: " << e.what() << std::endl; } catch (...) { std::cerr << "UNKNOWN ERROR" << std::endl; } return 1; }
int main(int argc, char *argv[]) { fprintf(stderr, "osm2pgsql version %s (%zu bit id space)\n\n", VERSION, 8 * sizeof(osmid_t)); try { //parse the args into the different options members options_t options = options_t(argc, argv); if(options.long_usage_bool) return 0; //setup the middle std::shared_ptr<middle_t> middle = middle_t::create_middle(options.slim); //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); fprintf(stderr, "Using projection SRS %d (%s)\n", options.projection->target_srs(), options.projection->target_desc()); //start it up time_t overall_start = time(nullptr); osmdata.start(); /* Processing * In this phase the input file(s) are read and parsed, populating some of the * tables. Not all ways can be handled before relations are processed, so they're * set as pending, to be handled in the next stage. */ parse_stats_t stats; //read in the input files one by one for (auto const filename : options.input_files) { //read the actual input fprintf(stderr, "\nReading in file: %s\n", filename.c_str()); time_t start = time(nullptr); parse_osmium_t parser(options.bbox, options.append, &osmdata); parser.stream_file(filename, options.input_reader); stats.update(parser.stats()); fprintf(stderr, " parse time: %ds\n", (int)(time(nullptr) - start)); } //show stats stats.print_summary(); //Process pending ways, relations, cluster, and create indexes osmdata.stop(); fprintf(stderr, "\nOsm2pgsql took %ds overall\n", (int)(time(nullptr) - overall_start)); return 0; }//something went wrong along the way catch(const std::runtime_error& e) { fprintf(stderr, "Osm2pgsql failed due to ERROR: %s\n", e.what()); exit(EXIT_FAILURE); } }
int main(int argc, char *argv[]) { boost::scoped_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 { boost::shared_ptr<middle_pgsql_t> mid_pgsql(new middle_pgsql_t()); options_t options; options.conninfo = db->conninfo().c_str(); options.num_procs = 1; options.prefix = "osm2pgsql_test"; options.tblsslim_index = "tablespacetest"; options.tblsslim_data = "tablespacetest"; options.slim = 1; boost::shared_ptr<geometry_processor> processor = geometry_processor::create("point", &options); export_list columns; { taginfo info; info.name = "amenity"; info.type = "text"; columns.add(OSMTYPE_NODE, info); } boost::shared_ptr<output_multi_t> out_test(new output_multi_t("foobar_amenities", processor, columns, mid_pgsql.get(), options)); osmdata_t osmdata(mid_pgsql, out_test); boost::scoped_ptr<parse_delegate_t> parser(new parse_delegate_t(options.extra_attributes, options.bbox, options.projection)); osmdata.start(); if (parser->streamFile("pbf", "tests/liechtenstein-2013-08-03.osm.pbf", options.sanitize, &osmdata) != 0) { throw std::runtime_error("Unable to read input file `tests/liechtenstein-2013-08-03.osm.pbf'."); } parser.reset(NULL); osmdata.stop(); // start a new connection to run tests on pg::conn_ptr test_conn = pg::conn::connect(db->conninfo()); check_count(test_conn, 1, "select count(*) from pg_catalog.pg_class " "where relname = 'osm2pgsql_test_foobar_amenities'"); check_count(test_conn, 244, "select count(*) from osm2pgsql_test_foobar_amenities"); check_count(test_conn, 36, "select count(*) from osm2pgsql_test_foobar_amenities where amenity='parking'"); check_count(test_conn, 34, "select count(*) from osm2pgsql_test_foobar_amenities where amenity='bench'"); check_count(test_conn, 1, "select count(*) from osm2pgsql_test_foobar_amenities where amenity='vending_machine'"); return 0; } catch (const std::exception &e) { std::cerr << "ERROR: " << e.what() << std::endl; } catch (...) { std::cerr << "UNKNOWN ERROR" << std::endl; } return 1; }
int main(int argc, char *argv[]) { boost::scoped_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 { boost::shared_ptr<middle_pgsql_t> mid_pgsql(new middle_pgsql_t()); options_t options; options.conninfo = db->conninfo().c_str(); options.num_procs = 1; options.prefix = "osm2pgsql_test"; options.tblsslim_index = "tablespacetest"; options.tblsslim_data = "tablespacetest"; options.slim = 1; boost::shared_ptr<geometry_processor> processor = geometry_processor::create("line", &options); export_list columns; { taginfo info; info.name = "highway"; info.type = "text"; columns.add(OSMTYPE_WAY, info); } boost::shared_ptr<output_multi_t> out_test(new output_multi_t("foobar_highways", processor, columns, mid_pgsql.get(), options)); osmdata_t osmdata(mid_pgsql, out_test); boost::scoped_ptr<parse_delegate_t> parser(new parse_delegate_t(options.extra_attributes, options.bbox, options.projection)); osmdata.start(); if (parser->streamFile("pbf", "tests/liechtenstein-2013-08-03.osm.pbf", options.sanitize, &osmdata) != 0) { throw std::runtime_error("Unable to read input file `tests/liechtenstein-2013-08-03.osm.pbf'."); } parser.reset(NULL); osmdata.stop(); // start a new connection to run tests on pg::conn_ptr test_conn = pg::conn::connect(db->conninfo()); check_count(test_conn, 1, "select count(*) from pg_catalog.pg_class where relname = 'osm2pgsql_test_foobar_highways'"); check_count(test_conn, 2753, "select count(*) from osm2pgsql_test_foobar_highways"); //check that we have the right spread check_count(test_conn, 13, "select count(*) from osm2pgsql_test_foobar_highways where highway='bridleway'"); check_count(test_conn, 3, "select count(*) from osm2pgsql_test_foobar_highways where highway='construction'"); check_count(test_conn, 96, "select count(*) from osm2pgsql_test_foobar_highways where highway='cycleway'"); check_count(test_conn, 249, "select count(*) from osm2pgsql_test_foobar_highways where highway='footway'"); check_count(test_conn, 18, "select count(*) from osm2pgsql_test_foobar_highways where highway='living_street'"); check_count(test_conn, 171, "select count(*) from osm2pgsql_test_foobar_highways where highway='path'"); check_count(test_conn, 6, "select count(*) from osm2pgsql_test_foobar_highways where highway='pedestrian'"); check_count(test_conn, 81, "select count(*) from osm2pgsql_test_foobar_highways where highway='primary'"); check_count(test_conn, 842, "select count(*) from osm2pgsql_test_foobar_highways where highway='residential'"); check_count(test_conn, 3, "select count(*) from osm2pgsql_test_foobar_highways where highway='road'"); check_count(test_conn, 90, "select count(*) from osm2pgsql_test_foobar_highways where highway='secondary'"); check_count(test_conn, 1, "select count(*) from osm2pgsql_test_foobar_highways where highway='secondary_link'"); check_count(test_conn, 352, "select count(*) from osm2pgsql_test_foobar_highways where highway='service'"); check_count(test_conn, 34, "select count(*) from osm2pgsql_test_foobar_highways where highway='steps'"); check_count(test_conn, 33, "select count(*) from osm2pgsql_test_foobar_highways where highway='tertiary'"); check_count(test_conn, 597, "select count(*) from osm2pgsql_test_foobar_highways where highway='track'"); check_count(test_conn, 164, "select count(*) from osm2pgsql_test_foobar_highways where highway='unclassified'"); return 0; } catch (const std::exception &e) { std::cerr << "ERROR: " << e.what() << std::endl; } catch (...) { std::cerr << "UNKNOWN ERROR" << std::endl; } return 1; }
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 { std::shared_ptr<middle_pgsql_t> mid_pgsql(new middle_pgsql_t()); options_t options; options.database_options = db->database_options; options.num_procs = 1; options.prefix = "osm2pgsql_test"; options.slim = true; export_list columns; { taginfo info; info.name = "amenity"; info.type = "text"; columns.add(OSMTYPE_NODE, info); } std::vector<std::shared_ptr<output_t> > outputs; // let's make lots of tables! for (int i = 0; i < 10; ++i) { std::string name = (boost::format("foobar_%d") % i).str(); std::shared_ptr<geometry_processor> processor = geometry_processor::create("point", &options); auto out_test = std::make_shared<output_multi_t>(name, processor, columns, mid_pgsql.get(), options); outputs.push_back(out_test); } osmdata_t osmdata(mid_pgsql, outputs); std::unique_ptr<parse_delegate_t> parser(new parse_delegate_t(options.extra_attributes, options.bbox, options.projection, options.append)); osmdata.start(); parser->stream_file("pbf", "tests/liechtenstein-2013-08-03.osm.pbf", &osmdata); parser.reset(nullptr); osmdata.stop(); for (int i = 0; i < 10; ++i) { std::string name = (boost::format("foobar_%d") % i).str(); db->check_count(1, (boost::format("select count(*) from pg_catalog.pg_class " "where relname = 'foobar_%d'") % i).str()); db->check_count(244, (boost::format("select count(*) from foobar_%d") % i).str()); db->check_count(36, (boost::format("select count(*) from foobar_%d " "where amenity='parking'") % i).str()); db->check_count(34, (boost::format("select count(*) from foobar_%d " "where amenity='bench'") % i).str()); db->check_count(1, (boost::format("select count(*) from foobar_%d " "where amenity='vending_machine'") % i).str()); } return 0; } catch (const std::exception &e) { std::cerr << "ERROR: " << e.what() << std::endl; } catch (...) { std::cerr << "UNKNOWN ERROR" << std::endl; } return 1; }
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 { std::shared_ptr<middle_pgsql_t> mid_pgsql(new middle_pgsql_t()); options_t options; options.database_options = db->database_options; options.num_procs = 1; options.slim = true; std::shared_ptr<geometry_processor> processor = geometry_processor::create("line", &options); export_list columns; { taginfo info; info.name = "highway"; info.type = "text"; columns.add(osmium::item_type::way, info); } // This actually uses the multi-backend with C transforms, not Lua transforms. This is unusual and doesn't reflect real practice auto out_test = std::make_shared<output_multi_t>("foobar_highways", processor, columns, mid_pgsql.get(), options); osmdata_t osmdata(mid_pgsql, out_test, options.projection); testing::parse("tests/liechtenstein-2013-08-03.osm.pbf", "pbf", options, &osmdata); // start a new connection to run tests on db->check_count(1, "select count(*) from pg_catalog.pg_class where relname = 'foobar_highways'"); db->check_count(2752, "select count(*) from foobar_highways"); //check that we have the right spread db->check_count(13, "select count(*) from foobar_highways where highway='bridleway'"); db->check_count(3, "select count(*) from foobar_highways where highway='construction'"); db->check_count(96, "select count(*) from foobar_highways where highway='cycleway'"); db->check_count(249, "select count(*) from foobar_highways where highway='footway'"); db->check_count(18, "select count(*) from foobar_highways where highway='living_street'"); db->check_count(171, "select count(*) from foobar_highways where highway='path'"); db->check_count(5, "select count(*) from foobar_highways where highway='pedestrian'"); db->check_count(81, "select count(*) from foobar_highways where highway='primary'"); db->check_count(842, "select count(*) from foobar_highways where highway='residential'"); db->check_count(3, "select count(*) from foobar_highways where highway='road'"); db->check_count(90, "select count(*) from foobar_highways where highway='secondary'"); db->check_count(1, "select count(*) from foobar_highways where highway='secondary_link'"); db->check_count(352, "select count(*) from foobar_highways where highway='service'"); db->check_count(34, "select count(*) from foobar_highways where highway='steps'"); db->check_count(33, "select count(*) from foobar_highways where highway='tertiary'"); db->check_count(597, "select count(*) from foobar_highways where highway='track'"); db->check_count(164, "select count(*) from foobar_highways where highway='unclassified'"); return 0; } catch (const std::exception &e) { std::cerr << "ERROR: " << e.what() << std::endl; } catch (...) { std::cerr << "UNKNOWN ERROR" << std::endl; } return 1; }
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_tags.json"; //setup the middle std::shared_ptr<middle_t> middle = middle_t::create_middle(options.slim); //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); testing::parse("tests/test_output_multi_tags.osm", "xml", options, &osmdata); // Check we got the right tables db->check_count(1, "select count(*) from pg_catalog.pg_class where relname = 'test_points_1'"); db->check_count(1, "select count(*) from pg_catalog.pg_class where relname = 'test_points_2'"); db->check_count(1, "select count(*) from pg_catalog.pg_class where relname = 'test_line_1'"); db->check_count(1, "select count(*) from pg_catalog.pg_class where relname = 'test_polygon_1'"); db->check_count(1, "select count(*) from pg_catalog.pg_class where relname = 'test_polygon_2'"); // Check we didn't get any extra in the tables db->check_count(2, "select count(*) from test_points_1"); db->check_count(2, "select count(*) from test_points_2"); db->check_count(1, "select count(*) from test_line_1"); db->check_count(1, "select count(*) from test_line_2"); db->check_count(1, "select count(*) from test_polygon_1"); db->check_count(1, "select count(*) from test_polygon_2"); // Check that the first table for each type got the right transform db->check_count(1, "SELECT COUNT(*) FROM test_points_1 WHERE foo IS NULL and bar = 'n1' AND baz IS NULL"); db->check_count(1, "SELECT COUNT(*) FROM test_points_1 WHERE foo IS NULL and bar = 'n2' AND baz IS NULL"); db->check_count(1, "SELECT COUNT(*) FROM test_line_1 WHERE foo IS NULL and bar = 'w1' AND baz IS NULL"); db->check_count(1, "SELECT COUNT(*) FROM test_polygon_1 WHERE foo IS NULL and bar = 'w2' AND baz IS NULL"); // Check that the second table also got the right transform db->check_count(1, "SELECT COUNT(*) FROM test_points_2 WHERE foo IS NULL and bar IS NULL AND baz = 'n1'"); db->check_count(1, "SELECT COUNT(*) FROM test_points_2 WHERE foo IS NULL and bar IS NULL AND baz = 'n2'"); db->check_count(1, "SELECT COUNT(*) FROM test_line_2 WHERE foo IS NULL and bar IS NULL AND baz = 'w1'"); db->check_count(1, "SELECT COUNT(*) FROM test_polygon_2 WHERE foo IS NULL and bar IS NULL AND baz = 'w2'"); return 0; } catch (const std::exception &e) { std::cerr << "ERROR: " << e.what() << std::endl; } catch (...) { std::cerr << "UNKNOWN ERROR" << std::endl; } return 1; }