NMEA: make nmeatool available with/without ENABLE_IO
[marnav.git] / test / ais / Test_ais_message_12.cpp
blobd084ac0023be4d5c4405e8a9753198b1d0228bdc
1 #include <marnav/ais/message_12.hpp>
2 #include <marnav/ais/ais.hpp>
3 #include <gtest/gtest.h>
5 namespace
7 using namespace marnav;
9 class Test_ais_message_12 : public ::testing::Test
13 TEST_F(Test_ais_message_12, parse)
15 std::vector<std::pair<std::string, uint32_t>> v;
16 v.push_back(std::make_pair("<02:oP0kKcv0@<51C5PB5@?BDPD?P:?2?EB7PDB16693P381>>5<PikP", 0));
18 auto result = ais::make_message(v);
19 ASSERT_TRUE(result != nullptr);
21 auto m = ais::message_cast<ais::message_12>(result);
22 ASSERT_TRUE(m != nullptr);
25 TEST_F(Test_ais_message_12, wrong_number_of_bits)
27 EXPECT_ANY_THROW(ais::message_parse<ais::message_12>(ais::raw(71)));
28 EXPECT_ANY_THROW(ais::message_parse<ais::message_12>(ais::raw(1009)));
31 TEST_F(Test_ais_message_12, encode_default_values)
33 ais::message_12 m;
35 auto v = ais::encode_message(m);
37 ASSERT_EQ(1u, v.size());
38 EXPECT_STREQ("<00000000000", v[0].first.c_str());
39 EXPECT_EQ(0u, v[0].second);
42 TEST_F(Test_ais_message_12, set_seqno_valid)
44 for (auto i = 0u; i < 4u; ++i) {
45 ais::message_12 m;
46 m.set_seqno(i);
47 EXPECT_EQ(i, m.get_seqno());
51 TEST_F(Test_ais_message_12, set_seqno_invalid)
53 ais::message_12 m;
54 EXPECT_ANY_THROW(m.set_seqno(4u));
57 TEST_F(Test_ais_message_12, set_text_too_large)
59 ais::message_12 m;
60 m.set_text(std::string(ais::message_12::SIZE_TEXT_MAX + 1, '#'));
61 EXPECT_EQ(ais::message_12::SIZE_TEXT_MAX, m.get_text().size());
64 static void test_string(
65 const char * expected, const std::vector<std::pair<std::string, uint32_t>> & v)
67 auto result = ais::make_message(v);
68 ASSERT_TRUE(result != nullptr);
69 auto m = ais::message_cast<ais::message_12>(result);
70 ASSERT_TRUE(m != nullptr);
71 EXPECT_STREQ(expected, m->get_text().c_str());
74 TEST_F(Test_ais_message_12, strings)
76 test_string("PLEASE REPORT TO JOBOURG TRAFFIC CHANNEL 13 ",
77 {{"<02:oP0kKcv0@<51C5PB5@?BDPD?P:?2?EB7PDB16693P381>>5<PikP", 0}});
79 test_string("GOOD", {{"<5?SIj1;GbD07??4", 0}});
81 test_string("THANX", {{"<5?SIj5Cp;NPD81>H0", 4}});
83 test_string("MSG FROM 271002099", {{"<42Lati0W:Ov=C7P6B?=Pjoihhjhqq0", 2}});
85 test_string("EP 531 CARS 80 TRACKS 103 MOTO 5 CREW 86",
86 {{"<CR3B@<0TO3j5@PmkiP31BCPphPDB13;CPihkP=?D?PmP3B5GPpn", 0}});
88 test_string("NI HAO.CALL TEST", {{"<9NS8O1ROcS0>9P81?f31<<PD5CD", 0}});
90 test_string("GUD PM 2U N HAPI NEW YIR OL D BES FRM AL FUJAIRAH",
91 {{"<39KdV8jIGtP7E4P@=PjEP>P81@9P>5GPI9BP?<P4P25CP6B=P1<P6E:19B1", 0}, {"80", 4}});