From 368fbccaa9a46ea4b8180b54478e17fdb2cf6dcc Mon Sep 17 00:00:00 2001 From: Jochen Topf Date: Mon, 21 Aug 2023 10:41:32 +0200 Subject: [PATCH] Refactor: Modernize get_count and require_has_table Use string_view parameters --- tests/common-pg.hpp | 6 ++++-- tests/test-properties.cpp | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/common-pg.hpp b/tests/common-pg.hpp index 4069a81de..a917ee9a3 100644 --- a/tests/common-pg.hpp +++ b/tests/common-pg.hpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "format.hpp" #include "options.hpp" @@ -76,7 +77,8 @@ class conn_t : public pg_conn_t return res; } - int get_count(char const *table_name, std::string const &where = "") const + int get_count(std::string_view table_name, + std::string_view where = "") const { auto const query = fmt::format("SELECT count(*) FROM {} {} {}", table_name, @@ -85,7 +87,7 @@ class conn_t : public pg_conn_t return result_as_int(query); } - void require_has_table(char const *table_name) const + void require_has_table(std::string_view table_name) const { auto const where = fmt::format("oid = '{}'::regclass", table_name); diff --git a/tests/test-properties.cpp b/tests/test-properties.cpp index 42f0a28c8..3edc8384a 100644 --- a/tests/test-properties.cpp +++ b/tests/test-properties.cpp @@ -67,14 +67,14 @@ TEST_CASE("Store and retrieve properties (with database)") std::string const full_table_name = (schema.empty() ? "" : schema + ".") + "osm2pgsql_properties"; - REQUIRE(conn.get_count(full_table_name.c_str()) == 4); - REQUIRE(conn.get_count(full_table_name.c_str(), + REQUIRE(conn.get_count(full_table_name) == 4); + REQUIRE(conn.get_count(full_table_name, "property='foo' AND value='bar'") == 1); - REQUIRE(conn.get_count(full_table_name.c_str(), + REQUIRE(conn.get_count(full_table_name, "property='empty' AND value=''") == 1); - REQUIRE(conn.get_count(full_table_name.c_str(), + REQUIRE(conn.get_count(full_table_name, "property='number' AND value='123'") == 1); - REQUIRE(conn.get_count(full_table_name.c_str(), + REQUIRE(conn.get_count(full_table_name, "property='decide' AND value='true'") == 1); properties_t properties{db.conninfo(), schema};