1 #include <marnav/ais/message_18.hpp>
2 #include <marnav/ais/ais.hpp>
3 #include <gtest/gtest.h>
8 using namespace marnav
;
10 class Test_ais_message_18
: public ::testing::Test
14 TEST_F(Test_ais_message_18
, parse
)
16 std::vector
<std::pair
<std::string
, uint32_t>> v
;
17 v
.push_back(std::make_pair("B000000000H0htY08D41qwv00000", 0));
19 auto result
= ais::make_message(v
);
20 ASSERT_TRUE(result
!= nullptr);
22 auto m
= ais::message_cast
<ais::message_18
>(result
);
23 ASSERT_TRUE(m
!= nullptr);
26 TEST_F(Test_ais_message_18
, wrong_number_of_bits
)
28 EXPECT_ANY_THROW(ais::message_parse
<ais::message_18
>(ais::raw(167)));
29 EXPECT_ANY_THROW(ais::message_parse
<ais::message_18
>(ais::raw(169)));
32 TEST_F(Test_ais_message_18
, encode_default_values
)
36 auto v
= ais::encode_message(m
);
38 ASSERT_EQ(1u, v
.size());
39 EXPECT_STREQ("B0000003wk?8mP=18D3Q3wv00000", v
[0].first
.c_str());
40 EXPECT_EQ(0u, v
[0].second
);
43 TEST_F(Test_ais_message_18
, set_lat
)
46 m
.set_lat(geo::latitude
{12.34});
48 auto v
= ais::encode_message(m
);
50 ASSERT_EQ(1u, v
.size());
51 EXPECT_STREQ("B0000003wk?8mP1hvN3Q3wv00000", v
[0].first
.c_str());
52 EXPECT_EQ(0u, v
[0].second
);
55 TEST_F(Test_ais_message_18
, get_lat
)
57 std::vector
<std::pair
<std::string
, uint32_t>> v
;
58 v
.push_back(std::make_pair("B000000003?8mP1hvN3Q3wv00000", 0));
60 auto result
= ais::make_message(v
);
61 ASSERT_TRUE(result
!= nullptr);
63 auto m
= ais::message_cast
<ais::message_18
>(result
);
64 ASSERT_TRUE(m
!= nullptr);
66 const geo::latitude expected
{12.34};
67 const geo::latitude decoded
= *m
->get_lat();
69 EXPECT_DOUBLE_EQ(expected
, decoded
);
72 TEST_F(Test_ais_message_18
, set_lon
)
75 m
.set_lon(geo::longitude
{123.45});
77 auto v
= ais::encode_message(m
);
79 ASSERT_EQ(1u, v
.size());
80 EXPECT_STREQ("B0000003wj=Agp=18D3Q3wv00000", v
[0].first
.c_str());
81 EXPECT_EQ(0u, v
[0].second
);
84 TEST_F(Test_ais_message_18
, get_lon
)
86 std::vector
<std::pair
<std::string
, uint32_t>> v
;
87 v
.push_back(std::make_pair("B000000002=Agp=18D3Q3wv00000", 0));
89 auto result
= ais::make_message(v
);
90 ASSERT_TRUE(result
!= nullptr);
92 auto m
= ais::message_cast
<ais::message_18
>(result
);
93 ASSERT_TRUE(m
!= nullptr);
95 const geo::longitude expected
{123.45};
96 const geo::longitude decoded
= *m
->get_lon();
98 EXPECT_DOUBLE_EQ(expected
, decoded
);