From 3ad5560982c01f4aa0d6737c4ea2f419b100c6cd Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 21 Dec 2010 00:34:22 +0200 Subject: [PATCH] Restore indexer_tests --- .../indexer_tests/feature_bucketer_test.cpp | 28 ++++---- indexer/indexer_tests/feature_routine.cpp | 49 ++++++++++++++ indexer/indexer_tests/feature_routine.hpp | 9 +++ indexer/indexer_tests/feature_test.cpp | 64 ++++++++++++------- omim.pro | 2 +- omim_light.pro | 2 +- 6 files changed, 114 insertions(+), 40 deletions(-) create mode 100644 indexer/indexer_tests/feature_routine.cpp create mode 100644 indexer/indexer_tests/feature_routine.hpp diff --git a/indexer/indexer_tests/feature_bucketer_test.cpp b/indexer/indexer_tests/feature_bucketer_test.cpp index d318b51ba1..eec9b87415 100644 --- a/indexer/indexer_tests/feature_bucketer_test.cpp +++ b/indexer/indexer_tests/feature_bucketer_test.cpp @@ -1,3 +1,5 @@ +#include "feature_routine.hpp" + #include "../../testing/testing.hpp" #include "../indexer_tool/feature_bucketer.hpp" @@ -17,14 +19,14 @@ namespace typedef map > * InitDataType; PushBackFeatureDebugStringOutput(string const & name, InitDataType const & initData) - : m_pContainer(&((*initData)[name])) {} - - void operator() (FeatureBuilderType const & fb) + : m_pContainer(&((*initData)[name])) { - FeatureType::read_source_t bytes; - fb.Serialize(bytes.m_data); + } - FeatureType f(bytes); + void operator() (FeatureBuilderGeom const & fb) + { + FeatureGeom f; + FeatureBuilder2Feature(fb, f); m_pContainer->push_back(f.DebugString()); } @@ -38,14 +40,6 @@ namespace MercatorBounds, RectId > FeatureBucketer; - - FeatureType MakeFeature(FeatureBuilderType const & fb) - { - FeatureType::read_source_t bytes; - fb.Serialize(bytes.m_data); - - return FeatureType(bytes); - } } UNIT_TEST(FeatureBucketerSmokeTest) @@ -53,12 +47,14 @@ UNIT_TEST(FeatureBucketerSmokeTest) map > out, expectedOut; FeatureBucketer bucketer(1, &out); - FeatureBuilderType fb; + FeatureBuilderGeom fb; fb.AddPoint(m2::PointD(10, 10)); fb.AddPoint(m2::PointD(20, 20)); bucketer(fb); - expectedOut["3"].push_back(MakeFeature(fb).DebugString()); + FeatureGeom f; + FeatureBuilder2Feature(fb, f); + expectedOut["3"].push_back(f.DebugString()); TEST_EQUAL(out, expectedOut, ()); vector bucketNames; diff --git a/indexer/indexer_tests/feature_routine.cpp b/indexer/indexer_tests/feature_routine.cpp new file mode 100644 index 0000000000..83da95bd24 --- /dev/null +++ b/indexer/indexer_tests/feature_routine.cpp @@ -0,0 +1,49 @@ +#include "../../base/SRC_FIRST.hpp" + +#include "feature_routine.hpp" + +#include "../../coding/file_writer.hpp" + + +void WriteToFile(string const & fName, vector const & buffer) +{ + FileWriter writer(fName); + if (!buffer.empty()) + writer.Write(&buffer[0], buffer.size()); +} + +string g_datFile = "indexer_tests_tmp.dat"; +FeatureGeomRef::read_source_t g_source(g_datFile); + +void FeatureBuilder2Feature(FeatureBuilderGeomRef const & fb, FeatureGeomRef & f) +{ + FeatureBuilderGeomRef::buffers_holder_t buffers; + buffers.m_lineOffset = buffers.m_trgOffset = 0; + fb.Serialize(buffers); + + WriteToFile(g_datFile + ".geom", buffers.m_buffers[1]); + WriteToFile(g_datFile + ".trg", buffers.m_buffers[2]); + + g_source.m_data.swap(buffers.m_buffers[0]); + f.Deserialize(g_source); +} + +void Feature2FeatureBuilder(FeatureGeomRef const & f, FeatureBuilderGeomRef & fb) +{ + f.InitFeatureBuilder(fb); +} + +void FeatureBuilder2Feature(FeatureBuilderGeom const & fb, FeatureGeom & f) +{ + FeatureBuilderGeom::buffers_holder_t buffers; + fb.Serialize(buffers); + + FeatureGeom::read_source_t source; + source.m_data.swap(buffers); + f.Deserialize(source); +} + +void Feature2FeatureBuilder(FeatureGeom const & f, FeatureBuilderGeom & fb) +{ + f.InitFeatureBuilder(fb); +} diff --git a/indexer/indexer_tests/feature_routine.hpp b/indexer/indexer_tests/feature_routine.hpp new file mode 100644 index 0000000000..330df0e49b --- /dev/null +++ b/indexer/indexer_tests/feature_routine.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "../feature.hpp" + +void FeatureBuilder2Feature(FeatureBuilderGeomRef const & fb, FeatureGeomRef & f); +void Feature2FeatureBuilder(FeatureGeomRef const & f, FeatureBuilderGeomRef & fb); + +void FeatureBuilder2Feature(FeatureBuilderGeom const & fb, FeatureGeom & f); +void Feature2FeatureBuilder(FeatureGeom const & f, FeatureBuilderGeom & fb); diff --git a/indexer/indexer_tests/feature_test.cpp b/indexer/indexer_tests/feature_test.cpp index d40b125cfd..a34176d727 100644 --- a/indexer/indexer_tests/feature_test.cpp +++ b/indexer/indexer_tests/feature_test.cpp @@ -1,7 +1,13 @@ +#include "feature_routine.hpp" + #include "../../testing/testing.hpp" #include "../feature.hpp" #include "../cell_id.hpp" +#include "../classificator.hpp" +#include "../classif_routine.hpp" + +#include "../../platform/platform.hpp" #include "../../geometry/point2d.hpp" @@ -34,12 +40,17 @@ namespace UNIT_TEST(Feature_Deserialize) { + Platform & platform = GetPlatform(); + classificator::Read(platform.ReadPathForFile("drawing_rules.bin"), + platform.ReadPathForFile("classificator.txt"), + platform.ReadPathForFile("visibility.txt")); + vector a; a.push_back(1); a.push_back(2); - FeatureBuilderType builder; + FeatureBuilderType fb; - builder.AddName("name"); + fb.AddName("name"); vector points; { @@ -48,7 +59,7 @@ UNIT_TEST(Feature_Deserialize) points.push_back(m2::PointD(0.25, 0.2)); points.push_back(m2::PointD(1.0, 1.0)); for (size_t i = 0; i < points.size(); ++i) - builder.AddPoint(points[i]); + fb.AddPoint(points[i]); } vector triangles; @@ -57,26 +68,34 @@ UNIT_TEST(Feature_Deserialize) triangles.push_back(m2::PointD(0.25, 0.5)); triangles.push_back(m2::PointD(1.0, 1.0)); for (size_t i = 0; i < triangles.size(); i += 3) - builder.AddTriangle(triangles[i], triangles[i+1], triangles[i+2]); + fb.AddTriangle(triangles[i], triangles[i+1], triangles[i+2]); } - builder.AddLayer(3); + fb.AddLayer(3); - size_t const typesCount = 2; - uint32_t arrTypes[typesCount+1] = { 5, 7, 0 }; - builder.AddTypes(arrTypes, arrTypes + typesCount); + vector types; + { + uint32_t type = ftype::GetEmptyValue(); - FeatureBuilderType::buffers_holder_t serial; - builder.Serialize(serial); - FeatureType::read_source_t serial1; - serial1.m_data = serial; - FeatureType f(serial1); + ClassifObjectPtr pObj = classif().GetRoot()->BinaryFind("natural"); + ASSERT ( pObj, () ); + ftype::PushValue(type, pObj.GetIndex()); + + pObj->BinaryFind("coastline"); + ftype::PushValue(type, pObj.GetIndex()); + + types.push_back(type); + fb.AddTypes(types.begin(), types.end()); + } + + FeatureType f; + FeatureBuilder2Feature(fb, f); TEST_EQUAL(f.GetFeatureType(), FeatureBase::FEATURE_TYPE_AREA, ()); - FeatureBase::GetTypesFn types; - f.ForEachTypeRef(types); - TEST_EQUAL(types.m_types, vector(arrTypes, arrTypes + typesCount), ()); + FeatureBase::GetTypesFn doGetTypes; + f.ForEachTypeRef(doGetTypes); + TEST_EQUAL(doGetTypes.m_types, types, ()); TEST_EQUAL(f.GetLayer(), 3, ()); TEST_EQUAL(f.GetName(), "name", ()); @@ -97,11 +116,12 @@ UNIT_TEST(Feature_Deserialize) TEST_LESS(fabs(f.GetLimitRect().maxX() - 1.00), eps, ()); TEST_LESS(fabs(f.GetLimitRect().maxY() - 1.00), eps, ()); - FeatureType::read_source_t serial2; - FeatureBuilderType builder2; - f.InitFeatureBuilder(builder2); - builder2.Serialize(serial2.m_data); + { + FeatureBuilderType fbTest; + Feature2FeatureBuilder(f, fbTest); - TEST_EQUAL(serial, serial2.m_data, - (f.DebugString(), FeatureType(serial2).DebugString())); + FeatureType fTest; + FeatureBuilder2Feature(fbTest, fTest); + TEST_EQUAL(f.DebugString(), fTest.DebugString(), ()); + } } diff --git a/omim.pro b/omim.pro index a5132797a1..ea41f04ee0 100644 --- a/omim.pro +++ b/omim.pro @@ -18,7 +18,7 @@ SUBDIRS = 3party \ version \ indexer/indexer_tool \ qt_tstfrm \ -# indexer/indexer_tests \ + indexer/indexer_tests \ # yg/yg_tests \ qt } diff --git a/omim_light.pro b/omim_light.pro index 8d32e0e0d3..0bbba5f012 100644 --- a/omim_light.pro +++ b/omim_light.pro @@ -17,7 +17,7 @@ SUBDIRS = \ indexer/indexer_tests \ map/map_tests \ indexer/indexer_tool \ - yg/yg_tests \ +# yg/yg_tests \ qt }