From 09c737b4178d4ff2e078be08d61fcf62c6eaf6a0 Mon Sep 17 00:00:00 2001 From: anarthal Date: Mon, 13 Jan 2020 17:28:05 +0100 Subject: [PATCH] Changes to build in MSVC --- .gitignore | 3 +++ CMakeLists.txt | 4 +-- examples/metadata.cpp | 2 -- include/mysql/impl/channel.ipp | 4 +-- include/mysql/impl/deserialize_row.ipp | 2 +- include/mysql/impl/handshake.ipp | 2 +- include/mysql/impl/messages.ipp | 3 ++- include/mysql/impl/query.ipp | 3 ++- include/mysql/impl/resultset.hpp | 2 +- include/mysql/impl/serialization.hpp | 20 ++++++++++++--- test/channel.cpp | 18 +++++++++----- test/common/test_common.hpp | 2 +- test/deserialize_row.cpp | 21 ++++++++++------ test/handshake.cpp | 33 ------------------------- test/integration/metadata_validator.cpp | 2 +- test/integration/query.cpp | 11 +++++---- test/integration/query_types.cpp | 6 +++-- test/metadata.cpp | 21 ++++++++-------- test/row.cpp | 2 +- test/serialization.cpp | 3 ++- test/value.cpp | 2 +- 21 files changed, 81 insertions(+), 85 deletions(-) delete mode 100644 test/handshake.cpp diff --git a/.gitignore b/.gitignore index 0adf2ef9..d6feb9a7 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,6 @@ build/ .pydevproject private/ build-*/ +CMakeSettings.json +out/ +.vs/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a2a255e..b1f07ece 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.11.0) +cmake_minimum_required(VERSION 3.15.0) project(mysql-asio) include(FetchContent) @@ -12,7 +12,7 @@ enable_testing() function (_mysql_set_target_warnings TARGET_NAME) if(MSVC) - target_compile_options(${TARGET_NAME} PRIVATE /W4 /WX) + target_compile_definitions(${TARGET_NAME} PRIVATE _CRT_SECURE_NO_WARNINGS) else() target_compile_options(${TARGET_NAME} PRIVATE -Wall -Wextra -pedantic -Werror) endif() diff --git a/examples/metadata.cpp b/examples/metadata.cpp index 81dc1f5f..f77368ad 100644 --- a/examples/metadata.cpp +++ b/examples/metadata.cpp @@ -2,8 +2,6 @@ #include "mysql/connection.hpp" #include #include -#include -#include #include /** diff --git a/include/mysql/impl/channel.ipp b/include/mysql/impl/channel.ipp index e9c0ccf6..1ea67ec9 100644 --- a/include/mysql/impl/channel.ipp +++ b/include/mysql/impl/channel.ipp @@ -3,11 +3,11 @@ #include #include -#include #include #include #include "mysql/impl/messages.hpp" #include "mysql/impl/constants.hpp" +#include namespace mysql { @@ -261,7 +261,7 @@ mysql::detail::channel::async_write( bool cont=true ) { - std::size_t size_to_write; + std::uint32_t size_to_write; reenter(*this) { diff --git a/include/mysql/impl/deserialize_row.ipp b/include/mysql/impl/deserialize_row.ipp index 4b195cb1..5b58dfe1 100644 --- a/include/mysql/impl/deserialize_row.ipp +++ b/include/mysql/impl/deserialize_row.ipp @@ -50,7 +50,7 @@ inline Error deserialize_text_value_impl( int parsed = decimals ? sscanf(buffer, "%4d:%2u:%2u.%6u", &hours, &minutes, &seconds, µs) : // sign adds 1 char sscanf(buffer, "%4d:%2u:%2u", &hours, &minutes, &seconds); if ((decimals && parsed != 4) || (!decimals && parsed != 3)) return Error::protocol_value_error; - micros *= std::pow(10, 6 - decimals); + micros *= static_cast(std::pow(10, 6 - decimals)); bool is_negative = hours < 0; hours = std::abs(hours); diff --git a/include/mysql/impl/handshake.ipp b/include/mysql/impl/handshake.ipp index 317fc2c0..4713aed9 100644 --- a/include/mysql/impl/handshake.ipp +++ b/include/mysql/impl/handshake.ipp @@ -5,9 +5,9 @@ #include "mysql/impl/auth.hpp" #include "mysql/error.hpp" #include -#include #include #include "mysql/impl/serialization.hpp" +#include namespace mysql { diff --git a/include/mysql/impl/messages.ipp b/include/mysql/impl/messages.ipp index 2eb105b8..6edb5cd6 100644 --- a/include/mysql/impl/messages.ipp +++ b/include/mysql/impl/messages.ipp @@ -66,7 +66,8 @@ inline mysql::Error mysql::detail::deserialize( reserved ); if (err != Error::ok) return err; - auto auth2_length = std::max(13, auth_plugin_data_len.value - auth1_length); + auto auth2_length = static_cast( + std::max(13, auth_plugin_data_len.value - auth1_length)); err = ctx.copy(output.auth_plugin_data_buffer.data() + auth1_length, auth2_length); if (err != Error::ok) return err; err = deserialize(output.auth_plugin_name, ctx); diff --git a/include/mysql/impl/query.ipp b/include/mysql/impl/query.ipp index 816135d7..a5020d8d 100644 --- a/include/mysql/impl/query.ipp +++ b/include/mysql/impl/query.ipp @@ -3,8 +3,9 @@ #include "mysql/impl/messages.hpp" #include "mysql/impl/deserialize_row.hpp" -#include #include "mysql/impl/serialization.hpp" +#include +#include namespace mysql { diff --git a/include/mysql/impl/resultset.hpp b/include/mysql/impl/resultset.hpp index 40ea4577..861c14ec 100644 --- a/include/mysql/impl/resultset.hpp +++ b/include/mysql/impl/resultset.hpp @@ -3,9 +3,9 @@ #include "mysql/impl/query.hpp" #include -#include #include #include +#include template const mysql::row* mysql::resultset::fetch_one( diff --git a/include/mysql/impl/serialization.hpp b/include/mysql/impl/serialization.hpp index 5e6fb0d0..993e341c 100644 --- a/include/mysql/impl/serialization.hpp +++ b/include/mysql/impl/serialization.hpp @@ -365,7 +365,10 @@ struct is_command : decltype(is_command_helper::get(nullptr)) }; template -Error deserialize_struct(T& output, DeserializationContext& ctx) noexcept +Error deserialize_struct( + [[maybe_unused]] T& output, + [[maybe_unused]] DeserializationContext& ctx +) noexcept { constexpr auto fields = get_struct_fields::value; if constexpr (index == std::tuple_size::value) @@ -395,7 +398,10 @@ deserialize(T& output, DeserializationContext& ctx) noexcept } template -void serialize_struct(const T& value, SerializationContext& ctx) noexcept +void serialize_struct( + [[maybe_unused]] const T& value, + [[maybe_unused]] SerializationContext& ctx +) noexcept { constexpr auto fields = get_struct_fields::value; if constexpr (index < std::tuple_size::value) @@ -408,7 +414,10 @@ void serialize_struct(const T& value, SerializationContext& ctx) noexcept template std::enable_if_t::value> -serialize(const T& input, SerializationContext& ctx) noexcept +serialize( + [[maybe_unused]] const T& input, + [[maybe_unused]] SerializationContext& ctx +) noexcept { // For commands, add the command ID. Commands are only sent by the client, // so this is not considered in the deserialization functions. @@ -420,7 +429,10 @@ serialize(const T& input, SerializationContext& ctx) noexcept } template -std::size_t get_size_struct(const T& input, const SerializationContext& ctx) noexcept +std::size_t get_size_struct( + [[maybe_unused]] const T& input, + [[maybe_unused]] const SerializationContext& ctx +) noexcept { constexpr auto fields = get_struct_fields::value; if constexpr (index == std::tuple_size::value) diff --git a/test/channel.cpp b/test/channel.cpp index c656f7ea..5f09b599 100644 --- a/test/channel.cpp +++ b/test/channel.cpp @@ -13,10 +13,10 @@ #include "mysql/impl/channel.hpp" using namespace testing; -using namespace mysql; using namespace mysql::detail; using namespace boost::asio; namespace errc = boost::system::errc; +using mysql::error_code; namespace { @@ -41,8 +41,14 @@ public: MockStream() { - ON_CALL(*this, read_buffer).WillByDefault(SetArgReferee<1>(errc::make_error_code(errc::timed_out))); - ON_CALL(*this, write_buffer).WillByDefault(SetArgReferee<1>(errc::make_error_code(errc::timed_out))); + ON_CALL(*this, read_buffer).WillByDefault(DoAll( + SetArgReferee<1>(errc::make_error_code(errc::timed_out)), + Return(0) + )); + ON_CALL(*this, write_buffer).WillByDefault(DoAll( + SetArgReferee<1>(errc::make_error_code(errc::timed_out)), + Return(0) + )); } template @@ -104,8 +110,8 @@ public: struct MysqlChannelFixture : public Test { - using MockChannel = channel; - MockStream stream; + using MockChannel = channel>; + NiceMock stream; MockChannel chan {stream}; mysql::error_code errc; InSequence seq; @@ -199,7 +205,7 @@ TEST_F(MysqlChannelReadTest, SyncRead_SequenceNumberMismatch_ReturnsAppropriateE EXPECT_CALL(stream, read_buffer) .WillOnce(Invoke(buffer_copier({0xff, 0xff, 0xff, 0x05}))); chan.read(buffer, errc); - EXPECT_EQ(errc, make_error_code(Error::sequence_number_mismatch)); + EXPECT_EQ(errc, make_error_code(mysql::Error::sequence_number_mismatch)); } TEST_F(MysqlChannelReadTest, SyncRead_SequenceNumberNotZero_RespectsCurrentSequenceNumber) diff --git a/test/common/test_common.hpp b/test/common/test_common.hpp index 0445baaa..cbb457fd 100644 --- a/test/common/test_common.hpp +++ b/test/common/test_common.hpp @@ -38,7 +38,7 @@ std::vector makerows(std::size_t row_size, Types&&... args) inline datetime makedt(int years, int months, int days, int hours=0, int mins=0, int secs=0, int micros=0) { - return mysql::date(::date::year(years)/months/days) + + return mysql::datetime(mysql::date(::date::year(years)/::date::month(months)/::date::day(days))) + std::chrono::hours(hours) + std::chrono::minutes(mins) + std::chrono::seconds(secs) + std::chrono::microseconds(micros); } diff --git a/test/deserialize_row.cpp b/test/deserialize_row.cpp index 4576d84f..5d474bf4 100644 --- a/test/deserialize_row.cpp +++ b/test/deserialize_row.cpp @@ -10,15 +10,20 @@ #include "mysql/impl/deserialize_row.hpp" #include "test_common.hpp" -using namespace mysql; using namespace mysql::detail; using namespace mysql::test; using namespace testing; -using namespace ::date::literals; +using namespace date::literals; +using mysql::value; +using mysql::collation; +using mysql::error_code; +using mysql::Error; namespace { +using mysql::operator<<; + struct TextValueParam { std::string name; @@ -59,7 +64,7 @@ TEST_P(DeserializeTextValueTest, CorrectFormat_SetsOutputValueReturnsTrue) coldef.type = GetParam().type; coldef.decimals.value = static_cast(GetParam().decimals); coldef.flags.value = GetParam().flags; - field_metadata meta (coldef); + mysql::field_metadata meta (coldef); value actual_value; auto err = deserialize_text_value(GetParam().from, meta, actual_value); EXPECT_EQ(err, Error::ok); @@ -287,15 +292,15 @@ INSTANTIATE_TEST_SUITE_P(TIME, DeserializeTextValueTest, Values( )); INSTANTIATE_TEST_SUITE_P(YEAR, DeserializeTextValueTest, Values( - TextValueParam("regular value", "1999", year(1999), protocol_field_type::year), - TextValueParam("min", "1901", year(1901), protocol_field_type::year), - TextValueParam("max", "2155", year(2155), protocol_field_type::year), - TextValueParam("zero", "0000", year(0), protocol_field_type::year) + TextValueParam("regular value", "1999", mysql::year(1999), protocol_field_type::year), + TextValueParam("min", "1901", mysql::year(1901), protocol_field_type::year), + TextValueParam("max", "2155", mysql::year(2155), protocol_field_type::year), + TextValueParam("zero", "0000", mysql::year(0), protocol_field_type::year) )); struct DeserializeTextRowTest : public Test { - std::vector meta { + std::vector meta { column_definition_packet { string_lenenc("def"), string_lenenc("awesome"), diff --git a/test/handshake.cpp b/test/handshake.cpp deleted file mode 100644 index bd5efab4..00000000 --- a/test/handshake.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * handshake.cpp - * - * Created on: Oct 27, 2019 - * Author: ruben - */ - -#include -#include -#include "mysql/impl/handshake.hpp" - -using namespace testing; -using namespace mysql; -using namespace detail; - -namespace -{ - -class MockChannel -{ -public: - MOCK_METHOD2(read_impl, void(std::vector&, error_code&)); - MOCK_METHOD2(write, void(boost::asio::const_buffer, error_code&)); - - template - void read(basic_bytestring& buffer, error_code& errc) - { - read_impl(buffer, errc); - } -}; - -} - diff --git a/test/integration/metadata_validator.cpp b/test/integration/metadata_validator.cpp index d5464d14..81c53d96 100644 --- a/test/integration/metadata_validator.cpp +++ b/test/integration/metadata_validator.cpp @@ -30,7 +30,7 @@ static struct flag_entry }; void meta_validator::validate( - const field_metadata& value + const mysql::field_metadata& value ) const { // Fixed fields diff --git a/test/integration/query.cpp b/test/integration/query.cpp index ce3b0310..a94351a3 100644 --- a/test/integration/query.cpp +++ b/test/integration/query.cpp @@ -14,12 +14,13 @@ namespace net = boost::asio; using namespace testing; -using namespace mysql; using namespace mysql::test; - using mysql::detail::make_error_code; using mysql::test::meta_validator; using mysql::test::validate_meta; +using mysql::field_metadata; +using mysql::field_type; +using mysql::error_code; namespace { @@ -195,7 +196,7 @@ TEST_F(QueryTest, QueryAsync_SelectOk) TEST_F(QueryTest, QueryAsync_SelectQueryFailed) { auto fut = conn.async_query("SELECT field_varchar, field_bad FROM one_row_table", net::use_future); - validate_future_exception(fut, make_error_code(Error::bad_field_error)); + validate_future_exception(fut, make_error_code(mysql::Error::bad_field_error)); } @@ -323,7 +324,7 @@ TEST_F(QueryTest, FetchOneAsync_OneRow) auto result = conn.query("SELECT * FROM one_row_table"); // Fetch only row - const row* row = result.async_fetch_one(net::use_future).get(); + const auto* row = result.async_fetch_one(net::use_future).get(); ASSERT_NE(row, nullptr); EXPECT_EQ(row->values(), makevalues(1, "f0")); EXPECT_FALSE(result.complete()); @@ -339,7 +340,7 @@ TEST_F(QueryTest, FetchOneAsync_TwoRows) auto result = conn.query("SELECT * FROM two_rows_table"); // Fetch first row - const row* row = result.async_fetch_one(net::use_future).get(); + const auto* row = result.async_fetch_one(net::use_future).get(); ASSERT_NE(row, nullptr); EXPECT_EQ(row->values(), makevalues(1, "f0")); EXPECT_FALSE(result.complete()); diff --git a/test/integration/query_types.cpp b/test/integration/query_types.cpp index a0601b6d..ae0de065 100644 --- a/test/integration/query_types.cpp +++ b/test/integration/query_types.cpp @@ -10,10 +10,12 @@ #include "test_common.hpp" #include -using namespace mysql; using namespace mysql::test; using namespace testing; -using namespace ::date::literals; +using namespace date::literals; +using mysql::value; +using mysql::field_metadata; +using mysql::field_type; namespace { diff --git a/test/metadata.cpp b/test/metadata.cpp index 0a8d6eaa..18e0d5a0 100644 --- a/test/metadata.cpp +++ b/test/metadata.cpp @@ -10,8 +10,7 @@ #include "mysql/impl/serialization.hpp" using namespace testing; -using namespace mysql; -using namespace detail; +using namespace mysql::detail; namespace { @@ -25,13 +24,13 @@ TEST(FieldMetadata, IntPrimaryKey) string_lenenc("test_table"), string_lenenc("id"), string_lenenc("id"), - collation::binary, + mysql::collation::binary, int4(11), protocol_field_type::long_, int2(column_flags::pri_key | column_flags::auto_increment | column_flags::not_null), int1(0) }; - field_metadata meta (msg); + mysql::field_metadata meta (msg); EXPECT_EQ(meta.database(), "awesome"); EXPECT_EQ(meta.table(), "test_table"); @@ -39,7 +38,7 @@ TEST(FieldMetadata, IntPrimaryKey) EXPECT_EQ(meta.field_name(), "id"); EXPECT_EQ(meta.original_field_name(), "id"); EXPECT_EQ(meta.column_length(), 11); - EXPECT_EQ(meta.type(), field_type::int_); + EXPECT_EQ(meta.type(), mysql::field_type::int_); EXPECT_EQ(meta.protocol_type(), protocol_field_type::long_); EXPECT_EQ(meta.decimals(), 0); EXPECT_TRUE(meta.is_not_null()); @@ -62,13 +61,13 @@ TEST(FieldMetadata, VarcharWithAlias) string_lenenc("child_table"), string_lenenc("field_alias"), string_lenenc("field_varchar"), - collation::utf8_general_ci, + mysql::collation::utf8_general_ci, int4(765), protocol_field_type::var_string, int2(0), int1(0) }; - field_metadata meta (msg); + mysql::field_metadata meta (msg); EXPECT_EQ(meta.database(), "awesome"); EXPECT_EQ(meta.table(), "child"); @@ -77,7 +76,7 @@ TEST(FieldMetadata, VarcharWithAlias) EXPECT_EQ(meta.original_field_name(), "field_varchar"); EXPECT_EQ(meta.column_length(), 765); EXPECT_EQ(meta.protocol_type(), protocol_field_type::var_string); - EXPECT_EQ(meta.type(), field_type::varchar); + EXPECT_EQ(meta.type(), mysql::field_type::varchar); EXPECT_EQ(meta.decimals(), 0); EXPECT_FALSE(meta.is_not_null()); EXPECT_FALSE(meta.is_primary_key()); @@ -99,13 +98,13 @@ TEST(FieldMetadata, FloatField) string_lenenc("test_table"), string_lenenc("field_float"), string_lenenc("field_float"), - collation::binary, + mysql::collation::binary, int4(12), protocol_field_type::float_, int2(0), int1(31) }; - field_metadata meta (msg); + mysql::field_metadata meta (msg); EXPECT_EQ(meta.database(), "awesome"); EXPECT_EQ(meta.table(), "test_table"); @@ -114,7 +113,7 @@ TEST(FieldMetadata, FloatField) EXPECT_EQ(meta.original_field_name(), "field_float"); EXPECT_EQ(meta.column_length(), 12); EXPECT_EQ(meta.protocol_type(), protocol_field_type::float_); - EXPECT_EQ(meta.type(), field_type::float_); + EXPECT_EQ(meta.type(), mysql::field_type::float_); EXPECT_EQ(meta.decimals(), 31); EXPECT_FALSE(meta.is_not_null()); EXPECT_FALSE(meta.is_primary_key()); diff --git a/test/row.cpp b/test/row.cpp index e95b7c14..72572223 100644 --- a/test/row.cpp +++ b/test/row.cpp @@ -9,9 +9,9 @@ #include "mysql/row.hpp" #include "test_common.hpp" -using namespace mysql; using namespace mysql::test; using namespace testing; +using mysql::row; namespace { diff --git a/test/serialization.cpp b/test/serialization.cpp index d93ca6b7..f921117b 100644 --- a/test/serialization.cpp +++ b/test/serialization.cpp @@ -10,9 +10,10 @@ using namespace testing; using namespace std; -using namespace mysql; using namespace mysql::detail; using namespace mysql::test; +using mysql::Error; +using mysql::collation; namespace { diff --git a/test/value.cpp b/test/value.cpp index 91b47a63..cb39fd22 100644 --- a/test/value.cpp +++ b/test/value.cpp @@ -12,7 +12,7 @@ using namespace mysql::test; using namespace testing; -using namespace ::date::literals; +using namespace date::literals; using namespace std::chrono; namespace