Skip to content

Commit

Permalink
AP_Common: improve bitmask test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
tpwrules committed Jul 8, 2024
1 parent 97faa83 commit 57fc79f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libraries/AP_Common/tests/test_bitmask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ void bitmask_tests(void)
EXPECT_EXIT(x.set(N+1), testing::KilledBySignal(SIGABRT), "AP_InternalError::error_t::bitmask_range");
#endif

#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
x.clear(N+1);
#elif CONFIG_HAL_BOARD == HAL_BOARD_SITL
EXPECT_EXIT(x.clear(N+1), testing::KilledBySignal(SIGABRT), "AP_InternalError::error_t::bitmask_range");
#endif

for (uint8_t i=0; i<N; i++) {
EXPECT_EQ(x2.get(i), x.get(i));
}
Expand Down Expand Up @@ -81,8 +87,10 @@ void bitmask_setall(void)
Bitmask<N> x;
EXPECT_EQ(-1, x.first_set());
EXPECT_EQ(false, x.get(N-4));
EXPECT_EQ(0, x.count());
x.setall();
EXPECT_EQ(0, x.first_set());
EXPECT_EQ(N, x.count());
x.clear(0);
EXPECT_EQ(1, x.first_set());
x.clear(1);
Expand All @@ -93,6 +101,7 @@ void bitmask_setall(void)
EXPECT_EQ(-1, x.first_set());
EXPECT_EQ(false, x.get(N-4));
EXPECT_EQ(true, x.empty());
EXPECT_EQ(0, x.count());
}

TEST(Bitmask, SetAll31) { bitmask_setall<31>(); }
Expand All @@ -116,6 +125,7 @@ void bitmask_assignment(void)

Bitmask<N> y;
y = x;
EXPECT_EQ(true, x == y);
x.clear(0);
EXPECT_EQ(true, y.get(0));
EXPECT_EQ(true, y.get(5));
Expand Down

0 comments on commit 57fc79f

Please sign in to comment.