From 157e95d717c9e1533bce072e06b79bbab72bf2f8 Mon Sep 17 00:00:00 2001 From: ruben Date: Sun, 17 May 2020 13:00:43 +0100 Subject: [PATCH] Removed 32bit ints from value::variant_type --- TODO.txt | 1 + .../protocol/impl/binary_deserialization.ipp | 18 +-- .../protocol/impl/binary_serialization.ipp | 2 - .../impl/prepared_statement_messages.hpp | 6 +- .../protocol/impl/text_deserialization.ipp | 11 +- include/boost/mysql/value.hpp | 9 +- test/integration/database_types.cpp | 111 +++++++++--------- .../protocol/binary_deserialization_value.cpp | 22 ++-- .../detail/protocol/binary_serialization.cpp | 4 - .../protocol/prepared_statement_messages.cpp | 30 +---- .../detail/protocol/row_deserialization.cpp | 12 +- .../protocol/text_deserialization_error.cpp | 50 ++------ .../protocol/text_deserialization_value.cpp | 67 ++++++----- 13 files changed, 137 insertions(+), 206 deletions(-) diff --git a/TODO.txt b/TODO.txt index 81372c7d..e55a8d14 100644 --- a/TODO.txt +++ b/TODO.txt @@ -4,6 +4,7 @@ Value class Implement conversions between ints Tests for new functions and conversions Review docs + Clean using boost::mysql::operatorxx Better docs Breaking up the tutorial in pieces Explaining the different overloads and async methods available diff --git a/include/boost/mysql/detail/protocol/impl/binary_deserialization.ipp b/include/boost/mysql/detail/protocol/impl/binary_deserialization.ipp index d47205a7..d29c3d7b 100644 --- a/include/boost/mysql/detail/protocol/impl/binary_deserialization.ipp +++ b/include/boost/mysql/detail/protocol/impl/binary_deserialization.ipp @@ -34,8 +34,6 @@ errc deserialize_binary_value_value_holder( } template < - typename TargetTypeUnsigned, - typename TargetTypeSigned, typename DeserializableTypeUnsigned, typename DeserializableTypeSigned > @@ -47,9 +45,9 @@ errc deserialize_binary_value_int( { return meta.is_unsigned() ? deserialize_binary_value_value_holder< - TargetTypeUnsigned, DeserializableTypeUnsigned>(ctx, output) : + std::uint64_t, DeserializableTypeUnsigned>(ctx, output) : deserialize_binary_value_value_holder< - TargetTypeSigned, DeserializableTypeSigned>(ctx, output); + std::int64_t, DeserializableTypeSigned>(ctx, output); } // Floats @@ -318,19 +316,15 @@ inline boost::mysql::errc boost::mysql::detail::deserialize_binary_value( switch (meta.protocol_type()) { case protocol_field_type::tiny: - return deserialize_binary_value_int< - std::uint32_t, std::int32_t, int1, int1_signed>(meta, ctx, output); + return deserialize_binary_value_int(meta, ctx, output); case protocol_field_type::short_: case protocol_field_type::year: - return deserialize_binary_value_int< - std::uint32_t, std::int32_t, int2, int2_signed>(meta, ctx, output); + return deserialize_binary_value_int(meta, ctx, output); case protocol_field_type::int24: case protocol_field_type::long_: - return deserialize_binary_value_int< - std::uint32_t, std::int32_t, int4, int4_signed>(meta, ctx, output); + return deserialize_binary_value_int(meta, ctx, output); case protocol_field_type::longlong: - return deserialize_binary_value_int< - std::uint64_t, std::int64_t, int8, int8_signed>(meta, ctx, output); + return deserialize_binary_value_int(meta, ctx, output); case protocol_field_type::float_: return deserialize_binary_value_float(ctx, output); case protocol_field_type::double_: diff --git a/include/boost/mysql/detail/protocol/impl/binary_serialization.ipp b/include/boost/mysql/detail/protocol/impl/binary_serialization.ipp index a3e5e115..7f686781 100644 --- a/include/boost/mysql/detail/protocol/impl/binary_serialization.ipp +++ b/include/boost/mysql/detail/protocol/impl/binary_serialization.ipp @@ -137,8 +137,6 @@ struct serialize_visitor template void operator()(const T& v) noexcept { serialize_binary_value_impl(ctx, v); } - void operator()(std::int32_t v) noexcept { serialize(ctx, int4_signed(v)); } - void operator()(std::uint32_t v) noexcept { serialize(ctx, int4(v)); } void operator()(std::int64_t v) noexcept { serialize(ctx, int8_signed(v)); } void operator()(std::uint64_t v) noexcept { serialize(ctx, int8(v)); } void operator()(std::string_view v) noexcept { serialize(ctx, string_lenenc(v)); } diff --git a/include/boost/mysql/detail/protocol/impl/prepared_statement_messages.hpp b/include/boost/mysql/detail/protocol/impl/prepared_statement_messages.hpp index 99bbc8e0..1341c10b 100644 --- a/include/boost/mysql/detail/protocol/impl/prepared_statement_messages.hpp +++ b/include/boost/mysql/detail/protocol/impl/prepared_statement_messages.hpp @@ -22,8 +22,6 @@ inline protocol_field_type get_protocol_field_type( { struct visitor { - constexpr auto operator()(std::int32_t) const noexcept { return protocol_field_type::long_; } - constexpr auto operator()(std::uint32_t) const noexcept { return protocol_field_type::long_; } constexpr auto operator()(std::int64_t) const noexcept { return protocol_field_type::longlong; } constexpr auto operator()(std::uint64_t) const noexcept { return protocol_field_type::longlong; } constexpr auto operator()(std::string_view) const noexcept { return protocol_field_type::varchar; } @@ -43,9 +41,7 @@ inline bool is_unsigned( const value& input ) noexcept { - auto v = input.to_variant(); - return std::holds_alternative(v) || - std::holds_alternative(v); + return std::holds_alternative(input.to_variant()); } } // detail diff --git a/include/boost/mysql/detail/protocol/impl/text_deserialization.ipp b/include/boost/mysql/detail/protocol/impl/text_deserialization.ipp index 642189a0..17ac4bfd 100644 --- a/include/boost/mysql/detail/protocol/impl/text_deserialization.ipp +++ b/include/boost/mysql/detail/protocol/impl/text_deserialization.ipp @@ -33,17 +33,15 @@ errc deserialize_text_value_int_impl( return errc::ok; } -template -errc deserialize_text_value_int( +inline errc deserialize_text_value_int( std::string_view from, value& to, const field_metadata& meta ) noexcept { - using SignedType = std::make_signed_t; return meta.is_unsigned() ? - deserialize_text_value_int_impl(from, to) : - deserialize_text_value_int_impl(from, to); + deserialize_text_value_int_impl(from, to) : + deserialize_text_value_int_impl(from, to); } // Floating points @@ -323,9 +321,8 @@ inline boost::mysql::errc boost::mysql::detail::deserialize_text_value( case protocol_field_type::int24: case protocol_field_type::long_: case protocol_field_type::year: - return deserialize_text_value_int(from, output, meta); case protocol_field_type::longlong: - return deserialize_text_value_int(from, output, meta); + return deserialize_text_value_int(from, output, meta); case protocol_field_type::float_: return deserialize_text_value_float(from, output); case protocol_field_type::double_: diff --git a/include/boost/mysql/value.hpp b/include/boost/mysql/value.hpp index f4156e3f..c17ee949 100644 --- a/include/boost/mysql/value.hpp +++ b/include/boost/mysql/value.hpp @@ -175,10 +175,8 @@ class value public: // The underlying representation using variant_type = std::variant< - std::int32_t, // signed TINYINT, SMALLINT, MEDIUMINT, INT - std::int64_t, // signed BIGINT - std::uint32_t, // unsigned TINYINT, SMALLINT, MEDIUMINT, INT, YEAR - std::uint64_t, // unsigned BIGINT + std::int64_t, // signed TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT + std::uint64_t, // unsigned TINYINT, SMALLINT, MEDIUMINT, INT, BIGINT, YEAR std::string_view, // CHAR, VARCHAR, BINARY, VARBINARY, TEXT (all sizes), BLOB (all sizes), ENUM, SET, DECIMAL, BIT, GEOMTRY float, // FLOAT double, // DOUBLE @@ -195,6 +193,9 @@ public: template explicit constexpr value(const T& v) noexcept : repr_(v) {} + explicit constexpr value(int v) noexcept : repr_(std::int64_t(v)) {} + explicit constexpr value(unsigned v) noexcept : repr_(std::uint64_t(v)) {} + // Tests for NULL constexpr bool is_null() const noexcept { return std::holds_alternative(repr_); } diff --git a/test/integration/database_types.cpp b/test/integration/database_types.cpp index fe35bbe6..4829bf4e 100644 --- a/test/integration/database_types.cpp +++ b/test/integration/database_types.cpp @@ -85,7 +85,8 @@ TEST_P(DatabaseTypesTest, Query_MetadataAndValueCorrect) // Validate the returned value row expected_row ({param.expected_value}); ASSERT_EQ(rows.size(), 1); - EXPECT_EQ(static_cast(rows[0]), expected_row); // make gtest pick operator<< + ASSERT_EQ(rows[0].values().size(), 1); + EXPECT_EQ(rows[0].values()[0], param.expected_value); } TEST_P(DatabaseTypesTest, PreparedStatementExecuteResult_MetadataAndValueCorrect) @@ -109,9 +110,9 @@ TEST_P(DatabaseTypesTest, PreparedStatementExecuteResult_MetadataAndValueCorrect validate_meta(result.fields(), {param.mvalid}); // Validate the returned value - row expected_row ({param.expected_value}); ASSERT_EQ(rows.size(), 1); - EXPECT_EQ(static_cast(rows[0]), expected_row); // make gtest pick operator<< + ASSERT_EQ(rows[0].values().size(), 1); + EXPECT_EQ(rows[0].values()[0], param.expected_value); } TEST_P(DatabaseTypesTest, PreparedStatementExecuteParam_ValueSerializedCorrectly) @@ -153,77 +154,77 @@ const flagsvec flags_zerofill { &field_metadata::is_unsigned, &field_metadata::i // Integers INSTANTIATE_TEST_SUITE_P(TINYINT, DatabaseTypesTest, Values( - database_types_testcase("types_tinyint", "field_signed", "regular", std::int32_t(20), field_type::tinyint), - database_types_testcase("types_tinyint", "field_signed", "negative", std::int32_t(-20), field_type::tinyint), - database_types_testcase("types_tinyint", "field_signed", "min", std::int32_t(-0x80), field_type::tinyint), - database_types_testcase("types_tinyint", "field_signed", "max", std::int32_t(0x7f), field_type::tinyint), + database_types_testcase("types_tinyint", "field_signed", "regular", std::int64_t(20), field_type::tinyint), + database_types_testcase("types_tinyint", "field_signed", "negative", std::int64_t(-20), field_type::tinyint), + database_types_testcase("types_tinyint", "field_signed", "min", std::int64_t(-0x80), field_type::tinyint), + database_types_testcase("types_tinyint", "field_signed", "max", std::int64_t(0x7f), field_type::tinyint), - database_types_testcase("types_tinyint", "field_unsigned", "regular", std::uint32_t(20), field_type::tinyint, flags_unsigned), - database_types_testcase("types_tinyint", "field_unsigned", "min", std::uint32_t(0), field_type::tinyint, flags_unsigned), - database_types_testcase("types_tinyint", "field_unsigned", "max", std::uint32_t(0xff), field_type::tinyint, flags_unsigned), + database_types_testcase("types_tinyint", "field_unsigned", "regular", std::uint64_t(20), field_type::tinyint, flags_unsigned), + database_types_testcase("types_tinyint", "field_unsigned", "min", std::uint64_t(0), field_type::tinyint, flags_unsigned), + database_types_testcase("types_tinyint", "field_unsigned", "max", std::uint64_t(0xff), field_type::tinyint, flags_unsigned), - database_types_testcase("types_tinyint", "field_width", "regular", std::int32_t(20), field_type::tinyint), - database_types_testcase("types_tinyint", "field_width", "negative", std::int32_t(-20), field_type::tinyint), + database_types_testcase("types_tinyint", "field_width", "regular", std::int64_t(20), field_type::tinyint), + database_types_testcase("types_tinyint", "field_width", "negative", std::int64_t(-20), field_type::tinyint), - database_types_testcase("types_tinyint", "field_zerofill", "regular", std::uint32_t(20), field_type::tinyint, flags_zerofill), - database_types_testcase("types_tinyint", "field_zerofill", "min", std::uint32_t(0), field_type::tinyint, flags_zerofill) + database_types_testcase("types_tinyint", "field_zerofill", "regular", std::uint64_t(20), field_type::tinyint, flags_zerofill), + database_types_testcase("types_tinyint", "field_zerofill", "min", std::uint64_t(0), field_type::tinyint, flags_zerofill) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(SMALLINT, DatabaseTypesTest, Values( - database_types_testcase("types_smallint", "field_signed", "regular", std::int32_t(20), field_type::smallint), - database_types_testcase("types_smallint", "field_signed", "negative", std::int32_t(-20), field_type::smallint), - database_types_testcase("types_smallint", "field_signed", "min", std::int32_t(-0x8000), field_type::smallint), - database_types_testcase("types_smallint", "field_signed", "max", std::int32_t(0x7fff), field_type::smallint), + database_types_testcase("types_smallint", "field_signed", "regular", std::int64_t(20), field_type::smallint), + database_types_testcase("types_smallint", "field_signed", "negative", std::int64_t(-20), field_type::smallint), + database_types_testcase("types_smallint", "field_signed", "min", std::int64_t(-0x8000), field_type::smallint), + database_types_testcase("types_smallint", "field_signed", "max", std::int64_t(0x7fff), field_type::smallint), - database_types_testcase("types_smallint", "field_unsigned", "regular", std::uint32_t(20), field_type::smallint, flags_unsigned), - database_types_testcase("types_smallint", "field_unsigned", "min", std::uint32_t(0), field_type::smallint, flags_unsigned), - database_types_testcase("types_smallint", "field_unsigned", "max", std::uint32_t(0xffff), field_type::smallint, flags_unsigned), + database_types_testcase("types_smallint", "field_unsigned", "regular", std::uint64_t(20), field_type::smallint, flags_unsigned), + database_types_testcase("types_smallint", "field_unsigned", "min", std::uint64_t(0), field_type::smallint, flags_unsigned), + database_types_testcase("types_smallint", "field_unsigned", "max", std::uint64_t(0xffff), field_type::smallint, flags_unsigned), - database_types_testcase("types_smallint", "field_width", "regular", std::int32_t(20), field_type::smallint), - database_types_testcase("types_smallint", "field_width", "negative", std::int32_t(-20), field_type::smallint), + database_types_testcase("types_smallint", "field_width", "regular", std::int64_t(20), field_type::smallint), + database_types_testcase("types_smallint", "field_width", "negative", std::int64_t(-20), field_type::smallint), - database_types_testcase("types_smallint", "field_zerofill", "regular", std::uint32_t(20), field_type::smallint, flags_zerofill), - database_types_testcase("types_smallint", "field_zerofill", "min", std::uint32_t(0), field_type::smallint, flags_zerofill) + database_types_testcase("types_smallint", "field_zerofill", "regular", std::uint64_t(20), field_type::smallint, flags_zerofill), + database_types_testcase("types_smallint", "field_zerofill", "min", std::uint64_t(0), field_type::smallint, flags_zerofill) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(MEDIUMINT, DatabaseTypesTest, Values( - database_types_testcase("types_mediumint", "field_signed", "regular", std::int32_t(20), field_type::mediumint), - database_types_testcase("types_mediumint", "field_signed", "negative", std::int32_t(-20), field_type::mediumint), - database_types_testcase("types_mediumint", "field_signed", "min", std::int32_t(-0x800000), field_type::mediumint), - database_types_testcase("types_mediumint", "field_signed", "max", std::int32_t(0x7fffff), field_type::mediumint), + database_types_testcase("types_mediumint", "field_signed", "regular", std::int64_t(20), field_type::mediumint), + database_types_testcase("types_mediumint", "field_signed", "negative", std::int64_t(-20), field_type::mediumint), + database_types_testcase("types_mediumint", "field_signed", "min", std::int64_t(-0x800000), field_type::mediumint), + database_types_testcase("types_mediumint", "field_signed", "max", std::int64_t(0x7fffff), field_type::mediumint), - database_types_testcase("types_mediumint", "field_unsigned", "regular", std::uint32_t(20), field_type::mediumint, flags_unsigned), - database_types_testcase("types_mediumint", "field_unsigned", "min", std::uint32_t(0), field_type::mediumint, flags_unsigned), - database_types_testcase("types_mediumint", "field_unsigned", "max", std::uint32_t(0xffffff), field_type::mediumint, flags_unsigned), + database_types_testcase("types_mediumint", "field_unsigned", "regular", std::uint64_t(20), field_type::mediumint, flags_unsigned), + database_types_testcase("types_mediumint", "field_unsigned", "min", std::uint64_t(0), field_type::mediumint, flags_unsigned), + database_types_testcase("types_mediumint", "field_unsigned", "max", std::uint64_t(0xffffff), field_type::mediumint, flags_unsigned), - database_types_testcase("types_mediumint", "field_width", "regular", std::int32_t(20), field_type::mediumint), - database_types_testcase("types_mediumint", "field_width", "negative", std::int32_t(-20), field_type::mediumint), + database_types_testcase("types_mediumint", "field_width", "regular", std::int64_t(20), field_type::mediumint), + database_types_testcase("types_mediumint", "field_width", "negative", std::int64_t(-20), field_type::mediumint), - database_types_testcase("types_mediumint", "field_zerofill", "regular", std::uint32_t(20), field_type::mediumint, flags_zerofill), - database_types_testcase("types_mediumint", "field_zerofill", "min", std::uint32_t(0), field_type::mediumint, flags_zerofill) + database_types_testcase("types_mediumint", "field_zerofill", "regular", std::uint64_t(20), field_type::mediumint, flags_zerofill), + database_types_testcase("types_mediumint", "field_zerofill", "min", std::uint64_t(0), field_type::mediumint, flags_zerofill) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(INT, DatabaseTypesTest, Values( - database_types_testcase("types_int", "field_signed", "regular", std::int32_t(20), field_type::int_), - database_types_testcase("types_int", "field_signed", "negative", std::int32_t(-20), field_type::int_), - database_types_testcase("types_int", "field_signed", "min", std::int32_t(-0x80000000), field_type::int_), - database_types_testcase("types_int", "field_signed", "max", std::int32_t(0x7fffffff), field_type::int_), + database_types_testcase("types_int", "field_signed", "regular", std::int64_t(20), field_type::int_), + database_types_testcase("types_int", "field_signed", "negative", std::int64_t(-20), field_type::int_), + database_types_testcase("types_int", "field_signed", "min", std::int64_t(-0x80000000LL), field_type::int_), + database_types_testcase("types_int", "field_signed", "max", std::int64_t(0x7fffffff), field_type::int_), - database_types_testcase("types_int", "field_unsigned", "regular", std::uint32_t(20), field_type::int_, flags_unsigned), - database_types_testcase("types_int", "field_unsigned", "min", std::uint32_t(0), field_type::int_, flags_unsigned), - database_types_testcase("types_int", "field_unsigned", "max", std::uint32_t(0xffffffff), field_type::int_, flags_unsigned), + database_types_testcase("types_int", "field_unsigned", "regular", std::uint64_t(20), field_type::int_, flags_unsigned), + database_types_testcase("types_int", "field_unsigned", "min", std::uint64_t(0), field_type::int_, flags_unsigned), + database_types_testcase("types_int", "field_unsigned", "max", std::uint64_t(0xffffffff), field_type::int_, flags_unsigned), - database_types_testcase("types_int", "field_width", "regular", std::int32_t(20), field_type::int_), - database_types_testcase("types_int", "field_width", "negative", std::int32_t(-20), field_type::int_), + database_types_testcase("types_int", "field_width", "regular", std::int64_t(20), field_type::int_), + database_types_testcase("types_int", "field_width", "negative", std::int64_t(-20), field_type::int_), - database_types_testcase("types_int", "field_zerofill", "regular", std::uint32_t(20), field_type::int_, flags_zerofill), - database_types_testcase("types_int", "field_zerofill", "min", std::uint32_t(0), field_type::int_, flags_zerofill) + database_types_testcase("types_int", "field_zerofill", "regular", std::uint64_t(20), field_type::int_, flags_zerofill), + database_types_testcase("types_int", "field_zerofill", "min", std::uint64_t(0), field_type::int_, flags_zerofill) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(BIGINT, DatabaseTypesTest, Values( database_types_testcase("types_bigint", "field_signed", "regular", std::int64_t(20), field_type::bigint), database_types_testcase("types_bigint", "field_signed", "negative", std::int64_t(-20), field_type::bigint), - database_types_testcase("types_bigint", "field_signed", "min", std::int64_t(-0x8000000000000000), field_type::bigint), + database_types_testcase("types_bigint", "field_signed", "min", std::int64_t(-0x7fffffffffffffff - 1), field_type::bigint), database_types_testcase("types_bigint", "field_signed", "max", std::int64_t(0x7fffffffffffffff), field_type::bigint), database_types_testcase("types_bigint", "field_unsigned", "regular", std::uint64_t(20), field_type::bigint, flags_unsigned), @@ -543,10 +544,10 @@ INSTANTIATE_TEST_SUITE_P(TIMESTAMP, DatabaseTypesTest, ValuesIn(generate_timesta INSTANTIATE_TEST_SUITE_P(TIME, DatabaseTypesTest, ValuesIn(generate_time_cases()), test_name_generator); INSTANTIATE_TEST_SUITE_P(YEAR, DatabaseTypesTest, Values( - database_types_testcase("types_year", "field_default", "regular", std::uint32_t(2019), field_type::year, flags_zerofill), - database_types_testcase("types_year", "field_default", "min", std::uint32_t(1901), field_type::year, flags_zerofill), - database_types_testcase("types_year", "field_default", "max", std::uint32_t(2155), field_type::year, flags_zerofill), - database_types_testcase("types_year", "field_default", "zero", std::uint32_t(0), field_type::year, flags_zerofill) + database_types_testcase("types_year", "field_default", "regular", std::uint64_t(2019), field_type::year, flags_zerofill), + database_types_testcase("types_year", "field_default", "min", std::uint64_t(1901), field_type::year, flags_zerofill), + database_types_testcase("types_year", "field_default", "max", std::uint64_t(2155), field_type::year, flags_zerofill), + database_types_testcase("types_year", "field_default", "zero", std::uint64_t(0), field_type::year, flags_zerofill) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(STRING, DatabaseTypesTest, Values( @@ -626,14 +627,14 @@ INSTANTIATE_TEST_SUITE_P(NOT_IMPLEMENTED_TYPES, DatabaseTypesTest, Values( INSTANTIATE_TEST_SUITE_P(METADATA_FLAGS, DatabaseTypesTest, Values( database_types_testcase("types_flags", "field_timestamp", "default", nullptr, field_type::timestamp, flagsvec{&field_metadata::is_set_to_now_on_update}, 0, flagsvec{&field_metadata::is_unsigned}), - database_types_testcase("types_flags", "field_primary_key", "default", std::int32_t(50), field_type::int_, + database_types_testcase("types_flags", "field_primary_key", "default", std::int64_t(50), field_type::int_, flagsvec{&field_metadata::is_primary_key, &field_metadata::is_not_null, &field_metadata::is_auto_increment}), database_types_testcase("types_flags", "field_not_null", "default", "char", field_type::char_, flagsvec{&field_metadata::is_not_null}), - database_types_testcase("types_flags", "field_unique", "default", std::int32_t(21), field_type::int_, + database_types_testcase("types_flags", "field_unique", "default", std::int64_t(21), field_type::int_, flagsvec{&field_metadata::is_unique_key}), - database_types_testcase("types_flags", "field_indexed", "default", std::int32_t(42), field_type::int_, + database_types_testcase("types_flags", "field_indexed", "default", std::int64_t(42), field_type::int_, flagsvec{&field_metadata::is_multiple_key}) ), test_name_generator); diff --git a/test/unit/detail/protocol/binary_deserialization_value.cpp b/test/unit/detail/protocol/binary_deserialization_value.cpp index 635fdb5d..88ecd14f 100644 --- a/test/unit/detail/protocol/binary_deserialization_value.cpp +++ b/test/unit/detail/protocol/binary_deserialization_value.cpp @@ -22,9 +22,6 @@ using boost::mysql::errc; namespace { -using boost::mysql::operator<<; - - struct binary_value_testcase : named_param { std::string name; @@ -54,7 +51,6 @@ struct DeserializeBinaryValueTest : public TestWithParam TEST_P(DeserializeBinaryValueTest, CorrectFormat_SetsOutputValueReturnsTrue) { - using boost::mysql::operator<<; column_definition_packet coldef; coldef.type = GetParam().type; coldef.flags.value = GetParam().flags; @@ -94,27 +90,27 @@ INSTANTIATE_TEST_SUITE_P(StringTypes, DeserializeBinaryValueTest, Values( // Note: these employ regular integer deserialization functions, which have // already been tested in serialization.cpp INSTANTIATE_TEST_SUITE_P(IntTypes, DeserializeBinaryValueTest, Values( - binary_value_testcase("tinyint_unsigned", {0x14}, std::uint32_t(20), + binary_value_testcase("tinyint_unsigned", {0x14}, std::uint64_t(20), protocol_field_type::tiny, column_flags::unsigned_), - binary_value_testcase("tinyint_signed", {0xec}, std::int32_t(-20), protocol_field_type::tiny), + binary_value_testcase("tinyint_signed", {0xec}, std::int64_t(-20), protocol_field_type::tiny), - binary_value_testcase("smallint_unsigned", {0x14, 0x00}, std::uint32_t(20), + binary_value_testcase("smallint_unsigned", {0x14, 0x00}, std::uint64_t(20), protocol_field_type::short_, column_flags::unsigned_), - binary_value_testcase("smallint_signed", {0xec, 0xff}, std::int32_t(-20), protocol_field_type::short_), + binary_value_testcase("smallint_signed", {0xec, 0xff}, std::int64_t(-20), protocol_field_type::short_), - binary_value_testcase("mediumint_unsigned", {0x14, 0x00, 0x00, 0x00}, std::uint32_t(20), + binary_value_testcase("mediumint_unsigned", {0x14, 0x00, 0x00, 0x00}, std::uint64_t(20), protocol_field_type::int24, column_flags::unsigned_), - binary_value_testcase("mediumint_signed", {0xec, 0xff, 0xff, 0xff}, std::int32_t(-20), protocol_field_type::int24), + binary_value_testcase("mediumint_signed", {0xec, 0xff, 0xff, 0xff}, std::int64_t(-20), protocol_field_type::int24), - binary_value_testcase("int_unsigned", {0x14, 0x00, 0x00, 0x00}, std::uint32_t(20), + binary_value_testcase("int_unsigned", {0x14, 0x00, 0x00, 0x00}, std::uint64_t(20), protocol_field_type::long_, column_flags::unsigned_), - binary_value_testcase("int_signed", {0xec, 0xff, 0xff, 0xff}, std::int32_t(-20), protocol_field_type::long_), + binary_value_testcase("int_signed", {0xec, 0xff, 0xff, 0xff}, std::int64_t(-20), protocol_field_type::long_), binary_value_testcase("bigint_unsigned", {0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, std::uint64_t(20), protocol_field_type::longlong, column_flags::unsigned_), binary_value_testcase("bigint_signed", {0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, std::int64_t(-20), protocol_field_type::longlong), - binary_value_testcase("year", {0xe3, 0x07}, std::uint32_t(2019), + binary_value_testcase("year", {0xe3, 0x07}, std::uint64_t(2019), protocol_field_type::year, column_flags::unsigned_) ), test_name_generator); diff --git a/test/unit/detail/protocol/binary_serialization.cpp b/test/unit/detail/protocol/binary_serialization.cpp index 3d4a5195..f69e73a8 100644 --- a/test/unit/detail/protocol/binary_serialization.cpp +++ b/test/unit/detail/protocol/binary_serialization.cpp @@ -65,10 +65,6 @@ INSTANTIATE_TEST_SUITE_P(StringTypes, SerializeBinaryValueTest, Values( // Same comment applies for ints INSTANTIATE_TEST_SUITE_P(IntTypes, SerializeBinaryValueTest, Values( - serialize_binary_value_testcase("uint32", std::uint32_t(0xfcfdfeff), - {0xff, 0xfe, 0xfd, 0xfc}), - serialize_binary_value_testcase("int32", std::int32_t(-0x3020101), - {0xff, 0xfe, 0xfd, 0xfc}), serialize_binary_value_testcase("uint64", std::uint64_t(0xf8f9fafbfcfdfeff), {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8}), serialize_binary_value_testcase("int64", std::int64_t(-0x0706050403020101), diff --git a/test/unit/detail/protocol/prepared_statement_messages.cpp b/test/unit/detail/protocol/prepared_statement_messages.cpp index e6c4990b..c1b1c2e1 100644 --- a/test/unit/detail/protocol/prepared_statement_messages.cpp +++ b/test/unit/detail/protocol/prepared_statement_messages.cpp @@ -72,22 +72,6 @@ serialization_testcase make_stmt_execute_test( } INSTANTIATE_TEST_SUITE_P(ComStmtExecute, SerializeTest, testing::Values( - make_stmt_execute_test(1, 0x80, 1, 1, // stmt ID, flags, itercount, new params - { value(std::uint32_t(0xabffff)) }, { - 0x17, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x03, 0x80, 0xff, 0xff, - 0xab, 0x00 - }, - "uint32_t" - ), - make_stmt_execute_test(1, 0, 1, 1, // stmt ID, flags, itercount, new params - { value(std::int32_t(-0xabffff)) }, { - 0x17, 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x03, 0x00, 0x01, 0x00, - 0x54, 0xff - }, - "int32_t" - ), make_stmt_execute_test(1, 0x80, 1, 1, // stmt ID, flags, itercount, new params { value(std::uint64_t(0xabffffabacadae)) }, { 0x17, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, @@ -162,8 +146,6 @@ INSTANTIATE_TEST_SUITE_P(ComStmtExecute, SerializeTest, testing::Values( "null" ), make_stmt_execute_test(2, 0, 1, 1, makevalues( - std::uint32_t(0xabffff), - std::int32_t(-0xabffff), std::uint64_t(0xabffffabacadae), std::int64_t(-0xabffffabacadae), std::string_view("test"), @@ -175,11 +157,9 @@ INSTANTIATE_TEST_SUITE_P(ComStmtExecute, SerializeTest, testing::Values( nullptr ), { 0x17, 0x02, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, - 0x00, 0x00, 0x20, 0x04, 0x01, 0x03, 0x80, 0x03, - 0x00, 0x08, 0x80, 0x08, 0x00, 0x0f, 0x00, 0x06, + 0x00, 0x00, 0x08, 0x01, 0x01, 0x08, 0x80, 0x08, 0x00, 0x0f, 0x00, 0x06, 0x00, 0x05, 0x00, 0x0a, 0x00, 0x0c, 0x00, 0x0b, - 0x00, 0x06, 0x00, 0xff, 0xff, 0xab, 0x00, 0x01, - 0x00, 0x54, 0xff, 0xae, 0xad, 0xac, 0xab, 0xff, + 0x00, 0x06, 0x00, 0xae, 0xad, 0xac, 0xab, 0xff, 0xff, 0xab, 0x00, 0x52, 0x52, 0x53, 0x54, 0x00, 0x00, 0x54, 0xff, 0x04, 0x74, 0x65, 0x73, 0x74, 0x56, 0xc0, 0xee, 0xa6, 0x95, 0x30, 0x6f, 0x6c, @@ -191,10 +171,10 @@ INSTANTIATE_TEST_SUITE_P(ComStmtExecute, SerializeTest, testing::Values( "several_params" ), make_stmt_execute_test>(1, 0x80, 1, 1, // stmt ID, flags, itercount, new params - { value(std::uint32_t(0xabffff)) }, { + { value(std::uint64_t(0xabffff)) }, { 0x17, 0x01, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, - 0x00, 0x00, 0x00, 0x01, 0x03, 0x80, 0xff, 0xff, - 0xab, 0x00 + 0x00, 0x00, 0x00, 0x01, 0x08, 0x80, 0xff, 0xff, + 0xab, 0x00, 0x00, 0x00, 0x00, 0x00 }, "forward_list_iterator" ) diff --git a/test/unit/detail/protocol/row_deserialization.cpp b/test/unit/detail/protocol/row_deserialization.cpp index 60643cbc..e53191be 100644 --- a/test/unit/detail/protocol/row_deserialization.cpp +++ b/test/unit/detail/protocol/row_deserialization.cpp @@ -130,7 +130,7 @@ INSTANTIATE_TEST_SUITE_P(Text, DeserializeRowTest, Values( text, "one_value", {0x01, 0x35}, - makevalues(std::int32_t(5)), + makevalues(std::int64_t(5)), { protocol_field_type::tiny } ), row_testcase( @@ -144,7 +144,7 @@ INSTANTIATE_TEST_SUITE_P(Text, DeserializeRowTest, Values( text, "several_values", {0x03, 0x76, 0x61, 0x6c, 0x02, 0x32, 0x31, 0x03, 0x30, 0x2e, 0x30}, - makevalues("val", std::int32_t(21), 0.0f), + makevalues("val", std::int64_t(21), 0.0f), { protocol_field_type::var_string, protocol_field_type::long_, protocol_field_type::float_ } ), row_testcase( @@ -183,13 +183,13 @@ INSTANTIATE_TEST_SUITE_P(Text, DeserializeRowErrorTest, testing::Values( // Instantiations for binary protocol INSTANTIATE_TEST_SUITE_P(Binary, DeserializeRowTest, testing::Values( row_testcase(bin, "one_value", {0x00, 0x00, 0x14}, - makevalues(std::int32_t(20)), + makevalues(std::int64_t(20)), {protocol_field_type::tiny}), row_testcase(bin, "one_null", {0x00, 0x04}, makevalues(nullptr), {protocol_field_type::tiny}), row_testcase(bin, "two_values", {0x00, 0x00, 0x03, 0x6d, 0x69, 0x6e, 0x6d, 0x07}, - makevalues("min", std::int32_t(1901)), + makevalues("min", std::int64_t(1901)), {protocol_field_type::var_string, protocol_field_type::short_}), row_testcase(bin, "one_value_one_null", {0x00, 0x08, 0x03, 0x6d, 0x61, 0x78}, makevalues("max", nullptr), @@ -209,8 +209,8 @@ INSTANTIATE_TEST_SUITE_P(Binary, DeserializeRowTest, testing::Values( 0x05, 0x71, 0x99, 0x6d, 0xe2, 0x93, 0x4d, 0xf5, 0x3d }, makevalues( - std::int32_t(-3), - std::int32_t(20), + std::int64_t(-3), + std::int64_t(20), nullptr, 3.14f, "ab", diff --git a/test/unit/detail/protocol/text_deserialization_error.cpp b/test/unit/detail/protocol/text_deserialization_error.cpp index 55332422..ba7c36ad 100644 --- a/test/unit/detail/protocol/text_deserialization_error.cpp +++ b/test/unit/detail/protocol/text_deserialization_error.cpp @@ -61,11 +61,7 @@ TEST_P(DeserializeTextValueErrorTest, Error_ReturnsExpectedErrc) } std::vector make_int_err_cases( - protocol_field_type t, - std::string_view signed_lt_min, - std::string_view signed_gt_max, - std::string_view unsigned_lt_min, - std::string_view unsigned_gt_max + protocol_field_type t ) { return { @@ -74,60 +70,36 @@ std::vector make_int_err_cases( err_text_value_testcase("signed_hex", "0x01", t), err_text_value_testcase("signed_fractional", "1.1", t), err_text_value_testcase("signed_exp", "2e10", t), - err_text_value_testcase("signed_lt_min", signed_lt_min, t), - err_text_value_testcase("signed_gt_max", signed_gt_max, t), + err_text_value_testcase("signed_lt_min", "-9223372036854775809", t), + err_text_value_testcase("signed_gt_max", "9223372036854775808", t), err_text_value_testcase("unsigned_blank", "", t, column_flags::unsigned_), err_text_value_testcase("unsigned_non_number", "abtrf", t, column_flags::unsigned_), err_text_value_testcase("unsigned_hex", "0x01", t, column_flags::unsigned_), err_text_value_testcase("unsigned_fractional", "1.1", t, column_flags::unsigned_), err_text_value_testcase("unsigned_exp", "2e10", t, column_flags::unsigned_), - err_text_value_testcase("unsigned_lt_min", unsigned_lt_min, t, column_flags::unsigned_), - err_text_value_testcase("unsigned_gt_max", unsigned_gt_max, t, column_flags::unsigned_) + err_text_value_testcase("unsigned_lt_min", "-18446744073709551616", t, column_flags::unsigned_), + err_text_value_testcase("unsigned_gt_max", "18446744073709551616", t, column_flags::unsigned_) }; } -std::vector make_int32_err_cases( - protocol_field_type t -) -{ - // Unsigned integers behaviour for negative inputs are determined by what iostreams - // do (accepting it and overflowing) - return make_int_err_cases(t, "-2147483649", "2147483648", "-4294967296", "4294967296"); -} - INSTANTIATE_TEST_SUITE_P(TINYINT, DeserializeTextValueErrorTest, ValuesIn( - make_int32_err_cases(protocol_field_type::tiny) + make_int_err_cases(protocol_field_type::tiny) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(SMALLINT, DeserializeTextValueErrorTest, ValuesIn( - make_int32_err_cases(protocol_field_type::short_) + make_int_err_cases(protocol_field_type::short_) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(MEDIUMINT, DeserializeTextValueErrorTest, ValuesIn( - make_int32_err_cases(protocol_field_type::int24) + make_int_err_cases(protocol_field_type::int24) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(INT, DeserializeTextValueErrorTest, ValuesIn( - make_int32_err_cases(protocol_field_type::long_) + make_int_err_cases(protocol_field_type::long_) ), test_name_generator); -std::vector make_int64_err_cases( - protocol_field_type t -) -{ - // Unsigned integers behaviour for negative inputs are determined by what iostreams - // do (accepting it and overflowing) - return make_int_err_cases( - t, - "-9223372036854775809", - "9223372036854775808", - "-18446744073709551616", - "18446744073709551616" - ); -} - INSTANTIATE_TEST_SUITE_P(BIGINT, DeserializeTextValueErrorTest, ValuesIn( - make_int64_err_cases(protocol_field_type::longlong) + make_int_err_cases(protocol_field_type::longlong) ), test_name_generator); std::vector make_float_err_cases( @@ -306,7 +278,7 @@ INSTANTIATE_TEST_SUITE_P(TIME, DeserializeTextValueErrorTest, Values( // Although range is smaller, YEAR is deserialized just as a regular int INSTANTIATE_TEST_SUITE_P(YEAR, DeserializeTextValueErrorTest, ValuesIn( - make_int32_err_cases(protocol_field_type::year) + make_int_err_cases(protocol_field_type::year) ), test_name_generator); } // anon namespace diff --git a/test/unit/detail/protocol/text_deserialization_value.cpp b/test/unit/detail/protocol/text_deserialization_value.cpp index 42f1810b..44956ed9 100644 --- a/test/unit/detail/protocol/text_deserialization_value.cpp +++ b/test/unit/detail/protocol/text_deserialization_value.cpp @@ -85,78 +85,77 @@ INSTANTIATE_TEST_SUITE_P(StringTypes, DeserializeTextValueTest, Values( "test", static_cast(0x23)) ), test_name_generator); -template std::vector make_int_cases( std::string signed_max_s, - SignedType signed_max_b, + std::int64_t signed_max_b, std::string signed_min_s, - SignedType signed_min_b, + std::int64_t signed_min_b, std::string unsigned_max_s, - UnsignedType unsigned_max_b, + std::uint64_t unsigned_max_b, std::string zerofill_s, - UnsignedType zerofill_b, + std::uint64_t zerofill_b, protocol_field_type type ) { return { - { "signed", "20", SignedType(20), type }, + { "signed", "20", std::int64_t(20), type }, { "signed_max", signed_max_s, signed_max_b, type }, - { "signed_negative", "-20", SignedType(-20), type }, + { "signed_negative", "-20", std::int64_t(-20), type }, { "signed_min", signed_min_s, signed_min_b, type }, - { "unsigned", "20", UnsignedType(20), type, column_flags::unsigned_ }, - { "usigned_min", "0", UnsignedType(0), type, column_flags::unsigned_ }, + { "unsigned", "20", std::uint64_t(20), type, column_flags::unsigned_ }, + { "usigned_min", "0", std::uint64_t(0), type, column_flags::unsigned_ }, { "usigned_max", unsigned_max_s, unsigned_max_b, type, column_flags::unsigned_ }, - { "unsigned_zerofill", zerofill_s, UnsignedType(zerofill_b), type, + { "unsigned_zerofill", zerofill_s, std::uint64_t(zerofill_b), type, column_flags::unsigned_ | column_flags::zerofill } }; } INSTANTIATE_TEST_SUITE_P(TINYINT, DeserializeTextValueTest, ValuesIn( make_int_cases( - "127", std::int32_t(127), - "-128", std::int32_t(-128), - "255", std::uint32_t(255), - "010", std::uint32_t(10), + "127", 127, + "-128", -128, + "255", 255, + "010", 10, protocol_field_type::tiny ) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(SMALLINT, DeserializeTextValueTest, ValuesIn( make_int_cases( - "32767", std::int32_t(32767), - "-32768", std::int32_t(-32768), - "65535", std::uint32_t(65535), - "00535", std::uint32_t(535), + "32767", 32767, + "-32768", -32768, + "65535", 65535, + "00535", 535, protocol_field_type::short_ ) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(MEDIUMINT, DeserializeTextValueTest, ValuesIn( make_int_cases( - "8388607", std::int32_t(8388607), - "-8388608", std::int32_t(-8388608), - "16777215", std::uint32_t(16777215), - "00007215", std::uint32_t(7215), + "8388607", 8388607, + "-8388608",-8388608, + "16777215", 16777215, + "00007215", 7215, protocol_field_type::int24 ) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(INT, DeserializeTextValueTest, ValuesIn( make_int_cases( - "2147483647", std::int32_t(2147483647), - "-2147483648", std::int32_t(-2147483648), - "4294967295", std::uint32_t(4294967295), - "0000067295", std::uint32_t(67295), + "2147483647", 2147483647, + "-2147483648", -2147483648, + "4294967295", 4294967295, + "0000067295", 67295, protocol_field_type::long_ ) ), test_name_generator); INSTANTIATE_TEST_SUITE_P(BIGINT, DeserializeTextValueTest, ValuesIn( make_int_cases( - "9223372036854775807", std::int64_t(9223372036854775807), - "-9223372036854775808", std::int64_t(-9223372036854775807 - 1), // minus is not part of literal, avoids warning - "18446744073709551615", std::uint64_t(18446744073709551615ULL), // suffix needed to avoid warning - "0000067295", std::uint64_t(67295), + "9223372036854775807", 9223372036854775807, + "-9223372036854775808", -9223372036854775807 - 1, // minus is not part of literal, avoids warning + "18446744073709551615", 18446744073709551615ULL, // suffix needed to avoid warning + "0000067295", 67295, protocol_field_type::longlong ) ), test_name_generator); @@ -366,10 +365,10 @@ INSTANTIATE_TEST_SUITE_P(TIME, DeserializeTextValueTest, Values( ), test_name_generator); INSTANTIATE_TEST_SUITE_P(YEAR, DeserializeTextValueTest, Values( - text_value_testcase("regular_value", "1999", std::uint32_t(1999), protocol_field_type::year, column_flags::unsigned_), - text_value_testcase("min", "1901", std::uint32_t(1901), protocol_field_type::year, column_flags::unsigned_), - text_value_testcase("max", "2155", std::uint32_t(2155), protocol_field_type::year, column_flags::unsigned_), - text_value_testcase("zero", "0000", std::uint32_t(0), protocol_field_type::year, column_flags::unsigned_) + text_value_testcase("regular_value", "1999", std::uint64_t(1999), protocol_field_type::year, column_flags::unsigned_), + text_value_testcase("min", "1901", std::uint64_t(1901), protocol_field_type::year, column_flags::unsigned_), + text_value_testcase("max", "2155", std::uint64_t(2155), protocol_field_type::year, column_flags::unsigned_), + text_value_testcase("zero", "0000", std::uint64_t(0), protocol_field_type::year, column_flags::unsigned_) ), test_name_generator); } // anon namespace