Debian Codegraph @

src/test/ais4_11_test.cc

raw symbols SCIP
1 // Test parsing message 4 for basestations and message 11 for date response.
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<Ais4_11> 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<Ais4_11> msg(new Ais4_11(body.c_str(), pad));
17 if (!msg || msg->had_error()) {
18 return nullptr;
19 }
20 return msg;
21 }
22
23 void Validate(
24 const Ais4_11 *msg,
25 const int message_id,
26 const int repeat_indicator,
27 const int mmsi,
28 const int year,
29 const int month,
30 const int day,
31 const int hour,
32 const int minute,
33 const int second,
34 const int position_accuracy,
35 const double x,
36 const double y,
37 const int fix_type,
38 const int transmission_ctl,
39 const int spare,
40 const bool raim) {
41 ASSERT_NE(nullptr, msg);
42 EXPECT_FALSE(msg->had_error());
43
44 ASSERT_EQ(message_id, msg->message_id);
45 EXPECT_EQ(repeat_indicator, msg->repeat_indicator);
46 EXPECT_EQ(mmsi, msg->mmsi);
47 EXPECT_EQ(year, msg->year);
48 EXPECT_EQ(month, msg->month);
49 EXPECT_EQ(day, msg->day);
50 EXPECT_EQ(hour, msg->hour);
51 EXPECT_EQ(minute, msg->minute);
52 EXPECT_EQ(second, msg->second);
53 EXPECT_EQ(position_accuracy, msg->position_accuracy);
54 EXPECT_DOUBLE_EQ(x, msg->position.lng_deg);
55 EXPECT_DOUBLE_EQ(y, msg->position.lat_deg);
56 EXPECT_EQ(fix_type, msg->fix_type);
57 EXPECT_EQ(transmission_ctl, msg->transmission_ctl);
58 EXPECT_EQ(spare, msg->spare);
59 EXPECT_EQ(raim, msg->raim);
60 }
61
62 void ValidateCommState(
63 const Ais4_11 *msg,
64 const int sync_state,
65 const int slot_timeout,
66 const bool received_stations_valid,
67 const int received_stations,
68 const bool slot_number_valid,
69 const int slot_number,
70 bool utc_valid,
71 const int utc_hour,
72 const int utc_min,
73 const int utc_spare,
74 const bool slot_offset_valid,
75 const int slot_offset) {
76 EXPECT_EQ(sync_state, msg->sync_state);
77 EXPECT_EQ(slot_timeout, msg->slot_timeout);
78
79 EXPECT_EQ(received_stations_valid, msg->received_stations_valid);
80 if (received_stations_valid) {
81 EXPECT_EQ(received_stations, msg->received_stations);
82 }
83
84 EXPECT_EQ(slot_number_valid, msg->slot_number_valid);
85 if (slot_number_valid) {
86 EXPECT_EQ(slot_number, msg->slot_number);
87 }
88
89 EXPECT_EQ(utc_valid, msg->utc_valid);
90 if (utc_valid) {
91 EXPECT_EQ(utc_hour, msg->utc_hour);
92 EXPECT_EQ(utc_min, msg->utc_min);
93 EXPECT_EQ(utc_spare, msg->utc_spare);
94 }
95
96 EXPECT_EQ(slot_offset_valid, msg->slot_offset_valid);
97 if (slot_offset_valid) {
98 EXPECT_EQ(slot_offset, msg->slot_offset);
99 }
100 }
101
102 TEST(Ais4Test, Decode4PosAcc1) {
103 // Verifies decode of Msg 4 with position accuracy of 1.
104 std::unique_ptr<Ais4_11> msg = Init(
105 "!AIVDM,1,1,,B,4h3Owoiuiq000rdhR6G>oQ?020S:,0*10,raishub,1342569600");
106
107 Validate(
108 msg.get(), 4, 3, 3669983, 2012, 7, 18, 0, 0, 0, 1, -74.108474999999999,
109 40.601393333333334, 15, 0, 0, true);
110
111 ValidateCommState(
112 msg.get(), 0, 0, false, 0, false, 0, false, 0, 0, 0, true, 2250);
113 }
114
115 TEST(Ais4Test, Decode4UtcCommState) {
116 // Verifies decode of Msg4 with UTC comm state.
117 std::unique_ptr<Ais4_11> msg = Init(
118 "!AIVDM,1,1,,A,402=3g1uiposjOP71jSQ1sA026sd,0*03,raishub,1342569609");
119
120 Validate(
121 msg.get(), 4, 0, 2311100, 2012, 7, 17, 23, 59, 50, 0,
122 -6.9665183333333331, 62.068874999999998, 1, 0, 0, true);
123
124 ValidateCommState(
125 msg.get(), 0, 1, false, 0, false, 0, true, 23, 59, false, 0, 0);
126 }
127
128 TEST(Ais4Test, Decode4SlotNumBadPos00) {
129 // Verifies decode of Msg4 slot number and bad 0, 0 position.
130 std::unique_ptr<Ais4_11> msg = Init(
131 "!AIVDM,1,1,,B,402FhL0000Htt000000000000@08,0*71,raishub,1342569629");
132
133 Validate(
134 msg.get(), 4, 0, 2470000, 0, 0, 0, 24, 60, 60, 0, 0.0, 0.0, 0, 0, 0,
135 false);
136
137 ValidateCommState(
138 msg.get(), 0, 4, false, 0, true, 8, false, 0, 0, 0, false, 0);
139 }
140
141 TEST(Ais4Test, Decode4SlotOffset) {
142 // Verifies decode of Msg4 with slot offset.
143 std::unique_ptr<Ais4_11> msg = Init(
144 "!AIVDM,1,1,,A,402VqV1uiq00e1KAk8OJHbC020S:,0*07,raishub,1342569645");
145
146 Validate(
147 msg.get(), 4, 0, 2734488, 2012, 7, 18, 0, 0, 45, 0, 19.940006666666665,
148 54.896921666666664, 3, 0, 0, true);
149
150 ValidateCommState(
151 msg.get(), 0, 0, false, 0, false, 0, false, 0, 0, 0, true, 2250);
152 }
153
154 TEST(Ais4Test, Decode4TransmissionCtl) {
155 // Verifies decode of message 4 with transmission control of 1.
156 std::unique_ptr<Ais4_11> msg = Init(
157 "!AIVDM,1,1,,B,4025bviuiq12e0hUg6OO?UbP0<=G,0*22,raishub,1342573365");
158
159 Validate(
160 msg.get(), 4, 0, 2190075, 2012, 7, 18, 1, 2, 45, 0, 10.614565,
161 55.029583333333335, 10, 1, 0, false);
162
163 ValidateCommState(
164 msg.get(), 0, 3, true, 855, false, 0, false, 0, 0, 0, false, 0);
165 }
166
167 TEST(Ais4Test, Decode4SyncState1) {
168 // Verifies decode of Msg4 sync state of 1.
169 std::unique_ptr<Ais4_11> msg = Init(
170 "!AIVDM,1,1,,B,403v7B0000000`Vhfh<qtso00d2A,0*43,raishub,1342569602");
171
172 Validate(
173 msg.get(), 4, 0, 4163400, 0, 0, 0, 0, 0, 0, 1, 120.31566666666667,
174 22.553998333333332, 7, 0, 0, false);
175
176 ValidateCommState(
177 msg.get(), 1, 3, true, 145, false, 0, false, 0, 0, 0, false, 0);
178 }
179
180 TEST(Ais4Test, Decode4SyncState2) {
181 // Verifies decode of Msg4 with a sync state of 2.
182 std::unique_ptr<Ais4_11> msg = Init(
183 "!AIVDM,1,1,,A,4FSR2mGO0oWdj<:TRhEM1oqrAFdE,0*1F,raishub,1342589098");
184
185 Validate(
186 msg.get(), 4, 1, 439911125, 7664, 3, 15, 7, 44, 50, 0, 170.08142666666666,
187 37.492851666666667, 9, 1, 420, false);
188
189 ValidateCommState(
190 msg.get(), 2, 5, true, 11029, false, 0, false, 0, 0, 0, false, 0);
191 }
192
193 TEST(Ais4Test, Decode4SyncState3) {
194 // Verifies decode of Msg4 with sync state 3.
195 std::unique_ptr<Ais4_11> msg = Init(
196 "!AIVDM,1,1,,B,4fBT7K`;RtT3wP42c2n0OgLS1hA=,0*3B,raishub,1342588546");
197
198 Validate(
199 msg.get(), 4, 2, 958990190, 8376, 11, 25, 4, 3, 63, 1, 0.882935,
200 94.38538166666666, 12, 1, 48, false);
201
202 ValidateCommState(
203 msg.get(), 3, 4, false, 0, true, 1101, false, 0, 0, 0, false, 0);
204 }
205
206 TEST(Ais11Test, Decode11) {
207 // Verifies decode of message 11 for UTC date and time response.
208 std::unique_ptr<Ais4_11> msg = Init(
209 "!AIVDM,1,1,,B,;028j>iuiq0DoO0ARF@EEmG008Pb,0*25,raishub,1342570856");
210
211 Validate(
212 msg.get(), 11, 0, 2241083, 2012, 7, 18, 0, 20, 55, 0, -13.921155,
213 28.544781666666665, 7, 0, 0, false);
214
215 ValidateCommState(
216 msg.get(), 0, 2, false, 0, true, 2090, false, 0, 0, 0, false, 0);
217 }
218
219 } // namespace
220 } // namespace libais