Version 0.8.0
[marnav.git] / test / seatalk / Test_seatalk_message_6c.cpp
blob6574430aed0ba5103166d7eaa86e3cd4231dffc4
1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_6c.hpp>
4 namespace
6 using namespace marnav;
7 using namespace marnav::seatalk;
9 class Test_seatalk_message_6c : public ::testing::Test
13 TEST_F(Test_seatalk_message_6c, construction)
15 message_6c m;
18 TEST_F(Test_seatalk_message_6c, parse_invalid_data_size)
20 EXPECT_ANY_THROW(message_6c::parse({7, 0x00}));
21 EXPECT_ANY_THROW(message_6c::parse({9, 0x00}));
24 TEST_F(Test_seatalk_message_6c, parse_invalid_length)
26 EXPECT_ANY_THROW(message_6c::parse({0x6c, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(message_6c::parse({0x6c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_6c, parse)
32 struct test_case {
33 seatalk::raw data;
34 equipment_id id;
37 std::vector<test_case> cases{
38 {{0x6C, 0x05, 0x04, 0xBA, 0x20, 0x28, 0x2D, 0x2D}, message_6c::st60_tridata},
39 {{0x6C, 0x05, 0x05, 0x70, 0x99, 0x10, 0x28, 0x2D}, message_6c::st60_log},
40 {{0x6C, 0x05, 0xF3, 0x18, 0x00, 0x26, 0x2D, 0x2D}, message_6c::st80_masterview},
43 for (auto const & t : cases) {
44 auto generic_message = message_6c::parse(t.data);
45 ASSERT_TRUE(generic_message != nullptr);
46 auto m = message_cast<message_6c>(generic_message);
47 ASSERT_TRUE(m != nullptr);
48 EXPECT_EQ(message_id::equipment_id_2, m->type());
49 EXPECT_EQ(t.id, m->get_equipment_id());
53 TEST_F(Test_seatalk_message_6c, write_default)
55 const raw expected{0x6c, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
56 message_6c m;
58 EXPECT_EQ(expected, m.get_data());
61 TEST_F(Test_seatalk_message_6c, write)
63 const raw expected{0x6c, 0x05, 0x04, 0xBA, 0x20, 0x28, 0x2D, 0x2D};
64 message_6c m;
65 m.set_equipment_id(message_6c::st60_tridata);
67 EXPECT_EQ(expected, m.get_data());