2018-11-02 18:29:18 -03:00
|
|
|
#include <AP_gtest.h>
|
2021-06-19 12:04:17 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2018-11-02 18:29:18 -03:00
|
|
|
|
|
|
|
#include <AP_Common/Bitmask.h>
|
|
|
|
|
2021-06-19 12:04:17 -03:00
|
|
|
const AP_HAL::HAL& hal = AP_HAL::get_HAL();
|
|
|
|
|
2018-11-02 18:29:18 -03:00
|
|
|
TEST(Bitmask, Tests)
|
|
|
|
{
|
2019-04-11 09:12:26 -03:00
|
|
|
Bitmask<49> x;
|
2021-06-19 12:04:17 -03:00
|
|
|
EXPECT_EQ(0, x.count());
|
2018-11-02 18:29:18 -03:00
|
|
|
EXPECT_EQ(-1, x.first_set());
|
|
|
|
x.set(5);
|
2021-06-19 12:04:17 -03:00
|
|
|
EXPECT_EQ(1, x.count());
|
2018-11-02 18:29:18 -03:00
|
|
|
EXPECT_EQ(5, x.first_set());
|
|
|
|
x.clear(5);
|
2021-06-19 12:04:17 -03:00
|
|
|
EXPECT_EQ(0, x.count());
|
2018-11-02 18:29:18 -03:00
|
|
|
EXPECT_EQ(-1, x.first_set());
|
|
|
|
|
|
|
|
EXPECT_EQ(-1, x.first_set());
|
|
|
|
x.set(42);
|
|
|
|
EXPECT_EQ(42, x.first_set());
|
|
|
|
x.clear(42);
|
|
|
|
EXPECT_EQ(-1, x.first_set());
|
|
|
|
|
|
|
|
EXPECT_EQ(-1, x.first_set());
|
|
|
|
x.set(0);
|
|
|
|
x.set(5);
|
|
|
|
x.set(6);
|
|
|
|
x.set(48);
|
2021-06-19 12:04:17 -03:00
|
|
|
EXPECT_EQ(4, x.count());
|
2018-11-02 18:29:18 -03:00
|
|
|
EXPECT_EQ(0, x.first_set());
|
|
|
|
EXPECT_EQ(0, x.first_set());
|
|
|
|
x.clear(0);
|
|
|
|
EXPECT_EQ(5, x.first_set());
|
|
|
|
EXPECT_EQ(5, x.first_set());
|
|
|
|
x.clear(5);
|
|
|
|
EXPECT_EQ(6, x.first_set());
|
|
|
|
EXPECT_EQ(6, x.first_set());
|
|
|
|
x.clear(6);
|
|
|
|
EXPECT_EQ(48, x.first_set());
|
|
|
|
EXPECT_EQ(48, x.first_set());
|
|
|
|
x.clear(48);
|
|
|
|
EXPECT_EQ(-1, x.first_set());
|
2021-06-19 12:04:17 -03:00
|
|
|
|
|
|
|
Bitmask<49> x2;
|
|
|
|
x2 = x;
|
2021-08-20 02:58:42 -03:00
|
|
|
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
2021-06-19 12:04:17 -03:00
|
|
|
x.set(50);
|
2021-08-20 02:58:42 -03:00
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
EXPECT_EXIT(x.set(50), testing::KilledBySignal(SIGABRT), "AP_InternalError::error_t::bitmask_range");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (uint8_t i=0; i<49; i++) {
|
2021-06-19 12:04:17 -03:00
|
|
|
EXPECT_EQ(x2.get(i), x.get(i));
|
|
|
|
}
|
2021-08-20 02:58:42 -03:00
|
|
|
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_LINUX
|
|
|
|
EXPECT_EQ(x2.get(50), x.get(50));
|
|
|
|
#elif CONFIG_HAL_BOARD == HAL_BOARD_SITL
|
|
|
|
EXPECT_EXIT(x2.get(50), testing::KilledBySignal(SIGABRT), "AP_InternalError::error_t::bitmask_range");
|
|
|
|
#endif
|
2018-11-02 18:29:18 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Bitmask, SetAll)
|
|
|
|
{
|
2019-04-11 09:12:26 -03:00
|
|
|
Bitmask<49> x;
|
2018-11-02 18:29:18 -03:00
|
|
|
EXPECT_EQ(-1, x.first_set());
|
|
|
|
EXPECT_EQ(false, x.get(45));
|
|
|
|
x.setall();
|
|
|
|
EXPECT_EQ(0, x.first_set());
|
|
|
|
x.clear(0);
|
|
|
|
EXPECT_EQ(1, x.first_set());
|
|
|
|
x.clear(1);
|
|
|
|
EXPECT_EQ(2, x.first_set());
|
|
|
|
EXPECT_EQ(true, x.get(45));
|
|
|
|
EXPECT_EQ(false, x.empty());
|
|
|
|
x.clearall();
|
|
|
|
EXPECT_EQ(-1, x.first_set());
|
|
|
|
EXPECT_EQ(false, x.get(45));
|
|
|
|
EXPECT_EQ(true, x.empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Bitmask, Assignment)
|
|
|
|
{
|
2019-04-11 09:12:26 -03:00
|
|
|
Bitmask<49> x;
|
2018-11-02 18:29:18 -03:00
|
|
|
x.set(0);
|
|
|
|
x.set(5);
|
|
|
|
x.set(6);
|
|
|
|
x.set(48);
|
|
|
|
|
2019-04-11 09:12:26 -03:00
|
|
|
Bitmask<49> y;
|
2018-11-02 18:29:18 -03:00
|
|
|
y = x;
|
|
|
|
x.clear(0);
|
|
|
|
EXPECT_EQ(true, y.get(0));
|
|
|
|
EXPECT_EQ(true, y.get(5));
|
|
|
|
EXPECT_EQ(true, y.get(6));
|
|
|
|
EXPECT_EQ(true, y.get(48));
|
|
|
|
}
|
|
|
|
|
2021-08-20 02:58:42 -03:00
|
|
|
AP_GTEST_PANIC()
|
2018-11-02 18:29:18 -03:00
|
|
|
AP_GTEST_MAIN()
|