From 2bdc25752fbb593ea0625c1df87f7d568dff0fa9 Mon Sep 17 00:00:00 2001 From: Marcelo Zimbres Date: Sun, 6 Nov 2022 22:40:00 +0100 Subject: [PATCH] Simplifications in the low-level tests. --- tests/low_level.cpp | 205 ++++++++++++++++++++++++-------------------- 1 file changed, 110 insertions(+), 95 deletions(-) diff --git a/tests/low_level.cpp b/tests/low_level.cpp index 831de234..794f5a06 100644 --- a/tests/low_level.cpp +++ b/tests/low_level.cpp @@ -119,8 +119,6 @@ void test_async(net::any_io_executor ex, expect e) std::optional op_int_ok = 11; std::optional op_bool_ok = true; -std::string const streamed_string_wire = "$?\r\n;4\r\nHell\r\n;5\r\no wor\r\n;1\r\nd\r\n;0\r\n"; -std::string const streamed_string_wire_error = "$?\r\n;b\r\nHell\r\n;5\r\no wor\r\n;1\r\nd\r\n;0\r\n"; // TODO: Test a streamed string that is not finished with a string of // size 0 but other command comes in. std::vector streamed_string_e1 @@ -132,40 +130,68 @@ std::vector streamed_string_e1 std::vector streamed_string_e2 { {resp3::type::streamed_string_part, 1UL, 1UL, {}} }; +#define S01 "#11\r\n" +#define S02 "#f\r\n" +#define S03 "#t\r\n" +#define S04 "$?\r\n;0\r\n" +#define S05 "%11\r\n" +#define S06 "$?\r\n;4\r\nHell\r\n;5\r\no wor\r\n;1\r\nd\r\n;0\r\n" +#define S07 "$?\r\n;b\r\nHell\r\n;5\r\no wor\r\n;1\r\nd\r\n;0\r\n" +#define S08 "*1\r\n:11\r\n" +#define S09 ":-3\r\n" +#define S10 ":11\r\n" +#define S11 ":3\r\n" +#define S12 "_\r\n" +#define S13 ">4\r\n+pubsub\r\n+message\r\n+some-channel\r\n+some message\r\n" +#define S14 ">0\r\n" +#define S15 "*3\r\n$2\r\n11\r\n$2\r\n22\r\n$1\r\n3\r\n" +#define S16 "%4\r\n$4\r\nkey1\r\n$6\r\nvalue1\r\n$4\r\nkey2\r\n$6\r\nvalue2\r\n$4\r\nkey3\r\n$6\r\nvalue3\r\n$4\r\nkey3\r\n$6\r\nvalue3\r\n" +#define S17 "*1\r\n" S16 +#define S18 "|1\r\n+key-popularity\r\n%2\r\n$1\r\na\r\n,0.1923\r\n$1\r\nb\r\n,0.0012\r\n" +#define S19 "|0\r\n" +#define S20 "*3\r\n$2\r\n11\r\n$2\r\n22\r\n$1\r\n3\r\n" +#define S21 "*1\r\n*1\r\n$2\r\nab\r\n" +#define S22 "*1\r\n*1\r\n*1\r\n*1\r\n*1\r\n*1\r\na\r\n" +#define S23 "*0\r\n" +#define S24 "*3\r\n$2\r\n11\r\n$2\r\n22\r\n$1\r\n3\r\n" +#define S25 "~6\r\n+orange\r\n+apple\r\n+one\r\n+two\r\n+three\r\n+orange\r\n" +#define S26 "*1\r\n" S25 +#define S27 "~0\r\n" +#define S28 "-Error\r\n" +#define S29 "-\r\n" #define NUMBER_TEST_CONDITIONS(test) \ - test(ex, make_expected("#11\r\n", std::optional{}, "bool.error", aedis::error::unexpected_bool_value)); \ - test(ex, make_expected("#f\r\n", bool{false}, "bool.bool (true)")); \ - test(ex, make_expected("#f\r\n", node_type{resp3::type::boolean, 1UL, 0UL, {"f"}}, "bool.node (false)")); \ - test(ex, make_expected("#t\r\n", bool{true}, "bool.bool (true)")); \ - test(ex, make_expected("#t\r\n", node_type{resp3::type::boolean, 1UL, 0UL, {"t"}}, "bool.node (true)")); \ - test(ex, make_expected("#t\r\n", op_bool_ok, "optional.int")); \ - test(ex, make_expected("#t\r\n", std::map{}, "bool.error", aedis::error::expects_resp3_map)); \ - test(ex, make_expected("#t\r\n", std::set{}, "bool.error", aedis::error::expects_resp3_set)); \ - test(ex, make_expected("#t\r\n", std::unordered_map{}, "bool.error", aedis::error::expects_resp3_map)); \ - test(ex, make_expected("#t\r\n", std::unordered_set{}, "bool.error", aedis::error::expects_resp3_set)); \ - test(ex, make_expected("$?\r\n;0\r\n", streamed_string_e2, "streamed_string.node.empty")); \ - test(ex, make_expected("%11\r\n", std::optional{}, "number.optional.int.error", aedis::error::expects_resp3_simple_type));; \ - test(ex, make_expected("*1\r\n:11\r\n", std::tuple{11}, "number.tuple.int")); \ - test(ex, make_expected(":-3\r\n", node_type{resp3::type::number, 1UL, 0UL, {"-3"}}, "number.node (negative)")); \ - test(ex, make_expected(":11\r\n", int{11}, "number.int")); \ - test(ex, make_expected(":11\r\n", op_int_ok, "number.optional.int")); \ - test(ex, make_expected(":11\r\n", std::list{}, "number.optional.int", aedis::error::expects_resp3_aggregate)); \ - test(ex, make_expected(":11\r\n", std::map{}, "number.optional.int", aedis::error::expects_resp3_map)); \ - test(ex, make_expected(":11\r\n", std::set{}, "number.optional.int", aedis::error::expects_resp3_set)); \ - test(ex, make_expected(":11\r\n", std::unordered_map{}, "number.optional.int", aedis::error::expects_resp3_map)); \ - test(ex, make_expected(":11\r\n", std::unordered_set{}, "number.optional.int", aedis::error::expects_resp3_set)); \ - test(ex, make_expected(":3\r\n", node_type{resp3::type::number, 1UL, 0UL, {"3"}}, "number.node (positive)")); \ - test(ex, make_expected("_\r\n", int{0}, "number.int.error.null", aedis::error::resp3_null)); \ - test(ex, make_expected(streamed_string_wire, std::string{"Hello word"}, "streamed_string.string")); \ - test(ex, make_expected(streamed_string_wire, int{}, "streamed_string.string", aedis::error::not_a_number)); \ - test(ex, make_expected(streamed_string_wire, streamed_string_e1, "streamed_string.node")); \ - test(ex, make_expected(streamed_string_wire_error, std::string{}, "streamed_string.error", aedis::error::not_a_number)); \ + test(ex, make_expected(S01, std::optional{}, "bool.error", aedis::error::unexpected_bool_value)); \ + test(ex, make_expected(S02, bool{false}, "bool.bool (true)")); \ + test(ex, make_expected(S02, node_type{resp3::type::boolean, 1UL, 0UL, {"f"}}, "bool.node (false)")); \ + test(ex, make_expected(S03, bool{true}, "bool.bool (true)")); \ + test(ex, make_expected(S03, node_type{resp3::type::boolean, 1UL, 0UL, {"t"}}, "bool.node (true)")); \ + test(ex, make_expected(S03, op_bool_ok, "optional.int")); \ + test(ex, make_expected(S03, std::map{}, "bool.error", aedis::error::expects_resp3_map)); \ + test(ex, make_expected(S03, std::set{}, "bool.error", aedis::error::expects_resp3_set)); \ + test(ex, make_expected(S03, std::unordered_map{}, "bool.error", aedis::error::expects_resp3_map)); \ + test(ex, make_expected(S03, std::unordered_set{}, "bool.error", aedis::error::expects_resp3_set)); \ + test(ex, make_expected(S04, streamed_string_e2, "streamed_string.node.empty")); \ + test(ex, make_expected(S05, std::optional{}, "number.optional.int.error", aedis::error::expects_resp3_simple_type));; \ + test(ex, make_expected(S06, int{}, "streamed_string.string", aedis::error::not_a_number)); \ + test(ex, make_expected(S06, std::string{"Hello word"}, "streamed_string.string")); \ + test(ex, make_expected(S06, streamed_string_e1, "streamed_string.node")); \ + test(ex, make_expected(S07, std::string{}, "streamed_string.error", aedis::error::not_a_number)); \ + test(ex, make_expected(S08, std::tuple{11}, "number.tuple.int")); \ + test(ex, make_expected(S09, node_type{resp3::type::number, 1UL, 0UL, {"-3"}}, "number.node (negative)")); \ + test(ex, make_expected(S10, int{11}, "number.int")); \ + test(ex, make_expected(S10, op_int_ok, "number.optional.int")); \ + test(ex, make_expected(S10, std::list{}, "number.optional.int", aedis::error::expects_resp3_aggregate)); \ + test(ex, make_expected(S10, std::map{}, "number.optional.int", aedis::error::expects_resp3_map)); \ + test(ex, make_expected(S10, std::set{}, "number.optional.int", aedis::error::expects_resp3_set)); \ + test(ex, make_expected(S10, std::unordered_map{}, "number.optional.int", aedis::error::expects_resp3_map)); \ + test(ex, make_expected(S10, std::unordered_set{}, "number.optional.int", aedis::error::expects_resp3_set)); \ + test(ex, make_expected(S11, node_type{resp3::type::number, 1UL, 0UL, {"3"}}, "number.node (positive)")); \ + test(ex, make_expected(S12, int{0}, "number.int.error.null", aedis::error::resp3_null)); \ BOOST_AUTO_TEST_CASE(test_push) { net::io_context ioc; - std::string const wire = ">4\r\n+pubsub\r\n+message\r\n+some-channel\r\n+some message\r\n"; std::vector e1a { {resp3::type::push, 4UL, 0UL, {}} @@ -177,8 +203,8 @@ BOOST_AUTO_TEST_CASE(test_push) std::vector e1b { {resp3::type::push, 0UL, 0UL, {}} }; - auto const in01 = expect>{wire, e1a, "push.node"}; - auto const in02 = expect>{">0\r\n", e1b, "push.node.empty"}; + auto const in01 = expect>{S13, e1a, "push.node"}; + auto const in02 = expect>{S14, e1b, "push.node.empty"}; auto ex = ioc.get_executor(); @@ -202,9 +228,6 @@ BOOST_AUTO_TEST_CASE(test_map) using op_vec_type = std::optional>; using tuple_type = std::tuple; - std::string const wire2 = "*3\r\n$2\r\n11\r\n$2\r\n22\r\n$1\r\n3\r\n"; - std::string const wire = "%4\r\n$4\r\nkey1\r\n$6\r\nvalue1\r\n$4\r\nkey2\r\n$6\r\nvalue2\r\n$4\r\nkey3\r\n$6\r\nvalue3\r\n$4\r\nkey3\r\n$6\r\nvalue3\r\n"; - std::vector expected_1a { {resp3::type::map, 4UL, 0UL, {}} , {resp3::type::blob_string, 1UL, 1UL, {"key1"}} @@ -263,20 +286,20 @@ BOOST_AUTO_TEST_CASE(test_map) , std::string{"key3"}, std::string{"value3"} }; - auto const in00 = expect>{wire, expected_1a, "map.node"}; + auto const in00 = expect>{S16, expected_1a, "map.node"}; auto const in01 = expect{"%0\r\n", map_type{}, "map.map.empty"}; - auto const in02 = expect{wire, expected_1b, "map.map"}; - auto const in03 = expect{wire, e1k, "map.multimap"}; - auto const in04 = expect{wire, e1g, "map.unordered_map"}; - auto const in05 = expect{wire, e1l, "map.unordered_multimap"}; - auto const in06 = expect{wire, expected_1c, "map.vector"}; - auto const in07 = expect{wire, expected_1d, "map.optional.map"}; - auto const in08 = expect{wire, expected_1e, "map.optional.vector"}; - auto const in09 = expect>{"*1\r\n" + wire, std::tuple{expected_1d}, "map.transaction.optional.map"}; + auto const in02 = expect{S16, expected_1b, "map.map"}; + auto const in03 = expect{S16, e1k, "map.multimap"}; + auto const in04 = expect{S16, e1g, "map.unordered_map"}; + auto const in05 = expect{S16, e1l, "map.unordered_multimap"}; + auto const in06 = expect{S16, expected_1c, "map.vector"}; + auto const in07 = expect{S16, expected_1d, "map.optional.map"}; + auto const in08 = expect{S16, expected_1e, "map.optional.vector"}; + auto const in09 = expect>{S17, std::tuple{expected_1d}, "map.transaction.optional.map"}; auto const in10 = expect{"%11\r\n", int{}, "map.invalid.int", aedis::error::expects_resp3_simple_type}; - auto const in11 = expect{wire, e1f, "map.tuple"}; - auto const in12 = expect{wire2, map_type{}, "map.error", aedis::error::expects_resp3_map}; - auto const in13 = expect{"_\r\n", map_type{}, "map.null", aedis::error::resp3_null}; + auto const in11 = expect{S16, e1f, "map.tuple"}; + auto const in12 = expect{S15, map_type{}, "map.error", aedis::error::expects_resp3_map}; + auto const in13 = expect{S12, map_type{}, "map.null", aedis::error::resp3_null}; auto ex = ioc.get_executor(); @@ -314,8 +337,6 @@ BOOST_AUTO_TEST_CASE(test_map) void test_attribute(net::io_context& ioc) { - char const* wire = "|1\r\n+key-popularity\r\n%2\r\n$1\r\na\r\n,0.1923\r\n$1\r\nb\r\n,0.0012\r\n"; - std::vector e1a { {resp3::type::attribute, 1UL, 0UL, {}} , {resp3::type::simple_string, 1UL, 1UL, "key-popularity"} @@ -328,8 +349,8 @@ void test_attribute(net::io_context& ioc) std::vector e1b; - auto const in01 = expect>{wire, e1a, "attribute.node"}; - auto const in02 = expect>{"|0\r\n", e1b, "attribute.node.empty"}; + auto const in01 = expect>{S18, e1a, "attribute.node"}; + auto const in02 = expect>{S19, e1b, "attribute.node.empty"}; auto ex = ioc.get_executor(); @@ -347,9 +368,6 @@ BOOST_AUTO_TEST_CASE(test_array) using array_type2 = std::array; net::io_context ioc; - char const* wire = "*3\r\n$2\r\n11\r\n$2\r\n22\r\n$1\r\n3\r\n"; - char const* wire_nested = "*1\r\n*1\r\n$2\r\nab\r\n"; - char const* wire_nested2 = "*1\r\n*1\r\n*1\r\n*1\r\n*1\r\n*1\r\na\r\n"; std::vector e1a { {resp3::type::array, 3UL, 0UL, {}} @@ -366,22 +384,22 @@ BOOST_AUTO_TEST_CASE(test_array) std::list const e1g{11, 22, 3}; std::deque const e1h{11, 22, 3}; - auto const in01 = expect>{wire, e1a, "array.node"}; - auto const in02 = expect>{wire, e1b, "array.int"}; - auto const in03 = expect>{"*0\r\n", e1e, "array.node.empty"}; - auto const in04 = expect>{"*0\r\n", e1d, "array.string.empty"}; - auto const in05 = expect>{wire, e1c, "array.string"}; - auto const in06 = expect{wire, e1f, "array.array"}; - auto const in07 = expect>{wire, e1g, "array.list"}; - auto const in08 = expect>{wire, e1h, "array.deque"}; - auto const in09 = expect>{"_\r\n", std::vector{}, "array.vector", aedis::error::resp3_null}; - auto const in10 = expect>{"_\r\n", std::list{}, "array.list", aedis::error::resp3_null}; - auto const in11 = expect{"_\r\n", array_type{}, "array.null", aedis::error::resp3_null}; - auto const in12 = expect{wire, tuple_type{}, "array.list", aedis::error::incompatible_size}; - auto const in13 = expect{wire_nested, array_type2{}, "array.nested", aedis::error::nested_aggregate_not_supported}; - auto const in14 = expect{wire, array_type2{}, "array.null", aedis::error::incompatible_size}; - auto const in15 = expect{":3\r\n", array_type2{}, "array.array", aedis::error::expects_resp3_aggregate}; - auto const in16 = expect{wire_nested2, vec_node_type{}, "array.depth.exceeds", aedis::error::exceeeds_max_nested_depth}; + auto const in01 = expect>{S20, e1a, "array.node"}; + auto const in02 = expect>{S20, e1b, "array.int"}; + auto const in03 = expect>{S23, e1e, "array.node.empty"}; + auto const in04 = expect>{S23, e1d, "array.string.empty"}; + auto const in05 = expect>{S20, e1c, "array.string"}; + auto const in06 = expect{S20, e1f, "array.array"}; + auto const in07 = expect>{S20, e1g, "array.list"}; + auto const in08 = expect>{S20, e1h, "array.deque"}; + auto const in09 = expect>{S12, std::vector{}, "array.vector", aedis::error::resp3_null}; + auto const in10 = expect>{S12, std::list{}, "array.list", aedis::error::resp3_null}; + auto const in11 = expect{S12, array_type{}, "array.null", aedis::error::resp3_null}; + auto const in12 = expect{S20, tuple_type{}, "array.list", aedis::error::incompatible_size}; + auto const in13 = expect{S21, array_type2{}, "array.nested", aedis::error::nested_aggregate_not_supported}; + auto const in14 = expect{S20, array_type2{}, "array.null", aedis::error::incompatible_size}; + auto const in15 = expect{S11, array_type2{}, "array.array", aedis::error::expects_resp3_aggregate}; + auto const in16 = expect{S22, vec_node_type{}, "array.depth.exceeds", aedis::error::exceeeds_max_nested_depth}; auto ex = ioc.get_executor(); @@ -432,9 +450,6 @@ BOOST_AUTO_TEST_CASE(test_set) using vec_type = std::vector; using op_vec_type = std::optional>; - std::string const wire2 = "*3\r\n$2\r\n11\r\n$2\r\n22\r\n$1\r\n3\r\n"; - std::string const wire = "~6\r\n+orange\r\n+apple\r\n+one\r\n+two\r\n+three\r\n+orange\r\n"; - std::vector const expected1a { {resp3::type::set, 6UL, 0UL, {}} , {resp3::type::simple_string, 1UL, 1UL, {"orange"}} @@ -452,16 +467,16 @@ BOOST_AUTO_TEST_CASE(test_set) op_vec_type expected_1e; expected_1e = e1d; - auto const in00 = expect>{wire, expected1a, "set.node"}; - auto const in01 = expect>{"~0\r\n", std::vector{ {resp3::type::set, 0UL, 0UL, {}} }, "set.node (empty)"}; - auto const in02 = expect{wire, set_type{"apple", "one", "orange", "three", "two"}, "set.set"}; - auto const in03 = expect{wire, e1f, "set.multiset"}; - auto const in04 = expect{wire, e1d, "set.vector "}; - auto const in05 = expect{wire, expected_1e, "set.vector "}; - auto const in06 = expect{wire, e1c, "set.unordered_set"}; - auto const in07 = expect{wire, e1g, "set.unordered_multiset"}; - auto const in08 = expect>{"*1\r\n" + wire, std::tuple{e1c}, "set.tuple"}; - auto const in09 = expect{wire2, set_type{}, "set.error", aedis::error::expects_resp3_set}; + auto const in00 = expect>{S25, expected1a, "set.node"}; + auto const in01 = expect>{S27, std::vector{ {resp3::type::set, 0UL, 0UL, {}} }, "set.node (empty)"}; + auto const in02 = expect{S25, set_type{"apple", "one", "orange", "three", "two"}, "set.set"}; + auto const in03 = expect{S25, e1f, "set.multiset"}; + auto const in04 = expect{S25, e1d, "set.vector "}; + auto const in05 = expect{S25, expected_1e, "set.vector "}; + auto const in06 = expect{S25, e1c, "set.unordered_set"}; + auto const in07 = expect{S25, e1g, "set.unordered_multiset"}; + auto const in08 = expect>{S26, std::tuple{e1c}, "set.tuple"}; + auto const in09 = expect{S24, set_type{}, "set.error", aedis::error::expects_resp3_set}; auto ex = ioc.get_executor(); @@ -492,9 +507,9 @@ BOOST_AUTO_TEST_CASE(test_set) BOOST_AUTO_TEST_CASE(test_simple_error) { net::io_context ioc; - auto const in01 = expect{"-Error\r\n", node_type{resp3::type::simple_error, 1UL, 0UL, {"Error"}}, "simple_error.node", aedis::error::resp3_simple_error}; - auto const in02 = expect{"-\r\n", node_type{resp3::type::simple_error, 1UL, 0UL, {""}}, "simple_error.node.empty", aedis::error::resp3_simple_error}; - auto const in03 = expect{"-Error\r\n", aedis::ignore{}, "simple_error.not.ignore.error", aedis::error::resp3_simple_error}; + auto const in01 = expect{S28, node_type{resp3::type::simple_error, 1UL, 0UL, {"Error"}}, "simple_error.node", aedis::error::resp3_simple_error}; + auto const in02 = expect{S29, node_type{resp3::type::simple_error, 1UL, 0UL, {""}}, "simple_error.node.empty", aedis::error::resp3_simple_error}; + auto const in03 = expect{S28, aedis::ignore{}, "simple_error.not.ignore.error", aedis::error::resp3_simple_error}; auto ex = ioc.get_executor(); @@ -696,15 +711,15 @@ BOOST_AUTO_TEST_CASE(test_null) using op_type_08 = std::optional>; using op_type_09 = std::optional>; - auto const in01 = expect{"_\r\n", op_type_01{}, "null.optional.bool"}; - auto const in02 = expect{"_\r\n", op_type_02{}, "null.optional.int"}; - auto const in03 = expect{"_\r\n", op_type_03{}, "null.optional.string"}; - auto const in04 = expect{"_\r\n", op_type_04{}, "null.optional.vector"}; - auto const in05 = expect{"_\r\n", op_type_05{}, "null.optional.list"}; - auto const in06 = expect{"_\r\n", op_type_06{}, "null.optional.map"}; - auto const in07 = expect{"_\r\n", op_type_07{}, "null.optional.unordered_map"}; - auto const in08 = expect{"_\r\n", op_type_08{}, "null.optional.set"}; - auto const in09 = expect{"_\r\n", op_type_09{}, "null.optional.unordered_set"}; + auto const in01 = expect{S12, op_type_01{}, "null.optional.bool"}; + auto const in02 = expect{S12, op_type_02{}, "null.optional.int"}; + auto const in03 = expect{S12, op_type_03{}, "null.optional.string"}; + auto const in04 = expect{S12, op_type_04{}, "null.optional.vector"}; + auto const in05 = expect{S12, op_type_05{}, "null.optional.list"}; + auto const in06 = expect{S12, op_type_06{}, "null.optional.map"}; + auto const in07 = expect{S12, op_type_07{}, "null.optional.unordered_map"}; + auto const in08 = expect{S12, op_type_08{}, "null.optional.set"}; + auto const in09 = expect{S12, op_type_09{}, "null.optional.unordered_set"}; auto ex = ioc.get_executor();