Version 0.8.0
[marnav.git] / test / seatalk / Test_seatalk_message_66.cpp
blob817bc930670adbdc6c122da0a2188e44dfcaa03b
1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_66.hpp>
4 namespace
7 using namespace marnav::seatalk;
9 class Test_seatalk_message_66 : public ::testing::Test
11 public:
12 using alarm = message_66::alarm;
14 struct test_case {
15 raw data;
16 alarm a;
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);
52 if (!generic_message)
53 continue;
54 auto m = message_cast<message_66>(generic_message);
55 EXPECT_TRUE(m != nullptr);
56 if (!m)
57 continue;
58 EXPECT_EQ(t.a, m->get_alarm());
62 TEST_F(Test_seatalk_message_66, write_default)
64 const raw expected{0x66, 0x00, 0x00};
65 message_66 m;
67 EXPECT_EQ(expected, m.get_data());
70 TEST_F(Test_seatalk_message_66, set_alarm)
72 for (auto const & t : cases) {
73 message_66 m;
74 m.set_alarm(t.a);
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);