Debian Codegraph @

src/test/ais9_test.cc

raw symbols SCIP
1 // Test parsing message 9 - SAR 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<Ais9> 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<Ais9> msg(new Ais9(body.c_str(), pad));
17 if (!msg || msg->had_error()) {
18 return nullptr;
19 }
20 return msg;
21 }
22
23 void Validate(
24 const Ais9 *msg,
25 const int repeat_indicator,
26 const int mmsi,
27 const int alt,
28 const float sog,
29 const int position_accuracy,
30 const double x,
31 const double y,
32 const float cog,
33 const int timestamp,
34 const int alt_sensor,
35 const int spare,
36 const int dte,
37 const int spare2,
38 const int assigned_mode,
39 const bool raim) {
40 ASSERT_NE(nullptr, msg);
41 EXPECT_FALSE(msg->had_error());
42
43 ASSERT_EQ(9, msg->message_id);
44 EXPECT_EQ(repeat_indicator, msg->repeat_indicator);
45 EXPECT_EQ(mmsi, msg->mmsi);
46 EXPECT_EQ(alt, msg->alt);
47 EXPECT_FLOAT_EQ(sog, msg->sog);
48 EXPECT_EQ(position_accuracy, msg->position_accuracy);
49 EXPECT_DOUBLE_EQ(x, msg->position.lng_deg);
50 EXPECT_DOUBLE_EQ(y, msg->position.lat_deg);
51 EXPECT_FLOAT_EQ(cog, msg->cog);
52 EXPECT_EQ(timestamp, msg->timestamp);
53 EXPECT_EQ(alt_sensor, msg->alt_sensor);
54 EXPECT_EQ(spare, msg->spare);
55 EXPECT_EQ(dte, msg->dte);
56 EXPECT_EQ(spare2, msg->spare2);
57 EXPECT_EQ(assigned_mode, msg->assigned_mode);
58 EXPECT_EQ(raim, msg->raim);
59 }
60
61 TEST(Ais9Test, DecodeAnything) {
62 std::unique_ptr<Ais9> msg = Init(
63 "!AIVDM,1,1,,B,9oVAuAI5;rRRv2OqTi?1uoP?=a@1,0*74");
64
65 Validate(
66 msg.get(), 3, 509902149, 2324, 762, 1,
67 35.601198333333336, -11.229340000000001,
68 50.3, 30, 0, 3, 1, 4, 1, true);
69
70 // TODO(schwehr): Validate commstate.
71 }
72
73 } // namespace
74 } // namespace libais