AIS: initialization of message fields modernized.
[marnav.git] / test / ais / Test_ais_message_03.cpp
blob4a1edb302d1ad6a53f71a3c3c52e1a39aee28e8e
1 #include <gtest/gtest.h>
2 #include <marnav/ais/message_03.hpp>
3 #include <marnav/ais/ais.hpp>
5 namespace
8 using namespace marnav;
10 class Test_ais_message_03 : public ::testing::Test
14 TEST_F(Test_ais_message_03, parse)
16 std::vector<std::pair<std::string, uint32_t>> v;
17 v.push_back(std::make_pair("333m@ogP00PD;88MD5MTDww@2D7k", 0));
19 auto result = ais::make_message(v);
20 ASSERT_TRUE(result != nullptr);
22 auto m = ais::message_cast<ais::message_03>(result);
23 ASSERT_TRUE(m != nullptr);
25 EXPECT_EQ(0u, m->get_repeat_indicator());
26 EXPECT_EQ(205344990u, m->get_mmsi());
27 EXPECT_EQ(-128, m->get_rot());
28 EXPECT_EQ(0u, m->get_sog());
29 EXPECT_EQ(true, m->get_position_accuracy());
30 EXPECT_NEAR(4.40705, m->get_longitude(), 4e-5);
31 EXPECT_NEAR(51.2296, m->get_latitude(), 4e-5);
32 EXPECT_EQ(1107u, m->get_cog());
33 EXPECT_EQ(511u, m->get_hdg());
34 EXPECT_EQ(52u, m->get_timestamp());
35 EXPECT_EQ(0u, m->get_maneuver_indicator());
36 EXPECT_EQ(true, m->get_raim());
37 EXPECT_EQ(82419u, m->get_radio_status());
40 TEST_F(Test_ais_message_03, encode_default_values)
42 ais::message_03 m;
44 auto v = ais::encode_message(m);
46 ASSERT_EQ(1u, v.size());
47 EXPECT_STREQ("300000?P?w<tSF0l4Q@>4?wh0000", v[0].first.c_str());
48 EXPECT_EQ(0u, v[0].second);
51 TEST_F(Test_ais_message_03, wrong_number_of_bits)
53 EXPECT_ANY_THROW(ais::message_03::parse(ais::raw{167}));
54 EXPECT_ANY_THROW(ais::message_03::parse(ais::raw{169}));