1 #include <gtest/gtest.h>
2 #include <marnav/nmea/checksum.hpp>
3 #include <marnav/nmea/nmea.hpp>
4 #include <marnav/nmea/sentence.hpp>
9 using namespace marnav
;
11 class Test_nmea
: public ::testing::Test
15 TEST_F(Test_nmea
, checksum_to_string
)
17 EXPECT_STREQ("00", nmea::checksum_to_string(0x00).c_str());
18 EXPECT_STREQ("01", nmea::checksum_to_string(0x01).c_str());
19 EXPECT_STREQ("02", nmea::checksum_to_string(0x02).c_str());
20 EXPECT_STREQ("04", nmea::checksum_to_string(0x04).c_str());
21 EXPECT_STREQ("08", nmea::checksum_to_string(0x08).c_str());
22 EXPECT_STREQ("10", nmea::checksum_to_string(0x10).c_str());
23 EXPECT_STREQ("20", nmea::checksum_to_string(0x20).c_str());
24 EXPECT_STREQ("40", nmea::checksum_to_string(0x40).c_str());
25 EXPECT_STREQ("80", nmea::checksum_to_string(0x80).c_str());
26 EXPECT_STREQ("5A", nmea::checksum_to_string(0x5a).c_str());
27 EXPECT_STREQ("A5", nmea::checksum_to_string(0xa5).c_str());
28 EXPECT_STREQ("FF", nmea::checksum_to_string(0xff).c_str());
31 TEST_F(Test_nmea
, make_sentence_empty_string
) { EXPECT_ANY_THROW(nmea::make_sentence("")); }
33 TEST_F(Test_nmea
, make_sentence_no_start_token
)
35 EXPECT_ANY_THROW(nmea::make_sentence("1234567890"));
38 TEST_F(Test_nmea
, make_sentence_to_short
) { EXPECT_ANY_THROW(nmea::make_sentence("12")); }
40 TEST_F(Test_nmea
, make_sentence_no_end_token
)
42 EXPECT_ANY_THROW(nmea::make_sentence("$GPMTW,,1E"));
45 TEST_F(Test_nmea
, make_sentence_invalid_checksum
)
47 EXPECT_ANY_THROW(nmea::make_sentence("$GPMTW,,*1E"));
50 TEST_F(Test_nmea
, make_sentence_minimal_possible_sentence
)
53 nmea::make_sentence("$XXYYY*59");
54 } catch (std::exception
& e
) {
55 EXPECT_STREQ("unknown sentence in nmea/find_parse_func: YYY", e
.what());
59 TEST_F(Test_nmea
, make_sentence_vendor_extension
)
62 nmea::make_sentence("$PXXX*08");
63 } catch (std::exception
& e
) {
64 EXPECT_STREQ("unknown sentence in nmea/find_parse_func: PXXX", e
.what());
68 TEST_F(Test_nmea
, make_sentence_invalid_checksum_what
)
71 nmea::make_sentence("$GPMTW,,*1E");
72 } catch (nmea::checksum_error
& e
) {
73 EXPECT_STREQ("checksum error (actual:59, expected:1E)", e
.what());
77 TEST_F(Test_nmea
, make_sentence_unknown_sentence
)
79 EXPECT_ANY_THROW(nmea::make_sentence("$XX???,1,2,3*23"));
82 TEST_F(Test_nmea
, get_supported_sentences_str
)
84 auto v
= nmea::get_supported_sentences_str();
86 EXPECT_EQ(76u, v
.size());
89 TEST_F(Test_nmea
, get_supported_sentences_id
)
91 auto v
= nmea::get_supported_sentences_id();
93 EXPECT_EQ(76u, v
.size());
96 TEST_F(Test_nmea
, tag_to_id
)
98 auto id
= nmea::tag_to_id("BOD");
100 EXPECT_EQ(nmea::sentence_id::BOD
, id
);
103 TEST_F(Test_nmea
, tag_to_id_invalid_tag
) { EXPECT_ANY_THROW(nmea::tag_to_id("???")); }
105 TEST_F(Test_nmea
, to_string_sentence_id
)
107 auto tag
= nmea::to_string(nmea::sentence_id::BOD
);
109 EXPECT_STREQ("BOD", tag
.c_str());
112 TEST_F(Test_nmea
, to_string_sentence_id_invalid_id
)
114 EXPECT_ANY_THROW(nmea::to_string(static_cast<nmea::sentence_id
>(-1)));
117 TEST_F(Test_nmea
, extract_id
)
119 EXPECT_EQ(nmea::sentence_id::BOD
, nmea::extract_id("$GPBOD,,T,,M,,*47"));
120 EXPECT_ANY_THROW(nmea::extract_id(""));
121 EXPECT_ANY_THROW(nmea::extract_id("$"));
122 EXPECT_ANY_THROW(nmea::extract_id("XGPBOD,,T,,M,,*47"));
123 EXPECT_NO_THROW(nmea::extract_id("$GPBOD,,T,,M,,*XX"));
124 EXPECT_NO_THROW(nmea::extract_id("!GPBOD,,T,,M,,*XX"));
125 EXPECT_NO_THROW(nmea::extract_id("$GPBOD,"));
126 EXPECT_ANY_THROW(nmea::extract_id("$GPBOD"));