| 1 | // Test parsing message 24 - Class B Static Data 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<Ais24> 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<Ais24> msg(new Ais24(body.c_str(), pad)); |
| 17 | if (!msg || msg->had_error()) { |
| 18 | return nullptr; |
| 19 | } |
| 20 | return msg; |
| 21 | } |
| 22 | |
| 23 | void Validate( |
| 24 | const Ais24 *msg, |
| 25 | const int repeat_indicator, |
| 26 | const int mmsi, |
| 27 | const int part_num, |
| 28 | const string name, |
| 29 | const int type_and_cargo, |
| 30 | const string vendor_id, |
| 31 | const string callsign, |
| 32 | const int dim_a, |
| 33 | const int dim_b, |
| 34 | const int dim_c, |
| 35 | const int dim_d, |
| 36 | const int spare) { |
| 37 | ASSERT_NE(nullptr, msg); |
| 38 | EXPECT_FALSE(msg->had_error()); |
| 39 | |
| 40 | ASSERT_EQ(24, msg->message_id); |
| 41 | EXPECT_EQ(repeat_indicator, msg->repeat_indicator); |
| 42 | EXPECT_EQ(mmsi, msg->mmsi); |
| 43 | EXPECT_EQ(part_num, msg->part_num); |
| 44 | EXPECT_EQ(name, msg->name); |
| 45 | EXPECT_EQ(type_and_cargo, msg->type_and_cargo); |
| 46 | EXPECT_EQ(vendor_id, msg->vendor_id); |
| 47 | EXPECT_EQ(callsign, msg->callsign); |
| 48 | EXPECT_EQ(dim_a, msg->dim_a); |
| 49 | EXPECT_EQ(dim_b, msg->dim_b); |
| 50 | EXPECT_EQ(dim_c, msg->dim_c); |
| 51 | EXPECT_EQ(dim_d, msg->dim_d); |
| 52 | EXPECT_EQ(spare, msg->spare); |
| 53 | } |
| 54 | |
| 55 | TEST(Ais24Test, DecodePartA) { |
| 56 | std::unique_ptr<Ais24> msg = Init( |
| 57 | "!AIVDM,1,1,,A,H44cj<0DdvlHhuB222222222220,2*46"); |
| 58 | |
| 59 | Validate( |
| 60 | msg.get(), 0, 273347120, 0, "EKO-FLOT ", |
| 61 | 0, "", "", 0, 0, 0, 0, 0); |
| 62 | } |
| 63 | |
| 64 | // Part A is supposed to be 160 bytes, but takes 168 too. |
| 65 | TEST(Ais24Test, DecodePartA168) { |
| 66 | std::unique_ptr<Ais24> msg = Init( |
| 67 | "!AIVDM,1,1,,A,H69LVS370a4d6222222222222200,0*29"); |
| 68 | |
| 69 | Validate( |
| 70 | msg.get(), 0, 412558988, 0, "10JQKA ", |
| 71 | 0, "", "", 0, 0, 0, 0, 0); |
| 72 | } |
| 73 | |
| 74 | TEST(Ais24Test, DecodePartB) { |
| 75 | std::unique_ptr<Ais24> msg = Init( |
| 76 | "!AIVDM,1,1,,A,H02IDPDm3?=1B00@9<?D00081110,0*6D"); |
| 77 | |
| 78 | Validate( |
| 79 | msg.get(), 0, 2512001, 1, "", 53, "COMAR@@", "PILOT@@", 1, 1, 1, 1, 0); |
| 80 | } |
| 81 | |
| 82 | // Incorrectly using part B to store part A. |
| 83 | TEST(Ais24Test, DecodePartAinB1) { |
| 84 | std::unique_ptr<Ais24> msg = Init( |
| 85 | "!AIVDM,1,1,,A,H34l584400Hh;M1@VL000000000,2*07"); |
| 86 | |
| 87 | // Suspiciously decodes like junk. It would be good to know |
| 88 | // why this message is being broadcast and what the actual |
| 89 | // vessel name is supposed to be. Is it bad AIS hardware? |
| 90 | // Is the ship name really supposed to be "A"? |
| 91 | Validate( |
| 92 | msg.get(), 0, 206374176, 0, "A@@FLB7PTI`@@@@@@@@@", |
| 93 | 0, "", "", 0, 0, 0, 0, 0); |
| 94 | } |
| 95 | |
| 96 | // Incorrectly using part B to store part A. |
| 97 | TEST(Ais24Test, DecodePartAinB2) { |
| 98 | std::unique_ptr<Ais24> msg = Init( |
| 99 | "!AIVDM,1,1,,A,H69oQAlh4V1QDr377C362222220,2*69"); |
| 100 | |
| 101 | Validate( |
| 102 | msg.get(), 0, 413000007, 0, "LAI XUN 11401 ", |
| 103 | 0, "", "", 0, 0, 0, 0, 0); |
| 104 | } |
| 105 | |
| 106 | // Incorrectly using part B to store part A. |
| 107 | TEST(Ais24Test, DecodePartAinB3) { |
| 108 | std::unique_ptr<Ais24> msg = Init( |
| 109 | "!AIVDM,1,1,,B,H3tlF0TTT0000000004>M3Q<4h0,2*23"); |
| 110 | |
| 111 | // Suspiciously decodes like junk. Is this ship really supposed to |
| 112 | // be named "II"? Is there a bad embedded software on this Class B AIS? |
| 113 | Validate( |
| 114 | msg.get(), 0, 265098754, 0, "II@@@@@@@@@AC`P8SAL@", |
| 115 | 0, "", "", 0, 0, 0, 0, 0); |
| 116 | } |
| 117 | |
| 118 | // Part C (2) is not defined as of ITU 1371-5. |
| 119 | TEST(Ais24Test, DecodePartC) { |
| 120 | std::unique_ptr<Ais24> msg = Init( |
| 121 | "!AIVDM,1,1,,A,H4eHhPLN000000038inPPP0P;330,0*4A"); |
| 122 | |
| 123 | ASSERT_EQ(nullptr, msg); |
| 124 | } |
| 125 | |
| 126 | // Part D (3) is not defined as of ITU 1371-5. |
| 127 | TEST(Ais24Test, DecodePartD) { |
| 128 | std::unique_ptr<Ais24> msg = Init( |
| 129 | "!AIVDM,1,1,,B,H3<D4q>0A8psB23B0tD4l000000,2*4C"); |
| 130 | |
| 131 | ASSERT_EQ(nullptr, msg); |
| 132 | } |
| 133 | |
| 134 | } // namespace |
| 135 | } // namespace libais |