From 593e9817534a7d884164597005578da2223d089b Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 30 Aug 2021 18:05:55 +0100 Subject: Fix up all remaining warnings --- test/helpers.cpp | 1 + test/test-e2e.cpp | 11 ++++++++--- test/test-misc.cpp | 24 ++++++++++++------------ test/test-postgresql.cpp | 2 +- test/test-rawDataReader.cpp | 6 ++++-- 5 files changed, 26 insertions(+), 18 deletions(-) (limited to 'test') diff --git a/test/helpers.cpp b/test/helpers.cpp index 6cb6fdc..c00e786 100644 --- a/test/helpers.cpp +++ b/test/helpers.cpp @@ -5,6 +5,7 @@ MemStream::MemStream() : out {nullptr}, len {}, s {open_memstream(&out, &len)} { MemStream::~MemStream() { fclose(s); + // NOLINTNEXTLINE(hicpp-no-malloc) free(out); } diff --git a/test/test-e2e.cpp b/test/test-e2e.cpp index ca65e34..3359160 100644 --- a/test/test-e2e.cpp +++ b/test/test-e2e.cpp @@ -65,6 +65,11 @@ public: } } + MockSetup(const MockSetup &) = delete; + MockSetup(MockSetup &&) = delete; + MockSetup & operator=(const MockSetup &) = delete; + MockSetup & operator=(MockSetup &&) = delete; + TestUpdateDatabase & getUpdateDatabase() { @@ -316,9 +321,9 @@ replication_data_type_impl(Test * test) auto rs {MyGrate::DbStmt<"SELECT val FROM testout.test ORDER BY id">::execute(&test->pqm)}; std::vector outs; outs.reserve(ROWS); - for (auto v : *rs) { - outs.push_back(v[0]); - } + std::transform(rs->begin(), rs->end(), std::back_inserter(outs), [](const auto & v) { + return static_cast(v[0]); + }); // Check values BOOST_CHECK_EQUAL_COLLECTIONS(vals.begin(), vals.end(), outs.begin(), outs.end()); diff --git a/test/test-misc.cpp b/test/test-misc.cpp index b4eeb41..2c4d311 100644 --- a/test/test-misc.cpp +++ b/test/test-misc.cpp @@ -94,7 +94,8 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(DbValueConvFloatToString, F, Floats) BOOST_AUTO_TEST_CASE(create_datetime) { - struct tm tm; + struct tm tm { + }; time_t t {1629222289}; gmtime_r(&t, &tm); BOOST_REQUIRE_EQUAL(tm.tm_gmtoff, 0); @@ -106,14 +107,12 @@ BOOST_AUTO_TEST_CASE(create_datetime) BOOST_AUTO_TEST_CASE(mod100_extract) { long unsigned int i {1629222289}; - BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 89); - BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 22); - BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 22); - BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 29); - BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 16); - BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 0); - BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 0); - BOOST_CHECK_EQUAL(MyGrate::mod100_extract(i), 0); + std::vector extracted; + while (i) { + extracted.push_back(MyGrate::mod100_extract(i)); + } + const std::initializer_list expected {89, 22, 22, 29, 16}; + BOOST_CHECK_EQUAL_COLLECTIONS(extracted.begin(), extracted.end(), expected.begin(), expected.end()); } using ConvertTimeData = std::tuple; @@ -137,11 +136,12 @@ BOOST_DATA_TEST_CASE(convert_time, BOOST_AUTO_TEST_CASE(getenv_with_default) { + using namespace std::literals; const char * tenv {"mygrate_something"}; ::unsetenv(tenv); - BOOST_CHECK_EQUAL(MyGrate::getenv(tenv, ""), ""); - BOOST_CHECK_EQUAL(MyGrate::getenv(tenv, "default"), "default"); + BOOST_CHECK_EQUAL(std::string_view(MyGrate::getenv(tenv, "")), ""sv); + BOOST_CHECK_EQUAL(std::string_view(MyGrate::getenv(tenv, "default")), "default"sv); ::setenv(tenv, "something else", 1); - BOOST_CHECK_EQUAL(MyGrate::getenv(tenv, "default"), "something else"); + BOOST_CHECK_EQUAL(std::string_view {MyGrate::getenv(tenv, "default")}, "something else"sv); ::unsetenv(tenv); } diff --git a/test/test-postgresql.cpp b/test/test-postgresql.cpp index f1c7990..eafe5b3 100644 --- a/test/test-postgresql.cpp +++ b/test/test-postgresql.cpp @@ -134,7 +134,7 @@ using FloatTypes = boost::mpl::list; BOOST_AUTO_TEST_CASE_TEMPLATE(write_floats, T, FloatTypes) { MyGrate::Output::Pq::WritePqCopyStream c {s}; - c(T {1.1F}); + c(T {static_cast(1.1F)}); flush(); BOOST_REQUIRE(out); diff --git a/test/test-rawDataReader.cpp b/test/test-rawDataReader.cpp index 3d34bff..d10f9a1 100644 --- a/test/test-rawDataReader.cpp +++ b/test/test-rawDataReader.cpp @@ -152,7 +152,8 @@ BOOST_DATA_TEST_CASE(read_field_type, bytes, exp) { RawDataReader rdr {bytes.data(), bytes.size()}; - BOOST_CHECK_EQUAL(rdr.readValue(1), exp); + const auto e {rdr.readValue(1)}; + BOOST_CHECK_EQUAL(e, exp); } BOOST_AUTO_TEST_CASE(rdr_from_MARIADB_STRING) @@ -160,7 +161,8 @@ BOOST_AUTO_TEST_CASE(rdr_from_MARIADB_STRING) std::string buf {"test"}; MARIADB_STRING str {buf.data(), buf.length()}; RawDataReader rdr {str}; - BOOST_CHECK_EQUAL(rdr.viewValue(buf.length()), buf); + const auto s {rdr.viewValue(buf.length())}; + BOOST_CHECK_EQUAL(s, buf); } using SimpleTypes = boost::mpl::list