Build: update docker build scripts
[marnav.git] / test / nmea / Test_nmea_glc.cpp
blob3ee266bb2e2dd1ca85a2c3e6f5671feab7c92230
1 #include <gtest/gtest.h>
2 #include <marnav/nmea/glc.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include "type_traits_helper.hpp"
6 namespace
9 using namespace marnav;
11 class Test_nmea_glc : public ::testing::Test
15 TEST_F(Test_nmea_glc, contruction)
17 EXPECT_NO_THROW(nmea::glc glc);
20 TEST_F(Test_nmea_glc, properties)
22 nmea_sentence_traits<nmea::glc>();
25 TEST_F(Test_nmea_glc, parse)
27 auto s = nmea::make_sentence("$GPGLC,1,1,A,1,A,2,A,3,A,4,V,,*21");
28 ASSERT_NE(nullptr, s);
30 auto glc = nmea::sentence_cast<nmea::glc>(s);
31 ASSERT_NE(nullptr, glc);
34 TEST_F(Test_nmea_glc, parse_invalid_number_of_arguments)
36 EXPECT_ANY_THROW(
37 nmea::detail::factory::sentence_parse<nmea::glc>(nmea::talker::none, {12, "@"}));
38 EXPECT_ANY_THROW(
39 nmea::detail::factory::sentence_parse<nmea::glc>(nmea::talker::none, {14, "@"}));
42 TEST_F(Test_nmea_glc, empty_to_string)
44 nmea::glc glc;
46 EXPECT_STREQ("$GPGLC,0,0,V,,,,,,,,,,*25", nmea::to_string(glc).c_str());
49 TEST_F(Test_nmea_glc, set_time_diff_invalid_index)
51 nmea::glc glc;
53 EXPECT_ANY_THROW(glc.set_time_diff(-1, {0.0, nmea::status::ok}));
54 EXPECT_ANY_THROW(glc.set_time_diff(5, {0.0, nmea::status::ok}));
57 TEST_F(Test_nmea_glc, get_time_diff_invalid_index)
59 nmea::glc glc;
61 EXPECT_ANY_THROW(glc.get_time_diff(-1));
62 EXPECT_ANY_THROW(glc.get_time_diff(5));
63 EXPECT_ANY_THROW(glc.get_time_diff(nmea::glc::max_differences));
66 TEST_F(Test_nmea_glc, set_time_diff)
69 nmea::glc glc;
70 glc.set_time_diff(0, {1.0, nmea::status::ok});
71 EXPECT_STREQ("$GPGLC,0,0,V,1,A,,,,,,,,*55", nmea::to_string(glc).c_str());
74 nmea::glc glc;
75 glc.set_time_diff(1, {1.0, nmea::status::ok});
76 EXPECT_STREQ("$GPGLC,0,0,V,,,1,A,,,,,,*55", nmea::to_string(glc).c_str());
79 nmea::glc glc;
80 glc.set_time_diff(2, {1.0, nmea::status::ok});
81 EXPECT_STREQ("$GPGLC,0,0,V,,,,,1,A,,,,*55", nmea::to_string(glc).c_str());
84 nmea::glc glc;
85 glc.set_time_diff(3, {1.0, nmea::status::ok});
86 EXPECT_STREQ("$GPGLC,0,0,V,,,,,,,1,A,,*55", nmea::to_string(glc).c_str());
89 nmea::glc glc;
90 glc.set_time_diff(4, {1.0, nmea::status::ok});
91 EXPECT_STREQ("$GPGLC,0,0,V,,,,,,,,,1,A*55", nmea::to_string(glc).c_str());
95 TEST_F(Test_nmea_glc, get_time_diff)
97 auto s = nmea::make_sentence("$GPGLC,1,1,A,1,A,2,A,3,A,4,V,,*21");
98 ASSERT_NE(nullptr, s);
100 auto glc = nmea::sentence_cast<nmea::glc>(s);
101 ASSERT_NE(nullptr, glc);
103 auto const t = glc->get_time_diff(0);
104 EXPECT_TRUE(static_cast<bool>(t));
105 EXPECT_NEAR(1.0, t->diff, 1e-8);
106 EXPECT_EQ(nmea::status::ok, t->status);