Debian Codegraph @

src/test/ais8_200_test.cc

raw symbols SCIP
1 // Test parsing EU River Information System (RIS) 8:200:* messages.
2
3 #include <array>
4 #include <memory>
5 // #include "third_party/absl/memory/memory.h"
6
7 #include "gtest/gtest.h"
8 #include "ais.h"
9
10 namespace libais {
11 namespace {
12
13 // TODO(schwehr): Test eu_id.
14 void Validate8_200_10(const Ais8_200_10 *msg, const int repeat_indicator,
15 const int mmsi, const string & /* eu_id */,
16 const float length, const float beam, const int ship_type,
17 const int haz_cargo, const float draught,
18 const int loaded, const int speed_qual,
19 const int course_qual, const int heading_qual,
20 const int spare2) {
21 ASSERT_NE(nullptr, msg);
22 EXPECT_FALSE(msg->had_error());
23
24 ASSERT_EQ(8, msg->message_id);
25 EXPECT_EQ(repeat_indicator, msg->repeat_indicator);
26 EXPECT_EQ(mmsi, msg->mmsi);
27 EXPECT_EQ(200, msg->dac);
28 ASSERT_EQ(10, msg->fi);
29
30 EXPECT_FLOAT_EQ(length, msg->length);
31 EXPECT_FLOAT_EQ(beam, msg->beam);
32 EXPECT_EQ(ship_type, msg->ship_type);
33 EXPECT_EQ(haz_cargo, msg->haz_cargo);
34 EXPECT_FLOAT_EQ(draught, msg->draught);
35 EXPECT_EQ(loaded, msg->loaded);
36 EXPECT_EQ(speed_qual, msg->speed_qual);
37 EXPECT_EQ(course_qual, msg->course_qual);
38 EXPECT_EQ(heading_qual, msg->heading_qual);
39 EXPECT_EQ(spare2, msg->spare2);
40 }
41
42 TEST(Ais8_200_10Test, DecodeAnything) {
43 // clang-format off
44 // !SAVDM,1,1,5,B,85NLn@0j2d<8000000BhI?`50000,0*2A,d,S1241,t002333.00,T33.111314,D08MN-NO-BSABS1,1429316613 NOLINT
45 // clang-format on
46
47 std::unique_ptr<Ais8_200_10> msg(
48 new Ais8_200_10("85NLn@0j2d<8000000BhI?`50000", 0));
49 Validate8_200_10(msg.get(), 0, 367474240, string("foo"), 15, 5, 8000, 5,
50 0, 0, 0, 0, 0, 0);
51 }
52
53 // TODO(pyrog): Test messages for 8:200:21.
54 // TODO(pyrog): Test messages for 8:200:22.
55
56 void Validate8_200_24(const Ais8_200_24 &msg, const int repeat_indicator,
57 const int mmsi, const string country,
58 std::array<int, 4> gauge_ids,
59 std::array<float, 4> levels) {
60 EXPECT_FALSE(msg.had_error());
61
62 ASSERT_EQ(8, msg.message_id);
63 ASSERT_EQ(repeat_indicator, msg.repeat_indicator);
64 EXPECT_EQ(mmsi, msg.mmsi);
65 EXPECT_EQ(200, msg.dac);
66 ASSERT_EQ(24, msg.fi);
67
68 EXPECT_EQ(country, msg.country);
69 for (int i = 0; i < 4; i++) {
70 EXPECT_EQ(gauge_ids[i], msg.gauge_ids[i]);
71 }
72 for (int i = 0; i < 4; i++) {
73 EXPECT_FLOAT_EQ(levels[i], msg.levels[i]);
74 }
75 }
76
77 TEST(Ais8_200_24, Issue162) {
78 // 8:200:24 EU River Information System (RIS) Water level
79 // https://github.com/schwehr/libais/issues/162
80 // \s:rORBCOMM000,q:u,c:1510617616,T:2017-11-14 00.00.16*5f\
81 // !AIVDM,1,1,,A,801tME0j60E04QJp1hhL10G20DH1,0*11
82 std::unique_ptr<Ais8_200_24> msg(
83 new Ais8_200_24("801tME0j60E04QJp1hhL10G20DH1", 0));
84 ASSERT_NE(nullptr, msg);
85 constexpr float level = 4294966528.0f;
86 Validate8_200_24(*msg, 0, 2039124, "AT", {9, 7, 8, 5},
87 {level, level, level, level});
88
89 // !AIVDM,1,1,,B,802ATu0j624P2@G80pEd0D5F0634,0*2F
90 msg.reset(new Ais8_200_24("802ATu0j624P2@G80pEd0D5F0634", 0));
91 Validate8_200_24(*msg, 0, 2385140, "HR", {4, 3, 2, 1},
92 {185.0f, 347.0f, 171.0f, 196.0f});
93 }
94
95 } // namespace
96 } // namespace libais