1
0
Fork 0
forked from lthn/blockchain

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 <crypto.sowle@gmail.com>
This commit is contained in:
Stёpa Dolgorukov 2024-08-02 02:10:19 +05:00 committed by GitHub
parent 168281f862
commit a1a53012fb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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<int_type>(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<int_type>(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, "");