NMEA: serialization of sentences changed, gains performance by about 7 percent on...
[marnav.git] / test / nmea / Test_nmea_hdg.cpp
blob37b239cb257c67fd9b2ecc85f15754e4bfa0027a
1 #include <gtest/gtest.h>
2 #include <marnav/nmea/hdg.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include "type_traits_helper.hpp"
6 namespace
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)
40 EXPECT_ANY_THROW(
41 nmea::detail::factory::sentence_parse<nmea::hdg>(nmea::talker_id::none, {4, "@"}));
42 EXPECT_ANY_THROW(
43 nmea::detail::factory::sentence_parse<nmea::hdg>(nmea::talker_id::none, {6, "@"}));
46 TEST_F(Test_nmea_hdg, empty_to_string)
48 nmea::hdg hdg;
50 EXPECT_STREQ("$HCHDG,,,,,*6C", nmea::to_string(hdg).c_str());
53 TEST_F(Test_nmea_hdg, set_heading)
55 nmea::hdg hdg;
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)
63 nmea::hdg hdg;
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)
71 nmea::hdg hdg;
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)
79 nmea::hdg hdg;
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));