Version 0.8.0
[marnav.git] / test / seatalk / Test_seatalk_message_11.cpp
blob938c0d0ae65d2886aed1ac2a0f538e22e38f0199
1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_11.hpp>
4 namespace
7 using namespace marnav;
9 class Test_seatalk_message_11 : public ::testing::Test
13 TEST_F(Test_seatalk_message_11, construction)
15 seatalk::message_11 m;
18 TEST_F(Test_seatalk_message_11, parse_invalid_data_size)
20 EXPECT_ANY_THROW(seatalk::message_11::parse({3, 0x00}));
21 EXPECT_ANY_THROW(seatalk::message_11::parse({5, 0x00}));
24 TEST_F(Test_seatalk_message_11, parse_invalid_length)
26 EXPECT_ANY_THROW(seatalk::message_11::parse({0x11, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(seatalk::message_11::parse({0x11, 0x02, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_11, parse)
32 struct test_case {
33 seatalk::raw data;
34 uint16_t speed;
35 char unit;
38 std::vector<test_case> cases{
39 {{0x11, 0x01, 0x00, 0x00}, 0, seatalk::unit::KNOT}, // 0.0 knotS
40 {{0x11, 0x01, 0x00, 0x08}, 8, seatalk::unit::KNOT}, // 0.8 knotS
41 {{0x11, 0x01, 0x08, 0x00}, 80, seatalk::unit::KNOT}, // 8.0 knotS
42 {{0x11, 0x01, 0x08, 0x08}, 88, seatalk::unit::KNOT}, // 8.8 knotS
43 {{0x11, 0x01, 0x0a, 0x00}, 100, seatalk::unit::KNOT}, // 10.0 knotS
44 {{0x11, 0x01, 0x08, 0x0a}, 90, seatalk::unit::KNOT}, // 9.0 knotS
45 {{0x11, 0x01, 0x08, 0x0b}, 91, seatalk::unit::KNOT}, // 9.1 knotS
46 {{0x11, 0x01, 0x80, 0x00}, 0, seatalk::unit::MPS}, // 0.0 m/s
47 {{0x11, 0x01, 0x80, 0x08}, 8, seatalk::unit::MPS}, // 0.8 m/s
48 {{0x11, 0x01, 0x88, 0x00}, 80, seatalk::unit::MPS}, // 8.0 m/s
49 {{0x11, 0x01, 0x88, 0x08}, 88, seatalk::unit::MPS}, // 8.8 m/s
52 for (auto const & t : cases) {
53 auto generic_message = seatalk::message_11::parse(t.data);
54 ASSERT_TRUE(generic_message != nullptr);
55 auto m = seatalk::message_cast<seatalk::message_11>(generic_message);
56 ASSERT_TRUE(m != nullptr);
57 EXPECT_EQ(seatalk::message_id::apparent_wind_speed, m->type());
58 EXPECT_EQ(t.speed, m->get_speed());
59 EXPECT_EQ(t.unit, m->get_unit());
63 TEST_F(Test_seatalk_message_11, write_default)
65 const seatalk::raw expected{0x11, 0x01, 0x00, 0x00};
66 seatalk::message_11 m;
68 EXPECT_EQ(expected, m.get_data());
71 TEST_F(Test_seatalk_message_11, write_unit)
73 const seatalk::raw expected{0x11, 0x01, 0x80, 0x00};
74 seatalk::message_11 m;
75 m.set_unit(seatalk::unit::MPS);
77 EXPECT_EQ(expected, m.get_data());
80 TEST_F(Test_seatalk_message_11, write_speed)
82 const seatalk::raw expected{0x11, 0x01, 0x00, 0x01};
83 seatalk::message_11 m;
84 m.set_speed(1);
86 EXPECT_EQ(expected, m.get_data());