fixes for review comments

Mostly style fixes. Also increased the size for the test
cache to make Windows builds happy.
This commit is contained in:
Sarah Hoffmann
2019-11-14 23:05:24 +01:00
parent e1795da9eb
commit 4dc31c5411
8 changed files with 53 additions and 48 deletions

View File

@ -1,3 +1,6 @@
#ifndef OSM2PGSQL_TESTS_COMMON_CLEANUP_HPP
#define OSM2PGSQL_TESTS_COMMON_CLEANUP_HPP
#include <string>
#include <boost/filesystem.hpp>
@ -8,7 +11,7 @@ namespace cleanup {
/**
* RAII structure to remove a file upon destruction.
*
* Per defualt will also make sure that the file does not exist
* Per default will also make sure that the file does not exist
* when it is constructed.
*/
class file_t
@ -21,10 +24,10 @@ public:
delete_file(false);
}
~file_t() { delete_file(true); }
~file_t() noexcept { delete_file(true); }
private:
void delete_file(bool warn)
void delete_file(bool warn) noexcept
{
boost::system::error_code ec;
boost::filesystem::remove(m_filename, ec);
@ -39,3 +42,5 @@ private:
} // namespace cleanup
} // namespace testing
#endif // OSM2PGSQL_TESTS_COMMON_CLEANUP_HPP

View File

@ -20,7 +20,8 @@
namespace testing {
inline void parse_file(options_t const &options, std::shared_ptr<middle_t> mid,
inline void parse_file(options_t const &options,
std::shared_ptr<middle_t> const &mid,
std::vector<std::shared_ptr<output_t>> const &outs,
char const *filename = nullptr)
{
@ -68,7 +69,7 @@ public:
options.database_options = m_db.db_options();
// setup the middle
std::shared_ptr<middle_t> middle(new middle_ram_t(&options));
auto middle = std::make_shared<middle_ram_t>(&options);
middle->start();
// setup the output
@ -92,7 +93,7 @@ public:
options.database_options = m_db.db_options();
// setup the middle
std::shared_ptr<middle_t> middle(new middle_ram_t(&options));
auto middle = std::make_shared<middle_ram_t>(&options);
middle->start();
// setup the output
@ -117,7 +118,7 @@ public:
columns.add(type, info);
}
std::shared_ptr<middle_t> mid_pgsql(new middle_pgsql_t(&options));
auto mid_pgsql = std::make_shared<middle_pgsql_t>(&options);
mid_pgsql->start();
auto midq = mid_pgsql->get_query_instance(mid_pgsql);

View File

@ -1,5 +1,5 @@
#ifndef __OSM2PGSQL_TESTS_COMMON_OPTIONS_HPP
#define __OSM2PGSQL_TESTS_COMMON_OPTIONS_HPP
#ifndef OSM2PGSQL_TESTS_COMMON_OPTIONS_HPP
#define OSM2PGSQL_TESTS_COMMON_OPTIONS_HPP
#include "options.hpp"
@ -15,7 +15,7 @@ public:
m_opt.prefix = "osm2pgsql_test";
m_opt.style = OSM2PGSQLDATA_DIR "default.style";
m_opt.num_procs = 1;
m_opt.cache = 1;
m_opt.cache = 2;
m_opt.append = false;
}
@ -82,4 +82,4 @@ private:
} // namespace testing
#endif // __OSM2PGSQL_TESTS_COMMON_OPTIONS_HPP
#endif // OSM2PGSQL_TESTS_COMMON_OPTIONS_HPP

View File

