From a9a1b21ca9417fbc9886de14ff9e511308e672ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Thu, 9 Feb 2023 09:15:04 +0100 Subject: [PATCH] Use ASSERT_COMPARE in test_suite_md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Manuel Pégourié-Gonnard --- tests/include/test/macros.h | 2 +- tests/suites/test_suite_md.function | 37 ++++++++--------------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/tests/include/test/macros.h b/tests/include/test/macros.h index 83a48cd1e2..2eba0c1028 100644 --- a/tests/include/test/macros.h +++ b/tests/include/test/macros.h @@ -168,7 +168,7 @@ #define ASSERT_COMPARE(p1, size1, p2, size2) \ do \ { \ - TEST_ASSERT((size1) == (size2)); \ + TEST_EQUAL((size1), (size2)); \ if ((size1) != 0) \ TEST_ASSERT(memcmp((p1), (p2), (size1)) == 0); \ } \ diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function index f117a2ce42..27c2063cb8 100644 --- a/tests/suites/test_suite_md.function +++ b/tests/suites/test_suite_md.function @@ -141,9 +141,7 @@ void md_text(int md_type, char *text_src_string, data_t *hash) TEST_EQUAL(0, mbedtls_md(md_info, src, src_len, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - mbedtls_md_get_size(md_info), - hash->len) == 0); + ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len); } /* END_CASE */ @@ -159,9 +157,7 @@ void md_hex(int md_type, data_t *src_str, data_t *hash) TEST_EQUAL(0, mbedtls_md(md_info, src_str->x, src_str->len, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - mbedtls_md_get_size(md_info), - hash->len) == 0); + ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len); } /* END_CASE */ @@ -196,18 +192,14 @@ void md_text_multi(int md_type, char *text_src_string, TEST_EQUAL(0, mbedtls_md_update(&ctx, src + halfway, src_len - halfway)); TEST_EQUAL(0, mbedtls_md_finish(&ctx, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - mbedtls_md_get_size(md_info), - hash->len) == 0); + ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len); /* Test clone */ memset(output, 0x00, sizeof(output)); TEST_EQUAL(0, mbedtls_md_update(&ctx_copy, src + halfway, src_len - halfway)); TEST_EQUAL(0, mbedtls_md_finish(&ctx_copy, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - mbedtls_md_get_size(md_info), - hash->len) == 0); + ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len); exit: mbedtls_md_free(&ctx); @@ -242,18 +234,14 @@ void md_hex_multi(int md_type, data_t *src_str, data_t *hash) TEST_EQUAL(0, mbedtls_md_update(&ctx, src_str->x + halfway, src_str->len - halfway)); TEST_EQUAL(0, mbedtls_md_finish(&ctx, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - mbedtls_md_get_size(md_info), - hash->len) == 0); + ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len); /* Test clone */ memset(output, 0x00, sizeof(output)); TEST_EQUAL(0, mbedtls_md_update(&ctx_copy, src_str->x + halfway, src_str->len - halfway)); TEST_EQUAL(0, mbedtls_md_finish(&ctx_copy, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - mbedtls_md_get_size(md_info), - hash->len) == 0); + ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len); exit: mbedtls_md_free(&ctx); @@ -276,8 +264,7 @@ void mbedtls_md_hmac(int md_type, int trunc_size, TEST_EQUAL(0, mbedtls_md_hmac(md_info, key_str->x, key_str->len, src_str->x, src_str->len, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - trunc_size, hash->len) == 0); + ASSERT_COMPARE(output, trunc_size, hash->x, hash->len); } /* END_CASE */ @@ -305,8 +292,7 @@ void md_hmac_multi(int md_type, int trunc_size, data_t *key_str, TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway)); TEST_EQUAL(0, mbedtls_md_hmac_finish(&ctx, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - trunc_size, hash->len) == 0); + ASSERT_COMPARE(output, trunc_size, hash->x, hash->len); /* Test again, for reset() */ memset(output, 0x00, sizeof(output)); @@ -316,8 +302,7 @@ void md_hmac_multi(int md_type, int trunc_size, data_t *key_str, TEST_EQUAL(0, mbedtls_md_hmac_update(&ctx, src_str->x + halfway, src_str->len - halfway)); TEST_EQUAL(0, mbedtls_md_hmac_finish(&ctx, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - trunc_size, hash->len) == 0); + ASSERT_COMPARE(output, trunc_size, hash->x, hash->len); exit: mbedtls_md_free(&ctx); @@ -336,8 +321,6 @@ void mbedtls_md_file(int md_type, char *filename, TEST_EQUAL(0, mbedtls_md_file(md_info, filename, output)); - TEST_ASSERT(mbedtls_test_hexcmp(output, hash->x, - mbedtls_md_get_size(md_info), - hash->len) == 0); + ASSERT_COMPARE(output, mbedtls_md_get_size(md_info), hash->x, hash->len); } /* END_CASE */