Fix map_tests. Now it works correct with geometry for needed scale.

Fix indexer_tests - correct deletion of temporary files.
This commit is contained in:
vng 2011-01-04 20:48:09 +02:00 committed by Alex Zolotarev
parent de7b01f1ac
commit 2673acf54a
6 changed files with 91 additions and 61 deletions

View file

@ -490,27 +490,34 @@ void FeatureGeom::ParseTriangles(int scale) const
ASSERT_EQUAL ( CalcOffset(source), m_Data.size() - m_Offset, () );
}
void FeatureGeom::ParseAll() const
void FeatureGeom::ParseAll(int scale) const
{
if (!m_bGeometryParsed)
ParseGeometry(m_defScale);
ParseGeometry(scale);
if (!m_bTrianglesParsed)
ParseTriangles(m_defScale);
ParseTriangles(scale);
}
string FeatureGeom::DebugString() const
string FeatureGeom::DebugString(int scale) const
{
ParseAll();
ParseAll(scale);
string res = base_type::DebugString();
res += debug_print(m_Geometry) + " ";
res += debug_print(m_Triangles) + ")";
return res;
}
string FeatureGeom::DebugString() const
{
string ret = DebugString(m_defScale);
ASSERT ( !ret.empty(), () );
return ret;
}
void FeatureGeom::InitFeatureBuilder(FeatureBuilderGeom & fb) const
{
ParseAll();
ParseAll(m_defScale);
base_type::InitFeatureBuilder(fb);
for (size_t i = 0; i < m_Geometry.size(); ++i)
@ -552,10 +559,22 @@ uint32_t FeatureGeomRef::GetOffset(int scale) const
return m_invalidOffset;
}
string FeatureGeomRef::DebugString(int scale) const
{
if (!m_bOffsetsParsed)
ParseOffsets();
if (!m_bGeometryParsed && GetOffset(scale) == m_invalidOffset)
return string();
else
return base_type::DebugString(scale);
}
void FeatureGeomRef::ParseGeometry(int scale) const
{
if (!m_bOffsetsParsed)
ParseOffsets();
if (m_bGeometryParsed)
return;

View file

@ -321,10 +321,11 @@ protected:
template <class TSource> void ParseGeometryImpl(TSource & src) const;
template <class TSource> void ParseTrianglesImpl(TSource & src) const;
virtual string DebugString(int scale) const;
virtual void ParseGeometry(int scale) const;
virtual void ParseTriangles(int scale) const;
void ParseAll() const;
void ParseAll(int scale) const;
mutable vector<m2::PointD> m_Geometry;
mutable vector<m2::PointD> m_Triangles;
@ -351,9 +352,10 @@ public:
void Deserialize(read_source_t & src);
protected:
/// @name Overwrite from base_type.
//@{
virtual string DebugString(int scale) const;
protected:
virtual void ParseGeometry(int scale) const;
virtual void ParseTriangles(int scale) const;
//@}
@ -379,11 +381,5 @@ inline string debug_print(FeatureGeom const & f)
return f.DebugString();
}
inline string debug_print(FeatureGeomRef const & f)
{
return f.DebugString();
}
typedef FeatureGeomRef FeatureType;
typedef FeatureBuilderGeomRef FeatureBuilderType;

View file

@ -12,6 +12,31 @@ void WriteToFile(string const & fName, vector<char> const & buffer)
writer.Write(&buffer[0], buffer.size());
}
namespace
{
class feature_source_initializer
{
string m_name;
public:
FeatureGeomRef::read_source_t * m_source;
feature_source_initializer(string const & fName)
: m_name(fName)
{
m_source = new FeatureGeomRef::read_source_t(
FileReader(fName + ".geom"), FileReader(fName + ".trg"));
}
~feature_source_initializer()
{
delete m_source;
FileWriter::DeleteFile(m_name + ".geom");
FileWriter::DeleteFile(m_name + ".trg");
}
};
}
void FeatureBuilder2Feature(FeatureBuilderGeomRef const & fb, FeatureGeomRef & f)
{
string const datFile = "indexer_tests_tmp.dat";
@ -23,12 +48,9 @@ void FeatureBuilder2Feature(FeatureBuilderGeomRef const & fb, FeatureGeomRef & f
WriteToFile(datFile + ".geom", buffers.m_buffers[1]);
WriteToFile(datFile + ".trg", buffers.m_buffers[2]);
static FeatureGeomRef::read_source_t g_source(FileReader(datFile + ".geom"), FileReader(datFile + ".trg"));
g_source.m_data.swap(buffers.m_buffers[0]);
f.Deserialize(g_source);
FileWriter::DeleteFile(datFile + ".geom");
FileWriter::DeleteFile(datFile + ".trg");
static feature_source_initializer staticInstance(datFile);
staticInstance.m_source->m_data.swap(buffers.m_buffers[0]);
f.Deserialize(*staticInstance.m_source);
}
void Feature2FeatureBuilder(FeatureGeomRef const & f, FeatureBuilderGeomRef & fb)

View file

@ -102,12 +102,14 @@ UNIT_TEST(Feature_Deserialize)
//TEST_EQUAL(f.GetGeometrySize(), 4, ());
//TEST_EQUAL(f.GetTriangleCount(), 1, ());
int const level = FeatureType::m_defScale;
PointAccumulator featurePoints;
f.ForEachPointRef(featurePoints, FeatureType::m_defScale);
f.ForEachPointRef(featurePoints, level);
TEST_EQUAL(points, featurePoints.m_V, ());
PointAccumulator featureTriangles;
f.ForEachTriangleRef(featureTriangles, FeatureType::m_defScale);
f.ForEachTriangleRef(featureTriangles, level);
TEST_EQUAL(triangles, featureTriangles.m_V, ());
double const eps = MercatorBounds::GetCellID2PointAbsEpsilon();
@ -122,6 +124,6 @@ UNIT_TEST(Feature_Deserialize)
FeatureType fTest;
FeatureBuilder2Feature(fbTest, fTest);
TEST_EQUAL(f.DebugString(), fTest.DebugString(), ());
TEST_EQUAL(f.DebugString(level), fTest.DebugString(level), ());
}
}

