diff options
author | Pauli <paul.dale@oracle.com> | 2017-04-13 00:51:28 +0200 |
---|---|---|
committer | Rich Salz <rsalz@openssl.org> | 2017-04-13 14:33:12 +0200 |
commit | d063add7cbdaf82e6208ef01414432320260e974 (patch) | |
tree | 794ad8006e58650653d962c8ae692efdd36e4a78 /test/test_test.c | |
parent | Update the internal siphash tests to use the framework's output. (diff) | |
download | openssl-d063add7cbdaf82e6208ef01414432320260e974.tar.xz openssl-d063add7cbdaf82e6208ef01414432320260e974.zip |
Guarantee single argument evaluation for test macros.
Add test case that checks some of them.
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/3208)
Diffstat (limited to 'test/test_test.c')
-rw-r--r-- | test/test_test.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/test_test.c b/test/test_test.c index df4725a7a4..a1542892e9 100644 --- a/test/test_test.c +++ b/test/test_test.c @@ -259,6 +259,61 @@ static int test_messages(void) return 1; } +static int test_single_eval(void) +{ + int i = 4; + long l = -9000; + char c = 'd'; + unsigned char uc = 22; + unsigned long ul = 500; + size_t st = 1234; + char buf[4] = { 0 }, *p = buf; + + /* int */ + return TEST_int_eq(i++, 4) + && TEST_int_eq(i, 5) + && TEST_int_gt(++i, 5) + && TEST_int_le(5, i++) + && TEST_int_ne(--i, 5) + && TEST_int_eq(12, i *= 2) + /* Long */ + && TEST_long_eq(l--, -9000L) + && TEST_long_eq(++l, -9000L) + && TEST_long_ne(-9000L, l /= 2) + && TEST_long_lt(--l, -4500L) + /* char */ + && TEST_char_eq(++c, 'e') + && TEST_char_eq('e', c--) + && TEST_char_ne('d', --c) + && TEST_char_le('b', --c) + && TEST_char_lt(c++, 'c') + /* unsigned char */ + && TEST_uchar_eq(22, uc++) + && TEST_uchar_eq(uc /= 2, 11) + && TEST_ulong_eq(ul ^= 1, 501) + && TEST_ulong_eq(502, ul ^= 3) + && TEST_ulong_eq(ul = ul * 3 - 6, 1500) + /* size_t */ + && TEST_size_t_eq((--i, st++), 1234) + && TEST_size_t_eq(st, 1235) + && TEST_int_eq(11, i) + /* pointers */ + && TEST_ptr_eq(p++, buf) + && TEST_ptr_eq(buf + 2, ++p) + && TEST_ptr_eq(buf, p -= 2) + && TEST_ptr(++p) + && TEST_ptr_eq(p, buf + 1) + && TEST_ptr_null(p = NULL) + /* strings */ + && TEST_str_eq(p = "123456" + 1, "23456") + && TEST_str_eq("3456", ++p) + && TEST_str_ne(p++, "456") + /* memory */ + && TEST_mem_eq(--p, sizeof("3456"), "3456", sizeof("3456")) + && TEST_mem_ne(p++, sizeof("456"), "456", sizeof("456")) + && TEST_mem_eq(p--, sizeof("456"), "456", sizeof("456")); +} + void register_tests(void) { ADD_TEST(test_int); @@ -273,4 +328,5 @@ void register_tests(void) ADD_TEST(test_string); ADD_TEST(test_memory); ADD_TEST(test_messages); + ADD_TEST(test_single_eval); } |