NMEA: serialization of sentences changed, gains performance by about 7 percent on...
[marnav.git] / test / nmea / Test_nmea_mwv.cpp
blob81346c508ef24def8063eb2c765ebe2d5486648b
1 #include <gtest/gtest.h>
2 #include <marnav/nmea/mwv.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include "type_traits_helper.hpp"
6 namespace
9 using namespace marnav;
11 class Test_nmea_mwv : public ::testing::Test
15 TEST_F(Test_nmea_mwv, contruction)
17 EXPECT_NO_THROW(nmea::mwv mwv);
20 TEST_F(Test_nmea_mwv, properties)
22 nmea_sentence_traits<nmea::mwv>();
25 TEST_F(Test_nmea_mwv, parse)
27 auto s = nmea::make_sentence("$IIMWV,084.0,R,10.4,N,A*04");
28 ASSERT_NE(nullptr, s);
30 auto mwv = nmea::sentence_cast<nmea::mwv>(s);
31 ASSERT_NE(nullptr, mwv);
33 auto angle = mwv->get_angle();
34 ASSERT_TRUE(angle.available());
35 EXPECT_NEAR(84.0, angle.value(), 1e-8);
37 auto speed = mwv->get_speed();
38 ASSERT_TRUE(speed.available());
39 EXPECT_NEAR(10.4, speed.value(), 1e-8);
42 TEST_F(Test_nmea_mwv, parse_invalid_number_of_arguments)
44 EXPECT_ANY_THROW(
45 nmea::detail::factory::sentence_parse<nmea::mwv>(nmea::talker_id::none, {4, "@"}));
46 EXPECT_ANY_THROW(
47 nmea::detail::factory::sentence_parse<nmea::mwv>(nmea::talker_id::none, {6, "@"}));
50 TEST_F(Test_nmea_mwv, empty_to_string)
52 nmea::mwv mwv;
54 EXPECT_STREQ("$IIMWV,,,,,*60", nmea::to_string(mwv).c_str());
57 TEST_F(Test_nmea_mwv, set_angle)
59 nmea::mwv mwv;
60 mwv.set_angle(12.5, nmea::reference::RELATIVE);
62 EXPECT_STREQ("$IIMWV,12.5,R,,,*2A", nmea::to_string(mwv).c_str());
65 TEST_F(Test_nmea_mwv, set_speed)
67 nmea::mwv mwv;
68 mwv.set_speed(22.5, nmea::unit::velocity::knot);
70 EXPECT_STREQ("$IIMWV,,,22.5,N,*35", nmea::to_string(mwv).c_str());