1 #include <gtest/gtest.h>
2 #include <marnav/nmea/split.hpp>
6 class Test_nmea_split
: public ::testing::Test
10 TEST_F(Test_nmea_split
, field_1_with_leading_start_token
)
12 const auto result
= marnav::nmea::detail::parse_fields("$A");
14 ASSERT_EQ(1u, result
.size());
15 EXPECT_STREQ("A", result
[0].c_str());
18 TEST_F(Test_nmea_split
, field_1_without_leading_start_token
)
20 const auto result
= marnav::nmea::detail::parse_fields("A");
22 ASSERT_EQ(1u, result
.size());
23 EXPECT_STREQ("", result
[0].c_str());
26 TEST_F(Test_nmea_split
, field_2_with_start_token
)
28 const auto result
= marnav::nmea::detail::parse_fields("$A,B");
30 ASSERT_EQ(2u, result
.size());
31 EXPECT_STREQ("A", result
[0].c_str());
32 EXPECT_STREQ("B", result
[1].c_str());
35 TEST_F(Test_nmea_split
, field_1_terminated
)
37 const auto result
= marnav::nmea::detail::parse_fields("$A*xx");
39 ASSERT_EQ(2u, result
.size());
40 EXPECT_STREQ("A", result
[0].c_str());
41 EXPECT_STREQ("xx", result
[1].c_str());
44 TEST_F(Test_nmea_split
, field_2_terminated
)
46 const auto result
= marnav::nmea::detail::parse_fields("$A,B*xx");
48 ASSERT_EQ(3u, result
.size());
49 EXPECT_STREQ("A", result
[0].c_str());
50 EXPECT_STREQ("B", result
[1].c_str());
51 EXPECT_STREQ("xx", result
[2].c_str());
54 TEST_F(Test_nmea_split
, field_2_oneempty_terminated
)
56 const auto result
= marnav::nmea::detail::parse_fields("$A,*xx");
58 ASSERT_EQ(3u, result
.size());
59 EXPECT_STREQ("A", result
[0].c_str());
60 EXPECT_STREQ("", result
[1].c_str());
61 EXPECT_STREQ("xx", result
[2].c_str());
64 TEST_F(Test_nmea_split
, field_10_all_empty_terminated
)
66 const auto result
= marnav::nmea::detail::parse_fields("$,,,,,,,,,*xx");
68 ASSERT_EQ(11u, result
.size());
71 TEST_F(Test_nmea_split
, field_10_terminated
)
73 const auto result
= marnav::nmea::detail::parse_fields("$0,1,2,3,4,5,6,7,8,9*xx");
75 ASSERT_EQ(11u, result
.size());
76 EXPECT_STREQ("0", result
[0].c_str());
77 EXPECT_STREQ("1", result
[1].c_str());
78 EXPECT_STREQ("2", result
[2].c_str());
79 EXPECT_STREQ("3", result
[3].c_str());
80 EXPECT_STREQ("4", result
[4].c_str());
81 EXPECT_STREQ("5", result
[5].c_str());
82 EXPECT_STREQ("6", result
[6].c_str());
83 EXPECT_STREQ("7", result
[7].c_str());
84 EXPECT_STREQ("8", result
[8].c_str());
85 EXPECT_STREQ("9", result
[9].c_str());
86 EXPECT_STREQ("xx", result
[10].c_str());
89 TEST_F(Test_nmea_split
, only_terminator
)
91 const auto result
= marnav::nmea::detail::parse_fields("$*xx");
93 ASSERT_EQ(2u, result
.size());
94 EXPECT_STREQ("", result
[0].c_str());
95 EXPECT_STREQ("xx", result
[1].c_str());
98 TEST_F(Test_nmea_split
, empty_string
)
100 const auto result
= marnav::nmea::detail::parse_fields("");
102 ASSERT_EQ(0u, result
.size());