View file

@ -29,7 +29,7 @@ UNIT_TEST(BuildIndexTest)
}
// Create a new mwm file.
string const fileName = p.WritablePathForFile("build_index_test" DATA_FILE_EXTENSION);
string const fileName = "build_index_test" DATA_FILE_EXTENSION;
FileWriter::DeleteFile(fileName);
// Copy original mwm file and replace index in it.
@ -50,12 +50,14 @@ UNIT_TEST(BuildIndexTest)
containerWriter.Append(serialIndex, INDEX_FILE_TAG);
}
// Check that index actually works.
Index<FileReader>::Type index;
index.Add(fileName);
{
// Check that index actually works.
Index<FileReader>::Type index;
index.Add(fileName);
// Make sure that index is actually parsed.
index.ForEachInScale(NoopFunctor(), 15);
// Make sure that index is actually parsed.
index.ForEachInScale(NoopFunctor(), 15);
}
// Clean after the test.
FileWriter::DeleteFile(fileName);

View file

@ -26,20 +26,24 @@ typedef vector<pair<FeatureType, string> > feature_cont_t;
class AccumulatorBase
{
int m_scale;
mutable string m_dbgString;
feature_cont_t & m_cont;
protected:
int m_scale;
bool is_drawable(FeatureType const & f) const
{
return feature::IsDrawableForIndex(f, m_scale);
m_dbgString = f.DebugString(m_scale);
CHECK(m_dbgString == f.DebugString(m_scale), ());
// Feature that hasn't any geometry for m_scale returns empty DebugString().
return (!m_dbgString.empty() && feature::IsDrawableForIndex(f, m_scale));
}
void add(FeatureType const & f) const
{
string const s = f.DebugString();
m_cont.push_back(make_pair(f, s));
m_cont.push_back(make_pair(f, m_dbgString));
}
public:
@ -51,9 +55,6 @@ public:
void operator() (FeatureType const & f) const
{
string const dbg = f.DebugString();
ASSERT ( dbg == f.DebugString(), () );
if (is_drawable(f))
add(f);
}
@ -101,7 +102,7 @@ class AccumulatorEtalon : public AccumulatorBase
bool is_intersect(FeatureType const & f) const
{
IntersectCheck check(m_rect);
f.ForEachPointRef(check, scales::GetScaleLevel(m_rect));
f.ForEachPointRef(check, m_scale);
return check.IsIntersect();
}
@ -113,8 +114,6 @@ public:
void operator() (FeatureType const & f, uint64_t /*offset*/) const
{
ASSERT ( f.DebugString() == f.DebugString(), () );
if (is_drawable(f) && is_intersect(f))
add(f);
}
@ -186,20 +185,6 @@ bool compare_sequence(TCont const & etalon, TCont const & test, TCompare comp, s
break;
case -1:
{
// *i1 exists in etalon, but not exists in test
//vector<int64_t> c = covering::CoverFeature((*i1).first);
//m2::RectD cRect;
//for (size_t i = 0; i < c.size(); ++i)
//{
// RectId id = RectId::FromInt64(c[i]);
// CoordT b[4];
// CellIdConverter<MercatorBounds, RectId>::GetCellBounds(id, b[0], b[1], b[2], b[3]);
// cRect.Add(m2::RectD(b[0], b[1], b[2], b[3]));
//}
//m2::RectD const fRect = (*i1).first.GetLimitRect();
//ASSERT ( cRect.IsPointInside(fRect.LeftTop()) && cRect.IsPointInside(fRect.RightBottom()), (fRect, cRect) );
errInd = distance(etalon.begin(), i1);
return false;
}
@ -217,16 +202,17 @@ namespace
class FindOffset
{
pair<FeatureType, string> const & m_test;
int m_level;
public:
FindOffset(pair<FeatureType, string> const & test) : m_test(test) {}
FindOffset(int level, pair<FeatureType, string> const & test)
: m_level(level), m_test(test)
{}
void operator() (FeatureType const & f, uint64_t offset)
{
if (f.DebugString() == m_test.second)
{
my::g_LogLevel = LDEBUG;
if (f.DebugString(m_level) == m_test.second)
LOG(LINFO, ("Offset = ", offset));
}
}
};
}
@ -256,14 +242,17 @@ UNIT_TEST(IndexForEachTest)
file_source_t src2(path);
for_each_in_rect<AccumulatorEtalon>(src2, v2, r);
int const level = scales::GetScaleLevel(r);
size_t errInd;
if (!compare_sequence(v2, v1, compare_strings(), errInd))
{
src2.ForEachFeature(r, FindOffset(v2[errInd]));
LOG(LINFO, ("Failed for rect: ", r, ". Etalon size = ", v2.size(), ". Index size = ", v1.size()));
src2.ForEachFeature(r, FindOffset(level, v2[errInd]));
TEST(false, ("Error in ForEachFeature test"));
}
if (!v2.empty() && (scales::GetScaleLevel(r) < scales::GetUpperScale()))
if (!v2.empty() && (level < scales::GetUpperScale()))
{
m2::RectD r1, r2;
r.DivideByGreaterSize(r1, r2);