@ -27,16 +27,18 @@ class result_t
public:
result_t(PGresult *result) : m_result(result) {}
~result_t() { PQclear(m_result); }
~result_t() noexcept { PQclear(m_result); }
ExecStatusType status() const { return PQresultStatus(m_result); }
int num_tuples() const { return PQntuples(m_result); }
std::string get_value(int row, int col) const
ExecStatusType status() const noexcept { return PQresultStatus(m_result); }
int num_tuples() const noexcept { return PQntuples(m_result); }
std::string get_value(int row, int col) const noexcept
{
return PQgetvalue(m_result, row, col);
}
bool is_null(int row, int col) const
bool is_null(int row, int col) const noexcept
{
return PQgetisnull(m_result, row, col) != 0;
}
@ -60,7 +62,7 @@ public:
}
}
~conn_t()
~conn_t() noexcept
{
if (m_conn) {
PQfinish(m_conn);
@ -108,7 +110,10 @@ public:
void assert_null(std::string const &cmd) const
{
REQUIRE(require_scalar<std::string>(cmd) == "");
result_t res = query(cmd);
REQUIRE(res.status() == PGRES_TUPLES_OK);
REQUIRE(res.num_tuples() == 1);
REQUIRE(res.is_null(0, 0));
}
result_t require_row(std::string const &cmd) const
@ -160,7 +165,7 @@ public:
local.exec("CREATE EXTENSION hstore");
}
~tempdb_t()
~tempdb_t() noexcept
{
if (!m_db_name.empty()) {
conn_t conn("dbname=postgres");

View File

@ -1,4 +1,5 @@
#include <string>
#include <utility>
#include <vector>
#include "catch.hpp"
@ -6,15 +7,13 @@
#include "common-pg.hpp"
#include "db-copy.hpp"
using fmt = boost::format;
static pg::tempdb_t db;
static std::shared_ptr<db_target_descr_t> setup_table(std::string const &cols)
{
auto conn = db.connect();
conn.exec("DROP TABLE IF EXISTS test_copy_mgr");
conn.exec(fmt("CREATE TABLE test_copy_mgr (id int8%1%%2%)") %
conn.exec(boost::format("CREATE TABLE test_copy_mgr (id int8%1%%2%)") %
(cols.empty() ? "" : ",") % cols);
auto table = std::make_shared<db_target_descr_t>();
@ -29,7 +28,7 @@ void add_row(db_copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> t,
ARGS &&... args)
{
mgr.new_line(t);
mgr.add_columns(args...);
mgr.add_columns(std::forward<ARGS>(args)...);
mgr.finish_line();
mgr.sync();
@ -37,7 +36,7 @@ void add_row(db_copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> t,
template <typename T>
void add_array(db_copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> t, int id,
std::vector<T> values)
std::vector<T> const &values)
{
mgr.new_line(t);
mgr.add_column(id);
@ -51,9 +50,9 @@ void add_array(db_copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> t, int id,
mgr.sync();
}
static void add_hash(db_copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> t,
int id,
std::vector<std::pair<std::string, std::string>> values)
static void
add_hash(db_copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> t, int id,
std::vector<std::pair<std::string, std::string>> const &values)
{
mgr.new_line(t);
@ -68,7 +67,7 @@ static void add_hash(db_copy_mgr_t &mgr, std::shared_ptr<db_target_descr_t> t,
mgr.sync();
}
static void check_row(std::vector<std::string> row)
static void check_row(std::vector<std::string> const &row)
{
auto conn = db.connect();
auto res = conn.require_row("SELECT * FROM test_copy_mgr");
@ -173,7 +172,7 @@ TEST_CASE("db_copy_mgr_t")
{
auto t = setup_table("h hstore");
std::vector<std::pair<std::string, std::string>> values = {
std::vector<std::pair<std::string, std::string>> const values = {
{"one", "two"}, {"key 1", "value 1"},
{"\"key\"", "\"value\""}, {"key\t2", "value\t2"},
{"key\n3", "value\n3"}, {"key\r4", "value\r4"},
@ -183,9 +182,9 @@ TEST_CASE("db_copy_mgr_t")
auto c = db.connect();
auto sql = boost::format("SELECT h->'%1%' from test_copy_mgr");
for (auto const &v : values) {
auto res = c.require_scalar<std::string>(
(fmt("SELECT h->'%1%' from test_copy_mgr") % v.first).str());
auto res = c.require_scalar<std::string>((sql % v.first).str());
CHECK(res == v.second);
}
}

View File

@ -7,28 +7,23 @@
static testing::db::import_t db;
using fmt = boost::format;
options_t options() { return testing::opt_t().gazetteer(); }
static options_t options() { return testing::opt_t().gazetteer(); }
static pg::result_t require_place(pg::conn_t const &conn, char type, osmid_t id,
char const *cls, char const *typ)
{
return conn.require_row(
(fmt("SELECT * FROM place WHERE osm_type = '%1%' AND osm_id = %2% AND "
"class = '%3%' AND type = '%4%'") %
type % id % cls % typ)
.str());
auto sql = boost::format("SELECT * FROM place"
" WHERE osm_type = '%1%' AND osm_id = %2%"
" AND class = '%3%' AND type = '%4%'");
return conn.require_row((sql % type % id % cls % typ).str());
}
static void require_place_not(pg::conn_t const &conn, char type, osmid_t id,
char const *cls)
{
REQUIRE(conn.require_scalar<int>(
(fmt("SELECT count(*) FROM place WHERE osm_type = '%1%' AND "
"osm_id = %2% AND class = '%3%'") %
type % id % cls)
.str()) == 0);
auto where = boost::format("osm_type = '%1%' AND osm_id = %2%"
" AND class = '%3%'");
REQUIRE(conn.get_count("place", (where % type % id % cls).str()) == 0);
}
TEST_CASE("output_gazetteer_t import")

View File

@ -25,7 +25,7 @@ TEST_CASE("parse point")
columns.add(osmium::item_type::node, info);
}
std::shared_ptr<middle_t> mid_pgsql(new middle_pgsql_t(&options));
auto mid_pgsql = std::make_shared<middle_pgsql_t>(&options);
mid_pgsql->start();
auto midq = mid_pgsql->get_query_instance(mid_pgsql);

View File

@ -133,7 +133,7 @@ TEST_CASE("parse xml file")
{
options_t options = testing::opt_t().slim();
std::shared_ptr<middle_t> middle(new counting_slim_middle_t());
auto middle = std::make_shared<counting_slim_middle_t>();
std::shared_ptr<output_t> output(new counting_output_t(options));
testing::parse_file(options, middle, {output}, "test_multipolygon.osm");
@ -168,7 +168,7 @@ TEST_CASE("parse diff file")
{
options_t options = testing::opt_t().slim().append();
std::shared_ptr<middle_t> middle(new counting_slim_middle_t());
auto middle = std::make_shared<counting_slim_middle_t>();
std::shared_ptr<output_t> output(new counting_output_t(options));
testing::parse_file(options, middle, {output}, "008-ch.osc.gz");
@ -201,7 +201,7 @@ TEST_CASE("parse xml file with extra args")
options_t options = testing::opt_t().slim().srs(PROJ_SPHERE_MERC);
options.extra_attributes = true;
std::shared_ptr<middle_t> middle(new counting_slim_middle_t());
auto middle = std::make_shared<counting_slim_middle_t>();
std::shared_ptr<output_t> output(new counting_output_t(options));
testing::parse_file(options, middle, {output}, "test_multipolygon.osm");