forked from organicmaps/organicmaps
Test for new serializer
This commit is contained in:
parent
6c57ac53cd
commit
8fc9f272cb
4 changed files with 54 additions and 32 deletions
|
@ -59,7 +59,7 @@ void Test(vector<TrafficGPSEncoder::DataPoint> & points)
|
|||
UNIT_TEST(Traffic_Serialization_Smoke)
|
||||
{
|
||||
vector<TrafficGPSEncoder::DataPoint> data = {
|
||||
{0, ms::LatLon(0.0, 1.0)}, {0, ms::LatLon(0.0, 2.0)},
|
||||
{0, ms::LatLon(0.0, 1.0), 1}, {0, ms::LatLon(0.0, 2.0), 2},
|
||||
};
|
||||
Test(data);
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ UNIT_TEST(Traffic_Serialization_EmptyPath)
|
|||
UNIT_TEST(Traffic_Serialization_StraightLine100m)
|
||||
{
|
||||
vector<TrafficGPSEncoder::DataPoint> path = {
|
||||
{0, ms::LatLon(0.0, 0.0)}, {0, ms::LatLon(0.0, 1e-3)},
|
||||
{0, ms::LatLon(0.0, 0.0), 1}, {0, ms::LatLon(0.0, 1e-3), 2},
|
||||
};
|
||||
Test(path);
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ UNIT_TEST(Traffic_Serialization_StraightLine100m)
|
|||
UNIT_TEST(Traffic_Serialization_StraightLine50Km)
|
||||
{
|
||||
vector<TrafficGPSEncoder::DataPoint> path = {
|
||||
{0, ms::LatLon(0.0, 0.0)}, {0, ms::LatLon(0.0, 0.5)},
|
||||
{0, ms::LatLon(0.0, 0.0), 1}, {0, ms::LatLon(0.0, 0.5), 2},
|
||||
};
|
||||
Test(path);
|
||||
}
|
||||
|
@ -93,7 +93,7 @@ UNIT_TEST(Traffic_Serialization_Zigzag500m)
|
|||
{
|
||||
double const x = i * 1e-3;
|
||||
double const y = i % 2 == 0 ? 0 : 1e-3;
|
||||
path.emplace_back(TrafficGPSEncoder::DataPoint(0, ms::LatLon(y, x)));
|
||||
path.emplace_back(TrafficGPSEncoder::DataPoint(0, ms::LatLon(y, x), 3));
|
||||
}
|
||||
Test(path);
|
||||
}
|
||||
|
@ -105,7 +105,7 @@ UNIT_TEST(Traffic_Serialization_Zigzag10Km)
|
|||
{
|
||||
double const x = i * 1e-2;
|
||||
double const y = i % 2 == 0 ? 0 : 1e-2;
|
||||
path.emplace_back(TrafficGPSEncoder::DataPoint(0, ms::LatLon(y, x)));
|
||||
path.emplace_back(TrafficGPSEncoder::DataPoint(0, ms::LatLon(y, x), 0));
|
||||
}
|
||||
Test(path);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ UNIT_TEST(Traffic_Serialization_Zigzag100Km)
|
|||
{
|
||||
double const x = i * 1e-1;
|
||||
double const y = i % 2 == 0 ? 0 : 1e-1;
|
||||
path.emplace_back(TrafficGPSEncoder::DataPoint(0, ms::LatLon(y, x)));
|
||||
path.emplace_back(TrafficGPSEncoder::DataPoint(0, ms::LatLon(y, x), 0));
|
||||
}
|
||||
Test(path);
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ UNIT_TEST(Traffic_Serialization_Circle20KmRadius)
|
|||
double const radius = 0.25;
|
||||
double const x = radius * cos(alpha);
|
||||
double const y = radius * sin(alpha);
|
||||
path.emplace_back(TrafficGPSEncoder::DataPoint(0, ms::LatLon(y, x)));
|
||||
path.emplace_back(TrafficGPSEncoder::DataPoint(0, ms::LatLon(y, x), 0));
|
||||
}
|
||||
Test(path);
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ UNIT_TEST(Traffic_Serialization_Circle20KmRadius)
|
|||
UNIT_TEST(Traffic_Serialization_ExtremeLatLon)
|
||||
{
|
||||
vector<TrafficGPSEncoder::DataPoint> path = {
|
||||
{0, ms::LatLon(-90, -180)}, {0, ms::LatLon(90, 180)},
|
||||
{0, ms::LatLon(-90, -180), 0}, {0, ms::LatLon(90, 180), 0},
|
||||
};
|
||||
Test(path);
|
||||
}
|
||||
|
|
|
@ -33,17 +33,30 @@ UNIT_TEST(Protocol_CreateDataPacket)
|
|||
{
|
||||
using Container = Protocol::DataElementsCirc;
|
||||
Container buffer(5);
|
||||
buffer.push_back(Container::value_type(1, ms::LatLon(10, 10)));
|
||||
buffer.push_back(Container::value_type(2, ms::LatLon(15, 15)));
|
||||
auto packet = Protocol::CreateDataPacket(buffer);
|
||||
TEST_EQUAL(packet.size(), 26, ());
|
||||
TEST_EQUAL(Protocol::PacketType(packet[0]), Protocol::PacketType::CurrentData, ());
|
||||
TEST_EQUAL(packet[1], 0x00, ());
|
||||
TEST_EQUAL(packet[2], 0x00, ());
|
||||
TEST_EQUAL(packet[3], 22, ());
|
||||
TEST_EQUAL(packet[4], 1, ());
|
||||
TEST_EQUAL(packet[5], 227, ());
|
||||
TEST_EQUAL(packet[6], 241, ());
|
||||
buffer.push_back(Container::value_type(1, ms::LatLon(10, 10), 1));
|
||||
buffer.push_back(Container::value_type(2, ms::LatLon(15, 15), 2));
|
||||
|
||||
auto packetV0 = Protocol::CreateDataPacket(buffer, Protocol::PacketType::DataV0);
|
||||
TEST_EQUAL(packetV0.size(), 26, ());
|
||||
TEST_EQUAL(Protocol::PacketType(packetV0[0]), Protocol::PacketType::DataV0, ());
|
||||
TEST_EQUAL(packetV0[1], 0x00, ());
|
||||
TEST_EQUAL(packetV0[2], 0x00, ());
|
||||
TEST_EQUAL(packetV0[3], 22, ());
|
||||
|
||||
TEST_EQUAL(packetV0[4], 1, ());
|
||||
TEST_EQUAL(packetV0[5], 227, ());
|
||||
TEST_EQUAL(packetV0[6], 241, ());
|
||||
|
||||
auto packetV1 = Protocol::CreateDataPacket(buffer);
|
||||
TEST_EQUAL(packetV1.size(), 28, ());
|
||||
TEST_EQUAL(Protocol::PacketType(packetV1[0]), Protocol::PacketType::DataV1, ());
|
||||
TEST_EQUAL(packetV1[1], 0x00, ());
|
||||
TEST_EQUAL(packetV1[2], 0x00, ());
|
||||
TEST_EQUAL(packetV1[3], 24, ());
|
||||
|
||||
TEST_EQUAL(packetV1[4], 1, ());
|
||||
TEST_EQUAL(packetV1[5], 227, ());
|
||||
TEST_EQUAL(packetV1[6], 241, ());
|
||||
}
|
||||
|
||||
UNIT_TEST(Protocol_DecodeAuthPacket)
|
||||
|
@ -57,21 +70,17 @@ UNIT_TEST(Protocol_DecodeAuthPacket)
|
|||
TEST_EQUAL(result, "ABC", ());
|
||||
}
|
||||
|
||||
UNIT_TEST(Protocol_DecodeDataPacket)
|
||||
template< typename Container>
|
||||
void DecodeDataPacketVersionTest(Container const & points, Protocol::PacketType version)
|
||||
{
|
||||
double const kEps = 1e-5;
|
||||
|
||||
using Container = Protocol::DataElementsVec;
|
||||
|
||||
Container points;
|
||||
points.push_back(Container::value_type(1, ms::LatLon(10, 10)));
|
||||
points.push_back(Container::value_type(2, ms::LatLon(15, 15)));
|
||||
auto packet = Protocol::CreateDataPacket(points);
|
||||
TEST_EQUAL(packet.size(), 26, ());
|
||||
TEST_EQUAL(Protocol::PacketType(packet[0]), Protocol::PacketType::CurrentData, ());
|
||||
auto packet = Protocol::CreateDataPacket(points, version);
|
||||
TEST_GREATER(packet.size(), 0, ());
|
||||
TEST_EQUAL(Protocol::PacketType(packet[0]), version, ());
|
||||
|
||||
auto payload = vector<uint8_t>(begin(packet) + sizeof(uint32_t /* header */), end(packet));
|
||||
Container result = Protocol::DecodeDataPacket(Protocol::PacketType::CurrentData, payload);
|
||||
Container result = Protocol::DecodeDataPacket(version, payload);
|
||||
|
||||
TEST_EQUAL(points.size(), result.size(), ());
|
||||
for (size_t i = 0; i < points.size(); ++i)
|
||||
|
@ -84,3 +93,15 @@ UNIT_TEST(Protocol_DecodeDataPacket)
|
|||
(points[i].m_latLon.lon, result[i].m_latLon.lon));
|
||||
}
|
||||
}
|
||||
|
||||
UNIT_TEST(Protocol_DecodeDataPacket)
|
||||
{
|
||||
using Container = Protocol::DataElementsVec;
|
||||
|
||||
Container points;
|
||||
points.push_back(Container::value_type(1, ms::LatLon(10, 10), 1));
|
||||
points.push_back(Container::value_type(2, ms::LatLon(15, 15), 2));
|
||||
|
||||
DecodeDataPacketVersionTest(points, Protocol::PacketType::DataV0);
|
||||
DecodeDataPacketVersionTest(points, Protocol::PacketType::DataV1);
|
||||
}
|
||||
|
|
|
@ -46,7 +46,8 @@ void TransferLocation(Reporter & reporter, TestSocket & testSocket, double times
|
|||
testSocket.WriteServer(tracking::Protocol::kOk);
|
||||
break;
|
||||
}
|
||||
case Packet::CurrentData:
|
||||
case Packet::DataV0:
|
||||
case Packet::DataV1:
|
||||
{
|
||||
readSize = 0;
|
||||
break;
|
||||
|
|
|
@ -299,7 +299,7 @@
|
|||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/../../iphone/Maps/MAPSME.plist";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = tracking_tests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "tracking-tests";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Debug;
|
||||
|
@ -309,7 +309,7 @@
|
|||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
INFOPLIST_FILE = "$(SRCROOT)/../../iphone/Maps/MAPSME.plist";
|
||||
PRODUCT_BUNDLE_IDENTIFIER = tracking_tests;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "tracking-tests";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
};
|
||||
name = Release;
|
||||
|
|
Loading…
Add table
Reference in a new issue