Version 0.8.0
[marnav.git] / test / seatalk / Test_seatalk_message_51.cpp
blobec18019b7a8aa34964bf835939c192eb1b752e0b
1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_51.hpp>
4 namespace
7 using namespace marnav::seatalk;
9 class Test_seatalk_message_51 : public ::testing::Test
13 TEST_F(Test_seatalk_message_51, construction)
15 EXPECT_NO_THROW(message_51 m);
18 TEST_F(Test_seatalk_message_51, parse_invalid_data_size)
20 EXPECT_ANY_THROW(message_51::parse({4, 0x00}));
21 EXPECT_ANY_THROW(message_51::parse({6, 0x00}));
24 TEST_F(Test_seatalk_message_51, parse_invalid_length)
26 EXPECT_ANY_THROW(message_51::parse({0x51, 0x01, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(message_51::parse({0x51, 0x03, 0x00, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_51, parse)
32 struct test_case {
33 raw data;
36 const std::vector<test_case> cases{
37 {{0x51, 0x02, 0x00, 0x00, 0x00}}, {{0x51, 0x02, 0x0a, 0x00, 0x00}},
38 {{0x51, 0x02, 0x00, 0x01, 0x00}}, {{0x51, 0x02, 0x00, 0x00, 0x01}},
41 for (auto const & t : cases) {
42 auto generic_message = message_51::parse(t.data);
43 EXPECT_TRUE(generic_message != nullptr);
44 if (!generic_message)
45 continue;
46 auto m = message_cast<message_51>(generic_message);
47 EXPECT_TRUE(m != nullptr);
48 if (!m)
49 continue;
53 TEST_F(Test_seatalk_message_51, write_default)
55 const raw expected{0x51, 0x02, 0x00, 0x80, 0x00};
56 message_51 m;
58 EXPECT_EQ(expected, m.get_data());
61 TEST_F(Test_seatalk_message_51, set_lon)
63 using longitude = marnav::geo::longitude;
64 using hemisphere = longitude::hemisphere;
66 struct test_case {
67 longitude lon;
68 raw expected;
71 const std::vector<test_case> cases{
72 {{0, 0, 0, hemisphere::west}, {0x51, 0x02, 0x00, 0x80, 0x00}},
73 {{0, 0, 0, hemisphere::east}, {0x51, 0x02, 0x00, 0x80, 0x00}},
74 {{1, 0, 0, hemisphere::west}, {0x51, 0x02, 0x01, 0x00, 0x00}},
75 {{1, 0, 0, hemisphere::east}, {0x51, 0x02, 0x01, 0x80, 0x00}},
76 {{0, 1, 0, hemisphere::west}, {0x51, 0x02, 0x00, 0x00, 0x64}},
77 {{0, 0, 1, hemisphere::west}, {0x51, 0x02, 0x00, 0x00, 0x01}},
78 {{0, 0, 2, hemisphere::west}, {0x51, 0x02, 0x00, 0x00, 0x03}},
79 {{0, 0, 3, hemisphere::west}, {0x51, 0x02, 0x00, 0x00, 0x05}},
80 {{0, 1, 59, hemisphere::west}, {0x51, 0x02, 0x00, 0x00, 0xc6}},
81 {{0, 2, 59, hemisphere::west}, {0x51, 0x02, 0x00, 0x01, 0x2a}},
84 for (auto const & t : cases) {
85 message_51 m;
86 m.set_lon(t.lon);
87 EXPECT_EQ(t.expected, m.get_data()) << "longitude=" << t.lon;