diff options
author | Sergey Yershov <yershov@corp.mail.ru> | 2015-08-06 12:53:57 +0300 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 03:00:48 +0300 |
commit | ee425939083ba554eea3f650b51674bfdfcd3bcb (patch) | |
tree | 122c6525996673fcf074e3dc7cd5e84cf0ce057f /generator | |
parent | 02a3ea65b7f0abdb15e62d116e29114db76c0651 (diff) |
Add dummy tests
Diffstat (limited to 'generator')
-rw-r--r-- | generator/generator_tests/source_to_element_test.cpp | 87 | ||||
-rw-r--r-- | generator/osm_source.cpp | 38 | ||||
-rw-r--r-- | generator/xml_element.hpp | 17 |
3 files changed, 137 insertions, 5 deletions
diff --git a/generator/generator_tests/source_to_element_test.cpp b/generator/generator_tests/source_to_element_test.cpp new file mode 100644 index 0000000000..75aff288fb --- /dev/null +++ b/generator/generator_tests/source_to_element_test.cpp @@ -0,0 +1,87 @@ +// +// source_to_element_test.cpp +// generator_tool +// +// Created by Sergey Yershov on 05.08.15. +// Copyright (c) 2015 maps.me. All rights reserved. +// + +#include "testing/testing.hpp" + +#include "coding/parse_xml.hpp" +#include "generator/osm_source.hpp" +#include "generator/xml_element.hpp" + + +char const node_xml_data[] = "<?xml version='1.0' encoding='UTF-8'?> \ + <osm version='0.6' upload='true' generator='JOSM'> \ + <node id='-273105' action='modify' visible='true' lat='62.18269750679' lon='-134.28965517091'> \ + <tag k='name' v='Продуктовый' /> \ + <tag k='opening_hours' v='24/7' /> \ + <tag k='shop' v='convenience' /> \ + </node> \ + </osm> \ +"; + +// binary data: node.o5m +uint8_t node_o5m_data1[] = /* 92 */ +{0xFF, 0xE0, 0x04, 0x6F, 0x35, 0x6D, 0x32, 0xFF, 0x10, 0x51, 0xA1, 0xAB, 0x21, 0x00, 0xCD, 0xE6, + 0xD7, 0x80, 0x0A, 0xBE, 0xCE, 0x82, 0xD1, 0x04, 0x00, 0x6E, 0x61, 0x6D, 0x65, 0x00, 0xD0, 0x9F, + 0xD1, 0x80, 0xD0, 0xBE, 0xD0, 0xB4, 0xD1, 0x83, 0xD0, 0xBA, 0xD1, 0x82, 0xD0, 0xBE, 0xD0, 0xB2, + 0xD1, 0x8B, 0xD0, 0xB9, 0x00, 0x00, 0x6F, 0x70, 0x65, 0x6E, 0x69, 0x6E, 0x67, 0x5F, 0x68, 0x6F, + 0x75, 0x72, 0x73, 0x00, 0x32, 0x34, 0x2F, 0x37, 0x00, 0x00, 0x73, 0x68, 0x6F, 0x70, 0x00, 0x63, + 0x6F, 0x6E, 0x76, 0x65, 0x6E, 0x69, 0x65, 0x6E, 0x63, 0x65, 0x00, 0xFE}; +static_assert(sizeof(node_o5m_data1) == 92, "Size check failed"); + + +struct DummyParser : public BaseOSMParser +{ + XMLElement & m_e; + DummyParser(XMLElement & e) : BaseOSMParser() , m_e(e) {} + void EmitElement(XMLElement * p) override + { + m_e = *p; + } +}; + +UNIT_TEST(Source_To_Element_check_equivalence) +{ + istringstream ss1(node_xml_data); + SourceReader reader1(ss1); + + XMLElement e1; + DummyParser parser1(e1); + ParseXMLSequence(reader1, parser1); + + string src(begin(node_o5m_data1), end(node_o5m_data1)); + istringstream ss2(src); + SourceReader reader2(ss2); + + XMLElement e2; + DummyParser parser2(e2); + BuildFeaturesFromO5M(reader2, parser2); + + TEST_EQUAL(e1, e2, ()); +} + + +UNIT_TEST(Source_To_Element_create_from_xml_test) +{ + istringstream ss(node_xml_data); + SourceReader reader(ss); + + XMLElement e; + DummyParser parser(e); + ParseXMLSequence(reader, parser); +} + +UNIT_TEST(Source_To_Element_create_from_o5m_test) +{ + string src(begin(node_o5m_data1), end(node_o5m_data1)); + istringstream ss(src); + SourceReader reader(ss); + + XMLElement e; + DummyParser parser(e); + BuildFeaturesFromO5M(reader, parser); +}
\ No newline at end of file diff --git a/generator/osm_source.cpp b/generator/osm_source.cpp index 705b3124f2..08e5fbd9b7 100644 --- a/generator/osm_source.cpp +++ b/generator/osm_source.cpp @@ -8,7 +8,6 @@ #include "generator/osm_source.hpp" #include "generator/point_storage.hpp" #include "generator/polygonizer.hpp" -#include "generator/source_reader.hpp" #include "generator/world_map_generator.hpp" #include "generator/xml_element.hpp" @@ -17,10 +16,39 @@ #include "coding/parse_xml.hpp" +#include "std/fstream.hpp" + #include "defines.hpp" #define DECODE_O5M_COORD(coord) (static_cast<double>(coord) / 1E+7) +SourceReader::SourceReader() +: m_file(unique_ptr<istream,Deleter>(&cin, Deleter(false))) +{ + LOG_SHORT(LINFO, ("Reading OSM data from stdin")); +} + +SourceReader::SourceReader(string const & filename) +: m_filename(filename) +, m_file(unique_ptr<istream, Deleter>(new ifstream(filename), Deleter())) +{ + CHECK(m_filename.empty() , ("Filename can't be empty")); + LOG_SHORT(LINFO, ("Reading OSM data from", filename)); +} + +SourceReader::SourceReader(istringstream & stream) +: m_file(unique_ptr<istream, Deleter>(&stream, Deleter(false))) +{ + LOG_SHORT(LINFO, ("Reading OSM data from memory")); +} + +uint64_t SourceReader::Read(char * buffer, uint64_t bufferSize) +{ + m_file->read(buffer, bufferSize); + return m_file->gcount(); +} + + namespace { template <class TNodesHolder> @@ -449,7 +477,7 @@ bool GenerateFeaturesImpl(feature::GenerateInfo & info) { try { - TNodesHolder nodes(info.GetIntermediateFileName(NODES_FILE)); + TNodesHolder nodes(info.GetIntermediateFileName(NODES_FILE, "")); using TDataCache = IntermediateDataReader<TNodesHolder>; TDataCache cache(nodes, info.m_intermediateDir); @@ -460,7 +488,7 @@ bool GenerateFeaturesImpl(feature::GenerateInfo & info) bucketer, cache, info.m_makeCoasts ? classif().GetCoastType() : 0, info.GetAddressesFileName()); - SourceReader reader(info.m_osmFileName); + SourceReader reader = info.m_osmFileName.empty() ? SourceReader() : SourceReader(info.m_osmFileName); switch (info.m_osmFileType) { case feature::GenerateInfo::OsmSourceType::XML: @@ -494,11 +522,11 @@ bool GenerateIntermediateDataImpl(feature::GenerateInfo & info) { try { - TNodesHolder nodes(info.GetIntermediateFileName(NODES_FILE)); + TNodesHolder nodes(info.GetIntermediateFileName(NODES_FILE, "")); using TDataCache = IntermediateDataWriter<TNodesHolder>; TDataCache cache(nodes, info.m_intermediateDir); - SourceReader reader(info.m_osmFileName); + SourceReader reader = info.m_osmFileName.empty() ? SourceReader() : SourceReader(info.m_osmFileName); LOG(LINFO, ("Data source:", info.m_osmFileName)); diff --git a/generator/xml_element.hpp b/generator/xml_element.hpp index fa435526c5..d1ebe1beb0 100644 --- a/generator/xml_element.hpp +++ b/generator/xml_element.hpp @@ -33,6 +33,23 @@ struct XMLElement XMLElement * parent = nullptr; vector<XMLElement> childs; + + bool operator == (XMLElement const & e) const + { + return ( + tagKey == e.tagKey + && id == e.id + && lng == e.lng + && lat == e.lat + && ref == e.ref + && k == e.k + && v == e.v + && type == e.type + && role == e.role + && childs == childs + ); + } + void AddKV(string const & k, string const & v); void AddND(uint64_t ref); void AddMEMBER(uint64_t ref, string const & type, string const & role); |