Fixed KML v.3 deserialization

This commit is contained in:
r.kuznetsov 2019-10-03 16:27:19 +03:00 committed by Arsentiy Milchakov
parent f588b14643
commit 3abaca1d78
4 changed files with 1427 additions and 200 deletions

View file

@ -3,6 +3,7 @@ project(kml_tests)
set(
SRC
serdes_tests.cpp
tests_data.hpp
)
omim_add_test(${PROJECT_NAME} ${SRC})

View file

@ -1,5 +1,7 @@
#include "testing/testing.hpp"
#include "kml/kml_tests/tests_data.hpp"
#include "kml/serdes.hpp"
#include "kml/serdes_binary.hpp"
@ -24,191 +26,6 @@
namespace
{
char const * kTextKml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<kml xmlns=\"http://earth.google.com/kml/2.2\">"
"<Document>"
"<name>MapName</name>"
"<description><![CDATA[MapDescription]]></description>"
"<visibility>0</visibility>"
"<Style id=\"placemark-blue\">"
"<IconStyle>"
"<Icon>"
"<href>http://www.mapswithme.com/placemarks/placemark-blue.png</href>"
"</Icon>"
"</IconStyle>"
"</Style>"
"<Style id=\"placemark-brown\">"
"<IconStyle>"
"<Icon>"
"<href>http://www.mapswithme.com/placemarks/placemark-brown.png</href>"
"</Icon>"
"</IconStyle>"
"</Style>"
"<Style id=\"placemark-green\">"
"<IconStyle>"
"<Icon>"
"<href>http://www.mapswithme.com/placemarks/placemark-green.png</href>"
"</Icon>"
"</IconStyle>"
"</Style>"
"<Style id=\"placemark-orange\">"
"<IconStyle>"
"<Icon>"
"<href>http://www.mapswithme.com/placemarks/placemark-orange.png</href>"
"</Icon>"
"</IconStyle>"
"</Style>"
"<Style id=\"placemark-pink\">"
"<IconStyle>"
"<Icon>"
"<href>http://www.mapswithme.com/placemarks/placemark-pink.png</href>"
"</Icon>"
"</IconStyle>"
"</Style>"
"<Style id=\"placemark-purple\">"
"<IconStyle>"
"<Icon>"
"<href>http://www.mapswithme.com/placemarks/placemark-purple.png</href>"
"</Icon>"
"</IconStyle>"
"</Style>"
"<Style id=\"placemark-red\">"
"<IconStyle>"
"<Icon>"
"<href>http://www.mapswithme.com/placemarks/placemark-red.png</href>"
"</Icon>"
"</IconStyle>"
"</Style>"
"<Placemark>"
"<name>Nebraska</name>"
"<description><![CDATA[]]></description>"
"<styleUrl>#placemark-red</styleUrl>"
"<Point>"
"<coordinates>-99.901810,41.492538,0.000000</coordinates>"
"</Point>"
"</Placemark>"
"<Placemark>"
"<name>Monongahela National Forest</name>"
"<description><![CDATA[Huttonsville, WV 26273<br>]]></description>"
"<styleUrl>#placemark-pink</styleUrl>"
"<TimeStamp>"
"<when>1986-08-12T07:10:43Z</when>"
"</TimeStamp>"
"<Point>"
"<coordinates>-79.829674,38.627785,0.000000</coordinates>"
"</Point>"
"</Placemark>"
"<Placemark>"
"<name>From: Минск, Минская область, Беларусь</name>"
"<description><![CDATA[]]></description>"
"<styleUrl>#placemark-blue</styleUrl>"
"<TimeStamp>"
"<when>1998-03-03T03:04:48+01:30</when>"
"</TimeStamp>"
"<Point>"
"<coordinates>27.566765,53.900047,0</coordinates>"
"</Point>"
"</Placemark>"
"<Placemark>"
"<name><![CDATA[<MWM & Sons>]]></name>"
"<description><![CDATA[Amps & <brackets>]]></description>"
"<styleUrl>#placemark-green</styleUrl>"
"<TimeStamp>"
"<when>2048 bytes in two kilobytes - some invalid timestamp</when>"
"</TimeStamp>"
"<Point>"
"<coordinates>27.551532,53.89306</coordinates>"
"</Point>"
"</Placemark>"
"</Document>"
"</kml>";
std::vector<uint8_t> const kBinKmlV3 = {
0x03, 0x00, 0x00, 0x1E, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xED, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEE, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x60, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x01,
0x00, 0x01, 0x00, 0x01, 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x8D, 0xB7, 0xF5, 0x71, 0xFC, 0x8C, 0xFC, 0xC0, 0x02, 0x00, 0x03, 0x01,
0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x05,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF3, 0xC2, 0xFB, 0xF9, 0x01, 0xE3, 0xB9, 0xBB, 0x8E,
0x01, 0xC3, 0xC5, 0xD2, 0xBB, 0x02, 0x00, 0x03, 0x01, 0x00, 0x05, 0x01, 0x00, 0x06, 0x01, 0x00,
0x07, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0xB8, 0xBC, 0xED, 0xA7, 0x03, 0x97, 0xB0, 0x9A, 0xA7, 0x02, 0xA4, 0xD6, 0xAE, 0xDB,
0x02, 0x00, 0x03, 0x01, 0x00, 0x08, 0x00, 0x01, 0x00, 0x09, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xCD, 0x97, 0xA7,
0x02, 0xFD, 0xC1, 0xAC, 0xDB, 0x02, 0x00, 0x03, 0x01, 0x00, 0x0A, 0x01, 0x00, 0x0B, 0x01, 0x00,
0x0C, 0x00, 0x6F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x0E, 0x08, 0x08, 0x1B,
0x1A, 0x1B, 0x41, 0x41, 0x0C, 0x11, 0x0C, 0x37, 0x3E, 0x00, 0x01, 0x00, 0x01, 0x06, 0x01, 0x03,
0x09, 0x03, 0x05, 0x05, 0x07, 0x07, 0x07, 0x41, 0x09, 0x06, 0x0A, 0x0B, 0x08, 0x8D, 0x01, 0x0D,
0x07, 0x10, 0x0F, 0x08, 0x71, 0x11, 0x05, 0x02, 0x13, 0x06, 0x04, 0x15, 0x06, 0x0B, 0x17, 0x07,
0x5E, 0x19, 0x05, 0x0D, 0x1B, 0x07, 0xBA, 0x01, 0x1D, 0x08, 0x1C, 0x1F, 0x06, 0x75, 0x21, 0x06,
0x06, 0x23, 0x06, 0x09, 0x27, 0x08, 0x4E, 0x29, 0x06, 0x12, 0x2B, 0x07, 0x91, 0x01, 0x2D, 0x08,
0x14, 0x2F, 0x07, 0x73, 0x33, 0x06, 0x05, 0x35, 0x07, 0x0C, 0x37, 0x08, 0x63, 0x3B, 0x07, 0xC0,
0x01, 0x3D, 0x08, 0x31, 0x3F, 0x07, 0x77, 0x43, 0x07, 0x08, 0x47, 0x08, 0x48, 0x4B, 0x08, 0x90,
0x01, 0x4D, 0x07, 0x13, 0x4F, 0x07, 0x72, 0x57, 0x07, 0x62, 0x5B, 0x07, 0xBD, 0x01, 0x5D, 0x07,
0x29, 0x67, 0x07, 0x57, 0x6B, 0x08, 0xA1, 0x01, 0x6D, 0x08, 0x18, 0x6F, 0x08, 0x76, 0x75, 0x07,
0x0F, 0x77, 0x07, 0x68, 0x7B, 0x07, 0xD1, 0x01, 0x7D, 0x08, 0x3F, 0x7F, 0x07, 0x79, 0x83, 0x01,
0x08, 0xB8, 0x01, 0x8B, 0x01, 0x08, 0x8F, 0x01, 0x8F, 0x01, 0x08, 0x74, 0x9D, 0x01, 0x08, 0x25,
0xA7, 0x01, 0x08, 0x59, 0xAD, 0x01, 0x08, 0x17, 0xB7, 0x01, 0x08, 0x6D, 0xBD, 0x01, 0x08, 0x3E,
0xC7, 0x01, 0x08, 0x4B, 0xCB, 0x01, 0x08, 0x96, 0x01, 0xEB, 0x01, 0x08, 0xB7, 0x01, 0xED, 0x01,
0x08, 0x19, 0xEF, 0x01, 0x08, 0x8A, 0x01, 0xFD, 0x01, 0x08, 0x40, 0x83, 0x02, 0x09, 0x0E, 0xA0,
0x02, 0xAF, 0x13, 0xE7, 0xEE, 0xAD, 0x1B, 0x51, 0x0F, 0x7D, 0x02, 0x8B, 0xBA, 0xDC, 0x17, 0x6C,
0x0C, 0xE8, 0x3F, 0xF4, 0x7A, 0x70, 0x54, 0x0E, 0x25, 0xE5, 0x6D, 0xFE, 0x26, 0xE1, 0xCF, 0xD5,
0xB1, 0x7A, 0xD1, 0x32, 0x1C, 0x8A, 0x5F, 0x54, 0xDA, 0xC4, 0x56, 0x9F, 0xFC, 0x54, 0x5C, 0x8A,
0x49, 0x94, 0x65, 0x55, 0x23, 0x49, 0x43, 0x2F, 0xE7, 0x51, 0xAE, 0x19, 0xFD, 0x9B, 0xCC, 0x95,
0xE7, 0x2C, 0xCB, 0xDF, 0xCF, 0x74, 0x1A, 0x01, 0x0C, 0x4D, 0x54, 0x52, 0x77, 0xB5, 0x8B, 0x51,
0xB3, 0x3C, 0x22, 0x31, 0x30, 0xD4, 0x5E, 0x8D, 0x41, 0x3D, 0x11, 0x88, 0x0D, 0xF3, 0x64, 0x9E,
0xFF, 0xD7, 0x70, 0x0F, 0x00, 0x80, 0x3D, 0x00, 0x00, 0x00, 0x80, 0x0E, 0xB0, 0x45, 0xA7, 0x9D,
0x65, 0x6B, 0x78, 0xC7, 0xC6, 0xBA, 0x2D, 0x46, 0x83, 0x76, 0x08, 0xAC, 0x14, 0x4B, 0x56, 0xA2,
0x09, 0x01, 0x00, 0x0D,
};
std::vector<uint8_t> const kBinKml = {
0x04, 0x00, 0x00, 0x1E, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4D, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x01, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x74, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x01, 0x00,
0x01, 0x00, 0x01, 0x00, 0x02, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x04, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x8D, 0xB7, 0xF5, 0x71, 0xFC, 0x8C, 0xFC, 0xC0, 0x02, 0x00, 0x01, 0x05,
0x01, 0x00, 0x03, 0x00, 0x01, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF3, 0xC2, 0xFB, 0xF9,
0x01, 0xE3, 0xB9, 0xBB, 0x8E, 0x01, 0xC3, 0xC5, 0xD2, 0xBB, 0x02, 0x00, 0x01, 0x05, 0x01, 0x00,
0x05, 0x01, 0x00, 0x06, 0x01, 0x00, 0x07, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8, 0xBC, 0xED, 0xA7,
0x03, 0x97, 0xB0, 0x9A, 0xA7, 0x02, 0xA4, 0xD6, 0xAE, 0xDB, 0x02, 0x00, 0x01, 0x05, 0x01, 0x00,
0x08, 0x00, 0x01, 0x00, 0x09, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9C, 0xCD, 0x97, 0xA7, 0x02,
0xFD, 0xC1, 0xAC, 0xDB, 0x02, 0x00, 0x01, 0x05, 0x01, 0x00, 0x0A, 0x01, 0x00, 0x0B, 0x01, 0x00,
0x0C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x6F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07,
0x0E, 0x08, 0x08, 0x1B, 0x1A, 0x1B, 0x41, 0x41, 0x0C, 0x11, 0x0C, 0x37, 0x3E, 0x00, 0x01, 0x00,
0x01, 0x06, 0x01, 0x03, 0x09, 0x03, 0x05, 0x05, 0x07, 0x07, 0x07, 0x41, 0x09, 0x06, 0x0A, 0x0B,
0x08, 0x8D, 0x01, 0x0D, 0x07, 0x10, 0x0F, 0x08, 0x71, 0x11, 0x05, 0x02, 0x13, 0x06, 0x04, 0x15,
0x06, 0x0B, 0x17, 0x07, 0x5E, 0x19, 0x05, 0x0D, 0x1B, 0x07, 0xBA, 0x01, 0x1D, 0x08, 0x1C, 0x1F,
0x06, 0x75, 0x21, 0x06, 0x06, 0x23, 0x06, 0x09, 0x27, 0x08, 0x4E, 0x29, 0x06, 0x12, 0x2B, 0x07,
0x91, 0x01, 0x2D, 0x08, 0x14, 0x2F, 0x07, 0x73, 0x33, 0x06, 0x05, 0x35, 0x07, 0x0C, 0x37, 0x08,
0x63, 0x3B, 0x07, 0xC0, 0x01, 0x3D, 0x08, 0x31, 0x3F, 0x07, 0x77, 0x43, 0x07, 0x08, 0x47, 0x08,
0x48, 0x4B, 0x08, 0x90, 0x01, 0x4D, 0x07, 0x13, 0x4F, 0x07, 0x72, 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22, 0x31, 0x30, 0xD4, 0x5E, 0x8D, 0x41, 0x3D, 0x11, 0x88,
0x0D, 0xF3, 0x64, 0x9E, 0xFF, 0xD7, 0x70, 0x0F, 0x00, 0x80, 0x3D, 0x00, 0x00, 0x00, 0x80, 0x0E,
0xB0, 0x45, 0xA7, 0x9D, 0x65, 0x6B, 0x78, 0xC7, 0xC6, 0xBA, 0x2D, 0x46, 0x83, 0x76, 0x08, 0xAC,
0x14, 0x4B, 0x56, 0xA2, 0x09, 0x01, 0x00, 0x0D,
};
// This function can be used to generate textual representation of vector<uint8_t> like you see above.
std::string FormatBytesFromBuffer(std::vector<uint8_t> const & buffer)
{
@ -733,23 +550,11 @@ UNIT_TEST(Kml_Serialization_Text_File)
// 8. Check binary deserialization of v.3 format.
UNIT_TEST(Kml_Deserialization_Bin_V3)
{
kml::FileData dataFromText;
try
{
kml::DeserializerKml des(dataFromText);
MemReader reader(kTextKml, strlen(kTextKml));
des.Deserialize(reader);
}
catch (kml::DeserializerKml::DeserializeException const & exc)
{
TEST(false, ("Exception raised", exc.what()));
}
kml::FileData dataFromBin;
kml::FileData dataFromBinV3;
try
{
MemReader reader(kBinKmlV3.data(), kBinKmlV3.size());
kml::binary::DeserializerKml des(dataFromBin);
kml::binary::DeserializerKml des(dataFromBinV3);
des.Deserialize(reader);
}
catch (kml::binary::DeserializerKml::DeserializeException const & exc)
@ -757,5 +562,17 @@ UNIT_TEST(Kml_Deserialization_Bin_V3)
TEST(false, ("Exception raised", exc.what()));
}
TEST_EQUAL(dataFromText, dataFromBin, ());
kml::FileData dataFromBinV4;
try
{
MemReader reader(kBinKmlV4.data(), kBinKmlV4.size());
kml::binary::DeserializerKml des(dataFromBinV4);
des.Deserialize(reader);
}
catch (kml::binary::DeserializerKml::DeserializeException const & exc)
{
TEST(false, ("Exception raised", exc.what()));
}
TEST_EQUAL(dataFromBinV3, dataFromBinV4, ());
}

1407
kml/kml_tests/tests_data.hpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -158,6 +158,8 @@ public:
{
// NOTE: v.2 and v.3 are binary compatible.
FileDataV3 dataV3;
dataV3.m_deviceId = m_data.m_deviceId;
dataV3.m_serverId = m_data.m_serverId;
DeserializeCategory(subReader, dataV3);
DeserializeBookmarks(subReader, dataV3);