Restore indexer_tests

This commit is contained in:
vng 2010-12-21 00:34:22 +02:00 committed by Alex Zolotarev
parent 94386697d7
commit 3ad5560982
6 changed files with 114 additions and 40 deletions

View file

@ -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<string, vector<string> > * 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<string, vector<string> > 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<string> bucketNames;

View file

@ -0,0 +1,49 @@
#include "../../base/SRC_FIRST.hpp"
#include "feature_routine.hpp"
#include "../../coding/file_writer.hpp"
void WriteToFile(string const & fName, vector<char> 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);
}

View file

@ -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);

View file

@ -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<int> a;
a.push_back(1);
a.push_back(2);
FeatureBuilderType builder;
FeatureBuilderType fb;
builder.AddName("name");
fb.AddName("name");
vector<m2::PointD> 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<m2::PointD> 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<uint32_t> 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<uint32_t>(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(), ());
}
}

View file

@ -18,7 +18,7 @@ SUBDIRS = 3party \
version \
indexer/indexer_tool \
qt_tstfrm \
# indexer/indexer_tests \
indexer/indexer_tests \
# yg/yg_tests \
qt
}

View file

@ -17,7 +17,7 @@ SUBDIRS = \
indexer/indexer_tests \
map/map_tests \
indexer/indexer_tool \
yg/yg_tests \
# yg/yg_tests \
qt
}