NMEA: make nmeatool available with/without ENABLE_IO
[marnav.git] / test / nmea / Test_nmea_aam.cpp
blobf83b7eb6c0219614f62530ddd638795c242092d0
1 #include <marnav/nmea/aam.hpp>
2 #include "type_traits_helper.hpp"
3 #include <marnav/nmea/nmea.hpp>
4 #include <gtest/gtest.h>
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_NEAR(0.5, radius.get<marnav::units::nautical_miles>().value(), 1e-8);
37 TEST_F(Test_nmea_aam, parse_wrong_distance_unit)
39 EXPECT_ANY_THROW(nmea::make_sentence("$GPAAM,,,0.5,M,POINT1*6D"));
42 TEST_F(Test_nmea_aam, parse_missing_distance_unit)
44 EXPECT_ANY_THROW(nmea::make_sentence("$GPAAM,,,0.5,,POINT1*20"));
47 TEST_F(Test_nmea_aam, parse_invalid_number_of_arguments)
49 EXPECT_ANY_THROW(
50 nmea::detail::factory::sentence_parse<nmea::aam>(nmea::talker::none, {4, "@"}));
51 EXPECT_ANY_THROW(
52 nmea::detail::factory::sentence_parse<nmea::aam>(nmea::talker::none, {6, "@"}));
55 TEST_F(Test_nmea_aam, empty_to_string)
57 nmea::aam aam;
59 EXPECT_STREQ("$GPAAM,V,V,0,N,*08", nmea::to_string(aam).c_str());
62 TEST_F(Test_nmea_aam, set_arrival_circle_entered_ok)
64 nmea::aam aam;
65 aam.set_arrival_circle_entered(nmea::status::ok);
67 EXPECT_STREQ("$GPAAM,A,V,0,N,*1F", nmea::to_string(aam).c_str());
70 TEST_F(Test_nmea_aam, set_arrival_circle_entered_warning)
72 nmea::aam aam;
73 aam.set_arrival_circle_entered(nmea::status::warning);
75 EXPECT_STREQ("$GPAAM,V,V,0,N,*08", nmea::to_string(aam).c_str());
78 TEST_F(Test_nmea_aam, set_arrival_circle_entered_invalid_status)
80 nmea::aam aam;
81 EXPECT_THROW(
82 aam.set_arrival_circle_entered(static_cast<nmea::status>('?')), std::invalid_argument);
85 TEST_F(Test_nmea_aam, set_perpendicular_passed_ok)
87 nmea::aam aam;
88 aam.set_perpendicular_passed(nmea::status::ok);
90 EXPECT_STREQ("$GPAAM,V,A,0,N,*1F", nmea::to_string(aam).c_str());
93 TEST_F(Test_nmea_aam, set_perpendicular_passed_warning)
95 nmea::aam aam;
96 aam.set_perpendicular_passed(nmea::status::warning);
98 EXPECT_STREQ("$GPAAM,V,V,0,N,*08", nmea::to_string(aam).c_str());
101 TEST_F(Test_nmea_aam, set_perpendicular_passed_invalid_status)
103 nmea::aam aam;
104 EXPECT_THROW(
105 aam.set_perpendicular_passed(static_cast<nmea::status>('?')), std::invalid_argument);
108 TEST_F(Test_nmea_aam, set_arrival_circle_radius)
110 nmea::aam aam;
111 aam.set_arrival_circle_radius(marnav::units::nautical_miles{1.2});
113 EXPECT_STREQ("$GPAAM,V,V,1.2,N,*15", nmea::to_string(aam).c_str());
116 TEST_F(Test_nmea_aam, set_arrival_circle_radius_negative)
118 nmea::aam aam;
120 EXPECT_THROW(aam.set_arrival_circle_radius(marnav::units::nautical_miles{-1.2}),
121 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,V,V,0,N,wpt1*4A", nmea::to_string(aam).c_str());