[generator:tests] Add way intermediate generation test

This commit is contained in:
Anatoly Serdtcev 2019-10-31 20:46:29 +03:00 committed by Sergey Yershov
parent 9ed90b4537
commit 68b5276514

View file

@ -7,17 +7,30 @@
//
#include "testing/testing.hpp"
#include "generator/generator_tests/common.hpp"
#include "generator/generator_tests/source_data.hpp"
#include "generator/intermediate_elements.hpp"
#include "generator/osm_element.hpp"
#include "generator/osm_source.hpp"
#include "coding/reader.hpp"
#include "coding/writer.hpp"
#include <cstdint>
#include <fstream>
#include <functional>
#include <map>
#include <string>
#include <vector>
using namespace generator_tests;
using namespace generator;
using namespace std;
using namespace std::literals;
using OsmFormatParser = std::function<void(SourceReader &, function<void(OsmElement *)>)>;
UNIT_TEST(Intermediate_Data_empty_way_element_save_load_test)
{
@ -109,3 +122,64 @@ UNIT_TEST(Intermediate_Data_relation_element_save_load_test)
TEST_NOT_EQUAL(e2.tags["key1old"], "value1old", ());
TEST_NOT_EQUAL(e2.tags["key2old"], "value2old", ());
}
std::vector<OsmElement> ReadOsmElements(
std::string const & filename, OsmElement::EntityType type, OsmFormatParser parser)
{
std::vector<OsmElement> elements;
auto stream = std::fstream{filename};
SourceReader reader(stream);
parser(reader, [&elements, type](OsmElement * e)
{
if (e->m_type == type)
elements.push_back(*e);
});
return elements;
}
UNIT_TEST(IntermediateData_WaysGenerationTest)
{
auto const osmSamples = std::map<std::string, std::string>{
{"xml", way_xml_data}, {"o5m", {std::begin(way_o5m_data), std::end(way_o5m_data)}}};
auto const osmFormatParsers = std::map<std::string, OsmFormatParser>{
{"xml", ProcessOsmElementsFromXML}, {"o5m", ProcessOsmElementsFromO5M}};
for (auto const & sample : osmSamples)
{
auto const & osmFileTypeExtension = sample.first;
auto const & osmFileData = sample.second;
// Skip test for node storage type "mem": 64Gb required.
for (auto const & nodeStorageType : {"raw"s, "map"s})
{
auto const & dataPath = ScopedDir("intermediate_data", true /* recursiveForceRemove */);
auto genInfo = feature::GenerateInfo{};
genInfo.m_dataPath = dataPath.GetFullPath();
genInfo.m_targetDir = dataPath.GetFullPath();
genInfo.m_tmpDir = dataPath.GetFullPath();
genInfo.m_osmFileName = "planet." + osmFileTypeExtension;
genInfo.SetOsmFileType(osmFileTypeExtension);
genInfo.SetNodeStorageType(nodeStorageType);
std::ofstream{genInfo.m_osmFileName} << osmFileData;
auto generation = GenerateIntermediateData(genInfo);
CHECK(generation, ());
auto ways = ReadOsmElements(genInfo.m_osmFileName, OsmElement::EntityType::Way,
osmFormatParsers.at(osmFileTypeExtension));
TEST_EQUAL(ways.size(), 1, ());
auto const & intermediateData = cache::IntermediateData{genInfo, true /* forceReload */};
auto const & cache = intermediateData.GetCache();
for (auto const & element : ways)
{
auto way = WayElement{element.m_id};
TEST(cache->GetWay(element.m_id, way), ());
TEST_EQUAL(way.m_wayOsmId, element.m_id, ());
TEST_EQUAL(way.nodes.size(), element.Nodes().size(), ());
}
}
}
}