MCPcopy Create free account
hub / github.com/comaps/comaps / UNIT_TEST

Function UNIT_TEST

libs/map/map_tests/gps_track_test.cpp:80–144  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78seconds const kWaitForCallbackTimeout = seconds(5);
79
80UNIT_TEST(GpsTrack_Simple)
81{
82 string const filePath = GetGpsTrackFilePath();
83 SCOPE_GUARD(gpsTestFileDeleter, bind(FileWriter::DeleteFileX, filePath));
84 FileWriter::DeleteFileX(filePath);
85
86 time_t const t = system_clock::to_time_t(system_clock::now());
87 double const timestamp = t;
88 LOG(LINFO, ("Timestamp", ctime(&t), timestamp));
89
90 size_t const writeItemCount = 50000;
91
92 vector<location::GpsInfo> points;
93 points.reserve(writeItemCount);
94 for (size_t i = 0; i < writeItemCount; ++i)
95 points.emplace_back(Make(timestamp + i, ms::LatLon(-90.0 + i, -180.0 + i), 10 + i));
96
97 // Store points
98 {
99 GpsTrack track(filePath);
100
101 track.AddPoints(points);
102
103 GpsTrackCallback callback;
104
105 track.SetCallback(bind(&GpsTrackCallback::OnUpdate, &callback, placeholders::_1, placeholders::_2));
106
107 TEST(callback.WaitForCallback(kWaitForCallbackTimeout), ());
108
109 TEST_EQUAL(callback.m_toRemove.first, GpsTrack::kInvalidId, ());
110 TEST_EQUAL(callback.m_toRemove.second, GpsTrack::kInvalidId, ());
111 TEST_EQUAL(callback.m_toAdd.size(), writeItemCount, ());
112 for (size_t i = 0; i < writeItemCount; ++i)
113 {
114 TEST_EQUAL(i, callback.m_toAdd[i].first, ());
115 TEST_EQUAL(points[i].m_timestamp, callback.m_toAdd[i].second.m_timestamp, ());
116 TEST_EQUAL(points[i].m_speed, callback.m_toAdd[i].second.m_speed, ());
117 TEST_EQUAL(points[i].m_latitude, callback.m_toAdd[i].second.m_latitude, ());
118 TEST_EQUAL(points[i].m_longitude, callback.m_toAdd[i].second.m_longitude, ());
119 }
120 }
121
122 // Restore points
123 {
124 GpsTrack track(filePath);
125
126 GpsTrackCallback callback;
127
128 track.SetCallback(bind(&GpsTrackCallback::OnUpdate, &callback, placeholders::_1, placeholders::_2));
129
130 TEST(callback.WaitForCallback(kWaitForCallbackTimeout), ());
131
132 TEST_EQUAL(callback.m_toRemove.first, GpsTrack::kInvalidId, ());
133 TEST_EQUAL(callback.m_toRemove.second, GpsTrack::kInvalidId, ());
134 TEST_EQUAL(callback.m_toAdd.size(), writeItemCount, ());
135 for (size_t i = 0; i < writeItemCount; ++i)
136 {
137 TEST_EQUAL(i, callback.m_toAdd[i].first, ());

Callers

nothing calls this directly

Calls 11

DeleteFileXFunction · 0.85
TESTFunction · 0.85
SetCallbackMethod · 0.80
WaitForCallbackMethod · 0.80
GetGpsTrackFilePathFunction · 0.70
MakeFunction · 0.70
LatLonClass · 0.50
reserveMethod · 0.45
emplace_backMethod · 0.45
AddPointsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected