Public Access
A Place is a named position the user marked (issue #16). The list is read from and written to a GPX file, so a map program opens it and waypoints made by one are read here. Host-tested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0162FokPdvY2KsS4NBfwyWPk
76 lines
3.0 KiB
C++
76 lines
3.0 KiB
C++
#include <unity.h>
|
|
|
|
#include <cmath>
|
|
#include <string>
|
|
|
|
#include "places.h"
|
|
|
|
using namespace roro::gnss;
|
|
|
|
void setUp() {}
|
|
void tearDown() {}
|
|
|
|
void test_places_round_trip() {
|
|
std::vector<Place> places = {{"Car", 50.8503123, 4.3517456}, {"Tent <A&B>", -33.9, -151.2}};
|
|
std::string gpx = placesGpx(places);
|
|
TEST_ASSERT_NOT_EQUAL(std::string::npos, gpx.find("<wpt lat=\"50.8503123\" lon=\"4.3517456\"><name>Car</name></wpt>"));
|
|
TEST_ASSERT_NOT_EQUAL(std::string::npos, gpx.find("<name>Tent <A&B></name>"));
|
|
TEST_ASSERT_NOT_EQUAL(std::string::npos, gpx.find("</gpx>"));
|
|
std::vector<Place> 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 <A&B>", 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("<gpx version=\"1.1\""));
|
|
TEST_ASSERT_EQUAL(0, parsePlaces(gpx).size());
|
|
TEST_ASSERT_EQUAL(0, parsePlaces("").size());
|
|
}
|
|
|
|
void test_waypoints_from_a_map_program() {
|
|
std::string gpx =
|
|
"<?xml version='1.0'?>\n<gpx>\n"
|
|
" <wpt lon='4.40' lat='51.22'>\n <ele>7</ele>\n <name>Antwerp</name>\n <sym>City</sym>\n </wpt>\n"
|
|
" <wpt lat=\"50.0\" lon=\"5.0\"/>\n"
|
|
" <wpt lat=\"95.0\" lon=\"5.0\"><name>Nowhere</name></wpt>\n"
|
|
" <wpt lat=\"x\" lon=\"5.0\"><name>Broken</name></wpt>\n"
|
|
" <wpt lat=\"50.5\" lon=\"5.5\"><desc>no name</desc></wpt>\n"
|
|
" <trk><trkseg><trkpt lat=\"1\" lon=\"2\"><name>not a place</name></trkpt></trkseg></trk>\n"
|
|
"</gpx>\n";
|
|
std::vector<Place> 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("<name>B"));
|
|
std::vector<Place> 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<Place> 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();
|
|
}
|