General: separation of marav-io as a library
[marnav.git] / test / marnav / nmea / Test_nmea_mob.cpp
blob1d7b120e8bdaa75443e6dbccbd731c601f4d1075
1 #include <marnav/nmea/mob.hpp>
2 #include "type_traits_helper.hpp"
3 #include <marnav/nmea/nmea.hpp>
4 #include <gtest/gtest.h>
6 namespace
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)
36 EXPECT_ANY_THROW(
37 nmea::detail::factory::sentence_parse<nmea::mob>(nmea::talker::none, {13, "@"}));
38 EXPECT_ANY_THROW(
39 nmea::detail::factory::sentence_parse<nmea::mob>(nmea::talker::none, {15, "@"}));
42 TEST_F(Test_nmea_mob, empty_to_string)
44 nmea::mob mob;
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)
57 nmea::mob mob;
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)
66 nmea::mob mob;
68 EXPECT_ANY_THROW(mob.set_emitter_id("012345"));
71 TEST_F(Test_nmea_mob, set_emitter_id_invalid_string_content)
73 nmea::mob mob;
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)
82 nmea::mob mob;
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)
93 nmea::mob mob;
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)
109 nmea::mob mob;
110 mob.set_mob_status(nmea::mob::mob_status::mob_activated);
111 EXPECT_STREQ(
112 "$INMOB,,A,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*0D",
113 to_string(mob).c_str());
116 nmea::mob mob;
117 mob.set_mob_status(nmea::mob::mob_status::test_mode);
118 EXPECT_STREQ(
119 "$INMOB,,T,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*18",
120 to_string(mob).c_str());
123 nmea::mob mob;
124 mob.set_mob_status(nmea::mob::mob_status::manual_button);
125 EXPECT_STREQ(
126 "$INMOB,,M,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*01",
127 to_string(mob).c_str());
130 nmea::mob mob;
131 mob.set_mob_status(nmea::mob::mob_status::mob_not_in_use);
132 EXPECT_STREQ(
133 "$INMOB,,V,000000,6,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*1A",
134 to_string(mob).c_str());
137 nmea::mob mob;
138 mob.set_mob_status(nmea::mob::mob_status::error);
139 EXPECT_STREQ(
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)
153 nmea::mob mob;
154 mob.set_mob_position_source(nmea::mob::mob_position_source::position_estimated);
155 EXPECT_STREQ(
156 "$INMOB,,E,000000,0,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*0F",
157 to_string(mob).c_str());
160 nmea::mob mob;
161 mob.set_mob_position_source(nmea::mob::mob_position_source::position_reported);
162 EXPECT_STREQ(
163 "$INMOB,,E,000000,1,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*0E",
164 to_string(mob).c_str());
167 nmea::mob mob;
168 mob.set_mob_position_source(nmea::mob::mob_position_source::reserved);
169 EXPECT_STREQ(
170 "$INMOB,,E,000000,2,010100,000000,0000.0000,N,00000.0000,E,0,0,000000000,6*0D",
171 to_string(mob).c_str());
174 nmea::mob mob;
175 mob.set_mob_position_source(nmea::mob::mob_position_source::error);
176 EXPECT_STREQ(
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)
185 const auto mob
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");
188 EXPECT_EQ(
189 nmea::mob::mob_position_source::position_estimated, mob.get_mob_position_source());
192 const auto mob
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");
195 EXPECT_EQ(
196 nmea::mob::mob_position_source::position_reported, mob.get_mob_position_source());
199 const auto mob
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());
205 const auto mob
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());
211 const auto mob
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());
217 const auto mob
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());
223 const auto mob
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)
232 nmea::mob mob;
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());