Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use anonymous namespace instead of static in test code #2229

Merged
merged 1 commit into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions tests/test-db-copy-mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
#include "common-pg.hpp"
#include "db-copy-mgr.hpp"

static testing::pg::tempdb_t db;
namespace {

testing::pg::tempdb_t db;

using copy_mgr_t = db_copy_mgr_t<db_deleter_by_id_t>;

static std::shared_ptr<db_target_descr_t> setup_table(std::string const &cols)
std::shared_ptr<db_target_descr_t> setup_table(std::string const &cols)
{
auto const conn = db.connect();
conn.exec("DROP TABLE IF EXISTS test_copy_mgr");
Expand Down Expand Up @@ -59,9 +61,9 @@ void add_array(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t,
mgr->sync();
}

static void
add_hash(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t, int id,
std::vector<std::pair<std::string, std::string>> const &values)
void add_hash(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t,
int id,
std::vector<std::pair<std::string, std::string>> const &values)
{
mgr->new_line(t);

Expand All @@ -76,7 +78,7 @@ add_hash(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t, int id,
mgr->sync();
}

static void check_row(std::vector<std::string> const &row)
void check_row(std::vector<std::string> const &row)
{
auto const conn = db.connect();
auto const res = conn.require_row("SELECT * FROM test_copy_mgr");
Expand All @@ -86,6 +88,8 @@ static void check_row(std::vector<std::string> const &row)
}
}

} // anonymous namespace

TEST_CASE("copy_mgr_t: Insert null")
{
copy_mgr_t mgr{std::make_shared<db_copy_thread_t>(db.connection_params())};
Expand Down
9 changes: 6 additions & 3 deletions tests/test-db-copy-thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
#include "common-pg.hpp"
#include "db-copy.hpp"

static testing::pg::tempdb_t db;
namespace {

static int table_count(testing::pg::conn_t const &conn,
std::string const &where = "")
testing::pg::tempdb_t db;

int table_count(testing::pg::conn_t const &conn, std::string const &where = "")
{
return conn.result_as_int("SELECT count(*) FROM test_copy_thread " + where);
}

} // anonymous namespace

TEST_CASE("db_copy_thread_t with db_deleter_by_id_t")
{
auto const conn = db.connect();
Expand Down
8 changes: 6 additions & 2 deletions tests/test-domain-matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

#include <cstring>

static osmium::Tag &fill_buffer(osmium::memory::Buffer *buffer, char const *key,
char const *value)
namespace {

osmium::Tag &fill_buffer(osmium::memory::Buffer *buffer, char const *key,
char const *value)
{
{
osmium::builder::TagListBuilder builder{*buffer};
Expand All @@ -29,6 +31,8 @@ static osmium::Tag &fill_buffer(osmium::memory::Buffer *buffer, char const *key,
return *buffer->get<osmium::TagList>(0).begin();
}

} // anonymous namespace

TEST_CASE("DomainMatcher: name", "[NoDB]")
{
osmium::memory::Buffer buffer{1024};
Expand Down
8 changes: 6 additions & 2 deletions tests/test-expire-from-geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
#include "tile-output.hpp"
#include "tile.hpp"

static std::shared_ptr<reprojection> defproj{
namespace {

std::shared_ptr<reprojection> defproj{
reprojection::create_projection(PROJ_SPHERE_MERC)};

// We are using zoom level 12 here, because at that level a tile is about
// 10,000 units wide/high which gives us easy numbers to work with.
static constexpr uint32_t const zoom = 12;
constexpr uint32_t const zoom = 12;

} // anonymous namespace

TEST_CASE("expire null geometry does nothing", "[NoDB]")
{
Expand Down
19 changes: 11 additions & 8 deletions tests/test-expire-tiles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
#include "tile-output.hpp"
#include "tile.hpp"

static std::shared_ptr<reprojection> defproj{
namespace {

std::shared_ptr<reprojection> defproj{
reprojection::create_projection(PROJ_SPHERE_MERC)};

static std::set<tile_t> generate_random(uint32_t zoom, size_t count)
std::set<tile_t> generate_random(uint32_t zoom, size_t count)
{
// Use a random device with a fixed seed. We don't really care about
// the quality of random numbers here, we just need to generate valid
Expand All @@ -39,24 +41,23 @@ static std::set<tile_t> generate_random(uint32_t zoom, size_t count)
return set;
}

static void expire_centroids(expire_tiles *et, std::set<tile_t> const &tiles)
void expire_centroids(expire_tiles *et, std::set<tile_t> const &tiles)
{
for (auto const &t : tiles) {
auto const p = t.center();
et->from_bbox({p.x(), p.y(), p.x(), p.y()}, expire_config_t{});
}
}

static void check_quadkey(quadkey_t quadkey_expected,
tile_t const &tile) noexcept
void check_quadkey(quadkey_t quadkey_expected, tile_t const &tile) noexcept
{
CHECK(tile.quadkey() == quadkey_expected);
auto const t = tile_t::from_quadkey(quadkey_expected, tile.zoom());
CHECK(t == tile);
}

static std::vector<tile_t> get_tiles_ordered(expire_tiles *et, uint32_t minzoom,
uint32_t maxzoom)
std::vector<tile_t> get_tiles_ordered(expire_tiles *et, uint32_t minzoom,
uint32_t maxzoom)
{
std::vector<tile_t> tiles;

Expand All @@ -66,7 +67,7 @@ static std::vector<tile_t> get_tiles_ordered(expire_tiles *et, uint32_t minzoom,
return tiles;
}

static std::set<tile_t> get_tiles_unordered(expire_tiles *et, uint32_t zoom)
std::set<tile_t> get_tiles_unordered(expire_tiles *et, uint32_t zoom)
{
std::set<tile_t> tiles;

Expand All @@ -76,6 +77,8 @@ static std::set<tile_t> get_tiles_unordered(expire_tiles *et, uint32_t zoom)
return tiles;
}

} // anonymous namespace

TEST_CASE("tile to quadkey", "[NoDB]")
{
check_quadkey(quadkey_t{0x27}, tile_t{3, 3, 5});
Expand Down
6 changes: 5 additions & 1 deletion tests/test-geom-transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
#include "geom.hpp"
#include "reprojection.hpp"

static void check(geom::point_t a, geom::point_t b)
namespace {

void check(geom::point_t a, geom::point_t b)
{
REQUIRE(a.x() == Approx(b.x()));
REQUIRE(a.y() == Approx(b.y()));
}

} // anonymous namespace

double const X55 = 612257.1993630046; // lon 5.5
double const Y44 = 490287.90003313165; // lat 4.4
double const X33 = 367354.31961780274; // lon 3.3
Expand Down
41 changes: 26 additions & 15 deletions tests/test-middle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@
#include "common-options.hpp"
#include "common-pg.hpp"

static testing::pg::tempdb_t db;

namespace {

testing::pg::tempdb_t db;

void check_locations_are_equal(osmium::Location a, osmium::Location b)
{
CHECK(a.lat() == Approx(b.lat()));
CHECK(a.lon() == Approx(b.lon()));
}

} // namespace
} // anonymous namespace

struct options_slim_default
{
Expand Down Expand Up @@ -323,11 +323,13 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
}
}

namespace {

/**
* Check that the node is in the mid with the right id and location.
*/
static void check_node(std::shared_ptr<middle_pgsql_t> const &mid,
osmium::Node const &node)
void check_node(std::shared_ptr<middle_pgsql_t> const &mid,
osmium::Node const &node)
{
test_buffer_t buffer;
auto &nodes = buffer.add_way(999, {node.id()}).nodes();
Expand All @@ -338,14 +340,16 @@ static void check_node(std::shared_ptr<middle_pgsql_t> const &mid,
}

/// Return true if the node with the specified id is not in the mid.
static bool no_node(std::shared_ptr<middle_pgsql_t> const &mid, osmid_t id)
bool no_node(std::shared_ptr<middle_pgsql_t> const &mid, osmid_t id)
{
test_buffer_t buffer;
auto &nodes = buffer.add_way(999, {id}).nodes();
auto const mid_q = mid->get_query_instance();
return mid_q->nodes_get_list(&nodes) == 0;
}

} // anonymous namespace

TEMPLATE_TEST_CASE("middle: add, delete and update node", "",
options_slim_default, options_flat_node_cache)
{
Expand Down Expand Up @@ -490,12 +494,14 @@ TEMPLATE_TEST_CASE("middle: add, delete and update node", "",
}
}

namespace {

/**
* Check that the way is in the mid with the right attributes and tags.
* Does not check node locations.
*/
static void check_way(std::shared_ptr<middle_pgsql_t> const &mid,
osmium::Way const &orig_way)
void check_way(std::shared_ptr<middle_pgsql_t> const &mid,
osmium::Way const &orig_way)
{
auto const mid_q = mid->get_query_instance();

Expand Down Expand Up @@ -535,9 +541,8 @@ static void check_way(std::shared_ptr<middle_pgsql_t> const &mid,
* Check that the nodes (ids and locations) of the way with the way_id in the
* mid are identical to the nodes in the nodes vector.
*/
static void check_way_nodes(std::shared_ptr<middle_pgsql_t> const &mid,
osmid_t way_id,
std::vector<osmium::Node const *> const &nodes)
void check_way_nodes(std::shared_ptr<middle_pgsql_t> const &mid, osmid_t way_id,
std::vector<osmium::Node const *> const &nodes)
{
auto const mid_q = mid->get_query_instance();

Expand All @@ -556,13 +561,15 @@ static void check_way_nodes(std::shared_ptr<middle_pgsql_t> const &mid,
}

/// Return true if the way with the specified id is not in the mid.
static bool no_way(std::shared_ptr<middle_pgsql_t> const &mid, osmid_t id)
bool no_way(std::shared_ptr<middle_pgsql_t> const &mid, osmid_t id)
{
auto const mid_q = mid->get_query_instance();
osmium::memory::Buffer outbuf{4096, osmium::memory::Buffer::auto_grow::yes};
return !mid_q->way_get(id, &outbuf);
}

} // anonymous namespace

TEMPLATE_TEST_CASE("middle: add, delete and update way", "",
options_slim_default, options_flat_node_cache)
{
Expand Down Expand Up @@ -762,12 +769,14 @@ TEMPLATE_TEST_CASE("middle: add way with attributes", "", options_slim_default,
}
}

namespace {

/**
* Check that the relation is in the mid with the right attributes, members
* and tags. Only checks the relation, does not recurse into members.
*/
static void check_relation(std::shared_ptr<middle_pgsql_t> const &mid,
osmium::Relation const &orig_relation)
void check_relation(std::shared_ptr<middle_pgsql_t> const &mid,
osmium::Relation const &orig_relation)
{
auto const mid_q = mid->get_query_instance();

Expand Down Expand Up @@ -807,13 +816,15 @@ static void check_relation(std::shared_ptr<middle_pgsql_t> const &mid,
}

/// Return true if the relation with the specified id is not in the mid.
static bool no_relation(std::shared_ptr<middle_pgsql_t> const &mid, osmid_t id)
bool no_relation(std::shared_ptr<middle_pgsql_t> const &mid, osmid_t id)
{
auto const mid_q = mid->get_query_instance();
osmium::memory::Buffer outbuf{4096, osmium::memory::Buffer::auto_grow::yes};
return !mid_q->relation_get(id, &outbuf);
}

} // anonymous namespace

TEMPLATE_TEST_CASE("middle: add, delete and update relation", "",
options_slim_default, options_flat_node_cache)
{
Expand Down
10 changes: 7 additions & 3 deletions tests/test-options-parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
#include "taginfo-impl.hpp"
#include "tagtransform.hpp"

static char const *const TEST_PBF = "foo.pbf";
namespace {

static void bad_opt(std::vector<char const *> opts, char const *msg)
char const *const TEST_PBF = "foo.pbf";

void bad_opt(std::vector<char const *> opts, char const *msg)
{
opts.insert(opts.begin(), "osm2pgsql");
opts.push_back(TEST_PBF);
Expand All @@ -27,14 +29,16 @@ static void bad_opt(std::vector<char const *> opts, char const *msg)
Catch::Matchers::Contains(msg));
}

static options_t opt(std::vector<char const *> opts)
options_t opt(std::vector<char const *> opts)
{
opts.insert(opts.begin(), "osm2pgsql");
opts.push_back(TEST_PBF);

return parse_command_line((int)opts.size(), (char **)opts.data());
}

} // anonymous namespace

TEST_CASE("Insufficient arguments", "[NoDB]")
{
std::vector<char const *> opts = {"osm2pgsql", "-c", "--slim"};
Expand Down
6 changes: 5 additions & 1 deletion tests/test-options-projection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
#include "command-line-parser.hpp"
#include "reprojection.hpp"

static testing::db::import_t db;
namespace {

testing::db::import_t db;

} // anonymous namespace

TEST_CASE("Projection setup")
{
Expand Down
8 changes: 6 additions & 2 deletions tests/test-output-flex-example-configs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
#include <string>
#include <vector>

static testing::db::import_t db;
namespace {

static char const *const data_file = "liechtenstein-2013-08-03.osm.pbf";
testing::db::import_t db;

char const *const data_file = "liechtenstein-2013-08-03.osm.pbf";

} // anonymous namespace

std::vector<std::string> get_files() {
// NOLINTNEXTLINE(concurrency-mt-unsafe)
Expand Down
Loading
Loading