| 1 | // Test parsing message 14 '>' - Addressed safety related |
| 2 | |
| 3 | // TODO(schwehr): Find more test cases. |
| 4 | |
| 5 | #include <memory> |
| 6 | |
| 7 | #include "gtest/gtest.h" |
| 8 | #include "ais.h" |
| 9 | |
| 10 | namespace libais { |
| 11 | namespace { |
| 12 | |
| 13 | std::unique_ptr<Ais14> Init(const string &nmea_string) { |
| 14 | const string body(GetBody(nmea_string)); |
| 15 | const int pad = GetPad(nmea_string); |
| 16 | |
| 17 | // TODO(schwehr): Switch to c++14 make_unique. |
| 18 | std::unique_ptr<Ais14> msg(new Ais14(body.c_str(), pad)); |
| 19 | if (!msg || msg->had_error()) { |
| 20 | return nullptr; |
| 21 | } |
| 22 | return msg; |
| 23 | } |
| 24 | |
| 25 | void Validate( |
| 26 | const Ais14 *msg, |
| 27 | const int repeat_indicator, |
| 28 | const int mmsi, |
| 29 | const int spare, |
| 30 | const string &text) { |
| 31 | ASSERT_NE(nullptr, msg); |
| 32 | EXPECT_FALSE(msg->had_error()); |
| 33 | |
| 34 | ASSERT_EQ(14, msg->message_id); |
| 35 | EXPECT_EQ(repeat_indicator, msg->repeat_indicator); |
| 36 | EXPECT_EQ(mmsi, msg->mmsi); |
| 37 | EXPECT_EQ(spare, msg->spare); |
| 38 | EXPECT_EQ(text, msg->text); |
| 39 | } |
| 40 | |
| 41 | TEST(Ais14Test, DecodeAnything) { |
| 42 | std::unique_ptr<Ais14> msg = Init( |
| 43 | "!AIVDM,1,1,,A,>>M@rl1<59B1@E=@0000000,2*0D"); |
| 44 | Validate( |
| 45 | msg.get(), 0, 970210000, 0, "SART TEST@@@@@@@"); |
| 46 | } |
| 47 | |
| 48 | } // namespace |
| 49 | } // namespace libais |