NMEA: serialization of sentences changed, gains performance by about 7 percent on...
[marnav.git] / test / nmea / Test_nmea_mtw.cpp
blobdb1c6b42032fdcad1bd928d14567c031a98e7639
1 #include <gtest/gtest.h>
2 #include <marnav/nmea/mtw.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include "type_traits_helper.hpp"
6 namespace
9 using namespace marnav;
11 class Test_nmea_mtw : public ::testing::Test
15 TEST_F(Test_nmea_mtw, contruction)
17 EXPECT_NO_THROW(nmea::mtw mtw);
20 TEST_F(Test_nmea_mtw, properties)
22 nmea_sentence_traits<nmea::mtw>();
25 TEST_F(Test_nmea_mtw, parse)
27 auto s = nmea::make_sentence("$IIMTW,9.5,C*2F");
28 ASSERT_NE(nullptr, s);
30 auto mtw = nmea::sentence_cast<nmea::mtw>(s);
31 ASSERT_NE(nullptr, mtw);
33 auto temperature = mtw->get_temperature();
34 ASSERT_TRUE(temperature.available());
35 EXPECT_NEAR(9.5, temperature.value(), 1e-8);
37 auto unit = mtw->get_temperature_unit();
38 ASSERT_TRUE(unit.available());
39 EXPECT_EQ(nmea::unit::temperature::celsius, unit.value());
42 TEST_F(Test_nmea_mtw, parse_invalid_number_of_arguments)
44 EXPECT_ANY_THROW(
45 nmea::detail::factory::sentence_parse<nmea::mtw>(nmea::talker_id::none, {1, "@"}));
46 EXPECT_ANY_THROW(
47 nmea::detail::factory::sentence_parse<nmea::mtw>(nmea::talker_id::none, {3, "@"}));
50 TEST_F(Test_nmea_mtw, empty_to_string)
52 nmea::mtw mtw;
54 EXPECT_STREQ("$IIMTW,,*4E", nmea::to_string(mtw).c_str());
57 TEST_F(Test_nmea_mtw, set_temperature_to_string)
59 nmea::mtw mtw;
60 mtw.set_temperature(22.5);
62 EXPECT_STREQ("$IIMTW,22.5,C*16", nmea::to_string(mtw).c_str());