1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_25.hpp>
7 using namespace marnav
;
9 class Test_seatalk_message_25
: public ::testing::Test
13 TEST_F(Test_seatalk_message_25
, construction
)
15 seatalk::message_25 m
;
18 TEST_F(Test_seatalk_message_25
, parse_invalid_data_size
)
20 EXPECT_ANY_THROW(seatalk::message_25::parse({6, 0x00}));
21 EXPECT_ANY_THROW(seatalk::message_25::parse({8, 0x00}));
24 TEST_F(Test_seatalk_message_25
, parse_invalid_length
)
26 EXPECT_ANY_THROW(seatalk::message_25::parse({0x25, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(seatalk::message_25::parse({0x25, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_25
, parse
)
38 std::vector
<test_case
> cases
{
39 {{0x25, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00}, 0, 0},
40 {{0x25, 0x04, 0x00, 0x00, 0x00, 0x00, 0x01}, 0, 65536}, // trip
41 {{0x25, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10}, 0, 0}, // trip
42 {{0x25, 0x04, 0x00, 0x00, 0x00, 0x01, 0x00}, 0, 256}, // trip
43 {{0x25, 0x04, 0x00, 0x00, 0x00, 0x10, 0x00}, 0, 4096}, // trip
44 {{0x25, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00}, 0, 1}, // trip
45 {{0x25, 0x04, 0x00, 0x00, 0x10, 0x00, 0x00}, 0, 16}, // trip
46 {{0x25, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00}, 256, 0}, // total
47 {{0x25, 0x04, 0x00, 0x10, 0x00, 0x00, 0x00}, 4096, 0}, // total
48 {{0x25, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00}, 1, 0}, // total
49 {{0x25, 0x04, 0x10, 0x00, 0x00, 0x00, 0x00}, 16, 0}, // total
50 {{0x25, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00}, 65536, 0}, // total
53 for (auto const & t
: cases
) {
54 auto generic_message
= seatalk::message_25::parse(t
.data
);
55 ASSERT_TRUE(generic_message
!= nullptr);
56 auto m
= seatalk::message_cast
<seatalk::message_25
>(generic_message
);
57 ASSERT_TRUE(m
!= nullptr);
58 EXPECT_EQ(seatalk::message_id::total_and_trip_log
, m
->type());
59 EXPECT_EQ(t
.total
, m
->get_total());
60 EXPECT_EQ(t
.trip
, m
->get_trip());
64 TEST_F(Test_seatalk_message_25
, write_default
)
66 const seatalk::raw expected
{0x25, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00};
67 seatalk::message_25 m
;
69 EXPECT_EQ(expected
, m
.get_data());
72 TEST_F(Test_seatalk_message_25
, write_total
)
74 const seatalk::raw expected
{0x25, 0x04, 0x00, 0x01, 0x00, 0x00, 0x00};
75 seatalk::message_25 m
;
78 EXPECT_EQ(expected
, m
.get_data());
81 TEST_F(Test_seatalk_message_25
, write_trip
)
83 const seatalk::raw expected
{0x25, 0x04, 0x00, 0x00, 0x01, 0x00, 0x00};
84 seatalk::message_25 m
;
87 EXPECT_EQ(expected
, m
.get_data());