General: separation of marav-io as a library
[marnav.git] / test / marnav / seatalk / Test_seatalk_message_86.cpp
blob3114e0885bce56e83843aeb08a38f019438ff464
1 #include <marnav/seatalk/message_86.hpp>
2 #include <gtest/gtest.h>
4 namespace
6 using namespace marnav::seatalk;
8 class Test_seatalk_message_86 : public ::testing::Test
10 public:
11 struct test_case {
12 raw data;
13 message_86::origin org;
14 key k;
17 const std::vector<test_case> cases{
18 {{0x86, 0x01, 0x02, 0xfd}, message_86::origin::st1000, key::key_standby},
19 {{0x86, 0x01, 0x05, 0xfa}, message_86::origin::st1000, key::key_m1},
20 {{0x86, 0x01, 0x06, 0xf9}, message_86::origin::st1000, key::key_m10},
21 {{0x86, 0x01, 0x07, 0xf8}, message_86::origin::st1000, key::key_p1},
22 {{0x86, 0x01, 0x08, 0xf7}, message_86::origin::st1000, key::key_p10},
26 TEST_F(Test_seatalk_message_86, construction)
28 EXPECT_NO_THROW(message_86 m);
31 TEST_F(Test_seatalk_message_86, parse_invalid_data_size)
33 EXPECT_ANY_THROW(message_86::parse({3, 0x00}));
34 EXPECT_ANY_THROW(message_86::parse({5, 0x00}));
37 TEST_F(Test_seatalk_message_86, parse_invalid_length)
39 EXPECT_ANY_THROW(message_86::parse({0x86, 0x00, 0x00, 0x00}));
40 EXPECT_ANY_THROW(message_86::parse({0x86, 0x02, 0x00, 0x00}));
43 TEST_F(Test_seatalk_message_86, parse)
45 for (auto const & t : cases) {
46 auto generic_message = message_86::parse(t.data);
47 EXPECT_TRUE(generic_message != nullptr);
48 if (!generic_message)
49 continue;
50 auto m = message_cast<message_86>(generic_message);
51 EXPECT_TRUE(m != nullptr);
52 if (!m)
53 continue;
54 EXPECT_EQ(t.org, m->get_org());
55 EXPECT_EQ(t.k, m->get_key());
59 TEST_F(Test_seatalk_message_86, parse_invalid_code)
61 const raw data{0x86, 0x01, 0x02, 0xfc};
63 EXPECT_ANY_THROW(message_86::parse(data));
66 TEST_F(Test_seatalk_message_86, write_default)
68 const raw expected{0x86, 0x01, 0x02, 0xfd};
69 message_86 m;
71 EXPECT_EQ(expected, m.get_data());