| 1 | // Test parsing message 17 - GNSS broadcast. |
| 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<Ais17> 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<Ais17> msg(new Ais17(body.c_str(), pad)); |
| 17 | if (!msg || msg->had_error()) { |
| 18 | return nullptr; |
| 19 | } |
| 20 | return msg; |
| 21 | } |
| 22 | |
| 23 | void Validate( |
| 24 | const Ais17 *msg, |
| 25 | const int repeat_indicator, |
| 26 | const int mmsi, |
| 27 | const int spare, |
| 28 | const float x, |
| 29 | const float y, |
| 30 | const int spare2, |
| 31 | const int gnss_type, |
| 32 | const int z_cnt, |
| 33 | const int station, |
| 34 | const int seq, |
| 35 | const int health) { |
| 36 | ASSERT_NE(nullptr, msg); |
| 37 | EXPECT_FALSE(msg->had_error()); |
| 38 | |
| 39 | ASSERT_EQ(17, msg->message_id); |
| 40 | EXPECT_EQ(repeat_indicator, msg->repeat_indicator); |
| 41 | EXPECT_EQ(mmsi, msg->mmsi); |
| 42 | EXPECT_EQ(spare, msg->spare); |
| 43 | EXPECT_NEAR(x, msg->position.lng_deg, 0.0001); |
| 44 | EXPECT_NEAR(y, msg->position.lat_deg, 0.0001); |
| 45 | EXPECT_EQ(spare2, msg->spare2); |
| 46 | EXPECT_EQ(gnss_type, msg->gnss_type); |
| 47 | EXPECT_EQ(z_cnt, msg->z_cnt); |
| 48 | EXPECT_EQ(station, msg->station); |
| 49 | EXPECT_EQ(seq, msg->seq); |
| 50 | EXPECT_EQ(health, msg->health); |
| 51 | } |
| 52 | |
| 53 | TEST(Ais17Test, DecodeAnything) { |
| 54 | std::unique_ptr<Ais17> msg = Init( |
| 55 | "!AIVDM,1,1,,A,A6WWW6gP00a3PDlEKLrarOwUr8Mg,0*03"); |
| 56 | |
| 57 | Validate( |
| 58 | msg.get(), |
| 59 | 0, 444196634, 3, -54.6133, 35.0333, 1, 19, 3513, 277, 6, 1); |
| 60 | |
| 61 | // TODO(schwehr): Handle GNSS payload. |
| 62 | } |
| 63 | |
| 64 | } // namespace |
| 65 | } // namespace libais |