NMEA: serialization of sentences changed, gains performance by about 7 percent on...
[marnav.git] / test / nmea / Test_nmea_aam.cpp
blob081fa9275a323ed847d9c790b74ef0e0a89384b9
1 #include <gtest/gtest.h>
2 #include <marnav/nmea/aam.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include "type_traits_helper.hpp"
6 namespace
9 using namespace marnav;
11 class Test_nmea_aam : public ::testing::Test
15 TEST_F(Test_nmea_aam, contruction)
17 EXPECT_NO_THROW(nmea::aam aam);
20 TEST_F(Test_nmea_aam, properties)
22 nmea_sentence_traits<nmea::aam>();
25 TEST_F(Test_nmea_aam, parse)
27 auto s = nmea::make_sentence("$GPAAM,A,A,0.5,N,POINT1*6E");
28 ASSERT_NE(nullptr, s);
30 auto aam = nmea::sentence_cast<nmea::aam>(s);
31 ASSERT_NE(nullptr, aam);
33 auto radius = aam->get_arrival_circle_radius();
34 EXPECT_TRUE(radius.available());
35 EXPECT_NEAR(0.5, radius.value(), 1e-8);
38 TEST_F(Test_nmea_aam, parse_wrong_distance_unit)
40 EXPECT_ANY_THROW(nmea::make_sentence("$GPAAM,,,0.5,M,POINT1*6D"));
43 TEST_F(Test_nmea_aam, parse_missing_distance_unit)
45 EXPECT_ANY_THROW(nmea::make_sentence("$GPAAM,,,0.5,,POINT1*20"));
48 TEST_F(Test_nmea_aam, parse_invalid_number_of_arguments)
50 EXPECT_ANY_THROW(
51 nmea::detail::factory::sentence_parse<nmea::aam>(nmea::talker_id::none, {4, "@"}));
52 EXPECT_ANY_THROW(
53 nmea::detail::factory::sentence_parse<nmea::aam>(nmea::talker_id::none, {6, "@"}));
56 TEST_F(Test_nmea_aam, empty_to_string)
58 nmea::aam aam;
60 EXPECT_STREQ("$GPAAM,,,,,*76", nmea::to_string(aam).c_str());
63 TEST_F(Test_nmea_aam, set_arrival_circle_entered_ok)
65 nmea::aam aam;
66 aam.set_arrival_circle_entered(nmea::status::ok);
68 EXPECT_STREQ("$GPAAM,A,,,,*37", nmea::to_string(aam).c_str());
71 TEST_F(Test_nmea_aam, set_arrival_circle_entered_warning)
73 nmea::aam aam;
74 aam.set_arrival_circle_entered(nmea::status::warning);
76 EXPECT_STREQ("$GPAAM,V,,,,*20", nmea::to_string(aam).c_str());
79 TEST_F(Test_nmea_aam, set_arrival_circle_entered_invalid_status)
81 nmea::aam aam;
82 EXPECT_THROW(
83 aam.set_arrival_circle_entered(static_cast<nmea::status>('?')), std::invalid_argument);
86 TEST_F(Test_nmea_aam, set_perpendicular_passed_ok)
88 nmea::aam aam;
89 aam.set_perpendicular_passed(nmea::status::ok);
91 EXPECT_STREQ("$GPAAM,,A,,,*37", nmea::to_string(aam).c_str());
94 TEST_F(Test_nmea_aam, set_perpendicular_passed_warning)
96 nmea::aam aam;
97 aam.set_perpendicular_passed(nmea::status::warning);
99 EXPECT_STREQ("$GPAAM,,V,,,*20", nmea::to_string(aam).c_str());
102 TEST_F(Test_nmea_aam, set_perpendicular_passed_invalid_status)
104 nmea::aam aam;
105 EXPECT_THROW(
106 aam.set_perpendicular_passed(static_cast<nmea::status>('?')), std::invalid_argument);
109 TEST_F(Test_nmea_aam, set_arrival_circle_radius)
111 nmea::aam aam;
112 aam.set_arrival_circle_radius(1.2);
114 EXPECT_STREQ("$GPAAM,,,1.2,N,*15", nmea::to_string(aam).c_str());
117 TEST_F(Test_nmea_aam, set_arrival_circle_radius_negative)
119 nmea::aam aam;
121 EXPECT_THROW(aam.set_arrival_circle_radius(-1.2), std::invalid_argument);
124 TEST_F(Test_nmea_aam, set_waypoint_id)
126 nmea::aam aam;
127 aam.set_waypoint_id(nmea::waypoint{"wpt1"});
129 EXPECT_STREQ("$GPAAM,,,,,wpt1*34", nmea::to_string(aam).c_str());