Skip to content

Commit a1dc8ec

Browse files
authored
Merge pull request #2229 from joto/static-to-ns
Use anonymous namespace instead of static in test code
2 parents 8f5bb21 + 7b6ed0d commit a1dc8ec

33 files changed

+226
-90
lines changed

tests/test-db-copy-mgr.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@
1616
#include "common-pg.hpp"
1717
#include "db-copy-mgr.hpp"
1818

19-
static testing::pg::tempdb_t db;
19+
namespace {
20+
21+
testing::pg::tempdb_t db;
2022

2123
using copy_mgr_t = db_copy_mgr_t<db_deleter_by_id_t>;
2224

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

62-
static void
63-
add_hash(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t, int id,
64-
std::vector<std::pair<std::string, std::string>> const &values)
64+
void add_hash(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t,
65+
int id,
66+
std::vector<std::pair<std::string, std::string>> const &values)
6567
{
6668
mgr->new_line(t);
6769

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

79-
static void check_row(std::vector<std::string> const &row)
81+
void check_row(std::vector<std::string> const &row)
8082
{
8183
auto const conn = db.connect();
8284
auto const res = conn.require_row("SELECT * FROM test_copy_mgr");
@@ -86,6 +88,8 @@ static void check_row(std::vector<std::string> const &row)
8688
}
8789
}
8890

91+
} // anonymous namespace
92+
8993
TEST_CASE("copy_mgr_t: Insert null")
9094
{
9195
copy_mgr_t mgr{std::make_shared<db_copy_thread_t>(db.connection_params())};

tests/test-db-copy-thread.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
#include "common-pg.hpp"
1313
#include "db-copy.hpp"
1414

15-
static testing::pg::tempdb_t db;
15+
namespace {
1616

17-
static int table_count(testing::pg::conn_t const &conn,
18-
std::string const &where = "")
17+
testing::pg::tempdb_t db;
18+
19+
int table_count(testing::pg::conn_t const &conn, std::string const &where = "")
1920
{
2021
return conn.result_as_int("SELECT count(*) FROM test_copy_thread " + where);
2122
}
2223

24+
} // anonymous namespace
25+
2326
TEST_CASE("db_copy_thread_t with db_deleter_by_id_t")
2427
{
2528
auto const conn = db.connect();

tests/test-domain-matcher.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
#include <cstring>
1919

20-
static osmium::Tag &fill_buffer(osmium::memory::Buffer *buffer, char const *key,
21-
char const *value)
20+
namespace {
21+
22+
osmium::Tag &fill_buffer(osmium::memory::Buffer *buffer, char const *key,
23+
char const *value)
2224
{
2325
{
2426
osmium::builder::TagListBuilder builder{*buffer};
@@ -29,6 +31,8 @@ static osmium::Tag &fill_buffer(osmium::memory::Buffer *buffer, char const *key,
2931
return *buffer->get<osmium::TagList>(0).begin();
3032
}
3133

34+
} // anonymous namespace
35+
3236
TEST_CASE("DomainMatcher: name", "[NoDB]")
3337
{
3438
osmium::memory::Buffer buffer{1024};

tests/test-expire-from-geometry.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@
1717
#include "tile-output.hpp"
1818
#include "tile.hpp"
1919

20-
static std::shared_ptr<reprojection> defproj{
20+
namespace {
21+
22+
std::shared_ptr<reprojection> defproj{
2123
reprojection::create_projection(PROJ_SPHERE_MERC)};
2224

2325
// We are using zoom level 12 here, because at that level a tile is about
2426
// 10,000 units wide/high which gives us easy numbers to work with.
25-
static constexpr uint32_t const zoom = 12;
27+
constexpr uint32_t const zoom = 12;
28+
29+
} // anonymous namespace
2630

2731
TEST_CASE("expire null geometry does nothing", "[NoDB]")
2832
{

tests/test-expire-tiles.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
#include "tile-output.hpp"
1818
#include "tile.hpp"
1919

20-
static std::shared_ptr<reprojection> defproj{
20+
namespace {
21+
22+
std::shared_ptr<reprojection> defproj{
2123
reprojection::create_projection(PROJ_SPHERE_MERC)};
2224

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

42-
static void expire_centroids(expire_tiles *et, std::set<tile_t> const &tiles)
44+
void expire_centroids(expire_tiles *et, std::set<tile_t> const &tiles)
4345
{
4446
for (auto const &t : tiles) {
4547
auto const p = t.center();
4648
et->from_bbox({p.x(), p.y(), p.x(), p.y()}, expire_config_t{});
4749
}
4850
}
4951

50-
static void check_quadkey(quadkey_t quadkey_expected,
51-
tile_t const &tile) noexcept
52+
void check_quadkey(quadkey_t quadkey_expected, tile_t const &tile) noexcept
5253
{
5354
CHECK(tile.quadkey() == quadkey_expected);
5455
auto const t = tile_t::from_quadkey(quadkey_expected, tile.zoom());
5556
CHECK(t == tile);
5657
}
5758

58-
static std::vector<tile_t> get_tiles_ordered(expire_tiles *et, uint32_t minzoom,
59-
uint32_t maxzoom)
59+
std::vector<tile_t> get_tiles_ordered(expire_tiles *et, uint32_t minzoom,
60+
uint32_t maxzoom)
6061
{
6162
std::vector<tile_t> tiles;
6263

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

69-
static std::set<tile_t> get_tiles_unordered(expire_tiles *et, uint32_t zoom)
70+
std::set<tile_t> get_tiles_unordered(expire_tiles *et, uint32_t zoom)
7071
{
7172
std::set<tile_t> tiles;
7273

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

80+
} // anonymous namespace
81+
7982
TEST_CASE("tile to quadkey", "[NoDB]")
8083
{
8184
check_quadkey(quadkey_t{0x27}, tile_t{3, 3, 5});

tests/test-geom-transform.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414
#include "geom.hpp"
1515
#include "reprojection.hpp"
1616

17-
static void check(geom::point_t a, geom::point_t b)
17+
namespace {
18+
19+
void check(geom::point_t a, geom::point_t b)
1820
{
1921
REQUIRE(a.x() == Approx(b.x()));
2022
REQUIRE(a.y() == Approx(b.y()));
2123
}
2224

25+
} // anonymous namespace
26+
2327
double const X55 = 612257.1993630046; // lon 5.5
2428
double const Y44 = 490287.90003313165; // lat 4.4
2529
double const X33 = 367354.31961780274; // lon 3.3

tests/test-middle.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@
2626
#include "common-options.hpp"
2727
#include "common-pg.hpp"
2828

29-
static testing::pg::tempdb_t db;
30-
3129
namespace {
3230

31+
testing::pg::tempdb_t db;
32+
3333
void check_locations_are_equal(osmium::Location a, osmium::Location b)
3434
{
3535
CHECK(a.lat() == Approx(b.lat()));
3636
CHECK(a.lon() == Approx(b.lon()));
3737
}
3838

39-
} // namespace
39+
} // anonymous namespace
4040

4141
struct options_slim_default
4242
{
@@ -323,11 +323,13 @@ TEMPLATE_TEST_CASE("middle import", "", options_slim_default,
323323
}
324324
}
325325

326+
namespace {
327+
326328
/**
327329
* Check that the node is in the mid with the right id and location.
328330
*/
329-
static void check_node(std::shared_ptr<middle_pgsql_t> const &mid,
330-
osmium::Node const &node)
331+
void check_node(std::shared_ptr<middle_pgsql_t> const &mid,
332+
osmium::Node const &node)
331333
{
332334
test_buffer_t buffer;
333335
auto &nodes = buffer.add_way(999, {node.id()}).nodes();
@@ -338,14 +340,16 @@ static void check_node(std::shared_ptr<middle_pgsql_t> const &mid,
338340
}
339341

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

351+
} // anonymous namespace
352+
349353
TEMPLATE_TEST_CASE("middle: add, delete and update node", "",
350354
options_slim_default, options_flat_node_cache)
351355
{
@@ -490,12 +494,14 @@ TEMPLATE_TEST_CASE("middle: add, delete and update node", "",
490494
}
491495
}
492496

497+
namespace {
498+
493499
/**
494500
* Check that the way is in the mid with the right attributes and tags.
495501
* Does not check node locations.
496502
*/
497-
static void check_way(std::shared_ptr<middle_pgsql_t> const &mid,
498-
osmium::Way const &orig_way)
503+
void check_way(std::shared_ptr<middle_pgsql_t> const &mid,
504+
osmium::Way const &orig_way)
499505
{
500506
auto const mid_q = mid->get_query_instance();
501507

@@ -535,9 +541,8 @@ static void check_way(std::shared_ptr<middle_pgsql_t> const &mid,
535541
* Check that the nodes (ids and locations) of the way with the way_id in the
536542
* mid are identical to the nodes in the nodes vector.
537543
*/
538-
static void check_way_nodes(std::shared_ptr<middle_pgsql_t> const &mid,
539-
osmid_t way_id,
540-
std::vector<osmium::Node const *> const &nodes)
544+
void check_way_nodes(std::shared_ptr<middle_pgsql_t> const &mid, osmid_t way_id,
545+
std::vector<osmium::Node const *> const &nodes)
541546
{
542547
auto const mid_q = mid->get_query_instance();
543548

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

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

571+
} // anonymous namespace
572+
566573
TEMPLATE_TEST_CASE("middle: add, delete and update way", "",
567574
options_slim_default, options_flat_node_cache)
568575
{
@@ -762,12 +769,14 @@ TEMPLATE_TEST_CASE("middle: add way with attributes", "", options_slim_default,
762769
}
763770
}
764771

772+
namespace {
773+
765774
/**
766775
* Check that the relation is in the mid with the right attributes, members
767776
* and tags. Only checks the relation, does not recurse into members.
768777
*/
769-
static void check_relation(std::shared_ptr<middle_pgsql_t> const &mid,
770-
osmium::Relation const &orig_relation)
778+
void check_relation(std::shared_ptr<middle_pgsql_t> const &mid,
779+
osmium::Relation const &orig_relation)
771780
{
772781
auto const mid_q = mid->get_query_instance();
773782

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

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

826+
} // anonymous namespace
827+
817828
TEMPLATE_TEST_CASE("middle: add, delete and update relation", "",
818829
options_slim_default, options_flat_node_cache)
819830
{

tests/test-options-parse.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
#include "taginfo-impl.hpp"
1616
#include "tagtransform.hpp"
1717

18-
static char const *const TEST_PBF = "foo.pbf";
18+
namespace {
1919

20-
static void bad_opt(std::vector<char const *> opts, char const *msg)
20+
char const *const TEST_PBF = "foo.pbf";
21+
22+
void bad_opt(std::vector<char const *> opts, char const *msg)
2123
{
2224
opts.insert(opts.begin(), "osm2pgsql");
2325
opts.push_back(TEST_PBF);
@@ -27,14 +29,16 @@ static void bad_opt(std::vector<char const *> opts, char const *msg)
2729
Catch::Matchers::Contains(msg));
2830
}
2931

30-
static options_t opt(std::vector<char const *> opts)
32+
options_t opt(std::vector<char const *> opts)
3133
{
3234
opts.insert(opts.begin(), "osm2pgsql");
3335
opts.push_back(TEST_PBF);
3436

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

40+
} // anonymous namespace
41+
3842
TEST_CASE("Insufficient arguments", "[NoDB]")
3943
{
4044
std::vector<char const *> opts = {"osm2pgsql", "-c", "--slim"};

tests/test-options-projection.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
#include "command-line-parser.hpp"
1717
#include "reprojection.hpp"
1818

19-
static testing::db::import_t db;
19+
namespace {
20+
21+
testing::db::import_t db;
22+
23+
} // anonymous namespace
2024

2125
TEST_CASE("Projection setup")
2226
{

tests/test-output-flex-example-configs.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@
1919
#include <string>
2020
#include <vector>
2121

22-
static testing::db::import_t db;
22+
namespace {
2323

24-
static char const *const data_file = "liechtenstein-2013-08-03.osm.pbf";
24+
testing::db::import_t db;
25+
26+
char const *const data_file = "liechtenstein-2013-08-03.osm.pbf";
27+
28+
} // anonymous namespace
2529

2630
std::vector<std::string> get_files() {
2731
// NOLINTNEXTLINE(concurrency-mt-unsafe)

0 commit comments

Comments
 (0)