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

Function TransferLocation

libs/tracking/tracking_tests/reporter_test.cpp:29–79  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27namespace
28{
29void TransferLocation(Reporter & reporter, TestSocket & testSocket, double timestamp, double latidute,
30 double longtitude)
31{
32 location::GpsInfo gpsInfo;
33 gpsInfo.m_timestamp = timestamp;
34 gpsInfo.m_latitude = latidute;
35 gpsInfo.m_longitude = longtitude;
36 gpsInfo.m_horizontalAccuracy = 1.0;
37 reporter.AddLocation(gpsInfo, traffic::SpeedGroup::Unknown);
38
39 using Packet = tracking::Protocol::PacketType;
40 vector<uint8_t> buffer;
41 size_t readSize = 0;
42 size_t attempts = 3;
43 do
44 {
45 readSize = testSocket.ReadServer(buffer);
46 if (attempts-- && readSize == 0)
47 continue;
48 switch (Packet(buffer[0]))
49 {
50 case Packet::CurrentAuth:
51 {
52 buffer.clear();
53 testSocket.WriteServer(tracking::Protocol::kOk);
54 break;
55 }
56 case Packet::Error:
57 case Packet::DataV0:
58 case Packet::DataV1:
59 {
60 readSize = 0;
61 break;
62 }
63 }
64 }
65 while (readSize);
66
67 TEST(!buffer.empty(), ());
68 vector<coding::TrafficGPSEncoder::DataPoint> points;
69 MemReader memReader(buffer.data(), buffer.size());
70 ReaderSource<MemReader> src(memReader);
71 src.Skip(sizeof(uint32_t /* header */));
72 coding::TrafficGPSEncoder::DeserializeDataPoints(coding::TrafficGPSEncoder::kLatestVersion, src, points);
73
74 TEST_EQUAL(points.size(), 1, ());
75 auto const & point = points[0];
76 TEST_EQUAL(point.m_timestamp, timestamp, ());
77 TEST(AlmostEqualAbs(point.m_latLon.m_lat, latidute, 0.001), ());
78 TEST(AlmostEqualAbs(point.m_latLon.m_lon, longtitude, 0.001), ());
79}
80} // namespace
81
82UNIT_TEST(Reporter_Smoke)

Callers 1

UNIT_TESTFunction · 0.85

Calls 11

PacketClass · 0.85
TESTFunction · 0.85
AddLocationMethod · 0.80
ReadServerMethod · 0.80
WriteServerMethod · 0.80
AlmostEqualAbsFunction · 0.50
clearMethod · 0.45
emptyMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45
SkipMethod · 0.45

Tested by

no test coverage detected