1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_66.hpp>
7 using namespace marnav::seatalk
;
9 class Test_seatalk_message_66
: public ::testing::Test
12 using alarm
= message_66::alarm
;
19 const std::vector
<test_case
> cases
{
20 {{0x66, 0x00, 0x00}, alarm::no_alarm
}, {{0x66, 0x00, 0x80}, alarm::apparent_angle_lo
},
21 {{0x66, 0x00, 0x40}, alarm::apparent_angle_hi
},
22 {{0x66, 0x00, 0x20}, alarm::apparent_speed_lo
},
23 {{0x66, 0x00, 0x10}, alarm::apparent_speed_hi
},
24 {{0x66, 0x00, 0x08}, alarm::true_angle_lo
}, {{0x66, 0x00, 0x04}, alarm::true_angle_hi
},
25 {{0x66, 0x00, 0x02}, alarm::true_speed_lo
}, {{0x66, 0x00, 0x01}, alarm::true_speed_hi
},
26 {{0x66, 0x00, 0x05}, alarm::true_angle_hi
| alarm::true_speed_hi
},
30 TEST_F(Test_seatalk_message_66
, construction
)
32 EXPECT_NO_THROW(message_66 m
);
35 TEST_F(Test_seatalk_message_66
, parse_invalid_data_size
)
37 EXPECT_ANY_THROW(message_66::parse({7, 0x00}));
38 EXPECT_ANY_THROW(message_66::parse({9, 0x00}));
41 TEST_F(Test_seatalk_message_66
, parse_invalid_length
)
43 EXPECT_ANY_THROW(message_66::parse({0x66, 0x01, 0x00}));
44 EXPECT_ANY_THROW(message_66::parse({0x66, 0x02, 0x00}));
47 TEST_F(Test_seatalk_message_66
, parse
)
49 for (auto const & t
: cases
) {
50 auto generic_message
= message_66::parse(t
.data
);
51 EXPECT_TRUE(generic_message
!= nullptr);
54 auto m
= message_cast
<message_66
>(generic_message
);
55 EXPECT_TRUE(m
!= nullptr);
58 EXPECT_EQ(t
.a
, m
->get_alarm());
62 TEST_F(Test_seatalk_message_66
, write_default
)
64 const raw expected
{0x66, 0x00, 0x00};
67 EXPECT_EQ(expected
, m
.get_data());
70 TEST_F(Test_seatalk_message_66
, set_alarm
)
72 for (auto const & t
: cases
) {
75 const auto raw
= m
.get_data();
76 EXPECT_EQ(t
.data
, raw
);
80 TEST_F(Test_seatalk_message_66
, operator_and
)
82 const alarm a
= static_cast<alarm
>(0xff);
84 EXPECT_EQ(alarm::apparent_angle_lo
, a
& alarm::apparent_angle_lo
);
85 EXPECT_EQ(alarm::apparent_angle_lo
, a
& alarm::apparent_angle_lo
);
86 EXPECT_EQ(alarm::apparent_angle_hi
, a
& alarm::apparent_angle_hi
);
87 EXPECT_EQ(alarm::apparent_speed_lo
, a
& alarm::apparent_speed_lo
);
88 EXPECT_EQ(alarm::apparent_speed_hi
, a
& alarm::apparent_speed_hi
);
89 EXPECT_EQ(alarm::true_angle_lo
, a
& alarm::true_angle_lo
);
90 EXPECT_EQ(alarm::true_angle_hi
, a
& alarm::true_angle_hi
);
91 EXPECT_EQ(alarm::true_speed_lo
, a
& alarm::true_speed_lo
);