Skip to content

Commit

Permalink
tests/unittests: add tests for bf_set_all()
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Nov 4, 2022
1 parent 60ab2db commit 1737430
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion tests/unittests/tests-bitfield/tests-bitfield.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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);
Expand Down

0 comments on commit 1737430

Please sign in to comment.