1 #include <gtest/gtest.h>
2 #include <marnav/nmea/io.hpp>
3 #include <marnav/nmea/angle.hpp>
9 using namespace marnav
;
11 class Test_nmea_io
: public ::testing::Test
15 TEST_F(Test_nmea_io
, read_empty_latitude_string
)
17 geo::latitude lat
{12.3};
20 EXPECT_DOUBLE_EQ(geo::latitude
{}, lat
);
23 TEST_F(Test_nmea_io
, read_empty_longitude_string
)
25 geo::longitude lon
{123.4};
28 EXPECT_DOUBLE_EQ(geo::longitude
{}, lon
);
31 TEST_F(Test_nmea_io
, read_int32_positive_hex
)
33 const std::string s
{"abc"};
36 read(s
, val
, nmea::data_format::hex
);
38 EXPECT_EQ(0xabc, val
);
41 TEST_F(Test_nmea_io
, read_int32_negative_hex
)
43 const std::string s
{"-abc"};
46 read(s
, val
, nmea::data_format::hex
);
48 EXPECT_EQ(-0xabc, val
);
51 TEST_F(Test_nmea_io
, format_int32_hex
)
53 const int32_t val
= 0xabcd;
54 auto s
= nmea::format(val
, 1, nmea::data_format::hex
);
56 EXPECT_STREQ("abcd", s
.c_str());
59 TEST_F(Test_nmea_io
, format_int32_none
)
61 const int32_t val
= -10;
62 auto s
= nmea::format(val
, 1, nmea::data_format::none
);
64 EXPECT_STREQ("-10", s
.c_str());
67 TEST_F(Test_nmea_io
, format_uint32_none
)
69 const uint32_t val
= 10;
70 auto s
= nmea::format(val
, 1, nmea::data_format::none
);
72 EXPECT_STREQ("10", s
.c_str());
75 TEST_F(Test_nmea_io
, read_double_classic_locale
)
77 auto old_locale
= std::locale::global(std::locale::classic());
80 marnav::nmea::read("3.14159", result
);
82 EXPECT_DOUBLE_EQ(3.14159, result
);
84 std::locale::global(old_locale
);
87 TEST_F(Test_nmea_io
, read_double_french_locale
)
89 std::locale old_locale
;
92 old_locale
= std::locale::global(std::locale("fr_FR.UTF-8"));
94 // locale not supported, disabling the test
96 // locale needs to be supported by the system, example for ubuntu:
97 // $ sudo locale-gen fr_FR.UTF-8
99 return; // TODO: use GTEST_SKIP() after upgrade to googletest >= 1.10.0
103 marnav::nmea::read("3.14159", result
);
105 EXPECT_DOUBLE_EQ(3.14159, result
);
107 std::locale::global(old_locale
);
110 TEST_F(Test_nmea_io
, format_double_classic_locale
)
112 auto old_locale
= std::locale::global(std::locale::classic());
114 EXPECT_STREQ("3.142", marnav::nmea::format(3.14159, 3).c_str());
115 EXPECT_STREQ("3.1416", marnav::nmea::format(3.14159, 4).c_str());
116 EXPECT_STREQ("3.14159", marnav::nmea::format(3.14159, 5).c_str());
117 EXPECT_STREQ("33.66", marnav::nmea::format(33.66, 2).c_str());
118 EXPECT_STREQ("33.660", marnav::nmea::format(33.66, 3).c_str());
120 std::locale::global(old_locale
);
123 TEST_F(Test_nmea_io
, format_double_french_locale
)
125 std::locale old_locale
;
128 old_locale
= std::locale::global(std::locale("fr_FR.UTF-8"));
130 // locale not supported, disabling the test
132 // locale needs to be supported by the system, example for ubuntu:
133 // $ sudo locale-gen fr_FR.UTF-8
135 return; // TODO: use GTEST_SKIP() after upgrade to googletest >= 1.10.0
138 EXPECT_STREQ("3.142", marnav::nmea::format(3.14159, 3).c_str());
139 EXPECT_STREQ("3.1416", marnav::nmea::format(3.14159, 4).c_str());
140 EXPECT_STREQ("3.14159", marnav::nmea::format(3.14159, 5).c_str());
141 EXPECT_STREQ("33.66", marnav::nmea::format(33.66, 2).c_str());
142 EXPECT_STREQ("33.660", marnav::nmea::format(33.66, 3).c_str());
144 std::locale::global(old_locale
);
145 std::locale::global(old_locale
);