From 7eba75a739ca32c14468f01212284e065af15af4 Mon Sep 17 00:00:00 2001 From: ruben Date: Sun, 2 Feb 2020 12:16:12 +0000 Subject: [PATCH] Now paremeterized tests get informative names --- TODO.txt | 1 + test/common/test_common.hpp | 10 +- test/integration/query_types.cpp | 33 ++- test/unit/binary_deserialization.cpp | 32 +-- test/unit/null_bitmap.cpp | 20 +- test/unit/serialization.cpp | 223 +++++++-------- test/unit/serialization_test_common.hpp | 56 ++-- test/unit/text_deserialization.cpp | 348 ++++++++++++------------ 8 files changed, 350 insertions(+), 373 deletions(-) diff --git a/TODO.txt b/TODO.txt index 097c7db6..4fcdb7be 100644 --- a/TODO.txt +++ b/TODO.txt @@ -33,3 +33,4 @@ Technical debt CMake exporting? Integration test for network errors (e.g. host unreachable) Refactor file structucture for serialization and tests + Deserialize common should be in namespace mysql::test, not in detail diff --git a/test/common/test_common.hpp b/test/common/test_common.hpp index d16e1507..9bbd8325 100644 --- a/test/common/test_common.hpp +++ b/test/common/test_common.hpp @@ -118,13 +118,17 @@ inline void compare_buffers(std::string_view s0, std::string_view s1, const char EXPECT_EQ(s0, s1) << msg << ":\n" << buffer_diff(s0, s1); } -struct named_test {}; +struct named_param {}; -template >> +template >> std::ostream& operator<<(std::ostream& os, const T& v) { return os << v.name; } constexpr auto test_name_generator = [](const auto& param_info) { - return param_info.param.name; + std::ostringstream os; + os << param_info.param; + std::string res = os.str(); + std::replace_if(res.begin(), res.end(), [](char c) { return !std::isalnum(c); }, '_'); + return res; }; } diff --git a/test/integration/query_types.cpp b/test/integration/query_types.cpp index 838b85cc..abb38817 100644 --- a/test/integration/query_types.cpp +++ b/test/integration/query_types.cpp @@ -105,7 +105,7 @@ INSTANTIATE_TEST_SUITE_P(TINYINT, QueryTypesTest, Values( QueryTypesParams("types_tinyint", "field_zerofill", "regular", std::uint32_t(20), field_type::tinyint, flags_zerofill), QueryTypesParams("types_tinyint", "field_zerofill", "min", std::uint32_t(0), field_type::tinyint, flags_zerofill) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(SMALLINT, QueryTypesTest, Values( QueryTypesParams("types_smallint", "field_signed", "regular", std::int32_t(20), field_type::smallint), @@ -122,7 +122,7 @@ INSTANTIATE_TEST_SUITE_P(SMALLINT, QueryTypesTest, Values( QueryTypesParams("types_smallint", "field_zerofill", "regular", std::uint32_t(20), field_type::smallint, flags_zerofill), QueryTypesParams("types_smallint", "field_zerofill", "min", std::uint32_t(0), field_type::smallint, flags_zerofill) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(MEDIUMINT, QueryTypesTest, Values( QueryTypesParams("types_mediumint", "field_signed", "regular", std::int32_t(20), field_type::mediumint), @@ -139,7 +139,7 @@ INSTANTIATE_TEST_SUITE_P(MEDIUMINT, QueryTypesTest, Values( QueryTypesParams("types_mediumint", "field_zerofill", "regular", std::uint32_t(20), field_type::mediumint, flags_zerofill), QueryTypesParams("types_mediumint", "field_zerofill", "min", std::uint32_t(0), field_type::mediumint, flags_zerofill) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(INT, QueryTypesTest, Values( QueryTypesParams("types_int", "field_signed", "regular", std::int32_t(20), field_type::int_), @@ -156,7 +156,7 @@ INSTANTIATE_TEST_SUITE_P(INT, QueryTypesTest, Values( QueryTypesParams("types_int", "field_zerofill", "regular", std::uint32_t(20), field_type::int_, flags_zerofill), QueryTypesParams("types_int", "field_zerofill", "min", std::uint32_t(0), field_type::int_, flags_zerofill) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(BIGINT, QueryTypesTest, Values( QueryTypesParams("types_bigint", "field_signed", "regular", std::int64_t(20), field_type::bigint), @@ -173,7 +173,7 @@ INSTANTIATE_TEST_SUITE_P(BIGINT, QueryTypesTest, Values( QueryTypesParams("types_bigint", "field_zerofill", "regular", std::uint64_t(20), field_type::bigint, flags_zerofill), QueryTypesParams("types_bigint", "field_zerofill", "min", std::uint64_t(0), field_type::bigint, flags_zerofill) -)); +), test_name_generator); // Floating point INSTANTIATE_TEST_SUITE_P(FLOAT, QueryTypesTest, Values( @@ -199,7 +199,7 @@ INSTANTIATE_TEST_SUITE_P(FLOAT, QueryTypesTest, Values( QueryTypesParams("types_float", "field_zerofill", "fractional_positive", 4.2f, field_type::float_, flags_zerofill, 31), QueryTypesParams("types_float", "field_zerofill", "positive_exp_positive_fractional", 3.14e20f, field_type::float_, flags_zerofill, 31), QueryTypesParams("types_float", "field_zerofill", "negative_exp_positive_fractional", 3.14e-20f, field_type::float_, flags_zerofill, 31) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(DOUBLE, QueryTypesTest, Values( QueryTypesParams("types_double", "field_signed", "zero", 0.0, field_type::double_, no_flags, 31), @@ -224,7 +224,7 @@ INSTANTIATE_TEST_SUITE_P(DOUBLE, QueryTypesTest, Values( QueryTypesParams("types_double", "field_zerofill", "fractional_positive", 4.2, field_type::double_, flags_zerofill, 31), QueryTypesParams("types_double", "field_zerofill", "positive_exp_positive_fractional", 3.14e200, field_type::double_, flags_zerofill, 31), QueryTypesParams("types_double", "field_zerofill", "negative_exp_positive_fractional", 3.14e-200, field_type::double_, flags_zerofill, 31) -)); +), test_name_generator); // Dates and times INSTANTIATE_TEST_SUITE_P(DATE, QueryTypesTest, Values( @@ -232,7 +232,7 @@ INSTANTIATE_TEST_SUITE_P(DATE, QueryTypesTest, Values( QueryTypesParams("types_date", "field_date", "leap", 1788_y/2/29_d, field_type::date), QueryTypesParams("types_date", "field_date", "min", 1000_y/1/1_d, field_type::date), QueryTypesParams("types_date", "field_date", "max", 9999_y/12/31_d, field_type::date) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(DATETIME, QueryTypesTest, Values( QueryTypesParams("types_datetime", "field_0", "date", makedt(2010, 5, 2), field_type::datetime), @@ -289,8 +289,7 @@ INSTANTIATE_TEST_SUITE_P(DATETIME, QueryTypesTest, Values( QueryTypesParams("types_datetime", "field_4", "max", makedt(9999, 12, 31, 23, 59, 59, 999900), field_type::datetime, no_flags, 4), QueryTypesParams("types_datetime", "field_5", "max", makedt(9999, 12, 31, 23, 59, 59, 999990), field_type::datetime, no_flags, 5), QueryTypesParams("types_datetime", "field_6", "max", makedt(9999, 12, 31, 23, 59, 59, 999999), field_type::datetime, no_flags, 6) - -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(TIMESTAMP, QueryTypesTest, Values( QueryTypesParams("types_timestamp", "field_0", "date", makedt(2010, 5, 2), field_type::timestamp), @@ -331,7 +330,7 @@ INSTANTIATE_TEST_SUITE_P(TIMESTAMP, QueryTypesTest, Values( QueryTypesParams("types_timestamp", "field_4", "hmsu", makedt(2010, 5, 2, 23, 1, 50, 123400), field_type::timestamp, no_flags, 4), QueryTypesParams("types_timestamp", "field_5", "hmsu", makedt(2010, 5, 2, 23, 1, 50, 123450), field_type::timestamp, no_flags, 5), QueryTypesParams("types_timestamp", "field_6", "hmsu", makedt(2010, 5, 2, 23, 1, 50, 123456), field_type::timestamp, no_flags, 6) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(TIME, QueryTypesTest, Values( QueryTypesParams("types_time", "field_0", "h", maket(1, 0, 0), field_type::time), @@ -404,14 +403,14 @@ INSTANTIATE_TEST_SUITE_P(TIME, QueryTypesTest, Values( QueryTypesParams("types_time", "field_4", "zero", maket(0, 0, 0), field_type::time, no_flags, 4), QueryTypesParams("types_time", "field_5", "zero", maket(0, 0, 0), field_type::time, no_flags, 5), QueryTypesParams("types_time", "field_6", "zero", maket(0, 0, 0), field_type::time, no_flags, 6) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(YEAR, QueryTypesTest, Values( QueryTypesParams("types_year", "field_default", "regular", std::uint32_t(2019), field_type::year, flags_zerofill), QueryTypesParams("types_year", "field_default", "min", std::uint32_t(1901), field_type::year, flags_zerofill), QueryTypesParams("types_year", "field_default", "max", std::uint32_t(2155), field_type::year, flags_zerofill), QueryTypesParams("types_year", "field_default", "zero", std::uint32_t(0), field_type::year, flags_zerofill) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(STRING, QueryTypesTest, Values( QueryTypesParams("types_string", "field_char", "regular", "test_char", field_type::char_), @@ -442,7 +441,7 @@ INSTANTIATE_TEST_SUITE_P(STRING, QueryTypesTest, Values( QueryTypesParams("types_string", "field_set", "regular", "red,green", field_type::set), QueryTypesParams("types_string", "field_set", "empty", "", field_type::set) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(BINARY, QueryTypesTest, Values( // BINARY values get padded with zeros to the declared length @@ -469,7 +468,7 @@ INSTANTIATE_TEST_SUITE_P(BINARY, QueryTypesTest, Values( QueryTypesParams("types_binary", "field_longblob", "regular", makesv("\0_longblob"), field_type::blob), QueryTypesParams("types_binary", "field_longblob", "nonascii", makesv("\5\xfa"), field_type::blob), QueryTypesParams("types_binary", "field_longblob", "empty", "", field_type::blob) -)); +), test_name_generator); // These types do not have a more concrete representation in the library yet. // Check we get them as strings and we get the metadata correctly @@ -484,7 +483,7 @@ INSTANTIATE_TEST_SUITE_P(NOT_IMPLEMENTED_TYPES, QueryTypesTest, Values( QueryTypesParams("types_not_implemented", "field_bit", "regular", "\xfe", field_type::bit, flags_unsigned), QueryTypesParams("types_not_implemented", "field_decimal", "regular", "300", field_type::decimal), QueryTypesParams("types_not_implemented", "field_geometry", "regular", makesv(geometry_value), field_type::geometry) -)); +), test_name_generator); // Tests for certain metadata flags and NULL values INSTANTIATE_TEST_SUITE_P(METADATA_FLAGS, QueryTypesTest, Values( @@ -499,7 +498,7 @@ INSTANTIATE_TEST_SUITE_P(METADATA_FLAGS, QueryTypesTest, Values( flagsvec{&field_metadata::is_unique_key}), QueryTypesParams("types_flags", "field_indexed", "default", std::int32_t(42), field_type::int_, flagsvec{&field_metadata::is_multiple_key}) -)); +), test_name_generator); } // anon namespace diff --git a/test/unit/binary_deserialization.cpp b/test/unit/binary_deserialization.cpp index b8610bcc..5f2157b2 100644 --- a/test/unit/binary_deserialization.cpp +++ b/test/unit/binary_deserialization.cpp @@ -38,7 +38,7 @@ std::vector make_meta( } // for deserialize_binary_value -struct BinaryValueParam +struct BinaryValueParam : named_param { std::string name; std::vector from; @@ -63,11 +63,7 @@ struct BinaryValueParam } }; -std::ostream& operator<<(std::ostream& os, const BinaryValueParam& value) { return os << value.name; } - -struct DeserializeBinaryValueTest : public TestWithParam -{ -}; +struct DeserializeBinaryValueTest : public TestWithParam {}; TEST_P(DeserializeBinaryValueTest, CorrectFormat_SetsOutputValueReturnsTrue) { @@ -100,7 +96,7 @@ INSTANTIATE_TEST_SUITE_P(StringTypes, DeserializeBinaryValueTest, Values( BinaryValueParam("bit", {0x02, 0x02, 0x01}, "\2\1", protocol_field_type::bit), BinaryValueParam("decimal", {0x02, 0x31, 0x30}, "10", protocol_field_type::newdecimal), BinaryValueParam("geomtry", {0x04, 0x74, 0x65, 0x73, 0x74}, "test", protocol_field_type::geometry) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(IntTypes, DeserializeBinaryValueTest, Values( BinaryValueParam("tinyint_unsigned", {0x14}, std::uint32_t(20), @@ -123,12 +119,12 @@ INSTANTIATE_TEST_SUITE_P(IntTypes, DeserializeBinaryValueTest, Values( protocol_field_type::longlong, column_flags::unsigned_), BinaryValueParam("bigint_signed", {0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, std::int64_t(-20), protocol_field_type::longlong) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(FloatingPointTypes, DeserializeBinaryValueTest, Values( BinaryValueParam("float", {0x66, 0x66, 0x86, 0xc0}, -4.2f, protocol_field_type::float_), BinaryValueParam("double", {0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0xc0}, -4.2, protocol_field_type::double_) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(TimeTypes, DeserializeBinaryValueTest, Values( BinaryValueParam("date", {0x04, 0xda, 0x07, 0x03, 0x1c}, makedate(2010, 3, 28), protocol_field_type::date), @@ -139,10 +135,10 @@ INSTANTIATE_TEST_SUITE_P(TimeTypes, DeserializeBinaryValueTest, Values( BinaryValueParam("time", { 0x0c, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x02, 0x03, 0xa0, 0x86, 0x01, 0x00}, maket(120, 2, 3, 100000), protocol_field_type::time), BinaryValueParam("year", {0xe3, 0x07}, std::uint32_t(2019), protocol_field_type::year, column_flags::unsigned_) -)); +), test_name_generator); // for deserialize_binary_row -struct BinaryRowParam +struct BinaryRowParam : named_param { std::string name; std::vector from; @@ -164,11 +160,7 @@ struct BinaryRowParam } }; -std::ostream& operator<<(std::ostream& os, const BinaryRowParam& value) { return os << value.name; } - -struct DeserializeBinaryRowTest : public TestWithParam -{ -}; +struct DeserializeBinaryRowTest : public TestWithParam {}; TEST_P(DeserializeBinaryRowTest, CorrectFormat_SetsOutputValueReturnsTrue) { @@ -220,10 +212,10 @@ INSTANTIATE_TEST_SUITE_P(Default, DeserializeBinaryRowTest, testing::Values( protocol_field_type::double_ } ) -)); +), test_name_generator); // Error cases for deserialize_binary_row -struct BinaryRowErrorParam : named_test +struct BinaryRowErrorParam : named_param { std::string name; std::vector from; @@ -244,9 +236,7 @@ struct BinaryRowErrorParam : named_test } }; -struct DeserializeBinaryRowErrorTest : public TestWithParam -{ -}; +struct DeserializeBinaryRowErrorTest : public TestWithParam {}; TEST_P(DeserializeBinaryRowErrorTest, ErrorCondition_ReturnsErrorCode) { diff --git a/test/unit/null_bitmap.cpp b/test/unit/null_bitmap.cpp index 668efe8d..1d193acc 100644 --- a/test/unit/null_bitmap.cpp +++ b/test/unit/null_bitmap.cpp @@ -2,10 +2,12 @@ #include #include #include "mysql/impl/null_bitmap_traits.hpp" +#include "test_common.hpp" using mysql::detail::null_bitmap_traits; using mysql::detail::stmt_execute_null_bitmap_offset; using mysql::detail::binary_row_null_bitmap_offset; +using namespace mysql::test; namespace { @@ -19,7 +21,7 @@ struct ByteCountParams }; std::ostream& operator<<(std::ostream& os, const ByteCountParams& v) { - return os << "(offset=" << v.offset << ", num_fields=" << v.num_fields << ")"; + return os << "offset=" << v.offset << ",num_fields=" << v.num_fields; } struct NullBitmapTraitsByteCountTest : testing::TestWithParam {}; @@ -49,7 +51,7 @@ INSTANTIATE_TEST_SUITE_P(StmtExecuteOffset, NullBitmapTraitsByteCountTest, testi ByteCountParams{stmt_execute_null_bitmap_offset, 15, 2}, ByteCountParams{stmt_execute_null_bitmap_offset, 16, 2}, ByteCountParams{stmt_execute_null_bitmap_offset, 17, 3} -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(BinaryRowOffset, NullBitmapTraitsByteCountTest, testing::Values( ByteCountParams{binary_row_null_bitmap_offset, 0, 1}, @@ -70,7 +72,7 @@ INSTANTIATE_TEST_SUITE_P(BinaryRowOffset, NullBitmapTraitsByteCountTest, testing ByteCountParams{binary_row_null_bitmap_offset, 15, 3}, ByteCountParams{binary_row_null_bitmap_offset, 16, 3}, ByteCountParams{binary_row_null_bitmap_offset, 17, 3} -)); +), test_name_generator); // is_null struct IsNullParams @@ -81,7 +83,7 @@ struct IsNullParams }; std::ostream& operator<<(std::ostream& os, const IsNullParams& v) { - return os << "(offset=" << v.offset << ", pos=" << v.pos << ")"; + return os << "offset=" << v.offset << ",pos=" << v.pos; } struct NullBitmapTraitsIsNullTest : testing::TestWithParam {}; @@ -111,7 +113,7 @@ INSTANTIATE_TEST_SUITE_P(StmtExecuteOffset, NullBitmapTraitsIsNullTest, testing: IsNullParams{stmt_execute_null_bitmap_offset, 14, true}, IsNullParams{stmt_execute_null_bitmap_offset, 15, true}, IsNullParams{stmt_execute_null_bitmap_offset, 16, false} -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(BinaryRowOffset, NullBitmapTraitsIsNullTest, testing::Values( IsNullParams{binary_row_null_bitmap_offset, 0, true}, @@ -131,7 +133,7 @@ INSTANTIATE_TEST_SUITE_P(BinaryRowOffset, NullBitmapTraitsIsNullTest, testing::V IsNullParams{binary_row_null_bitmap_offset, 14, false}, IsNullParams{binary_row_null_bitmap_offset, 15, false}, IsNullParams{binary_row_null_bitmap_offset, 16, false} -)); +), test_name_generator); TEST(NullBitmapTraits, IsNull_OneFieldStmtExecuteFirstBitZero_ReturnsFalse) { @@ -173,7 +175,7 @@ struct SetNullParams }; std::ostream& operator<<(std::ostream& os, const SetNullParams& v) { - return os << "(offset=" << v.offset << ", pos=" << v.pos << ")"; + return os << "offset=" << v.offset << ",pos=" << v.pos; } struct NullBitmapTraitsSetNullTest : testing::TestWithParam {}; @@ -205,7 +207,7 @@ INSTANTIATE_TEST_SUITE_P(StmtExecuteOffset, NullBitmapTraitsSetNullTest, testing SetNullParams(stmt_execute_null_bitmap_offset, 14, {0, 0b01000000, 0}), SetNullParams(stmt_execute_null_bitmap_offset, 15, {0, 0b10000000, 0}), SetNullParams(stmt_execute_null_bitmap_offset, 16, {0, 0, 0b00000001}) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(BinaryRowOffset, NullBitmapTraitsSetNullTest, testing::Values( SetNullParams(binary_row_null_bitmap_offset, 0, {0b00000100, 0, 0}), @@ -225,7 +227,7 @@ INSTANTIATE_TEST_SUITE_P(BinaryRowOffset, NullBitmapTraitsSetNullTest, testing:: SetNullParams(binary_row_null_bitmap_offset, 14, {0, 0, 0b00000001}), SetNullParams(binary_row_null_bitmap_offset, 15, {0, 0, 0b00000010}), SetNullParams(binary_row_null_bitmap_offset, 16, {0, 0, 0b00000100}) -)); +), test_name_generator); TEST(NullBitmapTraits, SetNull_OneFieldStmtExecute_SetsFirstBitToZero) { diff --git a/test/unit/serialization.cpp b/test/unit/serialization.cpp index 525f71fd..27607346 100644 --- a/test/unit/serialization.cpp +++ b/test/unit/serialization.cpp @@ -21,44 +21,7 @@ using mysql::value; namespace { -struct DeserializeErrorParams -{ - shared_ptr value; - vector buffer; - string test_name; - Error expected_error; - template - DeserializeErrorParams create(vector&& buffer, string&& test_name, Error err = Error::incomplete_message) - { - return DeserializeErrorParams { - make_shared>(T{}), - move(buffer), - move(test_name), - err - }; - } -}; - -ostream& operator<<(ostream& os, const DeserializeErrorParams& params) -{ - return os << params.value->get_type_name() << " - " << params.test_name; -} - -// Special error conditions -struct DeserializeErrorTest : testing::TestWithParam -{ -}; - -TEST_P(DeserializeErrorTest, Deserialize_ErrorCondition_ReturnsErrorCode) -{ - auto first = GetParam().buffer.data(); - auto last = GetParam().buffer.data() + GetParam().buffer.size(); - DeserializationContext ctx (first, last, capabilities(0)); - auto value = GetParam().value->default_construct(); - auto err = value->deserialize(ctx); - EXPECT_EQ(err, GetParam().expected_error); -} // Definitions for the parameterized tests string string_250 (250, 'a'); @@ -88,75 +51,75 @@ enum class EnumInt4 : uint32_t }; INSTANTIATE_TEST_SUITE_P(UnsignedFixedSizeInts, FullSerializationTest, ::testing::Values( - SerializeParams(int1(0xff), {0xff}), - SerializeParams(int2(0xfeff), {0xff, 0xfe}), - SerializeParams(int3(0xfdfeff), {0xff, 0xfe, 0xfd}), - SerializeParams(int4(0xfcfdfeff), {0xff, 0xfe, 0xfd, 0xfc}), - SerializeParams(int6(0xfafbfcfdfeff), {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa}), - SerializeParams(int8(0xf8f9fafbfcfdfeff), {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8}) -)); + SerializeParams(int1(0xff), {0xff}, "int1"), + SerializeParams(int2(0xfeff), {0xff, 0xfe}, "int2"), + SerializeParams(int3(0xfdfeff), {0xff, 0xfe, 0xfd}, "int3"), + SerializeParams(int4(0xfcfdfeff), {0xff, 0xfe, 0xfd, 0xfc}, "int4"), + SerializeParams(int6(0xfafbfcfdfeff), {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa}, "int6"), + SerializeParams(int8(0xf8f9fafbfcfdfeff), {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8}, "int8") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(SignedFixedSizeInts, FullSerializationTest, ::testing::Values( - SerializeParams(int1_signed(-1), {0xff}, "Negative"), - SerializeParams(int2_signed(-0x101), {0xff, 0xfe}, "Negative"), - SerializeParams(int4_signed(-0x3020101), {0xff, 0xfe, 0xfd, 0xfc}, "Negative"), - SerializeParams(int8_signed(-0x0706050403020101), {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8}, "Negative"), - SerializeParams(int1_signed(0x01), {0x01}, "Positive"), - SerializeParams(int2_signed(0x0201), {0x01, 0x02}, "Positive"), - SerializeParams(int4_signed(0x04030201), {0x01, 0x02, 0x03, 0x04}, "Positive"), - SerializeParams(int8_signed(0x0807060504030201), {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, "Positive") -)); + SerializeParams(int1_signed(-1), {0xff}, "int1_negative"), + SerializeParams(int2_signed(-0x101), {0xff, 0xfe}, "int2_negative"), + SerializeParams(int4_signed(-0x3020101), {0xff, 0xfe, 0xfd, 0xfc}, "int4_negative"), + SerializeParams(int8_signed(-0x0706050403020101), {0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8}, "int8_negative"), + SerializeParams(int1_signed(0x01), {0x01}, "int1_positive"), + SerializeParams(int2_signed(0x0201), {0x01, 0x02}, "int2_positive"), + SerializeParams(int4_signed(0x04030201), {0x01, 0x02, 0x03, 0x04}, "int4_positive"), + SerializeParams(int8_signed(0x0807060504030201), {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08}, "int8_positive") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(LengthEncodedInt, FullSerializationTest, ::testing::Values( - SerializeParams(int_lenenc(1), {0x01}, "1 byte (regular value)"), - SerializeParams(int_lenenc(250), {0xfa}, "1 byte (max value)"), - SerializeParams(int_lenenc(0xfeb7), {0xfc, 0xb7, 0xfe}, "2 bytes (regular value)"), - SerializeParams(int_lenenc(0xffff), {0xfc, 0xff, 0xff}, "2 bytes (max value)"), - SerializeParams(int_lenenc(0xa0feff), {0xfd, 0xff, 0xfe, 0xa0}, "3 bytes (regular value)"), - SerializeParams(int_lenenc(0xffffff), {0xfd, 0xff, 0xff, 0xff}, "3 bytes (max value)"), + SerializeParams(int_lenenc(1), {0x01}, "1_byte_regular"), + SerializeParams(int_lenenc(250), {0xfa}, "1_byte_max"), + SerializeParams(int_lenenc(0xfeb7), {0xfc, 0xb7, 0xfe}, "2_bytes_regular"), + SerializeParams(int_lenenc(0xffff), {0xfc, 0xff, 0xff}, "2_bytes_max"), + SerializeParams(int_lenenc(0xa0feff), {0xfd, 0xff, 0xfe, 0xa0}, "3_bytes_regular"), + SerializeParams(int_lenenc(0xffffff), {0xfd, 0xff, 0xff, 0xff}, "3_bytes_max"), SerializeParams(int_lenenc(0xf8f9fafbfcfdfeff), - {0xfe, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8}, "8 bytes (regular value)"), + {0xfe, 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8}, "8_bytes_regular"), SerializeParams(int_lenenc(0xffffffffffffffff), - {0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, "8 bytes (max value)") -)); + {0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, "8_bytes_max") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(FixedSizeString, FullSerializationTest, ::testing::Values( - SerializeParams(string_fixed<4>({'a', 'b', 'd', 'e'}), {0x61, 0x62, 0x64, 0x65}, "Regular characters"), - SerializeParams(string_fixed<3>({'\0', '\1', 'a'}), {0x00, 0x01, 0x61}, "Null characters"), - SerializeParams(string_fixed<3>({char(0xc3), char(0xb1), 'a'}), {0xc3, 0xb1, 0x61}, "UTF-8 characters"), - SerializeParams(string_fixed<1>({'a'}), {0x61}, "Size 1 string") -)); + SerializeParams(string_fixed<4>({'a', 'b', 'd', 'e'}), {0x61, 0x62, 0x64, 0x65}, "4c_regular_characters"), + SerializeParams(string_fixed<3>({'\0', '\1', 'a'}), {0x00, 0x01, 0x61}, "3c_null_characters"), + SerializeParams(string_fixed<3>({char(0xc3), char(0xb1), 'a'}), {0xc3, 0xb1, 0x61}, "3c_utf8_characters"), + SerializeParams(string_fixed<1>({'a'}), {0x61}, "1c_regular_characters") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(NullTerminatedString, FullSerializationTest, ::testing::Values( - SerializeParams(string_null("abc"), {0x61, 0x62, 0x63, 0x00}, "Regular characters"), - SerializeParams(string_null("\xc3\xb1"), {0xc3, 0xb1, 0x00}, "UTF-8 characters"), - SerializeParams(string_null(""), {0x00}, "Empty string") -)); + SerializeParams(string_null("abc"), {0x61, 0x62, 0x63, 0x00}, "regular_characters"), + SerializeParams(string_null("\xc3\xb1"), {0xc3, 0xb1, 0x00}, "utf8_characters"), + SerializeParams(string_null(""), {0x00}, "empty") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(LengthEncodedString, FullSerializationTest, ::testing::Values( - SerializeParams(string_lenenc(""), {0x00}, "Empty string"), - SerializeParams(string_lenenc("abc"), {0x03, 0x61, 0x62, 0x63}, "1 byte size, regular characters"), - SerializeParams(string_lenenc(string_view("a\0b", 3)), {0x03, 0x61, 0x00, 0x62}, "1 byte size, null characters"), - SerializeParams(string_lenenc(string_250), concat({250}, vector(250, 0x61)), "1 byte size, max"), - SerializeParams(string_lenenc(string_251), concat({0xfc, 251, 0}, vector(251, 0x61)), "2 byte size, min"), - SerializeParams(string_lenenc(string_ffff), concat({0xfc, 0xff, 0xff}, vector(0xffff, 0x61)), "2 byte size, max"), - SerializeParams(string_lenenc(string_10000), concat({0xfd, 0x00, 0x00, 0x01}, vector(0x10000, 0x61)), "3 byte size, max") -)); + SerializeParams(string_lenenc(""), {0x00}, "empty"), + SerializeParams(string_lenenc("abc"), {0x03, 0x61, 0x62, 0x63}, "1_byte_size_regular_characters"), + SerializeParams(string_lenenc(string_view("a\0b", 3)), {0x03, 0x61, 0x00, 0x62}, "1_byte_size_null_characters"), + SerializeParams(string_lenenc(string_250), concat({250}, vector(250, 0x61)), "1_byte_size_max"), + SerializeParams(string_lenenc(string_251), concat({0xfc, 251, 0}, vector(251, 0x61)), "2_byte_size_min"), + SerializeParams(string_lenenc(string_ffff), concat({0xfc, 0xff, 0xff}, vector(0xffff, 0x61)), "2_byte_size_max"), + SerializeParams(string_lenenc(string_10000), concat({0xfd, 0x00, 0x00, 0x01}, vector(0x10000, 0x61)), "3_byte_size_min") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(EofString, SerializeDeserializeTest, ::testing::Values( - SerializeParams(string_eof("abc"), {0x61, 0x62, 0x63}, "Regular characters"), - SerializeParams(string_eof(string_view("a\0b", 3)), {0x61, 0x00, 0x62}, "Null characters"), - SerializeParams(string_eof(""), {}, "Empty string") -)); + SerializeParams(string_eof("abc"), {0x61, 0x62, 0x63}, "regular_characters"), + SerializeParams(string_eof(string_view("a\0b", 3)), {0x61, 0x00, 0x62}, "null_characters"), + SerializeParams(string_eof(""), {}, "empty") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(Enums, FullSerializationTest, ::testing::Values( - SerializeParams(EnumInt1::value1, {0x03}, "low value"), - SerializeParams(EnumInt1::value2, {0xff}, "high value"), - SerializeParams(EnumInt2::value1, {0x03, 0x00}, "low value"), - SerializeParams(EnumInt2::value2, {0xff, 0xfe}, "high value"), - SerializeParams(EnumInt4::value1, {0x03, 0x00, 0x00, 0x00}, "low value"), - SerializeParams(EnumInt4::value2, {0xff, 0xfe, 0xfd, 0xfc}, "high value") -)); + SerializeParams(EnumInt1::value1, {0x03}, "int1_low_value"), + SerializeParams(EnumInt1::value2, {0xff}, "int1_high_value"), + SerializeParams(EnumInt2::value1, {0x03, 0x00}, "int2_low_value"), + SerializeParams(EnumInt2::value2, {0xff, 0xfe}, "int2_high_value"), + SerializeParams(EnumInt4::value1, {0x03, 0x00, 0x00, 0x00}, "int4_low_value"), + SerializeParams(EnumInt4::value2, {0xff, 0xfe, 0xfd, 0xfc}, "int4_high_value") +), test_name_generator); // Other binary values INSTANTIATE_TEST_SUITE_P(Float, FullSerializationTest, ::testing::Values( @@ -164,20 +127,20 @@ INSTANTIATE_TEST_SUITE_P(Float, FullSerializationTest, ::testing::Values( SerializeParams(value_holder( 4.2f), {0x66, 0x66, 0x86, 0x40}, "fractional_positive"), SerializeParams(value_holder(3.14e20f), {0x01, 0x2d, 0x88, 0x61}, "positive_exp_positive_fractional"), SerializeParams(value_holder(0.0f), {0x00, 0x00, 0x00, 0x00}, "zero") -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(Double, FullSerializationTest, ::testing::Values( SerializeParams(value_holder(-4.2), {0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0xc0}, "fractional_negative"), SerializeParams(value_holder( 4.2), {0xcd, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x10, 0x40}, "fractional_positive"), SerializeParams(value_holder(3.14e200), {0xce, 0x46, 0x3c, 0x76, 0x9c, 0x68, 0x90, 0x69}, "positive_exp_positive_fractional"), SerializeParams(value_holder(0.0), {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, "zero") -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(Date, FullSerializationTest, ::testing::Values( SerializeParams(makedate(2010, 3, 28), {0x04, 0xda, 0x07, 0x03, 0x1c}, "regular"), SerializeParams(makedate(1000, 1, 1), {0x04, 0xe8, 0x03, 0x01, 0x01}, "min"), SerializeParams(makedate(9999, 12, 31), {0x04, 0x0f, 0x27, 0x0c, 0x1f}, "max") -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(Datetime, FullSerializationTest, ::testing::Values( SerializeParams(makedt(2010, 1, 1), {0x04, 0xda, 0x07, 0x01, 0x01}, "only_date"), @@ -204,7 +167,7 @@ INSTANTIATE_TEST_SUITE_P(Datetime, FullSerializationTest, ::testing::Values( 0x56, 0xc3, 0x0e, 0x00}, "date_hsu"), SerializeParams(makedt(2010, 1, 1, 23, 1, 59, 967510), {0x0b, 0xda, 0x07, 0x01, 0x01, 0x17, 0x01, 0x3b, 0x56, 0xc3, 0x0e, 0x00}, "date_hmsu") -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(Time, FullSerializationTest, ::testing::Values( SerializeParams(maket(0, 0, 0), {0x00}, "zero"), @@ -232,15 +195,15 @@ INSTANTIATE_TEST_SUITE_P(Time, FullSerializationTest, ::testing::Values( 0x00, 0xe8, 0xe5, 0x04, 0x00}, "negative_u"), SerializeParams(-maket(838, 59, 58, 999000), {0x0c, 0x01, 0x22, 0x00, 0x00, 0x00, 0x16, 0x3b, 0x3a, 0x58, 0x3e, 0x0f, 0x00}, "negative_hmsu") -)); +), test_name_generator); // Messages INSTANTIATE_TEST_SUITE_P(PacketHeader, FullSerializationTest, ::testing::Values( - SerializeParams(packet_header{int3(3), int1(0)}, {0x03, 0x00, 0x00, 0x00}, "small packet, seqnum==0"), - SerializeParams(packet_header{int3(9), int1(2)}, {0x09, 0x00, 0x00, 0x02}, "small packet, seqnum!=0"), - SerializeParams(packet_header{int3(0xcacbcc), int1(0xfa)}, {0xcc, 0xcb, 0xca, 0xfa}, "big packet, seqnum!=0"), - SerializeParams(packet_header{int3(0xffffff), int1(0xff)}, {0xff, 0xff, 0xff, 0xff}, "max packet, max seqnum") -)); + SerializeParams(packet_header{int3(3), int1(0)}, {0x03, 0x00, 0x00, 0x00}, "small_packet_seqnum_0"), + SerializeParams(packet_header{int3(9), int1(2)}, {0x09, 0x00, 0x00, 0x02}, "small_packet_seqnum_not_0"), + SerializeParams(packet_header{int3(0xcacbcc), int1(0xfa)}, {0xcc, 0xcb, 0xca, 0xfa}, "big_packet_seqnum_0"), + SerializeParams(packet_header{int3(0xffffff), int1(0xff)}, {0xff, 0xff, 0xff, 0xff}, "max_packet_max_seqnum") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(OkPacket, DeserializeTest, ::testing::Values( SerializeParams(ok_packet{ @@ -254,7 +217,7 @@ INSTANTIATE_TEST_SUITE_P(OkPacket, DeserializeTest, ::testing::Values( 0x20, 0x6d, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x3a, 0x20, 0x35, 0x20, 0x20, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x64, 0x3a, 0x20, 0x34, 0x20, 0x20, 0x57, 0x61, 0x72, 0x6e, 0x69, 0x6e, 0x67, 0x73, 0x3a, 0x20, 0x30 - }, "successful UPDATE"), + }, "successful_update"), SerializeParams(ok_packet{ int_lenenc(1), // affected rows @@ -264,7 +227,7 @@ INSTANTIATE_TEST_SUITE_P(OkPacket, DeserializeTest, ::testing::Values( string_lenenc("") // no message },{ 0x01, 0x06, 0x02, 0x00, 0x00, 0x00 - }, "successful INSERT"), + }, "successful_insert"), SerializeParams(ok_packet{ int_lenenc(0), // affected rows @@ -274,8 +237,8 @@ INSTANTIATE_TEST_SUITE_P(OkPacket, DeserializeTest, ::testing::Values( string_lenenc("") // no message }, { 0x00, 0x00, 0x02, 0x00, 0x00, 0x00 - }, "Successful login") -)); + }, "successful_login") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(ErrPacket, DeserializeTest, ::testing::Values( SerializeParams(err_packet{ @@ -287,7 +250,7 @@ INSTANTIATE_TEST_SUITE_P(ErrPacket, DeserializeTest, ::testing::Values( 0x19, 0x04, 0x23, 0x34, 0x32, 0x30, 0x30, 0x30, 0x55, 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x20, 0x27, 0x61, 0x27 - }, "Wrong USE database"), + }, "wrong_use_database"), SerializeParams(err_packet{ int2(1146), // eror code @@ -301,7 +264,7 @@ INSTANTIATE_TEST_SUITE_P(ErrPacket, DeserializeTest, ::testing::Values( 0x6e, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x27, 0x20, 0x64, 0x6f, 0x65, 0x73, 0x6e, 0x27, 0x74, 0x20, 0x65, 0x78, 0x69, 0x73, 0x74 - }, "Unknown table"), + }, "unknown_table"), SerializeParams(err_packet{ int2(1045), // error code @@ -318,8 +281,8 @@ INSTANTIATE_TEST_SUITE_P(ErrPacket, DeserializeTest, ::testing::Values( 0x27, 0x20, 0x28, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3a, 0x20, 0x59, 0x45, 0x53, 0x29 - }, "Failed login") -)); + }, "failed_login") +), test_name_generator); constexpr std::uint8_t handshake_auth_plugin_data [] = { 0x52, 0x1a, 0x50, 0x3a, 0x4b, 0x12, 0x70, 0x2f, @@ -377,8 +340,8 @@ INSTANTIATE_TEST_SUITE_P(Handhsake, DeserializeSpaceTest, ::testing::Values( 0x6c, 0x5f, 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x00 - }) -)); + }, "regular") +), test_name_generator); constexpr std::uint8_t handshake_response_auth_data [] = { 0xfe, 0xc6, 0x2c, 0x9f, 0xab, 0x43, 0x69, 0x46, @@ -424,7 +387,7 @@ INSTANTIATE_TEST_SUITE_P(HandhsakeResponse, SerializeTest, ::testing::Values( 0x34, 0xc9, 0x6d, 0x79, 0x73, 0x71, 0x6c, 0x5f, 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x00 - }, "without database", handshake_response_caps), + }, "without_database", handshake_response_caps), SerializeParams(handshake_response_packet{ int4(handshake_response_caps | CLIENT_CONNECT_WITH_DB), @@ -447,8 +410,8 @@ INSTANTIATE_TEST_SUITE_P(HandhsakeResponse, SerializeTest, ::testing::Values( 0x5f, 0x6e, 0x61, 0x74, 0x69, 0x76, 0x65, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x00 - }, "with database", handshake_response_caps | CLIENT_CONNECT_WITH_DB) -)); + }, "with_database", handshake_response_caps | CLIENT_CONNECT_WITH_DB) +), test_name_generator); constexpr std::uint8_t auth_switch_request_auth_data [] = { 0x49, 0x49, 0x7e, 0x51, 0x5d, 0x1f, 0x19, 0x6a, @@ -467,8 +430,8 @@ INSTANTIATE_TEST_SUITE_P(AuthSwitchRequest, DeserializeTest, testing::Values( 0x72, 0x64, 0x00, 0x49, 0x49, 0x7e, 0x51, 0x5d, 0x1f, 0x19, 0x6a, 0x0f, 0x5a, 0x63, 0x15, 0x3e, 0x28, 0x31, 0x3e, 0x3c, 0x79, 0x09, 0x7c, 0x00 - }) -)); + }, "regular") +), test_name_generator); constexpr std::uint8_t auth_switch_response_auth_data [] = { 0xba, 0x55, 0x9c, 0xc5, 0x9c, 0xbf, 0xca, 0x06, @@ -483,8 +446,8 @@ INSTANTIATE_TEST_SUITE_P(AuthSwitchResponse, SerializeTest, testing::Values( 0xba, 0x55, 0x9c, 0xc5, 0x9c, 0xbf, 0xca, 0x06, 0x91, 0xff, 0xaa, 0x72, 0x59, 0xfc, 0x53, 0xdf, 0x88, 0x2d, 0xf9, 0xcf - }) -)); + }, "regular") +), test_name_generator); // Column definition INSTANTIATE_TEST_SUITE_P(ColumnDefinition, DeserializeSpaceTest, testing::Values( @@ -513,7 +476,7 @@ INSTANTIATE_TEST_SUITE_P(ColumnDefinition, DeserializeSpaceTest, testing::Values 0x6c, 0x65, 0x02, 0x69, 0x64, 0x02, 0x69, 0x64, 0x0c, 0x3f, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x03, 0x03, 0x42, 0x00, 0x00, 0x00 - }, "Numeric, auto-increment primary key"), + }, "numeric_auto_increment_primary_key"), SerializeParams(column_definition_packet{ string_lenenc("def"), //catalog string_lenenc("awesome"), // schema (database) @@ -536,7 +499,7 @@ INSTANTIATE_TEST_SUITE_P(ColumnDefinition, DeserializeSpaceTest, testing::Values 0x5f, 0x76, 0x61, 0x72, 0x63, 0x68, 0x61, 0x72, 0x0c, 0x21, 0x00, 0xfd, 0x02, 0x00, 0x00, 0xfd, 0x00, 0x00, 0x00, 0x00, 0x00 - }, "Varchar field, aliased field and table names (query with a JOIN)"), + }, "varchar_field_aliased_field_and_table_names_join"), SerializeParams(column_definition_packet{ string_lenenc("def"), //catalog @@ -560,8 +523,8 @@ INSTANTIATE_TEST_SUITE_P(ColumnDefinition, DeserializeSpaceTest, testing::Values 0x69, 0x65, 0x6c, 0x64, 0x5f, 0x66, 0x6c, 0x6f, 0x61, 0x74, 0x0c, 0x3f, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x1f, 0x00, 0x00 - }, "Float field") -)); + }, "float_field") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(ComQuery, SerializeTest, testing::Values( SerializeParams(com_query_packet{ @@ -569,8 +532,8 @@ INSTANTIATE_TEST_SUITE_P(ComQuery, SerializeTest, testing::Values( }, { 0x03, 0x73, 0x68, 0x6f, 0x77, 0x20, 0x64, 0x61, 0x74, 0x61, 0x62, 0x61, 0x73, 0x65, 0x73 - }) -)); + }, "regular") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(ComStmtPrepare, SerializeTest, testing::Values( SerializeParams(com_stmt_prepare_packet{ @@ -582,8 +545,8 @@ INSTANTIATE_TEST_SUITE_P(ComStmtPrepare, SerializeTest, testing::Values( 0x73, 0x5f, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x20, 0x57, 0x48, 0x45, 0x52, 0x45, 0x20, 0x69, 0x64, 0x20, 0x3d, 0x20, 0x3f - }) -)); + }, "regular") +), test_name_generator); INSTANTIATE_TEST_SUITE_P(ComStmtPrepareResponse, DeserializeSpaceTest, testing::Values( SerializeParams(com_stmt_prepare_ok_packet{ @@ -594,8 +557,8 @@ INSTANTIATE_TEST_SUITE_P(ComStmtPrepareResponse, DeserializeSpaceTest, testing:: }, { 0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00 - }) -)); + }, "regular") +), test_name_generator); // Helper for composing ComStmtExecute tests SerializeParams make_stmt_execute_test( @@ -744,11 +707,11 @@ INSTANTIATE_TEST_SUITE_P(ComStmtExecute, SerializeTest, testing::Values( }, "several_params" ) -)); +), test_name_generator); INSTANTIATE_TEST_SUITE_P(ComStmtClose, SerializeTest, testing::Values( - SerializeParams(com_stmt_close_packet{int4(1)}, {0x19, 0x01, 0x00, 0x00, 0x00}) -)); + SerializeParams(com_stmt_close_packet{int4(1)}, {0x19, 0x01, 0x00, 0x00, 0x00}, "regular") +), test_name_generator); } // anon namespace diff --git a/test/unit/serialization_test_common.hpp b/test/unit/serialization_test_common.hpp index 1a2c2e90..0cf48457 100644 --- a/test/unit/serialization_test_common.hpp +++ b/test/unit/serialization_test_common.hpp @@ -91,9 +91,6 @@ operator<<(std::ostream& os, const T& value) return os; } - - - class TypeErasedValue { public: @@ -101,7 +98,6 @@ public: virtual void serialize(SerializationContext& ctx) const = 0; virtual std::size_t get_size(const SerializationContext& ctx) const = 0; virtual Error deserialize(DeserializationContext& ctx) = 0; - virtual std::string get_type_name() const = 0; virtual std::shared_ptr default_construct() const = 0; virtual bool equals(const TypeErasedValue& rhs) const = 0; virtual void print(std::ostream& os) const = 0; @@ -123,10 +119,6 @@ public: void serialize(SerializationContext& ctx) const override { ::mysql::detail::serialize(value_, ctx); } std::size_t get_size(const SerializationContext& ctx) const override { return ::mysql::detail::get_size(value_, ctx); } Error deserialize(DeserializationContext& ctx) override { return ::mysql::detail::deserialize(value_, ctx); } - std::string get_type_name() const override - { - return boost::typeindex::type_id().pretty_name(); - } std::shared_ptr default_construct() const override { return std::make_shared>(T{}); @@ -142,31 +134,26 @@ public: } }; -struct SerializeParams +struct SerializeParams : test::named_param { std::shared_ptr value; std::vector expected_buffer; - std::string test_name; + std::string name; capabilities caps; std::any additional_storage; template SerializeParams(const T& v, std::vector&& buff, - std::string&& name="default", std::uint32_t caps=0, std::any storage = {}): + std::string&& name, std::uint32_t caps=0, std::any storage = {}): value(std::make_shared>(v)), expected_buffer(move(buff)), - test_name(move(name)), + name(move(name)), caps(caps), additional_storage(std::move(storage)) { } }; -std::ostream& operator<<(std::ostream& os, const SerializeParams& params) -{ - return os << params.value->get_type_name() << " - " << params.test_name; -} - std::vector concat(std::vector&& lhs, const std::vector& rhs) { size_t lhs_size = lhs.size(); @@ -288,6 +275,41 @@ TEST_P(FullSerializationTest, deserialize_extra_space) { deserialize_extra_space TEST_P(FullSerializationTest, deserialize_not_enough_space) { deserialize_not_enough_space_test(); } +// Error tests +struct DeserializeErrorParams : test::named_param +{ + std::shared_ptr value; + std::vector buffer; + std::string name; + Error expected_error; + + template + DeserializeErrorParams( + std::vector&& buffer, + std::string&& test_name, + Error err = Error::incomplete_message + ) : + value(std::make_shared>(T{})), + buffer(std::move(buffer)), + name(std::move(name)), + expected_error(err) + { + } +}; + +struct DeserializeErrorTest : testing::TestWithParam {}; + +TEST_P(DeserializeErrorTest, Deserialize_ErrorCondition_ReturnsErrorCode) +{ + auto first = GetParam().buffer.data(); + auto last = GetParam().buffer.data() + GetParam().buffer.size(); + DeserializationContext ctx (first, last, capabilities(0)); + auto value = GetParam().value->default_construct(); + auto err = value->deserialize(ctx); + EXPECT_EQ(err, GetParam().expected_error); +} + + } } diff --git a/test/unit/text_deserialization.cpp b/test/unit/text_deserialization.cpp index fcf7aacf..3dc5742d 100644 --- a/test/unit/text_deserialization.cpp +++ b/test/unit/text_deserialization.cpp @@ -23,7 +23,7 @@ namespace using mysql::operator<<; -struct TextValueParam +struct TextValueParam : named_param { std::string name; std::string_view from; @@ -51,11 +51,7 @@ struct TextValueParam } }; -std::ostream& operator<<(std::ostream& os, const TextValueParam& value) { return os << value.name; } - -struct DeserializeTextValueTest : public TestWithParam -{ -}; +struct DeserializeTextValueTest : public TestWithParam {}; TEST_P(DeserializeTextValueTest, CorrectFormat_SetsOutputValueReturnsTrue) { @@ -71,231 +67,231 @@ TEST_P(DeserializeTextValueTest, CorrectFormat_SetsOutputValueReturnsTrue) } INSTANTIATE_TEST_SUITE_P(StringTypes, DeserializeTextValueTest, Values( - TextValueParam("VARCHAR non-empty", "string", "string", protocol_field_type::var_string), - TextValueParam("VARCHAR empty", "", "", protocol_field_type::var_string), - TextValueParam("CHAR", "", "", protocol_field_type::string), - TextValueParam("VARBINARY", "value", "value", protocol_field_type::var_string, column_flags::binary), - TextValueParam("BINARY", "value", "value", protocol_field_type::string, column_flags::binary), - TextValueParam("TEXT and BLOB", "value", "value", protocol_field_type::blob, column_flags::blob), - TextValueParam("ENUM", "value", "value", protocol_field_type::string, column_flags::enum_), - TextValueParam("SET", "value1,value2", "value1,value2", protocol_field_type::string, column_flags::set), + TextValueParam("varchar_non_empty", "string", "string", protocol_field_type::var_string), + TextValueParam("varchar_empty", "", "", protocol_field_type::var_string), + TextValueParam("char", "", "", protocol_field_type::string), + TextValueParam("varbinary", "value", "value", protocol_field_type::var_string, column_flags::binary), + TextValueParam("binary", "value", "value", protocol_field_type::string, column_flags::binary), + TextValueParam("text_blob", "value", "value", protocol_field_type::blob, column_flags::blob), + TextValueParam("enum", "value", "value", protocol_field_type::string, column_flags::enum_), + TextValueParam("set", "value1,value2", "value1,value2", protocol_field_type::string, column_flags::set), - TextValueParam("BIT", "\1", "\1", protocol_field_type::bit), - TextValueParam("DECIMAL", "\1", "\1", protocol_field_type::newdecimal), - TextValueParam("GEOMTRY", "\1", "\1", protocol_field_type::geometry, column_flags::binary | column_flags::blob) -)); + TextValueParam("bit", "\1", "\1", protocol_field_type::bit), + TextValueParam("decimal", "\1", "\1", protocol_field_type::newdecimal), + TextValueParam("geomtry", "\1", "\1", protocol_field_type::geometry, column_flags::binary | column_flags::blob) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(TINYINT, DeserializeTextValueTest, Values( TextValueParam("signed", "20", std::int32_t(20), protocol_field_type::tiny), - TextValueParam("signed max", "127", std::int32_t(127), protocol_field_type::tiny), - TextValueParam("signed negative", "-20", std::int32_t(-20), protocol_field_type::tiny), - TextValueParam("signed negative max", "-128", std::int32_t(-128), protocol_field_type::tiny), + TextValueParam("signed_max", "127", std::int32_t(127), protocol_field_type::tiny), + TextValueParam("signed_negative", "-20", std::int32_t(-20), protocol_field_type::tiny), + TextValueParam("signed_negative_max", "-128", std::int32_t(-128), protocol_field_type::tiny), TextValueParam("unsigned", "20", std::uint32_t(20), protocol_field_type::tiny, column_flags::unsigned_), - TextValueParam("usigned min", "0", std::uint32_t(0), protocol_field_type::tiny, column_flags::unsigned_), - TextValueParam("usigned max", "255", std::uint32_t(255), protocol_field_type::tiny, column_flags::unsigned_), - TextValueParam("usigned zerofill", "010", std::uint32_t(10), protocol_field_type::tiny, column_flags::unsigned_) -)); + TextValueParam("usigned_min", "0", std::uint32_t(0), protocol_field_type::tiny, column_flags::unsigned_), + TextValueParam("usigned_max", "255", std::uint32_t(255), protocol_field_type::tiny, column_flags::unsigned_), + TextValueParam("usigned_zerofill", "010", std::uint32_t(10), protocol_field_type::tiny, column_flags::unsigned_) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(SMALLINT, DeserializeTextValueTest, Values( TextValueParam("signed", "20", std::int32_t(20), protocol_field_type::short_), - TextValueParam("signed max", "32767", std::int32_t(32767), protocol_field_type::short_), - TextValueParam("signed negative", "-20", std::int32_t(-20), protocol_field_type::short_), - TextValueParam("signed negative max", "-32768", std::int32_t(-32768), protocol_field_type::short_), + TextValueParam("signed_max", "32767", std::int32_t(32767), protocol_field_type::short_), + TextValueParam("signed_negative", "-20", std::int32_t(-20), protocol_field_type::short_), + TextValueParam("signed_negative_max", "-32768", std::int32_t(-32768), protocol_field_type::short_), TextValueParam("unsigned", "20", std::uint32_t(20), protocol_field_type::short_, column_flags::unsigned_), - TextValueParam("usigned min", "0", std::uint32_t(0), protocol_field_type::short_, column_flags::unsigned_), - TextValueParam("usigned max", "65535", std::uint32_t(65535), protocol_field_type::short_, column_flags::unsigned_), - TextValueParam("usigned zerofill", "00535", std::uint32_t(535), protocol_field_type::short_, column_flags::unsigned_) -)); + TextValueParam("usigned_min", "0", std::uint32_t(0), protocol_field_type::short_, column_flags::unsigned_), + TextValueParam("usigned_max", "65535", std::uint32_t(65535), protocol_field_type::short_, column_flags::unsigned_), + TextValueParam("usigned_zerofill", "00535", std::uint32_t(535), protocol_field_type::short_, column_flags::unsigned_) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(MEDIUMINT, DeserializeTextValueTest, Values( TextValueParam("signed", "20", std::int32_t(20), protocol_field_type::int24), - TextValueParam("signed max", "8388607", std::int32_t(8388607), protocol_field_type::int24), - TextValueParam("signed negative", "-20", std::int32_t(-20), protocol_field_type::int24), - TextValueParam("signed negative max", "-8388607", std::int32_t(-8388607), protocol_field_type::int24), + TextValueParam("signed_max", "8388607", std::int32_t(8388607), protocol_field_type::int24), + TextValueParam("signed_negative", "-20", std::int32_t(-20), protocol_field_type::int24), + TextValueParam("signed_negative_max", "-8388607", std::int32_t(-8388607), protocol_field_type::int24), TextValueParam("unsigned", "20", std::uint32_t(20), protocol_field_type::int24, column_flags::unsigned_), - TextValueParam("usigned min", "0", std::uint32_t(0), protocol_field_type::int24, column_flags::unsigned_), - TextValueParam("usigned max", "16777215", std::uint32_t(16777215), protocol_field_type::int24, column_flags::unsigned_), - TextValueParam("usigned zerofill", "00007215", std::uint32_t(7215), protocol_field_type::int24, column_flags::unsigned_) -)); + TextValueParam("usigned_min", "0", std::uint32_t(0), protocol_field_type::int24, column_flags::unsigned_), + TextValueParam("usigned_max", "16777215", std::uint32_t(16777215), protocol_field_type::int24, column_flags::unsigned_), + TextValueParam("usigned_zerofill", "00007215", std::uint32_t(7215), protocol_field_type::int24, column_flags::unsigned_) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(INT, DeserializeTextValueTest, Values( TextValueParam("signed", "20", std::int32_t(20), protocol_field_type::long_), - TextValueParam("signed max", "2147483647", std::int32_t(2147483647), protocol_field_type::long_), - TextValueParam("signed negative", "-20", std::int32_t(-20), protocol_field_type::long_), - TextValueParam("signed negative max", "-2147483648", std::int32_t(-2147483648), protocol_field_type::long_), + TextValueParam("signed_max", "2147483647", std::int32_t(2147483647), protocol_field_type::long_), + TextValueParam("signed_negative", "-20", std::int32_t(-20), protocol_field_type::long_), + TextValueParam("signed_negative_max", "-2147483648", std::int32_t(-2147483648), protocol_field_type::long_), TextValueParam("unsigned", "20", std::uint32_t(20), protocol_field_type::long_, column_flags::unsigned_), - TextValueParam("usigned min", "0", std::uint32_t(0), protocol_field_type::long_, column_flags::unsigned_), - TextValueParam("usigned max", "4294967295", std::uint32_t(4294967295), protocol_field_type::long_, column_flags::unsigned_), - TextValueParam("usigned zerofill", "0000067295", std::uint32_t(67295), protocol_field_type::long_, column_flags::unsigned_) -)); + TextValueParam("usigned_min", "0", std::uint32_t(0), protocol_field_type::long_, column_flags::unsigned_), + TextValueParam("usigned_max", "4294967295", std::uint32_t(4294967295), protocol_field_type::long_, column_flags::unsigned_), + TextValueParam("usigned_zerofill", "0000067295", std::uint32_t(67295), protocol_field_type::long_, column_flags::unsigned_) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(BIGINT, DeserializeTextValueTest, Values( TextValueParam("signed", "20", std::int64_t(20), protocol_field_type::longlong), - TextValueParam("signed max", "9223372036854775807", std::int64_t(9223372036854775807), protocol_field_type::longlong), - TextValueParam("signed negative", "-20", std::int64_t(-20), protocol_field_type::longlong), - TextValueParam("signed negative max", "-9223372036854775808", std::numeric_limits::min(), protocol_field_type::longlong), + TextValueParam("signed_max", "9223372036854775807", std::int64_t(9223372036854775807), protocol_field_type::longlong), + TextValueParam("signed_negative", "-20", std::int64_t(-20), protocol_field_type::longlong), + TextValueParam("signed_negative max", "-9223372036854775808", std::numeric_limits::min(), protocol_field_type::longlong), TextValueParam("unsigned", "20", std::uint64_t(20), protocol_field_type::longlong, column_flags::unsigned_), - TextValueParam("usigned min", "0", std::uint64_t(0), protocol_field_type::longlong, column_flags::unsigned_), - TextValueParam("usigned max", "18446744073709551615", std::uint64_t(18446744073709551615ULL), protocol_field_type::longlong, column_flags::unsigned_), - TextValueParam("usigned max", "000615", std::uint64_t(615), protocol_field_type::longlong, column_flags::unsigned_) -)); + TextValueParam("usigned_min", "0", std::uint64_t(0), protocol_field_type::longlong, column_flags::unsigned_), + TextValueParam("usigned_max", "18446744073709551615", std::uint64_t(18446744073709551615ULL), protocol_field_type::longlong, column_flags::unsigned_), + TextValueParam("usigned_zerofill", "000615", std::uint64_t(615), protocol_field_type::longlong, column_flags::unsigned_) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(FLOAT, DeserializeTextValueTest, Values( TextValueParam("zero", "0", 0.0f, protocol_field_type::float_), - TextValueParam("integer positive", "4", 4.0f, protocol_field_type::float_), - TextValueParam("integer negative", "-5", -5.0f, protocol_field_type::float_), - TextValueParam("fractional positive", "3.147", 3.147f, protocol_field_type::float_), - TextValueParam("fractional negative", "-3.147", -3.147f, protocol_field_type::float_), - TextValueParam("positive exponent positive integer", "3e20", 3e20f, protocol_field_type::float_), - TextValueParam("positive exponent negative integer", "-3e20", -3e20f, protocol_field_type::float_), - TextValueParam("positive exponent positive fractional", "3.14e20", 3.14e20f, protocol_field_type::float_), - TextValueParam("positive exponent negative fractional", "-3.45e20", -3.45e20f, protocol_field_type::float_), - TextValueParam("negative exponent positive integer", "3e-20", 3e-20f, protocol_field_type::float_), - TextValueParam("negative exponent negative integer", "-3e-20", -3e-20f, protocol_field_type::float_), - TextValueParam("negative exponent positive fractional", "3.14e-20", 3.14e-20f, protocol_field_type::float_), - TextValueParam("negative exponent negative fractional", "-3.45e-20", -3.45e-20f, protocol_field_type::float_) -)); + TextValueParam("integer_positive", "4", 4.0f, protocol_field_type::float_), + TextValueParam("integer_negative", "-5", -5.0f, protocol_field_type::float_), + TextValueParam("fractional_positive", "3.147", 3.147f, protocol_field_type::float_), + TextValueParam("fractional_negative", "-3.147", -3.147f, protocol_field_type::float_), + TextValueParam("positive_exponent_positive_integer", "3e20", 3e20f, protocol_field_type::float_), + TextValueParam("positive_exponent_negative_integer", "-3e20", -3e20f, protocol_field_type::float_), + TextValueParam("positive_exponent_positive_fractional", "3.14e20", 3.14e20f, protocol_field_type::float_), + TextValueParam("positive_exponent_negative_fractional", "-3.45e20", -3.45e20f, protocol_field_type::float_), + TextValueParam("negative_exponent_positive_integer", "3e-20", 3e-20f, protocol_field_type::float_), + TextValueParam("negative_exponent_negative_integer", "-3e-20", -3e-20f, protocol_field_type::float_), + TextValueParam("negative_exponent_positive_fractional", "3.14e-20", 3.14e-20f, protocol_field_type::float_), + TextValueParam("negative_exponent_negative_fractional", "-3.45e-20", -3.45e-20f, protocol_field_type::float_) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(DOUBLE, DeserializeTextValueTest, Values( TextValueParam("zero", "0", 0.0, protocol_field_type::double_), - TextValueParam("integer positive", "4", 4.0, protocol_field_type::double_), - TextValueParam("integer negative", "-5", -5.0, protocol_field_type::double_), - TextValueParam("fractional positive", "3.147", 3.147, protocol_field_type::double_), - TextValueParam("fractional negative", "-3.147", -3.147, protocol_field_type::double_), - TextValueParam("positive exponent positive integer", "3e20", 3e20, protocol_field_type::double_), - TextValueParam("positive exponent negative integer", "-3e20", -3e20, protocol_field_type::double_), - TextValueParam("positive exponent positive fractional", "3.14e20", 3.14e20, protocol_field_type::double_), - TextValueParam("positive exponent negative fractional", "-3.45e20", -3.45e20, protocol_field_type::double_), - TextValueParam("negative exponent positive integer", "3e-20", 3e-20, protocol_field_type::double_), - TextValueParam("negative exponent negative integer", "-3e-20", -3e-20, protocol_field_type::double_), - TextValueParam("negative exponent positive fractional", "3.14e-20", 3.14e-20, protocol_field_type::double_), - TextValueParam("negative exponent negative fractional", "-3.45e-20", -3.45e-20, protocol_field_type::double_) -)); + TextValueParam("integer_positive", "4", 4.0, protocol_field_type::double_), + TextValueParam("integer_negative", "-5", -5.0, protocol_field_type::double_), + TextValueParam("fractional_positive", "3.147", 3.147, protocol_field_type::double_), + TextValueParam("fractional_negative", "-3.147", -3.147, protocol_field_type::double_), + TextValueParam("positive_exponent_positive_integer", "3e20", 3e20, protocol_field_type::double_), + TextValueParam("positive_exponent_negative_integer", "-3e20", -3e20, protocol_field_type::double_), + TextValueParam("positive_exponent_positive_fractional", "3.14e20", 3.14e20, protocol_field_type::double_), + TextValueParam("positive_exponent_negative_fractional", "-3.45e20", -3.45e20, protocol_field_type::double_), + TextValueParam("negative_exponent_positive_integer", "3e-20", 3e-20, protocol_field_type::double_), + TextValueParam("negative_exponent_negative_integer", "-3e-20", -3e-20, protocol_field_type::double_), + TextValueParam("negative_exponent_positive_fractional", "3.14e-20", 3.14e-20, protocol_field_type::double_), + TextValueParam("negative_exponent_negative_fractional", "-3.45e-20", -3.45e-20, protocol_field_type::double_) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(DATE, DeserializeTextValueTest, Values( - TextValueParam("regular date", "2019-02-28", mysql::date(2019_y/2/28), protocol_field_type::date), - TextValueParam("leap year", "1788-02-29", mysql::date(1788_y/2/29), protocol_field_type::date), + TextValueParam("regular_date", "2019-02-28", mysql::date(2019_y/2/28), protocol_field_type::date), + TextValueParam("leap_year", "1788-02-29", mysql::date(1788_y/2/29), protocol_field_type::date), TextValueParam("min", "1000-01-01", mysql::date(1000_y/1/1), protocol_field_type::date), TextValueParam("max", "9999-12-31", mysql::date(9999_y/12/31), protocol_field_type::date), - TextValueParam("unofficial min", "0100-01-01", mysql::date(100_y/1/1), protocol_field_type::date) -)); + TextValueParam("unofficial_min", "0100-01-01", mysql::date(100_y/1/1), protocol_field_type::date) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(DATETIME, DeserializeTextValueTest, Values( - TextValueParam("0 decimals, only date", "2010-02-15 00:00:00", makedt(2010, 2, 15), protocol_field_type::datetime), - TextValueParam("0 decimals, date, h", "2010-02-15 02:00:00", makedt(2010, 2, 15, 2), protocol_field_type::datetime), - TextValueParam("0 decimals, date, hm", "2010-02-15 02:05:00", makedt(2010, 2, 15, 2, 5), protocol_field_type::datetime), - TextValueParam("0 decimals, date, hms", "2010-02-15 02:05:30", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime), - TextValueParam("0 decimals, min", "1000-01-01 00:00:00", makedt(1000, 1, 1), protocol_field_type::datetime), - TextValueParam("0 decimals, max", "9999-12-31 23:59:59", makedt(9999, 12, 31, 23, 59, 59), protocol_field_type::datetime), + TextValueParam("0_decimals_date", "2010-02-15 00:00:00", makedt(2010, 2, 15), protocol_field_type::datetime), + TextValueParam("0_decimals_h", "2010-02-15 02:00:00", makedt(2010, 2, 15, 2), protocol_field_type::datetime), + TextValueParam("0_decimals_hm", "2010-02-15 02:05:00", makedt(2010, 2, 15, 2, 5), protocol_field_type::datetime), + TextValueParam("0_decimals_hms", "2010-02-15 02:05:30", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime), + TextValueParam("0_decimals_min", "1000-01-01 00:00:00", makedt(1000, 1, 1), protocol_field_type::datetime), + TextValueParam("0_decimals_max", "9999-12-31 23:59:59", makedt(9999, 12, 31, 23, 59, 59), protocol_field_type::datetime), - TextValueParam("1 decimals, only date", "2010-02-15 00:00:00.0", makedt(2010, 2, 15), protocol_field_type::datetime, 0, 1), - TextValueParam("1 decimals, date, h", "2010-02-15 02:00:00.0", makedt(2010, 2, 15, 2), protocol_field_type::datetime, 0, 1), - TextValueParam("1 decimals, date, hm", "2010-02-15 02:05:00.0", makedt(2010, 2, 15, 2, 5), protocol_field_type::datetime, 0, 1), - TextValueParam("1 decimals, date, hms", "2010-02-15 02:05:30.0", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 1), - TextValueParam("1 decimals, date, hmsu", "2010-02-15 02:05:30.5", makedt(2010, 2, 15, 2, 5, 30, 500000), protocol_field_type::datetime, 0, 1), - TextValueParam("1 decimals, min", "1000-01-01 00:00:00.0", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 1), - TextValueParam("1 decimals, max", "9999-12-31 23:59:59.9", makedt(9999, 12, 31, 23, 59, 59, 900000), protocol_field_type::datetime, 0, 1), + TextValueParam("1_decimals_date", "2010-02-15 00:00:00.0", makedt(2010, 2, 15), protocol_field_type::datetime, 0, 1), + TextValueParam("1_decimals_h", "2010-02-15 02:00:00.0", makedt(2010, 2, 15, 2), protocol_field_type::datetime, 0, 1), + TextValueParam("1_decimals_hm", "2010-02-15 02:05:00.0", makedt(2010, 2, 15, 2, 5), protocol_field_type::datetime, 0, 1), + TextValueParam("1_decimals_hms", "2010-02-15 02:05:30.0", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 1), + TextValueParam("1_decimals_hmsu", "2010-02-15 02:05:30.5", makedt(2010, 2, 15, 2, 5, 30, 500000), protocol_field_type::datetime, 0, 1), + TextValueParam("1_decimals_min", "1000-01-01 00:00:00.0", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 1), + TextValueParam("1_decimals_max", "9999-12-31 23:59:59.9", makedt(9999, 12, 31, 23, 59, 59, 900000), protocol_field_type::datetime, 0, 1), - TextValueParam("2 decimals, date, hms", "2010-02-15 02:05:30.00", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 2), - TextValueParam("2 decimals, date, hmsu", "2010-02-15 02:05:30.05", makedt(2010, 2, 15, 2, 5, 30, 50000), protocol_field_type::datetime, 0, 2), - TextValueParam("2 decimals, min", "1000-01-01 00:00:00.00", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 2), - TextValueParam("2 decimals, max", "9999-12-31 23:59:59.99", makedt(9999, 12, 31, 23, 59, 59, 990000), protocol_field_type::datetime, 0, 2), + TextValueParam("2_decimals_hms", "2010-02-15 02:05:30.00", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 2), + TextValueParam("2_decimals_hmsu", "2010-02-15 02:05:30.05", makedt(2010, 2, 15, 2, 5, 30, 50000), protocol_field_type::datetime, 0, 2), + TextValueParam("2_decimals_min", "1000-01-01 00:00:00.00", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 2), + TextValueParam("2_decimals_max", "9999-12-31 23:59:59.99", makedt(9999, 12, 31, 23, 59, 59, 990000), protocol_field_type::datetime, 0, 2), - TextValueParam("3 decimals, date, hms", "2010-02-15 02:05:30.000", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 3), - TextValueParam("3 decimals, date, hmsu", "2010-02-15 02:05:30.420", makedt(2010, 2, 15, 2, 5, 30, 420000), protocol_field_type::datetime, 0, 3), - TextValueParam("3 decimals, min", "1000-01-01 00:00:00.000", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 3), - TextValueParam("3 decimals, max", "9999-12-31 23:59:59.999", makedt(9999, 12, 31, 23, 59, 59, 999000), protocol_field_type::datetime, 0, 3), + TextValueParam("3_decimals_hms", "2010-02-15 02:05:30.000", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 3), + TextValueParam("3_decimals_hmsu", "2010-02-15 02:05:30.420", makedt(2010, 2, 15, 2, 5, 30, 420000), protocol_field_type::datetime, 0, 3), + TextValueParam("3_decimals_min", "1000-01-01 00:00:00.000", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 3), + TextValueParam("3_decimals_max", "9999-12-31 23:59:59.999", makedt(9999, 12, 31, 23, 59, 59, 999000), protocol_field_type::datetime, 0, 3), - TextValueParam("4 decimals, date, hms", "2010-02-15 02:05:30.0000", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 4), - TextValueParam("4 decimals, date, hmsu", "2010-02-15 02:05:30.4267", makedt(2010, 2, 15, 2, 5, 30, 426700), protocol_field_type::datetime, 0, 4), - TextValueParam("4 decimals, min", "1000-01-01 00:00:00.0000", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 4), - TextValueParam("4 decimals, max", "9999-12-31 23:59:59.9999", makedt(9999, 12, 31, 23, 59, 59, 999900), protocol_field_type::datetime, 0, 4), + TextValueParam("4_decimals_hms", "2010-02-15 02:05:30.0000", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 4), + TextValueParam("4_decimals_hmsu", "2010-02-15 02:05:30.4267", makedt(2010, 2, 15, 2, 5, 30, 426700), protocol_field_type::datetime, 0, 4), + TextValueParam("4_decimals_min", "1000-01-01 00:00:00.0000", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 4), + TextValueParam("4_decimals_max", "9999-12-31 23:59:59.9999", makedt(9999, 12, 31, 23, 59, 59, 999900), protocol_field_type::datetime, 0, 4), - TextValueParam("5 decimals, date, hms", "2010-02-15 02:05:30.00000", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 5), - TextValueParam("5 decimals, date, hmsu", "2010-02-15 02:05:30.00239", makedt(2010, 2, 15, 2, 5, 30, 2390), protocol_field_type::datetime, 0, 5), - TextValueParam("5 decimals, min", "1000-01-01 00:00:00.00000", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 5), - TextValueParam("5 decimals, max", "9999-12-31 23:59:59.99999", makedt(9999, 12, 31, 23, 59, 59, 999990), protocol_field_type::datetime, 0, 5), + TextValueParam("5_decimals_hms", "2010-02-15 02:05:30.00000", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 5), + TextValueParam("5_decimals_hmsu", "2010-02-15 02:05:30.00239", makedt(2010, 2, 15, 2, 5, 30, 2390), protocol_field_type::datetime, 0, 5), + TextValueParam("5_decimals_min", "1000-01-01 00:00:00.00000", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 5), + TextValueParam("5_decimals_max", "9999-12-31 23:59:59.99999", makedt(9999, 12, 31, 23, 59, 59, 999990), protocol_field_type::datetime, 0, 5), - TextValueParam("6 decimals, date, hms", "2010-02-15 02:05:30.000000", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 6), - TextValueParam("6 decimals, date, hmsu", "2010-02-15 02:05:30.002395", makedt(2010, 2, 15, 2, 5, 30, 2395), protocol_field_type::datetime, 0, 6), - TextValueParam("6 decimals, min", "1000-01-01 00:00:00.000000", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 6), - TextValueParam("6 decimals, max", "9999-12-31 23:59:59.999999", makedt(9999, 12, 31, 23, 59, 59, 999999), protocol_field_type::datetime, 0, 6) -)); + TextValueParam("6_decimals_hms", "2010-02-15 02:05:30.000000", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::datetime, 0, 6), + TextValueParam("6_decimals_hmsu", "2010-02-15 02:05:30.002395", makedt(2010, 2, 15, 2, 5, 30, 2395), protocol_field_type::datetime, 0, 6), + TextValueParam("6_decimals_min", "1000-01-01 00:00:00.000000", makedt(1000, 1, 1), protocol_field_type::datetime, 0, 6), + TextValueParam("6_decimals_max", "9999-12-31 23:59:59.999999", makedt(9999, 12, 31, 23, 59, 59, 999999), protocol_field_type::datetime, 0, 6) +), test_name_generator); // Right now, timestamps are deserialized as DATETIMEs. TODO: update this when we consider time zones INSTANTIATE_TEST_SUITE_P(TIMESTAMP, DeserializeTextValueTest, Values( - TextValueParam("0 decimals", "2010-02-15 02:05:30", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::timestamp), - TextValueParam("6 decimals", "2010-02-15 02:05:30.085670", makedt(2010, 2, 15, 2, 5, 30, 85670), protocol_field_type::timestamp, 0, 6), - TextValueParam("6 decimals, min", "1970-01-01 00:00:01.000000", makedt(1970, 1, 1, 0, 0, 1), protocol_field_type::timestamp, 0, 6), - TextValueParam("6 decimals, max", "2038-01-19 03:14:07.999999", makedt(2038, 1, 19, 3, 14, 7, 999999), protocol_field_type::timestamp, 0, 6) -)); + TextValueParam("0_decimals", "2010-02-15 02:05:30", makedt(2010, 2, 15, 2, 5, 30), protocol_field_type::timestamp), + TextValueParam("6_decimals", "2010-02-15 02:05:30.085670", makedt(2010, 2, 15, 2, 5, 30, 85670), protocol_field_type::timestamp, 0, 6), + TextValueParam("6_decimals_min", "1970-01-01 00:00:01.000000", makedt(1970, 1, 1, 0, 0, 1), protocol_field_type::timestamp, 0, 6), + TextValueParam("6_decimals_max", "2038-01-19 03:14:07.999999", makedt(2038, 1, 19, 3, 14, 7, 999999), protocol_field_type::timestamp, 0, 6) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(TIME, DeserializeTextValueTest, Values( - TextValueParam("0 decimals, positive h", "01:00:00", maket(1, 0, 0), protocol_field_type::time), - TextValueParam("0 decimals, positive hm", "12:03:00", maket(12, 3, 0), protocol_field_type::time), - TextValueParam("0 decimals, positive hms", "14:51:23", maket(14, 51, 23), protocol_field_type::time), - TextValueParam("0 decimals, max", "838:59:59", maket(838, 59, 59), protocol_field_type::time), - TextValueParam("0 decimals, negative h", "-06:00:00", -maket(6, 0, 0), protocol_field_type::time), - TextValueParam("0 decimals, negative hm", "-12:03:00", -maket(12, 3, 0), protocol_field_type::time), - TextValueParam("0 decimals, negative hms", "-14:51:23", -maket(14, 51, 23), protocol_field_type::time), - TextValueParam("0 decimals, min", "-838:59:59", -maket(838, 59, 59), protocol_field_type::time), - TextValueParam("0 decimals, zero", "00:00:00", maket(0, 0, 0), protocol_field_type::time), + TextValueParam("0_decimals_positive_h", "01:00:00", maket(1, 0, 0), protocol_field_type::time), + TextValueParam("0_decimals_positive_hm", "12:03:00", maket(12, 3, 0), protocol_field_type::time), + TextValueParam("0_decimals_positive_hms", "14:51:23", maket(14, 51, 23), protocol_field_type::time), + TextValueParam("0_decimals_max", "838:59:59", maket(838, 59, 59), protocol_field_type::time), + TextValueParam("0_decimals_negative_h", "-06:00:00", -maket(6, 0, 0), protocol_field_type::time), + TextValueParam("0_decimals_negative_hm", "-12:03:00", -maket(12, 3, 0), protocol_field_type::time), + TextValueParam("0_decimals_negative_hms", "-14:51:23", -maket(14, 51, 23), protocol_field_type::time), + TextValueParam("0_decimals_min", "-838:59:59", -maket(838, 59, 59), protocol_field_type::time), + TextValueParam("0_decimals_zero", "00:00:00", maket(0, 0, 0), protocol_field_type::time), - TextValueParam("1 decimals, positive hms", "14:51:23.0", maket(14, 51, 23), protocol_field_type::time, 0, 1), - TextValueParam("1 decimals, positive hmsu", "14:51:23.5", maket(14, 51, 23, 500000), protocol_field_type::time, 0, 1), - TextValueParam("1 decimals, max", "838:59:58.9", maket(838, 59, 58, 900000), protocol_field_type::time, 0, 1), - TextValueParam("1 decimals, negative hms", "-14:51:23.0", -maket(14, 51, 23), protocol_field_type::time, 0, 1), - TextValueParam("1 decimals, negative hmsu", "-14:51:23.5", -maket(14, 51, 23, 500000), protocol_field_type::time, 0, 1), - TextValueParam("1 decimals, min", "-838:59:58.9", -maket(838, 59, 58, 900000), protocol_field_type::time, 0, 1), - TextValueParam("1 decimals, zero", "00:00:00.0", maket(0, 0, 0), protocol_field_type::time, 0, 1), + TextValueParam("1_decimals_positive_hms", "14:51:23.0", maket(14, 51, 23), protocol_field_type::time, 0, 1), + TextValueParam("1_decimals_positive_hmsu", "14:51:23.5", maket(14, 51, 23, 500000), protocol_field_type::time, 0, 1), + TextValueParam("1_decimals_max", "838:59:58.9", maket(838, 59, 58, 900000), protocol_field_type::time, 0, 1), + TextValueParam("1_decimals_negative_hms", "-14:51:23.0", -maket(14, 51, 23), protocol_field_type::time, 0, 1), + TextValueParam("1_decimals_negative_hmsu", "-14:51:23.5", -maket(14, 51, 23, 500000), protocol_field_type::time, 0, 1), + TextValueParam("1_decimals_min", "-838:59:58.9", -maket(838, 59, 58, 900000), protocol_field_type::time, 0, 1), + TextValueParam("1_decimals_zero", "00:00:00.0", maket(0, 0, 0), protocol_field_type::time, 0, 1), - TextValueParam("2 decimals, positive hms", "14:51:23.00", maket(14, 51, 23), protocol_field_type::time, 0, 2), - TextValueParam("2 decimals, positive hmsu", "14:51:23.52", maket(14, 51, 23, 520000), protocol_field_type::time, 0, 2), - TextValueParam("2 decimals, max", "838:59:58.99", maket(838, 59, 58, 990000), protocol_field_type::time, 0, 2), - TextValueParam("2 decimals, negative hms", "-14:51:23.00", -maket(14, 51, 23), protocol_field_type::time, 0, 2), - TextValueParam("2 decimals, negative hmsu", "-14:51:23.50", -maket(14, 51, 23, 500000), protocol_field_type::time, 0, 2), - TextValueParam("2 decimals, min", "-838:59:58.99", -maket(838, 59, 58, 990000), protocol_field_type::time, 0, 2), - TextValueParam("2 decimals, zero", "00:00:00.00", maket(0, 0, 0), protocol_field_type::time, 0, 2), + TextValueParam("2_decimals_positive_hms", "14:51:23.00", maket(14, 51, 23), protocol_field_type::time, 0, 2), + TextValueParam("2_decimals_positive_hmsu", "14:51:23.52", maket(14, 51, 23, 520000), protocol_field_type::time, 0, 2), + TextValueParam("2_decimals_max", "838:59:58.99", maket(838, 59, 58, 990000), protocol_field_type::time, 0, 2), + TextValueParam("2_decimals_negative_hms", "-14:51:23.00", -maket(14, 51, 23), protocol_field_type::time, 0, 2), + TextValueParam("2_decimals_negative_hmsu", "-14:51:23.50", -maket(14, 51, 23, 500000), protocol_field_type::time, 0, 2), + TextValueParam("2_decimals_min", "-838:59:58.99", -maket(838, 59, 58, 990000), protocol_field_type::time, 0, 2), + TextValueParam("2_decimals_zero", "00:00:00.00", maket(0, 0, 0), protocol_field_type::time, 0, 2), - TextValueParam("3 decimals, positive hms", "14:51:23.000", maket(14, 51, 23), protocol_field_type::time, 0, 3), - TextValueParam("3 decimals, positive hmsu", "14:51:23.501", maket(14, 51, 23, 501000), protocol_field_type::time, 0, 3), - TextValueParam("3 decimals, max", "838:59:58.999", maket(838, 59, 58, 999000), protocol_field_type::time, 0, 3), - TextValueParam("3 decimals, negative hms", "-14:51:23.000", -maket(14, 51, 23), protocol_field_type::time, 0, 3), - TextValueParam("3 decimals, negative hmsu", "-14:51:23.003", -maket(14, 51, 23, 3000), protocol_field_type::time, 0, 3), - TextValueParam("3 decimals, min", "-838:59:58.999", -maket(838, 59, 58, 999000), protocol_field_type::time, 0, 3), - TextValueParam("3 decimals, zero", "00:00:00.000", maket(0, 0, 0), protocol_field_type::time, 0, 3), + TextValueParam("3_decimals_positive_hms", "14:51:23.000", maket(14, 51, 23), protocol_field_type::time, 0, 3), + TextValueParam("3_decimals_positive_hmsu", "14:51:23.501", maket(14, 51, 23, 501000), protocol_field_type::time, 0, 3), + TextValueParam("3_decimals_max", "838:59:58.999", maket(838, 59, 58, 999000), protocol_field_type::time, 0, 3), + TextValueParam("3_decimals_negative_hms", "-14:51:23.000", -maket(14, 51, 23), protocol_field_type::time, 0, 3), + TextValueParam("3_decimals_negative_hmsu", "-14:51:23.003", -maket(14, 51, 23, 3000), protocol_field_type::time, 0, 3), + TextValueParam("3_decimals_min", "-838:59:58.999", -maket(838, 59, 58, 999000), protocol_field_type::time, 0, 3), + TextValueParam("3_decimals_zero", "00:00:00.000", maket(0, 0, 0), protocol_field_type::time, 0, 3), - TextValueParam("4 decimals, positive hms", "14:51:23.0000", maket(14, 51, 23), protocol_field_type::time, 0, 4), - TextValueParam("4 decimals, positive hmsu", "14:51:23.5017", maket(14, 51, 23, 501700), protocol_field_type::time, 0, 4), - TextValueParam("4 decimals, max", "838:59:58.9999", maket(838, 59, 58, 999900), protocol_field_type::time, 0, 4), - TextValueParam("4 decimals, negative hms", "-14:51:23.0000", -maket(14, 51, 23), protocol_field_type::time, 0, 4), - TextValueParam("4 decimals, negative hmsu", "-14:51:23.0038", -maket(14, 51, 23, 3800), protocol_field_type::time, 0, 4), - TextValueParam("4 decimals, min", "-838:59:58.9999", -maket(838, 59, 58, 999900), protocol_field_type::time, 0, 4), - TextValueParam("4 decimals, zero", "00:00:00.0000", maket(0, 0, 0), protocol_field_type::time, 0, 4), + TextValueParam("4_decimals_positive_hms", "14:51:23.0000", maket(14, 51, 23), protocol_field_type::time, 0, 4), + TextValueParam("4_decimals_positive_hmsu", "14:51:23.5017", maket(14, 51, 23, 501700), protocol_field_type::time, 0, 4), + TextValueParam("4_decimals_max", "838:59:58.9999", maket(838, 59, 58, 999900), protocol_field_type::time, 0, 4), + TextValueParam("4_decimals_negative_hms", "-14:51:23.0000", -maket(14, 51, 23), protocol_field_type::time, 0, 4), + TextValueParam("4_decimals_negative_hmsu", "-14:51:23.0038", -maket(14, 51, 23, 3800), protocol_field_type::time, 0, 4), + TextValueParam("4_decimals_min", "-838:59:58.9999", -maket(838, 59, 58, 999900), protocol_field_type::time, 0, 4), + TextValueParam("4_decimals_zero", "00:00:00.0000", maket(0, 0, 0), protocol_field_type::time, 0, 4), - TextValueParam("5 decimals, positive hms", "14:51:23.00000", maket(14, 51, 23), protocol_field_type::time, 0, 5), - TextValueParam("5 decimals, positive hmsu", "14:51:23.50171", maket(14, 51, 23, 501710), protocol_field_type::time, 0, 5), - TextValueParam("5 decimals, max", "838:59:58.99999", maket(838, 59, 58, 999990), protocol_field_type::time, 0, 5), - TextValueParam("5 decimals, negative hms", "-14:51:23.00000", -maket(14, 51, 23), protocol_field_type::time, 0, 5), - TextValueParam("5 decimals, negative hmsu", "-14:51:23.00009", -maket(14, 51, 23, 90), protocol_field_type::time, 0, 5), - TextValueParam("5 decimals, min", "-838:59:58.99999", -maket(838, 59, 58, 999990), protocol_field_type::time, 0, 5), - TextValueParam("5 decimals, zero", "00:00:00.00000", maket(0, 0, 0), protocol_field_type::time, 0, 5), + TextValueParam("5_decimals_positive_hms", "14:51:23.00000", maket(14, 51, 23), protocol_field_type::time, 0, 5), + TextValueParam("5_decimals_positive_hmsu", "14:51:23.50171", maket(14, 51, 23, 501710), protocol_field_type::time, 0, 5), + TextValueParam("5_decimals_max", "838:59:58.99999", maket(838, 59, 58, 999990), protocol_field_type::time, 0, 5), + TextValueParam("5_decimals_negative_hms", "-14:51:23.00000", -maket(14, 51, 23), protocol_field_type::time, 0, 5), + TextValueParam("5_decimals_negative_hmsu", "-14:51:23.00009", -maket(14, 51, 23, 90), protocol_field_type::time, 0, 5), + TextValueParam("5_decimals_min", "-838:59:58.99999", -maket(838, 59, 58, 999990), protocol_field_type::time, 0, 5), + TextValueParam("5_decimals_zero", "00:00:00.00000", maket(0, 0, 0), protocol_field_type::time, 0, 5), - TextValueParam("6 decimals, positive hms", "14:51:23.000000", maket(14, 51, 23), protocol_field_type::time, 0, 6), - TextValueParam("6 decimals, positive hmsu", "14:51:23.501717", maket(14, 51, 23, 501717), protocol_field_type::time, 0, 6), - TextValueParam("6 decimals, max", "838:59:58.999999", maket(838, 59, 58, 999999), protocol_field_type::time, 0, 6), - TextValueParam("6 decimals, negative hms", "-14:51:23.000000", -maket(14, 51, 23), protocol_field_type::time, 0, 6), - TextValueParam("6 decimals, negative hmsu", "-14:51:23.900000", -maket(14, 51, 23, 900000), protocol_field_type::time, 0, 6), - TextValueParam("6 decimals, min", "-838:59:58.999999", -maket(838, 59, 58, 999999), protocol_field_type::time, 0, 6), - TextValueParam("6 decimals, zero", "00:00:00.000000", maket(0, 0, 0), protocol_field_type::time, 0, 6) -)); + TextValueParam("6_decimals_positive_hms", "14:51:23.000000", maket(14, 51, 23), protocol_field_type::time, 0, 6), + TextValueParam("6_decimals_positive_hmsu", "14:51:23.501717", maket(14, 51, 23, 501717), protocol_field_type::time, 0, 6), + TextValueParam("6_decimals_max", "838:59:58.999999", maket(838, 59, 58, 999999), protocol_field_type::time, 0, 6), + TextValueParam("6_decimals_negative_hms", "-14:51:23.000000", -maket(14, 51, 23), protocol_field_type::time, 0, 6), + TextValueParam("6_decimals_negative_hmsu", "-14:51:23.900000", -maket(14, 51, 23, 900000), protocol_field_type::time, 0, 6), + TextValueParam("6_decimals_min", "-838:59:58.999999", -maket(838, 59, 58, 999999), protocol_field_type::time, 0, 6), + TextValueParam("6_decimals_zero", "00:00:00.000000", maket(0, 0, 0), protocol_field_type::time, 0, 6) +), test_name_generator); INSTANTIATE_TEST_SUITE_P(YEAR, DeserializeTextValueTest, Values( - TextValueParam("regular value", "1999", std::uint32_t(1999), protocol_field_type::year, column_flags::unsigned_), + TextValueParam("regular_value", "1999", std::uint32_t(1999), protocol_field_type::year, column_flags::unsigned_), TextValueParam("min", "1901", std::uint32_t(1901), protocol_field_type::year, column_flags::unsigned_), TextValueParam("max", "2155", std::uint32_t(2155), protocol_field_type::year, column_flags::unsigned_), TextValueParam("zero", "0000", std::uint32_t(0), protocol_field_type::year, column_flags::unsigned_) -)); +), test_name_generator); struct DeserializeTextRowTest : public Test {