1 #include <marnav/nmea/mob.hpp>
2 #include "type_traits_helper.hpp"
3 #include <marnav/nmea/nmea.hpp>
4 #include <gtest/gtest.h>
8 using namespace marnav
;
10 class Test_nmea_mob
: public ::testing::Test
14 TEST_F(Test_nmea_mob
, construction
)
16 EXPECT_NO_THROW(nmea::mob mob
);
19 TEST_F(Test_nmea_mob
, properties
)
21 nmea_sentence_traits
<nmea::mob
>();
24 TEST_F(Test_nmea_mob
, parse
)
26 auto s
= nmea::make_sentence("$INMOB,ABCDE,V,123456.987,0,311219,132456.876,12.34,N,123.45,"
27 "E,12.34,23.45,269104520,0*53");
28 ASSERT_NE(nullptr, s
);
30 auto mob
= nmea::sentence_cast
<nmea::mob
>(s
);
31 ASSERT_NE(nullptr, mob
);
34 TEST_F(Test_nmea_mob
, parse_invalid_number_of_arguments
)
37 nmea::detail::factory::sentence_parse
<nmea::mob
>(nmea::talker::none
, {13, "@"}));
39 nmea::detail::factory::sentence_parse
<nmea::mob
>(nmea::talker::none
, {15, "@"}));
42 TEST_F(Test_nmea_mob
, empty_to_string
)
46 EXPECT_STREQ("$INMOB,,E,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*09",
47 nmea::to_string(mob
).c_str());
50 TEST_F(Test_nmea_mob
, get_emitter_id_default_value
)
52 ASSERT_FALSE(nmea::mob
{}.get_emitter_id().has_value());
55 TEST_F(Test_nmea_mob
, set_emitter_id_empty_string
)
59 EXPECT_NO_THROW(mob
.set_emitter_id(""));
60 const auto id
= mob
.get_emitter_id();
61 ASSERT_FALSE(id
.has_value());
64 TEST_F(Test_nmea_mob
, set_emitter_id_large_string
)
68 EXPECT_ANY_THROW(mob
.set_emitter_id("012345"));
71 TEST_F(Test_nmea_mob
, set_emitter_id_invalid_string_content
)
75 EXPECT_ANY_THROW(mob
.set_emitter_id("xyz"));
76 EXPECT_ANY_THROW(mob
.set_emitter_id("hello"));
77 EXPECT_ANY_THROW(mob
.set_emitter_id("foobar"));
80 TEST_F(Test_nmea_mob
, set_emitter_id_valid_max_size_string
)
84 EXPECT_NO_THROW(mob
.set_emitter_id("fffff"));
86 const auto id
= mob
.get_emitter_id();
87 ASSERT_TRUE(id
.has_value());
88 EXPECT_STREQ("FFFFF", id
->c_str());
91 TEST_F(Test_nmea_mob
, set_emitter_id_valid_short_string
)
95 EXPECT_NO_THROW(mob
.set_emitter_id("fff"));
96 const auto id
= mob
.get_emitter_id();
97 ASSERT_TRUE(id
.has_value());
98 EXPECT_STREQ("00FFF", id
->c_str());
101 TEST_F(Test_nmea_mob
, mob_status_default
)
103 EXPECT_EQ(nmea::mob::mob_status::error
, nmea::mob
{}.get_mob_status());
106 TEST_F(Test_nmea_mob
, set_and_mob_status
)
110 mob
.set_mob_status(nmea::mob::mob_status::mob_activated
);
112 "$INMOB,,A,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*0D",
113 to_string(mob
).c_str());
117 mob
.set_mob_status(nmea::mob::mob_status::test_mode
);
119 "$INMOB,,T,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*18",
120 to_string(mob
).c_str());
124 mob
.set_mob_status(nmea::mob::mob_status::manual_button
);
126 "$INMOB,,M,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*01",
127 to_string(mob
).c_str());
131 mob
.set_mob_status(nmea::mob::mob_status::mob_not_in_use
);
133 "$INMOB,,V,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*1A",
134 to_string(mob
).c_str());
138 mob
.set_mob_status(nmea::mob::mob_status::error
);
140 "$INMOB,,E,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*09",
141 to_string(mob
).c_str());
145 TEST_F(Test_nmea_mob
, set_mob_position_source_default
)
147 EXPECT_EQ(nmea::mob::mob_position_source::error
, nmea::mob
{}.get_mob_position_source());
150 TEST_F(Test_nmea_mob
, set_mob_position_source
)
154 mob
.set_mob_position_source(nmea::mob::mob_position_source::position_estimated
);
156 "$INMOB,,E,000000,0,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*0F",
157 to_string(mob
).c_str());
161 mob
.set_mob_position_source(nmea::mob::mob_position_source::position_reported
);
163 "$INMOB,,E,000000,1,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*0E",
164 to_string(mob
).c_str());
168 mob
.set_mob_position_source(nmea::mob::mob_position_source::reserved
);
170 "$INMOB,,E,000000,2,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*0D",
171 to_string(mob
).c_str());
175 mob
.set_mob_position_source(nmea::mob::mob_position_source::error
);
177 "$INMOB,,E,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*09",
178 to_string(mob
).c_str());
182 TEST_F(Test_nmea_mob
, parse_mob_position_source
)
186 = nmea::create_sentence
<nmea::mob
>("$INMOB,ABCDE,V,123456.987,0,311219,132456.876,"
187 "12.34,N,123.45,E,12.34,23.45,269104520,0*53");
189 nmea::mob::mob_position_source::position_estimated
, mob
.get_mob_position_source());
193 = nmea::create_sentence
<nmea::mob
>("$INMOB,ABCDE,V,123456.987,1,311219,132456.876,"
194 "12.34,N,123.45,E,12.34,23.45,269104520,0*52");
196 nmea::mob::mob_position_source::position_reported
, mob
.get_mob_position_source());
200 = nmea::create_sentence
<nmea::mob
>("$INMOB,ABCDE,V,123456.987,2,311219,132456.876,"
201 "12.34,N,123.45,E,12.34,23.45,269104520,0*51");
202 EXPECT_EQ(nmea::mob::mob_position_source::reserved
, mob
.get_mob_position_source());
206 = nmea::create_sentence
<nmea::mob
>("$INMOB,ABCDE,V,123456.987,3,311219,132456.876,"
207 "12.34,N,123.45,E,12.34,23.45,269104520,0*50");
208 EXPECT_EQ(nmea::mob::mob_position_source::reserved
, mob
.get_mob_position_source());
212 = nmea::create_sentence
<nmea::mob
>("$INMOB,ABCDE,V,123456.987,4,311219,132456.876,"
213 "12.34,N,123.45,E,12.34,23.45,269104520,0*57");
214 EXPECT_EQ(nmea::mob::mob_position_source::reserved
, mob
.get_mob_position_source());
218 = nmea::create_sentence
<nmea::mob
>("$INMOB,ABCDE,V,123456.987,5,311219,132456.876,"
219 "12.34,N,123.45,E,12.34,23.45,269104520,0*56");
220 EXPECT_EQ(nmea::mob::mob_position_source::reserved
, mob
.get_mob_position_source());
224 = nmea::create_sentence
<nmea::mob
>("$INMOB,ABCDE,V,123456.987,6,311219,132456.876,"
225 "12.34,N,123.45,E,12.34,23.45,269104520,0*55");
226 EXPECT_EQ(nmea::mob::mob_position_source::error
, mob
.get_mob_position_source());
230 TEST_F(Test_nmea_mob
, set_mmsi
)
234 mob
.set_mmsi(utils::mmsi
{269104520});
236 EXPECT_STREQ("$INMOB,,E,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,269104520,6*06",
237 to_string(mob
).c_str());