From a1a53012fbb02e87c9be402de64b0d3aaf3bdb8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=D1=91pa=20Dolgorukov?= Date: Fri, 2 Aug 2024 02:10:19 +0500 Subject: [PATCH] Implement xtype_from_string tests for types int16_t, int32_t, int64_t (#447) * Change macros for creating test names * Add test for values of types int{16,32,64}_t --------- Co-authored-by: sowle --- tests/unit_tests/get_xtype_from_string.cpp | 48 ++++++++++++++++++---- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/tests/unit_tests/get_xtype_from_string.cpp b/tests/unit_tests/get_xtype_from_string.cpp index dd4d2e41..5bcb74df 100644 --- a/tests/unit_tests/get_xtype_from_string.cpp +++ b/tests/unit_tests/get_xtype_from_string.cpp @@ -26,14 +26,20 @@ namespace } } -#define TEST_pos(int_type, expected, str) \ - TEST(get_xtype_from_string, handles_pos_ ## int_type ## _ ## expected) \ - { \ - do_pos_test(expected, str); \ - } +#define MAKE_TEST_NAME(prefix, int_type, ln, test_type) \ + test_type ## _ ## prefix ## _ ## int_type ## _ ## ln -#define DO_MAKE_NEG_TEST_NAME(prefix, int_type, ln) prefix ## int_type ## _ ## ln -#define MAKE_NEG_TEST_NAME(prefix, int_type, ln) DO_MAKE_NEG_TEST_NAME(prefix, int_type, ln) +#define MAKE_POS_TEST_NAME(prefix, int_type, ln) \ + MAKE_TEST_NAME(prefix, int_type, ln, POS) + +#define MAKE_NEG_TEST_NAME(prefix, int_type, ln) \ + MAKE_TEST_NAME(prefix, int_type, ln, NEG) + +#define TEST_pos(int_type, expected, str) \ + TEST(get_xtype_from_string, MAKE_POS_TEST_NAME(handles_pos, int_type, __LINE__)) \ + { \ + do_pos_test(expected, str); \ + } #define TEST_neg(int_type, str) \ TEST(get_xtype_from_string, MAKE_NEG_TEST_NAME(handles_neg, int_type, __LINE__)) \ @@ -134,3 +140,31 @@ TEST_neg(uint64_t, "1w1"); TEST_neg(uint64_t, "18446744073709551615w"); TEST_neg(uint64_t, "18446744073709551616"); + +TEST_pos(int16_t, 32'767, "32767"); // 2^15 - 1 +TEST_pos(int16_t, -32'768, "-32768"); // -2^15 +TEST_pos(int16_t, 0, "-0"); +TEST_pos(int16_t, 0, "+0"); + +TEST_neg(int16_t, "32768"); // 2^15 +TEST_neg(int16_t, "+32768"); // 2^15 +TEST_neg(int16_t, "-32769"); // -2^15 - 1 +TEST_neg(int16_t, ""); + +TEST_pos(int32_t, 2'147'483'647, "2147483647"); // 2^31 - 1 +TEST_pos(int32_t, -2'147'483'648, "-2147483648"); // -2^31 +TEST_pos(int32_t, 0, "-0"); +TEST_pos(int32_t, 0, "+0"); + +TEST_neg(int32_t, "-2147483649"); +TEST_neg(int32_t, "2147483648"); +TEST_neg(int32_t, ""); + +TEST_pos(int64_t, 9'223'372'036'854'775'807LL, "9223372036854775807"); // 2^63 - 1 +TEST_pos(int64_t, -9'223'372'036'854'775'807LL - 1LL, "-9223372036854775808"); // -2^63 +TEST_pos(int64_t, 0LL, "-0"); +TEST_pos(int64_t, 0LL, "+0"); + +TEST_neg(int64_t, "-9223372036854775809"); // -2^63 - 1 +TEST_neg(int64_t, "9223372036854775808"); // 2^63 +TEST_neg(int64_t, "");