1 #include <gtest/gtest.h>
2 #include <marnav/nmea/dbt.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include "type_traits_helper.hpp"
9 using namespace marnav
;
11 class Test_nmea_dbt
: public ::testing::Test
15 TEST_F(Test_nmea_dbt
, contruction
)
17 EXPECT_NO_THROW(nmea::dbt dbt
);
20 TEST_F(Test_nmea_dbt
, properties
)
22 nmea_sentence_traits
<nmea::dbt
>();
25 TEST_F(Test_nmea_dbt
, parse
)
27 auto s
= nmea::make_sentence("$IIDBT,9.3,f,2.84,M,1.55,F*14");
28 ASSERT_NE(nullptr, s
);
30 auto dbt
= nmea::sentence_cast
<nmea::dbt
>(s
);
31 ASSERT_NE(nullptr, dbt
);
34 TEST_F(Test_nmea_dbt
, parse_invalid_number_of_arguments
)
37 nmea::detail::factory::sentence_parse
<nmea::dbt
>(nmea::talker::none
, {5, "@"}));
39 nmea::detail::factory::sentence_parse
<nmea::dbt
>(nmea::talker::none
, {7, "@"}));
42 TEST_F(Test_nmea_dbt
, empty_to_string
)
46 EXPECT_STREQ("$IIDBT,,,,,,*52", nmea::to_string(dbt
).c_str());
49 TEST_F(Test_nmea_dbt
, get_depth_feet
)
51 auto s
= nmea::make_sentence("$IIDBT,9.3,f,,,,*10");
52 ASSERT_NE(nullptr, s
);
54 auto dbt
= nmea::sentence_cast
<nmea::dbt
>(s
);
55 ASSERT_NE(nullptr, dbt
);
57 ASSERT_TRUE(dbt
->get_depth_feet().has_value());
58 ASSERT_FALSE(dbt
->get_depth_meter().has_value());
59 ASSERT_FALSE(dbt
->get_depth_fathom().has_value());
61 const auto d
= dbt
->get_depth_feet();
62 EXPECT_EQ(units::length
{units::feet
{9.3}}, d
.value());
63 EXPECT_EQ(units::length
{units::feet
{9.3}}, *d
);
66 TEST_F(Test_nmea_dbt
, set_depth_feet
)
69 dbt
.set_depth_feet(units::feet
{12.5});
71 EXPECT_STREQ("$IIDBT,12.5,f,,,,*2C", nmea::to_string(dbt
).c_str());
74 TEST_F(Test_nmea_dbt
, get_depth_meter
)
76 auto s
= nmea::make_sentence("$IIDBT,,,2.84,M,,*0F");
77 ASSERT_NE(nullptr, s
);
79 auto dbt
= nmea::sentence_cast
<nmea::dbt
>(s
);
80 ASSERT_NE(nullptr, dbt
);
82 ASSERT_FALSE(dbt
->get_depth_feet().has_value());
83 ASSERT_TRUE(dbt
->get_depth_meter().has_value());
84 ASSERT_FALSE(dbt
->get_depth_fathom().has_value());
86 const auto d
= dbt
->get_depth_meter();
87 EXPECT_EQ(units::length
{units::meters
{2.84}}, d
.value());
88 EXPECT_EQ(units::length
{units::meters
{2.84}}, *d
);
91 TEST_F(Test_nmea_dbt
, set_depth_meter
)
94 dbt
.set_depth_meter(units::meters
{12.5});
96 EXPECT_STREQ("$IIDBT,,,12.5,M,,*07", nmea::to_string(dbt
).c_str());
99 TEST_F(Test_nmea_dbt
, get_depth_fathom
)
101 auto s
= nmea::make_sentence("$IIDBT,,,,,1.55,F*0B");
102 ASSERT_NE(nullptr, s
);
104 auto dbt
= nmea::sentence_cast
<nmea::dbt
>(s
);
105 ASSERT_NE(nullptr, dbt
);
107 ASSERT_FALSE(dbt
->get_depth_feet().has_value());
108 ASSERT_FALSE(dbt
->get_depth_meter().has_value());
109 ASSERT_TRUE(dbt
->get_depth_fathom().has_value());
111 const auto d
= dbt
->get_depth_fathom();
112 EXPECT_EQ(units::length
{units::fathoms
{1.55}}, d
.value());
113 EXPECT_EQ(units::length
{units::fathoms
{1.55}}, *d
);
116 TEST_F(Test_nmea_dbt
, set_depth_fathom
)
119 dbt
.set_depth_fathom(units::fathoms
{12.5});
121 EXPECT_STREQ("$IIDBT,,,,,12.5,F*0C", nmea::to_string(dbt
).c_str());
124 TEST_F(Test_nmea_dbt
, set_depth_meter_different_unit
)
127 dbt
.set_depth_meter(units::feet
{41.0105});
129 EXPECT_STREQ("$IIDBT,,,12.5,M,,*07", nmea::to_string(dbt
).c_str());