General: separation of marav-io as a library
[marnav.git] / test / marnav / seatalk / Test_seatalk_message_53.cpp
blobdf5b2fec954bf907430d779fd5e4e25848042e37
1 #include <marnav/seatalk/message_53.hpp>
2 #include <gtest/gtest.h>
4 namespace
7 using namespace marnav::seatalk;
9 class Test_seatalk_message_53 : public ::testing::Test
11 public:
12 struct test_case {
13 raw data;
14 double cog;
17 const std::vector<test_case> cases{
18 {{0x53, 0x00, 0x00}, 0.0},
19 {{0x53, 0x00, 0x01}, 2.0},
20 {{0x53, 0x00, 0x02}, 4.0},
21 {{0x53, 0x00, 0x04}, 8.0},
22 {{0x53, 0x00, 0x08}, 16.0},
23 {{0x53, 0x00, 0x10}, 32.0},
24 {{0x53, 0x00, 0x20}, 64.0},
25 {{0x53, 0x10, 0x00}, 90.0},
26 {{0x53, 0x20, 0x00}, 180.0},
27 {{0x53, 0x30, 0x00}, 270.0},
28 {{0x53, 0x40, 0x00}, 0.5},
29 {{0x53, 0x80, 0x00}, 1.0},
30 {{0x53, 0xc0, 0x00}, 1.5},
34 TEST_F(Test_seatalk_message_53, construction)
36 EXPECT_NO_THROW(message_53 m);
39 TEST_F(Test_seatalk_message_53, parse_invalid_data_size)
41 EXPECT_ANY_THROW(message_53::parse({2, 0x00}));
42 EXPECT_ANY_THROW(message_53::parse({4, 0x00}));
45 TEST_F(Test_seatalk_message_53, parse_invalid_length)
47 EXPECT_ANY_THROW(message_53::parse({0x53, 0x01, 0x00}));
48 EXPECT_ANY_THROW(message_53::parse({0x53, 0x02, 0x00}));
51 TEST_F(Test_seatalk_message_53, parse)
53 for (auto const & t : cases) {
54 auto generic_message = message_53::parse(t.data);
55 EXPECT_TRUE(generic_message != nullptr);
56 if (!generic_message)
57 continue;
58 auto m = message_cast<message_53>(generic_message);
59 EXPECT_TRUE(m != nullptr);
60 if (!m)
61 continue;
65 TEST_F(Test_seatalk_message_53, write_default)
67 const raw expected{0x53, 0x00, 0x00};
68 message_53 m;
70 EXPECT_EQ(expected, m.get_data());
73 TEST_F(Test_seatalk_message_53, set_cog)
75 for (auto const & t : cases) {
76 message_53 m;
77 m.set_cog(t.cog);
78 const auto raw = m.get_data();
79 EXPECT_EQ(t.data, raw) << "cog=" << t.cog;