General: separation of marav-io as a library
[marnav.git] / test / marnav / seatalk / Test_seatalk_message_59.cpp
blobe0e5ef58df031995a8c31415f12ba1ec0ba90319
1 #include <marnav/seatalk/message_59.hpp>
2 #include <gtest/gtest.h>
4 namespace
6 using namespace marnav::seatalk;
8 using mode = marnav::seatalk::message_59::mode;
10 class Test_seatalk_message_59 : public ::testing::Test
12 public:
13 struct test_case {
14 raw data;
15 uint8_t hours;
16 uint8_t minutes;
17 uint8_t seconds;
18 mode m;
21 const std::vector<test_case> cases{
22 {{0x59, 0x22, 0x00, 0x00, 0x00}, 0, 0, 0, mode::up_and_start},
23 {{0x59, 0x22, 0x01, 0x00, 0x00}, 0, 0, 1, mode::up_and_start},
24 {{0x59, 0x22, 0x00, 0x01, 0x00}, 0, 1, 0, mode::up_and_start},
25 {{0x59, 0x22, 0x00, 0x00, 0x01}, 1, 0, 0, mode::up_and_start},
26 {{0x59, 0x22, 0x00, 0x00, 0x40}, 0, 0, 0, mode::down},
27 {{0x59, 0x22, 0x00, 0x00, 0x80}, 0, 0, 0, mode::down_and_start},
31 TEST_F(Test_seatalk_message_59, construction)
33 EXPECT_NO_THROW(message_59 m);
36 TEST_F(Test_seatalk_message_59, parse_invalid_data_size)
38 EXPECT_ANY_THROW(message_59::parse({4, 0x00}));
39 EXPECT_ANY_THROW(message_59::parse({6, 0x00}));
42 TEST_F(Test_seatalk_message_59, parse_invalid_length)
44 EXPECT_ANY_THROW(message_59::parse({0x59, 0x21, 0x00, 0x00, 0x00}));
45 EXPECT_ANY_THROW(message_59::parse({0x59, 0x23, 0x00, 0x00, 0x00}));
48 TEST_F(Test_seatalk_message_59, parse)
50 for (auto const & t : cases) {
51 auto generic_message = message_59::parse(t.data);
52 EXPECT_TRUE(generic_message != nullptr);
53 if (!generic_message)
54 continue;
55 auto m = message_cast<message_59>(generic_message);
56 EXPECT_TRUE(m != nullptr);
57 if (!m)
58 continue;
59 EXPECT_EQ(t.hours, m->get_hours());
60 EXPECT_EQ(t.minutes, m->get_minutes());
61 EXPECT_EQ(t.seconds, m->get_seconds());
62 EXPECT_EQ(t.m, m->get_mode());
66 TEST_F(Test_seatalk_message_59, write_default)
68 const raw expected{0x59, 0x22, 0x00, 0x00, 0x00};
69 message_59 m;
71 EXPECT_EQ(expected, m.get_data());
74 TEST_F(Test_seatalk_message_59, set_timer)
76 for (auto const & t : cases) {
77 message_59 m;
78 m.set_timer(t.hours, t.minutes, t.seconds, t.m);
79 const auto raw = m.get_data();
80 EXPECT_EQ(t.data, raw);
84 TEST_F(Test_seatalk_message_59, set_timer_boundaries)
87 message_59 m;
88 m.set_timer(10, 0, 0, mode::up_and_start);
89 EXPECT_EQ(9u, m.get_hours());
92 message_59 m;
93 m.set_timer(0, 60, 0, mode::up_and_start);
94 EXPECT_EQ(59u, m.get_minutes());
97 message_59 m;
98 m.set_timer(0, 0, 60, mode::up_and_start);
99 EXPECT_EQ(59u, m.get_seconds());