1 #include <gtest/gtest.h>
2 #include <marnav/nmea/gtd.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include "type_traits_helper.hpp"
9 using namespace marnav
;
11 class Test_nmea_gtd
: public ::testing::Test
15 TEST_F(Test_nmea_gtd
, contruction
)
17 EXPECT_NO_THROW(nmea::gtd gtd
);
20 TEST_F(Test_nmea_gtd
, properties
)
22 nmea_sentence_traits
<nmea::gtd
>();
25 TEST_F(Test_nmea_gtd
, parse
)
27 auto s
= nmea::make_sentence("$GPGTD,1.0,2.0,3.0,4.0,5.0*43");
28 ASSERT_NE(nullptr, s
);
30 auto gtd
= nmea::sentence_cast
<nmea::gtd
>(s
);
31 ASSERT_NE(nullptr, gtd
);
34 TEST_F(Test_nmea_gtd
, parse_invalid_number_of_arguments
)
37 nmea::detail::factory::sentence_parse
<nmea::gtd
>(nmea::talker::none
, {4, "@"}));
39 nmea::detail::factory::sentence_parse
<nmea::gtd
>(nmea::talker::none
, {6, "@"}));
42 TEST_F(Test_nmea_gtd
, empty_to_string
)
46 EXPECT_STREQ("$GPGTD,0,0,0,0,0*5C", nmea::to_string(gtd
).c_str());
49 TEST_F(Test_nmea_gtd
, set_time_diff
)
52 gtd
.set_time_diff(0, 1.0);
53 gtd
.set_time_diff(1, 2.0);
54 gtd
.set_time_diff(2, 3.0);
55 gtd
.set_time_diff(3, 4.0);
56 gtd
.set_time_diff(4, 5.0);
58 EXPECT_STREQ("$GPGTD,1,2,3,4,5*5D", nmea::to_string(gtd
).c_str());
61 TEST_F(Test_nmea_gtd
, set_time_diff_invalid_index
)
65 EXPECT_ANY_THROW(gtd
.set_time_diff(-1, 0.0));
66 EXPECT_ANY_THROW(gtd
.set_time_diff(5, 0.0));
67 EXPECT_ANY_THROW(gtd
.set_time_diff(nmea::gtd::max_time_diffs
, 0.0));
70 TEST_F(Test_nmea_gtd
, get_time_diff
)
72 auto s
= nmea::make_sentence("$GPGTD,1.0,2.0,3.0,4.0,5.0*43");
73 ASSERT_NE(nullptr, s
);
75 auto gtd
= nmea::sentence_cast
<nmea::gtd
>(s
);
76 ASSERT_NE(nullptr, gtd
);
78 EXPECT_NEAR(1.0, gtd
->get_time_diff(0), 1e-8);
79 EXPECT_NEAR(2.0, gtd
->get_time_diff(1), 1e-8);
80 EXPECT_NEAR(3.0, gtd
->get_time_diff(2), 1e-8);
81 EXPECT_NEAR(4.0, gtd
->get_time_diff(3), 1e-8);
82 EXPECT_NEAR(5.0, gtd
->get_time_diff(4), 1e-8);
85 TEST_F(Test_nmea_gtd
, get_time_diff_invalid_index
)
89 EXPECT_ANY_THROW(gtd
.get_time_diff(-1));
90 EXPECT_ANY_THROW(gtd
.get_time_diff(5));
91 EXPECT_ANY_THROW(gtd
.get_time_diff(nmea::gtd::max_time_diffs
));