From 17374301c9695474cd9fe74a69c9f9c86d312d65 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 2 Nov 2022 13:55:29 +0100 Subject: [PATCH] tests/unittests: add tests for bf_set_all() --- .../unittests/tests-bitfield/tests-bitfield.c | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/unittests/tests-bitfield/tests-bitfield.c b/tests/unittests/tests-bitfield/tests-bitfield.c index a92475442d..5b478674e5 100644 --- a/tests/unittests/tests-bitfield/tests-bitfield.c +++ b/tests/unittests/tests-bitfield/tests-bitfield.c @@ -274,8 +274,32 @@ static void test_bf_find_first_unset(void) TEST_ASSERT_EQUAL_INT(3, res); } -Test *tests_bitfield_tests(void) +static void test_bf_set_all(void) { + uint8_t field[5]; + + memset(field, 0, sizeof(field)); + bf_set_all(field, 5); + TEST_ASSERT_EQUAL_INT(0xf8, field[0]); + TEST_ASSERT_EQUAL_INT(0, field[1]); + + memset(field, 0, sizeof(field)); + bf_set_all(field, 24); + TEST_ASSERT_EQUAL_INT(0xff, field[0]); + TEST_ASSERT_EQUAL_INT(0xff, field[1]); + TEST_ASSERT_EQUAL_INT(0xff, field[2]); + TEST_ASSERT_EQUAL_INT(0, field[3]); + + memset(field, 0, sizeof(field)); + bf_set_all(field, 30); + TEST_ASSERT_EQUAL_INT(0xff, field[0]); + TEST_ASSERT_EQUAL_INT(0xff, field[1]); + TEST_ASSERT_EQUAL_INT(0xff, field[2]); + TEST_ASSERT_EQUAL_INT(0xfc, field[3]); + TEST_ASSERT_EQUAL_INT(0, field[4]); +} + +Test *tests_bitfield_tests(void) { EMB_UNIT_TESTFIXTURES(fixtures) { new_TestFixture(test_bf_set), new_TestFixture(test_bf_unset), @@ -288,6 +312,7 @@ Test *tests_bitfield_tests(void) new_TestFixture(test_bf_ops), new_TestFixture(test_bf_find_first_set), new_TestFixture(test_bf_find_first_unset), + new_TestFixture(test_bf_set_all), }; EMB_UNIT_TESTCALLER(bitfield_tests, NULL, NULL, fixtures);