1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_89.hpp>
7 using namespace marnav::seatalk
;
9 class Test_seatalk_message_89
: public ::testing::Test
18 const std::vector
<test_case
> cases
{
19 // testing lower parts of 'u'
20 {{0x89, 0x02, 0x00, 0x00, 0x20}, 0.0},
21 {{0x89, 0x12, 0x00, 0x00, 0x20}, 90.0},
22 {{0x89, 0x22, 0x00, 0x00, 0x20}, 180.0},
23 {{0x89, 0x32, 0x00, 0x00, 0x20}, 270.0},
25 {{0x89, 0x02, 0x01, 0x00, 0x20}, 2.0},
26 {{0x89, 0x02, 0x02, 0x00, 0x20}, 4.0},
27 {{0x89, 0x02, 0x03, 0x00, 0x20}, 6.0},
28 {{0x89, 0x02, 0x04, 0x00, 0x20}, 8.0},
29 {{0x89, 0x02, 0x05, 0x00, 0x20}, 10.0},
30 {{0x89, 0x02, 0x06, 0x00, 0x20}, 12.0},
31 {{0x89, 0x02, 0x07, 0x00, 0x20}, 14.0},
32 {{0x89, 0x02, 0x08, 0x00, 0x20}, 16.0},
33 {{0x89, 0x02, 0x09, 0x00, 0x20}, 18.0},
34 {{0x89, 0x02, 0x0a, 0x00, 0x20}, 20.0},
35 {{0x89, 0x02, 0x0b, 0x00, 0x20}, 22.0},
36 {{0x89, 0x02, 0x0c, 0x00, 0x20}, 24.0},
37 {{0x89, 0x02, 0x0d, 0x00, 0x20}, 26.0},
38 {{0x89, 0x02, 0x0e, 0x00, 0x20}, 28.0},
39 {{0x89, 0x02, 0x0f, 0x00, 0x20}, 30.0},
40 {{0x89, 0x02, 0x10, 0x00, 0x20}, 32.0},
41 {{0x89, 0x02, 0x20, 0x00, 0x20}, 64.0},
42 {{0x89, 0x02, 0x30, 0x00, 0x20}, 96.0},
43 {{0x89, 0x02, 0x40, 0x00, 0x20}, 0.0},
44 {{0x89, 0x02, 0x50, 0x00, 0x20}, 32.0},
45 {{0x89, 0x02, 0x60, 0x00, 0x20}, 64.0},
46 {{0x89, 0x02, 0x70, 0x00, 0x20}, 96.0},
47 {{0x89, 0x02, 0x80, 0x00, 0x20}, 0.0},
48 // testing upper parts of 'u'
49 {{0x89, 0x02, 0x00, 0x00, 0x20}, 0.0},
50 {{0x89, 0x42, 0x00, 0x00, 0x20}, 0.5},
51 {{0x89, 0x82, 0x00, 0x00, 0x20}, 1.0},
52 {{0x89, 0xc2, 0x00, 0x00, 0x20}, 1.5},
57 TEST_F(Test_seatalk_message_89
, construction
)
59 EXPECT_NO_THROW(message_89 m
);
62 TEST_F(Test_seatalk_message_89
, parse_invalid_data_size
)
64 EXPECT_ANY_THROW(message_89::parse({4, 0x00}));
65 EXPECT_ANY_THROW(message_89::parse({6, 0x00}));
68 TEST_F(Test_seatalk_message_89
, parse_invalid_length
)
70 EXPECT_ANY_THROW(message_89::parse({0x89, 0x01, 0x00, 0x00, 0x20}));
71 EXPECT_ANY_THROW(message_89::parse({0x89, 0x03, 0x00, 0x00, 0x20}));
74 TEST_F(Test_seatalk_message_89
, parse
)
76 for (auto const & t
: cases
) {
77 auto generic_message
= message_89::parse(t
.data
);
78 EXPECT_TRUE(generic_message
!= nullptr);
81 auto m
= message_cast
<message_89
>(generic_message
);
82 EXPECT_TRUE(m
!= nullptr);
85 EXPECT_NEAR(t
.heading
, m
->get_heading(), 1e-3);
89 TEST_F(Test_seatalk_message_89
, write_default
)
91 const raw expected
{0x89, 0x02, 0x00, 0x00, 0x20};
94 EXPECT_EQ(expected
, m
.get_data());
97 TEST_F(Test_seatalk_message_89
, set_heading_get_data
)
99 for (auto const & t
: cases
) {
101 // this cases are not possible to test because the upper two
102 // bits of 'vw' will never be set this way.
103 if (t
.data
[2] & 0xc0)
106 // this case does not make sense in setting heading and getting
107 // the data, because it is not unique. it makes sense to be able
108 // to parse it, but it is not necessary to generate it.
109 if (t
.data
[2] == 0x30)
113 msg
.set_heading(t
.heading
);
115 const auto raw
= msg
.get_data();
116 EXPECT_EQ(t
.data
, raw
) << "heading: " << t
.heading
;
120 TEST_F(Test_seatalk_message_89
, set_heading__interval
)
125 EXPECT_NEAR(0.0, m
.get_heading(), 1e-3);
130 EXPECT_NEAR(1.0, m
.get_heading(), 1e-3);
134 m
.set_heading(360.0);
135 EXPECT_NEAR(0.0, m
.get_heading(), 1e-3);
139 m
.set_heading(361.0);
140 EXPECT_NEAR(1.0, m
.get_heading(), 1e-3);
144 m
.set_heading(-361.0);
145 EXPECT_NEAR(1.0, m
.get_heading(), 1e-3);