1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_54.hpp>
7 using namespace marnav::seatalk
;
9 class Test_seatalk_message_54
: public ::testing::Test
19 const std::vector
<test_case
> cases
{
20 {{0x54, 0x01, 0x00, 0x00}, 0, 0, 0}, {{0x54, 0x01, 0x00, 0x01}, 1, 0, 0},
21 {{0x54, 0x01, 0x00, 0x10}, 16, 0, 0}, {{0x54, 0x01, 0x04, 0x00}, 0, 1, 0},
22 {{0x54, 0x01, 0x08, 0x00}, 0, 2, 0}, {{0x54, 0x01, 0x10, 0x00}, 0, 4, 0},
23 {{0x54, 0x01, 0x20, 0x00}, 0, 8, 0}, {{0x54, 0x01, 0x40, 0x00}, 0, 16, 0},
24 {{0x54, 0x01, 0x80, 0x00}, 0, 32, 0}, {{0x54, 0x11, 0x00, 0x00}, 0, 0, 1},
25 {{0x54, 0x21, 0x00, 0x00}, 0, 0, 2}, {{0x54, 0x41, 0x00, 0x00}, 0, 0, 4},
26 {{0x54, 0x81, 0x00, 0x00}, 0, 0, 8}, {{0x54, 0x01, 0x01, 0x00}, 0, 0, 16},
27 {{0x54, 0x01, 0x02, 0x00}, 0, 0, 32},
31 TEST_F(Test_seatalk_message_54
, construction
)
33 EXPECT_NO_THROW(message_54 m
);
36 TEST_F(Test_seatalk_message_54
, parse_invalid_data_size
)
38 EXPECT_ANY_THROW(message_54::parse({3, 0x00}));
39 EXPECT_ANY_THROW(message_54::parse({5, 0x00}));
42 TEST_F(Test_seatalk_message_54
, parse_invalid_length
)
44 EXPECT_ANY_THROW(message_54::parse({0x54, 0x00, 0x00, 0x00}));
45 EXPECT_ANY_THROW(message_54::parse({0x54, 0x02, 0x00, 0x00}));
48 TEST_F(Test_seatalk_message_54
, parse
)
50 for (auto const & t
: cases
) {
51 auto generic_message
= message_54::parse(t
.data
);
52 EXPECT_TRUE(generic_message
!= nullptr);
55 auto m
= message_cast
<message_54
>(generic_message
);
56 EXPECT_TRUE(m
!= nullptr);
59 EXPECT_EQ(t
.h
, m
->get_hour());
60 EXPECT_EQ(t
.m
, m
->get_minute());
61 EXPECT_EQ(t
.s
, m
->get_second());
65 TEST_F(Test_seatalk_message_54
, write_default
)
67 const raw expected
{0x54, 0x01, 0x00, 0x00};
70 EXPECT_EQ(expected
, m
.get_data());
73 TEST_F(Test_seatalk_message_54
, set_time
)
75 for (auto const & t
: cases
) {
77 m
.set_time(t
.h
, t
.m
, t
.s
);
78 const auto raw
= m
.get_data();
79 EXPECT_EQ(t
.data
, raw
);