#include #include #include #include "places.h" using namespace roro::gnss; void setUp() {} void tearDown() {} void test_places_round_trip() { std::vector places = {{"Car", 50.8503123, 4.3517456}, {"Tent ", -33.9, -151.2}}; std::string gpx = placesGpx(places); TEST_ASSERT_NOT_EQUAL(std::string::npos, gpx.find("Car")); TEST_ASSERT_NOT_EQUAL(std::string::npos, gpx.find("Tent <A&B>")); TEST_ASSERT_NOT_EQUAL(std::string::npos, gpx.find("")); std::vector back = parsePlaces(gpx); TEST_ASSERT_EQUAL(2, back.size()); TEST_ASSERT_EQUAL_STRING("Car", back[0].name.c_str()); TEST_ASSERT_TRUE(std::fabs(back[0].latitude - (50.8503123)) < 1e-7); TEST_ASSERT_TRUE(std::fabs(back[0].longitude - (4.3517456)) < 1e-7); TEST_ASSERT_EQUAL_STRING("Tent ", back[1].name.c_str()); TEST_ASSERT_TRUE(std::fabs(back[1].longitude - (-151.2)) < 1e-7); } void test_an_empty_list_is_still_gpx() { std::string gpx = placesGpx({}); TEST_ASSERT_NOT_EQUAL(std::string::npos, gpx.find("\n 7\n Antwerp\n City\n \n" " \n" " Nowhere\n" " Broken\n" " no name\n" " not a place\n" "\n"; std::vector p = parsePlaces(gpx); TEST_ASSERT_EQUAL(3, p.size()); TEST_ASSERT_EQUAL_STRING("Antwerp", p[0].name.c_str()); TEST_ASSERT_TRUE(std::fabs(p[0].latitude - (51.22)) < 1e-7); TEST_ASSERT_TRUE(std::fabs(p[0].longitude - (4.40)) < 1e-7); TEST_ASSERT_EQUAL_STRING("Place 2", p[1].name.c_str()); TEST_ASSERT_EQUAL_STRING("Place 3", p[2].name.c_str()); } void test_a_cut_file_gives_what_is_whole() { std::string gpx = placesGpx({{"A", 1, 2}, {"B", 3, 4}}); gpx.resize(gpx.find("B")); std::vector p = parsePlaces(gpx); TEST_ASSERT_EQUAL(1, p.size()); TEST_ASSERT_EQUAL_STRING("A", p[0].name.c_str()); } void test_no_more_than_the_limit() { std::vector many(kMaxPlaces + 10, Place{"P", 1, 2}); TEST_ASSERT_EQUAL(kMaxPlaces, parsePlaces(placesGpx(many)).size()); } int main() { UNITY_BEGIN(); RUN_TEST(test_places_round_trip); RUN_TEST(test_an_empty_list_is_still_gpx); RUN_TEST(test_waypoints_from_a_map_program); RUN_TEST(test_a_cut_file_gives_what_is_whole); RUN_TEST(test_no_more_than_the_limit); return UNITY_END(); }