AIS: messages 1,2,3,18 offer more reasonable setter/getter with conversion.
[marnav.git] / test / ais / Test_ais_message_03.cpp
blob2f6b95725374001de657afc10584299887673017
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(ais::rot_not_available, m->get_rot());
28 EXPECT_NEAR(0.0, *m->get_sog(), 1e-4);
29 EXPECT_EQ(true, m->get_position_accuracy());
30 const auto lon = m->get_longitude();
31 EXPECT_TRUE(!!lon);
32 EXPECT_NEAR(4.40705, lon.value(), 4e-5);
33 const auto lat = m->get_latitude();
34 EXPECT_TRUE(!!lat);
35 EXPECT_NEAR(51.2296, lat.value(), 4e-5);
36 EXPECT_NEAR(110.7, *m->get_cog(), 1e-4);
37 EXPECT_TRUE(!m->get_hdg());
38 EXPECT_EQ(52u, m->get_timestamp());
39 EXPECT_EQ(ais::maneuver_indicator_id::not_available, m->get_maneuver_indicator());
40 EXPECT_EQ(true, m->get_raim());
41 EXPECT_EQ(82419u, m->get_radio_status());
44 TEST_F(Test_ais_message_03, encode_default_values)
46 ais::message_03 m;
48 auto v = ais::encode_message(m);
50 ASSERT_EQ(1u, v.size());
51 EXPECT_STREQ("300000?P?w<tSF0l4Q@>4?wh0000", v[0].first.c_str());
52 EXPECT_EQ(0u, v[0].second);
55 TEST_F(Test_ais_message_03, wrong_number_of_bits)
57 EXPECT_ANY_THROW(ais::message_parse<ais::message_03>(ais::raw{167}));
58 EXPECT_ANY_THROW(ais::message_parse<ais::message_03>(ais::raw{169}));