Version 0.8.0
[marnav.git] / test / seatalk / Test_seatalk_message_22.cpp
blob854300e9514fcfef826e5f3ddfd86bdd7deca436
1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_22.hpp>
4 namespace
7 using namespace marnav;
9 class Test_seatalk_message_22 : public ::testing::Test
13 TEST_F(Test_seatalk_message_22, construction)
15 seatalk::message_22 m;
18 TEST_F(Test_seatalk_message_22, parse_invalid_data_size)
20 EXPECT_ANY_THROW(seatalk::message_22::parse({4, 0x00}));
21 EXPECT_ANY_THROW(seatalk::message_22::parse({6, 0x00}));
24 TEST_F(Test_seatalk_message_22, parse_invalid_length)
26 EXPECT_ANY_THROW(seatalk::message_22::parse({0x22, 0x01, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(seatalk::message_22::parse({0x22, 0x03, 0x00, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_22, parse)
32 struct test_case {
33 seatalk::raw data;
34 uint32_t distance;
37 std::vector<test_case> cases{
38 {{0x22, 0x02, 0x00, 0x00, 0x00}, 0}, // 0.0 nm
39 {{0x22, 0x02, 0x00, 0x00, 0x0f}, 0}, // 0.0 nm
40 {{0x22, 0x02, 0x00, 0x00, 0xf0}, 0}, // 0.0 nm
41 {{0x22, 0x02, 0x00, 0x01, 0x00}, 1}, // 0.1 nm
42 {{0x22, 0x02, 0x00, 0x10, 0x00}, 16}, // 1.6 nm
43 {{0x22, 0x02, 0x01, 0x00, 0x00}, 256}, // 25.6 nm
44 {{0x22, 0x02, 0x10, 0x00, 0x00}, 4096}, // 409.6 nm
47 for (auto const & t : cases) {
48 auto generic_message = seatalk::message_22::parse(t.data);
49 ASSERT_TRUE(generic_message != nullptr);
50 auto m = seatalk::message_cast<seatalk::message_22>(generic_message);
51 ASSERT_TRUE(m != nullptr);
52 EXPECT_EQ(seatalk::message_id::total_mileage, m->type());
53 EXPECT_EQ(t.distance, m->get_distance());
57 TEST_F(Test_seatalk_message_22, write_default)
59 const seatalk::raw expected{0x22, 0x02, 0x00, 0x00, 0x00};
60 seatalk::message_22 m;
62 EXPECT_EQ(expected, m.get_data());
65 TEST_F(Test_seatalk_message_22, write_distance)
67 const seatalk::raw expected{0x22, 0x02, 0x00, 0x01, 0x00};
68 seatalk::message_22 m;
69 m.set_distance(1);
71 EXPECT_EQ(expected, m.get_data());