Build: update docker build scripts
[marnav.git] / test / seatalk / Test_seatalk_message_10.cpp
blob2989813d5174357885010207da72d33e1d1347ed
1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_10.hpp>
4 namespace
7 using namespace marnav;
9 class Test_seatalk_message_10 : public ::testing::Test
13 TEST_F(Test_seatalk_message_10, construction)
15 seatalk::message_10 m;
18 TEST_F(Test_seatalk_message_10, parse_invalid_data_size)
20 EXPECT_ANY_THROW(seatalk::message_10::parse({3, 0x00}));
21 EXPECT_ANY_THROW(seatalk::message_10::parse({5, 0x00}));
24 TEST_F(Test_seatalk_message_10, parse_invalid_length)
26 EXPECT_ANY_THROW(seatalk::message_10::parse({0x10, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(seatalk::message_10::parse({0x10, 0x02, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_10, parse)
32 struct test_case {
33 seatalk::raw data;
34 uint16_t angle;
37 std::vector<test_case> cases{
38 {{0x10, 0x01, 0x00, 0x00}, 0}, // 0.0 deg
39 {{0x10, 0x01, 0x00, 0x01}, 5}, // 0.5 deg
40 {{0x10, 0x01, 0x00, 0x02}, 10}, // 1.0 deg
41 {{0x10, 0x01, 0x00, 0x03}, 15}, // 1.5 deg
42 {{0x10, 0x01, 0x00, 0x04}, 20}, // 2.0 deg
43 {{0x10, 0x01, 0x00, 0x14}, 100}, // 10.0 deg
44 {{0x10, 0x01, 0x00, 0xb4}, 900}, // 90.0 deg
47 for (auto const & t : cases) {
48 auto generic_message = seatalk::message_10::parse(t.data);
49 ASSERT_TRUE(generic_message != nullptr);
50 auto m = seatalk::message_cast<seatalk::message_10>(generic_message);
51 ASSERT_TRUE(m != nullptr);
52 EXPECT_EQ(seatalk::message_id::apparent_wind_angle, m->type());
53 EXPECT_EQ(t.angle, m->get_angle());
57 TEST_F(Test_seatalk_message_10, write_default)
59 const seatalk::raw expected{0x10, 0x01, 0x00, 0x00};
60 seatalk::message_10 m;
62 EXPECT_EQ(expected, m.get_data());
65 TEST_F(Test_seatalk_message_10, write_angle)
67 const seatalk::raw expected{0x10, 0x01, 0x01, 0x00};
68 seatalk::message_10 m;
69 m.set_angle(1);
71 EXPECT_EQ(expected, m.get_data());