1 #include <gtest/gtest.h>
2 #include <marnav/nmea/hdg.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include "type_traits_helper.hpp"
9 using namespace marnav
;
11 class Test_nmea_hdg
: public ::testing::Test
15 TEST_F(Test_nmea_hdg
, contruction
)
17 EXPECT_NO_THROW(nmea::hdg hdg
);
20 TEST_F(Test_nmea_hdg
, properties
)
22 nmea_sentence_traits
<nmea::hdg
>();
25 TEST_F(Test_nmea_hdg
, parse
)
27 auto s
= nmea::make_sentence("$HCHDG,45.8,,,0.6,E*16");
28 ASSERT_NE(nullptr, s
);
30 auto hdg
= nmea::sentence_cast
<nmea::hdg
>(s
);
31 ASSERT_NE(nullptr, hdg
);
33 auto heading
= hdg
->get_heading();
34 EXPECT_TRUE(heading
.available());
35 EXPECT_NEAR(45.8, heading
.value(), 1e-8);
38 TEST_F(Test_nmea_hdg
, parse_invalid_number_of_arguments
)
41 nmea::detail::factory::sentence_parse
<nmea::hdg
>(nmea::talker_id::none
, {4, "@"}));
43 nmea::detail::factory::sentence_parse
<nmea::hdg
>(nmea::talker_id::none
, {6, "@"}));
46 TEST_F(Test_nmea_hdg
, empty_to_string
)
50 EXPECT_STREQ("$HCHDG,,,,,*6C", nmea::to_string(hdg
).c_str());
53 TEST_F(Test_nmea_hdg
, set_heading
)
56 hdg
.set_heading(45.8);
58 EXPECT_STREQ("$HCHDG,45.8,,,,*7B", nmea::to_string(hdg
).c_str());
61 TEST_F(Test_nmea_hdg
, set_magn_dev
)
64 hdg
.set_magn_dev(5.8, nmea::direction::west
);
66 EXPECT_STREQ("$HCHDG,,5.8,W,,*18", nmea::to_string(hdg
).c_str());
69 TEST_F(Test_nmea_hdg
, set_magn_var
)
72 hdg
.set_magn_var(5.8, nmea::direction::west
);
74 EXPECT_STREQ("$HCHDG,,,,5.8,W*18", nmea::to_string(hdg
).c_str());
77 TEST_F(Test_nmea_hdg
, set_magn_dev_wrong_hemisphere
)
81 EXPECT_ANY_THROW(hdg
.set_magn_dev(5.8, nmea::direction::north
));
82 EXPECT_ANY_THROW(hdg
.set_magn_dev(5.8, nmea::direction::south
));