Skip to content

Commit 716e6bf

Browse files
theob-prokartben
authored andcommitted
Tests: Util: Add unit tests for util_eq/util_memeq
Add two unit tests for the newly added functions `util_eq` and `util_memeq`. Signed-off-by: Théo Battrel <[email protected]>
1 parent 2158f48 commit 716e6bf

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/unit/util/main.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,4 +918,55 @@ ZTEST(util, test_utf8_lcpy_null_termination)
918918
zassert_str_equal(dest_str, expected_result, "Failed to truncate");
919919
}
920920

921+
ZTEST(util, test_util_eq)
922+
{
923+
uint8_t src1[16];
924+
uint8_t src2[16];
925+
926+
bool mem_area_matching_1;
927+
bool mem_area_matching_2;
928+
929+
memset(src1, 0, sizeof(src1));
930+
memset(src2, 0, sizeof(src2));
931+
932+
for (size_t i = 0U; i < 16; i++) {
933+
src1[i] = 0xAB;
934+
src2[i] = 0xAB;
935+
}
936+
937+
src1[15] = 0xCD;
938+
src2[15] = 0xEF;
939+
940+
mem_area_matching_1 = util_eq(src1, sizeof(src1), src2, sizeof(src2));
941+
mem_area_matching_2 = util_eq(src1, sizeof(src1) - 1, src2, sizeof(src2) - 1);
942+
943+
zassert_false(mem_area_matching_1);
944+
zassert_true(mem_area_matching_2);
945+
}
946+
947+
ZTEST(util, test_util_memeq)
948+
{
949+
uint8_t src1[16];
950+
uint8_t src2[16];
951+
uint8_t src3[16];
952+
953+
bool mem_area_matching_1;
954+
bool mem_area_matching_2;
955+
956+
memset(src1, 0, sizeof(src1));
957+
memset(src2, 0, sizeof(src2));
958+
959+
for (size_t i = 0U; i < 16; i++) {
960+
src1[i] = 0xAB;
961+
src2[i] = 0xAB;
962+
src3[i] = 0xCD;
963+
}
964+
965+
mem_area_matching_1 = util_memeq(src1, src2, sizeof(src1));
966+
mem_area_matching_2 = util_memeq(src1, src3, sizeof(src1));
967+
968+
zassert_true(mem_area_matching_1);
969+
zassert_false(mem_area_matching_2);
970+
}
971+
921972
ZTEST_SUITE(util, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)