Skip to content

Commit 5245112

Browse files
authored
Merge pull request #1726 from joto/cleanup-const-and-constructors
Cleanup some test code, use const and new constructor {} syntax
2 parents dbf4cb7 + 8e4f21a commit 5245112

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

tests/test-db-copy-mgr.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using copy_mgr_t = db_copy_mgr_t<db_deleter_by_id_t>;
2222

2323
static std::shared_ptr<db_target_descr_t> setup_table(std::string const &cols)
2424
{
25-
auto conn = db.connect();
25+
auto const conn = db.connect();
2626
conn.exec("DROP TABLE IF EXISTS test_copy_mgr");
2727
conn.exec("CREATE TABLE test_copy_mgr (id int8{}{})"_format(
2828
cols.empty() ? "" : ",", cols));
@@ -36,7 +36,7 @@ static std::shared_ptr<db_target_descr_t> setup_table(std::string const &cols)
3636

3737
template <typename... ARGS>
3838
void add_row(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t,
39-
ARGS &&... args)
39+
ARGS &&...args)
4040
{
4141
mgr->new_line(t);
4242
mgr->add_columns(std::forward<ARGS>(args)...);
@@ -80,8 +80,8 @@ add_hash(copy_mgr_t *mgr, std::shared_ptr<db_target_descr_t> const &t, int id,
8080

8181
static void check_row(std::vector<std::string> const &row)
8282
{
83-
auto conn = db.connect();
84-
auto res = conn.require_row("SELECT * FROM test_copy_mgr");
83+
auto const conn = db.connect();
84+
auto const res = conn.require_row("SELECT * FROM test_copy_mgr");
8585

8686
for (std::size_t i = 0; i < row.size(); ++i) {
8787
CHECK(res.get_value(0, (int)i) == row[i]);
@@ -90,11 +90,11 @@ static void check_row(std::vector<std::string> const &row)
9090

9191
TEST_CASE("copy_mgr_t")
9292
{
93-
copy_mgr_t mgr(std::make_shared<db_copy_thread_t>(db.conninfo()));
93+
copy_mgr_t mgr{std::make_shared<db_copy_thread_t>(db.conninfo())};
9494

9595
SECTION("Insert null")
9696
{
97-
auto t = setup_table("big int8, t text");
97+
auto const t = setup_table("big int8, t text");
9898

9999
mgr.new_line(t);
100100
mgr.add_column(0);
@@ -103,24 +103,24 @@ TEST_CASE("copy_mgr_t")
103103
mgr.finish_line();
104104
mgr.sync();
105105

106-
auto conn = db.connect();
107-
auto res = conn.require_row("SELECT * FROM test_copy_mgr");
106+
auto const conn = db.connect();
107+
auto const res = conn.require_row("SELECT * FROM test_copy_mgr");
108108

109109
CHECK(res.is_null(0, 1));
110110
CHECK(res.is_null(0, 2));
111111
}
112112

113113
SECTION("Insert numbers")
114114
{
115-
auto t = setup_table("big int8, small smallint");
115+
auto const t = setup_table("big int8, small smallint");
116116

117117
add_row(&mgr, t, 34, 0xfff12345678ULL, -4457);
118118
check_row({"34", "17588196497016", "-4457"});
119119
}
120120

121121
SECTION("Insert strings")
122122
{
123-
auto t = setup_table("s0 text, s1 varchar");
123+
auto const t = setup_table("s0 text, s1 varchar");
124124

125125
SECTION("Simple strings")
126126
{
@@ -149,15 +149,15 @@ TEST_CASE("copy_mgr_t")
149149

150150
SECTION("Insert int arrays")
151151
{
152-
auto t = setup_table("a int[]");
152+
auto const t = setup_table("a int[]");
153153

154154
add_array<int>(&mgr, t, -9000, {45, -2, 0, 56});
155155
check_row({"-9000", "{45,-2,0,56}"});
156156
}
157157

158158
SECTION("Insert string arrays")
159159
{
160-
auto t = setup_table("a text[]");
160+
auto const t = setup_table("a text[]");
161161

162162
add_array<std::string>(&mgr, t, 3,
163163
{"foo", "", "with space", "with \"quote\"",
@@ -166,7 +166,7 @@ TEST_CASE("copy_mgr_t")
166166
"\\\"quote\\\"\",\"the\t\",\"line\nbreak\","
167167
"\"rr\rrr\",\"s\\\\l\"}"});
168168

169-
auto c = db.connect();
169+
auto const c = db.connect();
170170
CHECK(c.result_as_string("SELECT a[4] FROM test_copy_mgr") ==
171171
"with \"quote\"");
172172
CHECK(c.result_as_string("SELECT a[5] FROM test_copy_mgr") == "the\t");
@@ -178,7 +178,7 @@ TEST_CASE("copy_mgr_t")
178178

179179
SECTION("Insert hashes")
180180
{
181-
auto t = setup_table("h hstore");
181+
auto const t = setup_table("h hstore");
182182

183183
std::vector<std::pair<std::string, std::string>> const values = {
184184
{"one", "two"}, {"key 1", "value 1"},
@@ -188,7 +188,7 @@ TEST_CASE("copy_mgr_t")
188188

189189
add_hash(&mgr, t, 42, values);
190190

191-
auto c = db.connect();
191+
auto const c = db.connect();
192192

193193
for (auto const &[k, v] : values) {
194194
auto const res = c.result_as_string(

tests/test-db-copy-thread.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ static int table_count(testing::pg::conn_t const &conn,
2323

2424
TEST_CASE("db_copy_thread_t with db_deleter_by_id_t")
2525
{
26-
auto conn = db.connect();
26+
auto const conn = db.connect();
2727
conn.exec("DROP TABLE IF EXISTS test_copy_thread");
2828
conn.exec("CREATE TABLE test_copy_thread (id int8)");
2929

30-
auto table = std::make_shared<db_target_descr_t>();
30+
auto const table = std::make_shared<db_target_descr_t>();
3131
table->name = "test_copy_thread";
3232
table->id = "id";
3333

@@ -150,7 +150,7 @@ TEST_CASE("db_copy_thread_t with db_deleter_by_id_t")
150150

151151
TEST_CASE("db_copy_thread_t with db_deleter_place_t")
152152
{
153-
auto conn = db.connect();
153+
auto const conn = db.connect();
154154
conn.exec("DROP TABLE IF EXISTS test_copy_thread");
155155
conn.exec("CREATE TABLE test_copy_thread ("
156156
"osm_type char(1),"

0 commit comments

Comments
 (0)