Version 0.8.0
[marnav.git] / test / seatalk / Test_seatalk_message_52.cpp
blob462cf5ddba398a2f8e4ae6c6905dfd1ad34c612d
1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_52.hpp>
4 namespace
7 using namespace marnav::seatalk;
9 class Test_seatalk_message_52 : public ::testing::Test
13 TEST_F(Test_seatalk_message_52, construction)
15 EXPECT_NO_THROW(message_52 m);
18 TEST_F(Test_seatalk_message_52, parse_invalid_data_size)
20 EXPECT_ANY_THROW(message_52::parse({3, 0x00}));
21 EXPECT_ANY_THROW(message_52::parse({5, 0x00}));
24 TEST_F(Test_seatalk_message_52, parse_invalid_length)
26 EXPECT_ANY_THROW(message_52::parse({0x52, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(message_52::parse({0x52, 0x02, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_52, parse)
32 struct test_case {
33 raw data;
34 double sog;
37 const std::vector<test_case> cases{
38 {{0x52, 0x01, 0x00, 0x01}, 0.1}, {{0x52, 0x01, 0x00, 0x10}, 1.6},
39 {{0x52, 0x01, 0x01, 0x00}, 25.6}, {{0x52, 0x01, 0x10, 0x00}, 409.6},
42 for (auto const & t : cases) {
43 auto generic_message = message_52::parse(t.data);
44 EXPECT_TRUE(generic_message != nullptr);
45 if (!generic_message)
46 continue;
47 auto m = message_cast<message_52>(generic_message);
48 EXPECT_TRUE(m != nullptr);
49 if (!m)
50 continue;
51 EXPECT_NEAR(t.sog, m->get_sog(), 1e-5);
55 TEST_F(Test_seatalk_message_52, write_default)
57 const raw expected{0x52, 0x01, 0x00, 0x00};
58 message_52 m;
60 EXPECT_EQ(expected, m.get_data());