1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_50.hpp>
7 using namespace marnav::seatalk
;
9 class Test_seatalk_message_50
: public ::testing::Test
13 TEST_F(Test_seatalk_message_50
, construction
)
15 EXPECT_NO_THROW(message_50 m
);
18 TEST_F(Test_seatalk_message_50
, parse_invalid_data_size
)
20 EXPECT_ANY_THROW(message_50::parse({4, 0x00}));
21 EXPECT_ANY_THROW(message_50::parse({6, 0x00}));
24 TEST_F(Test_seatalk_message_50
, parse_invalid_length
)
26 EXPECT_ANY_THROW(message_50::parse({0x50, 0x01, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(message_50::parse({0x50, 0x03, 0x00, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_50
, parse
)
36 const std::vector
<test_case
> cases
{
37 {{0x50, 0x02, 0x00, 0x00, 0x00}}, {{0x50, 0x02, 0x0a, 0x00, 0x00}},
38 {{0x50, 0x02, 0x00, 0x01, 0x00}}, {{0x50, 0x02, 0x00, 0x00, 0x01}},
41 for (auto const & t
: cases
) {
42 auto generic_message
= message_50::parse(t
.data
);
43 EXPECT_TRUE(generic_message
!= nullptr);
46 auto m
= message_cast
<message_50
>(generic_message
);
47 EXPECT_TRUE(m
!= nullptr);
53 TEST_F(Test_seatalk_message_50
, write_default
)
55 const raw expected
{0x50, 0x02, 0x00, 0x00, 0x00};
58 EXPECT_EQ(expected
, m
.get_data());
61 TEST_F(Test_seatalk_message_50
, set_lat
)
63 using latitude
= marnav::geo::latitude
;
64 using hemisphere
= latitude::hemisphere
;
71 const std::vector
<test_case
> cases
{
72 {{0, 0, 0, hemisphere::north
}, {0x50, 0x02, 0x00, 0x00, 0x00}},
73 {{0, 0, 0, hemisphere::south
}, {0x50, 0x02, 0x00, 0x00, 0x00}},
74 {{1, 0, 0, hemisphere::north
}, {0x50, 0x02, 0x01, 0x00, 0x00}},
75 {{1, 0, 0, hemisphere::south
}, {0x50, 0x02, 0x01, 0x80, 0x00}},
76 {{0, 1, 0, hemisphere::north
}, {0x50, 0x02, 0x00, 0x00, 0x64}},
77 {{0, 0, 1, hemisphere::north
}, {0x50, 0x02, 0x00, 0x00, 0x01}},
78 {{0, 0, 2, hemisphere::north
}, {0x50, 0x02, 0x00, 0x00, 0x03}},
79 {{0, 0, 3, hemisphere::north
}, {0x50, 0x02, 0x00, 0x00, 0x05}},
80 {{0, 1, 59, hemisphere::north
}, {0x50, 0x02, 0x00, 0x00, 0xc6}},
81 {{0, 2, 59, hemisphere::north
}, {0x50, 0x02, 0x00, 0x01, 0x2a}},
84 for (auto const & t
: cases
) {
87 EXPECT_EQ(t
.expected
, m
.get_data()) << "latitude=" << t
.lat
;