bug fix: MMSI MID mapping completed.
[marnav.git] / test / seatalk / Test_seatalk_message_27.cpp
blob8de9008df0ab2ba7f814ce0a95ea55998917443b
1 #include <gtest/gtest.h>
2 #include <marnav/seatalk/message_27.hpp>
4 namespace
7 using namespace marnav;
9 class Test_seatalk_message_27 : public ::testing::Test
13 TEST_F(Test_seatalk_message_27, construction)
15 seatalk::message_27 m;
18 TEST_F(Test_seatalk_message_27, parse_invalid_data_size)
20 EXPECT_ANY_THROW(seatalk::message_27::parse({3, 0x00}));
21 EXPECT_ANY_THROW(seatalk::message_27::parse({5, 0x00}));
24 TEST_F(Test_seatalk_message_27, parse_invalid_length)
26 EXPECT_ANY_THROW(seatalk::message_27::parse({0x27, 0x00, 0x00, 0x00}));
27 EXPECT_ANY_THROW(seatalk::message_27::parse({0x27, 0x02, 0x00, 0x00}));
30 TEST_F(Test_seatalk_message_27, parse)
32 struct test_case {
33 seatalk::raw data;
34 int32_t temperature;
37 std::vector<test_case> cases{
38 {{0x27, 0x01, 0x00, 0x00}, -100}, // -10.0 degree celsius
39 {{0x27, 0x01, 0x10, 0x00}, 3996}, // 399.6 degree celsius
40 {{0x27, 0x01, 0x00, 0x10}, -84}, // -8.4 degree celsius
41 {{0x27, 0x01, 0x10, 0x10}, 4012}, // 401.2 degree celsius
42 {{0x27, 0x01, 0x00, 0x64}, 0}, // 0.0 degree celsius
43 {{0x27, 0x01, 0x00, 0x65}, 1}, // 1.0 degree celsius
44 {{0x27, 0x01, 0x00, 0x63}, -1}, // -1.0 degree celsius
47 for (auto const & t : cases) {
48 auto generic_message = seatalk::message_27::parse(t.data);
49 ASSERT_TRUE(generic_message != nullptr);
50 auto m = seatalk::message_cast<seatalk::message_27>(generic_message);
51 ASSERT_TRUE(m != nullptr);
52 EXPECT_EQ(seatalk::message_id::water_temperature_2, m->type());
53 EXPECT_EQ(t.temperature, m->get_temperature());
57 TEST_F(Test_seatalk_message_27, write_default)
59 const seatalk::raw expected{0x27, 0x01, 0x00, 0x64};
60 seatalk::message_27 m;
62 EXPECT_EQ(expected, m.get_data());
65 TEST_F(Test_seatalk_message_27, write_distance)
67 const seatalk::raw expected{0x27, 0x01, 0x00, 0x01};
68 seatalk::message_27 m;
69 m.set_temperature(-99);
71 EXPECT_EQ(expected, m.get_data());