NMEA: sentence HFB added
[marnav.git] / test / nmea / Test_nmea.cpp
blob976eb8ed4b4714b17b0287b5ef8a719bddea7055
1 #include <gtest/gtest.h>
2 #include <marnav/nmea/nmea.hpp>
4 namespace
7 using namespace marnav;
9 class Test_nmea : public ::testing::Test
13 TEST_F(Test_nmea, make_sentence_empty_string) { EXPECT_ANY_THROW(nmea::make_sentence("")); }
15 TEST_F(Test_nmea, checksum_error_construction)
17 nmea::checksum_error e(0x12, 0x34);
20 TEST_F(Test_nmea, make_sentence_no_start_token)
22 EXPECT_ANY_THROW(nmea::make_sentence("1234567890"));
25 TEST_F(Test_nmea, make_sentence_to_short) { EXPECT_ANY_THROW(nmea::make_sentence("12")); }
27 TEST_F(Test_nmea, make_sentence_no_end_token)
29 EXPECT_ANY_THROW(nmea::make_sentence("$GPMTW,,1E"));
32 TEST_F(Test_nmea, make_sentence_invalid_checksum)
34 EXPECT_ANY_THROW(nmea::make_sentence("$GPMTW,,*1E"));
37 TEST_F(Test_nmea, make_sentence_minimal_possible_sentence)
39 try {
40 nmea::make_sentence("$XXYYY*59");
41 } catch (std::exception & e) {
42 EXPECT_STREQ("unknown sentence in nmea/instantiate_sentence: YYY", e.what());
46 TEST_F(Test_nmea, make_sentence_vendor_extension)
48 try {
49 nmea::make_sentence("$PXXX*08");
50 } catch (std::exception & e) {
51 EXPECT_STREQ("unknown sentence in nmea/instantiate_sentence: PXXX", e.what());
55 TEST_F(Test_nmea, make_sentence_invalid_checksum_what)
57 try {
58 nmea::make_sentence("$GPMTW,,*1E");
59 } catch (nmea::checksum_error & e) {
60 EXPECT_STREQ("checksum error (actual:59, expected:1E)", e.what());
64 TEST_F(Test_nmea, make_sentence_unknown_sentence)
66 EXPECT_ANY_THROW(nmea::make_sentence("$XX???,1,2,3*23"));
69 TEST_F(Test_nmea, get_supported_sentences_str)
71 auto v = nmea::get_supported_sentences_str();
73 EXPECT_EQ(72u, v.size());
76 TEST_F(Test_nmea, get_supported_sentences_id)
78 auto v = nmea::get_supported_sentences_id();
80 EXPECT_EQ(72u, v.size());
83 TEST_F(Test_nmea, tag_to_id)
85 auto id = nmea::tag_to_id("BOD");
87 EXPECT_EQ(nmea::sentence_id::BOD, id);
90 TEST_F(Test_nmea, tag_to_id_invalid_tag)
92 EXPECT_ANY_THROW(nmea::tag_to_id("???"));
95 TEST_F(Test_nmea, to_string_sentence_id)
97 auto tag = nmea::to_string(nmea::sentence_id::BOD);
99 EXPECT_STREQ("BOD", tag.c_str());
102 TEST_F(Test_nmea, to_string_sentence_id_invalid_id)
104 EXPECT_ANY_THROW(nmea::to_string(static_cast<nmea::sentence_id>(-1)));