Debian Codegraph @

src/test/ais27_test.cc

raw symbols SCIP
1 // Test parsing message 27 - Long-range position report.
2
3 #include <memory>
4
5 #include "gtest/gtest.h"
6 #include "ais.h"
7
8 namespace libais {
9 namespace {
10
11 std::unique_ptr<Ais27> Init(const string &nmea_string) {
12 const string body(GetBody(nmea_string));
13 const int pad = GetPad(nmea_string);
14
15 // TODO(schwehr): Switch to c++14 make_unique.
16 std::unique_ptr<Ais27> msg(new Ais27(body.c_str(), pad));
17 if (!msg || msg->had_error()) {
18 return nullptr;
19 }
20 return msg;
21 }
22
23 void Validate(
24 const Ais27 *msg,
25 const int repeat_indicator,
26 const int mmsi,
27 const int position_accuracy,
28 const bool raim,
29 const int nav_status,
30 const double x,
31 const double y,
32 const int sog,
33 const int cog,
34 const bool gnss,
35 const int spare) {
36 ASSERT_NE(nullptr, msg);
37 EXPECT_FALSE(msg->had_error());
38
39 ASSERT_EQ(27, msg->message_id);
40 EXPECT_EQ(repeat_indicator, msg->repeat_indicator);
41 EXPECT_EQ(mmsi, msg->mmsi);
42 EXPECT_EQ(position_accuracy, msg->position_accuracy);
43 EXPECT_EQ(raim, msg->raim);
44 EXPECT_EQ(nav_status, msg->nav_status);
45 EXPECT_DOUBLE_EQ(x, msg->position.lng_deg);
46 EXPECT_DOUBLE_EQ(y, msg->position.lat_deg);
47 EXPECT_EQ(sog, msg->sog);
48 EXPECT_EQ(cog, msg->cog);
49 EXPECT_EQ(gnss, msg->gnss);
50 EXPECT_EQ(spare, msg->spare);
51 }
52
53 TEST(Ais27Test, DecodeAnything) {
54 std::unique_ptr<Ais27> msg = Init(
55 "!AIVDM,1,1,,B,K815>P8=5EikdUet,0*6B");
56
57 Validate(
58 msg.get(), 0, 538005120, 1, false, 0,
59 -79.641666666666666, 24.681666666666668,
60 11, 223, true, 0);
61 }
62
63 } // namespace
64 } // namespace libais