[search] More integration tests.

This commit is contained in:
Yuri Gorshenin 2015-09-11 15:20:39 +03:00 committed by Sergey Yershov
parent ea12165eba
commit 044d4a2dd0
12 changed files with 172 additions and 81 deletions

View file

@ -70,6 +70,11 @@ void FeatureBuilder1::SetCenter(m2::PointD const & p)
m_limitRect.Add(p);
}
void FeatureBuilder1::SetRank(uint8_t rank)
{
m_params.rank = rank;
}
void FeatureBuilder1::AddPoint(m2::PointD const & p)
{
m_polygons.front().push_back(p);

View file

@ -31,6 +31,8 @@ public:
/// Set center (origin) point of feature and set that feature is point.
void SetCenter(m2::PointD const & p);
void SetRank(uint8_t rank);
/// Add point to geometry.
void AddPoint(m2::PointD const & p);

View file

@ -1,15 +0,0 @@
TARGET = generator_tests_support
TEMPLATE = lib
CONFIG += staticlib warn_on
ROOT_DIR = ../..
include($$ROOT_DIR/common.pri)
INCLUDEPATH *= $$ROOT_DIR/3party/expat/lib
HEADERS += \
test_mwm_builder.hpp \
SOURCES += \
test_mwm_builder.cpp \

View file

@ -140,20 +140,16 @@ SUBDIRS = 3party base coding geometry indexer routing
pedestrian_routing_tests.depends = $$MapDepLibs routing
SUBDIRS *= pedestrian_routing_tests
generator_tests_support.subdir = generator/generator_tests_support
generator_tests_support.depends = $$MapDepLibs generator
SUBDIRS *= generator_tests_support
search_tests_support.subdir = search/search_tests_support
search_tests_support.depends = $$MapDepLibs generator
SUBDIRS *= search_tests_support
search_integration_tests.subdir = search/search_integration_tests
search_integration_tests.depends = $$MapDepLibs generator generator_tests_support search_tests_support
search_integration_tests.depends = $$MapDepLibs search_tests_support generator
SUBDIRS *= search_integration_tests
generator_tests.subdir = generator/generator_tests
generator_tests.depends = $$MapDepLibs routing generator generator_tests_support
generator_tests.depends = $$MapDepLibs routing generator
SUBDIRS *= generator_tests
SUBDIRS *= qt_tstfrm

View file

@ -1,7 +1,5 @@
#include "testing/testing.hpp"
#include "generator/generator_tests_support/test_mwm_builder.hpp"
#include "indexer/classificator_loader.hpp"
#include "indexer/index.hpp"
#include "indexer/mwm_set.hpp"
@ -11,13 +9,19 @@
#include "search/retrieval.hpp"
#include "search/search_query_params.hpp"
#include "search/search_tests_support/test_mwm_builder.hpp"
#include "search/search_tests_support/test_search_engine.hpp"
#include "search/search_tests_support/test_search_request.hpp"
#include "platform/local_country_file.hpp"
#include "platform/local_country_file_utils.hpp"
#include "platform/platform.hpp"
#include "base/scope_guard.hpp"
#include "base/string_utils.hpp"
using namespace search::tests_support;
namespace
{
void InitParams(string const & query, search::SearchQueryParams & params)
@ -33,6 +37,18 @@ void InitParams(string const & query, search::SearchQueryParams & params)
params.m_langs.insert(StringUtf8Multilang::GetLangIndex("en"));
}
void Cleanup(platform::LocalCountryFile const & map)
{
platform::CountryIndexes::DeleteFromDisk(map);
map.DeleteFromDisk(MapOptions::Map);
}
void Cleanup(initializer_list<platform::LocalCountryFile> const & maps)
{
for (auto const & map : maps)
Cleanup(map);
}
class TestCallback : public search::Retrieval::Callback
{
public:
@ -95,14 +111,15 @@ UNIT_TEST(Retrieval_Smoke)
Platform & platform = GetPlatform();
platform::LocalCountryFile file(platform.WritableDir(), platform::CountryFile("WhiskeyTown"), 0);
Cleanup(file);
MY_SCOPE_GUARD(deleteFile, [&]()
{
file.DeleteFromDisk(MapOptions::Map);
Cleanup(file);
});
// Create a test mwm with 100 whiskey bars.
{
TestMwmBuilder builder(file);
TestMwmBuilder builder(file, feature::DataHeader::country);
for (int x = 0; x < 10; ++x)
{
for (int y = 0; y < 10; ++y)
@ -175,23 +192,22 @@ UNIT_TEST(Retrieval_3Mwms)
platform::LocalCountryFile msk(platform.WritableDir(), platform::CountryFile("msk"), 0);
platform::LocalCountryFile mtv(platform.WritableDir(), platform::CountryFile("mtv"), 0);
platform::LocalCountryFile zrh(platform.WritableDir(), platform::CountryFile("zrh"), 0);
MY_SCOPE_GUARD(deleteFiles, [&]()
Cleanup({msk, mtv, zrh});
MY_SCOPE_GUARD(cleanup, [&]()
{
msk.DeleteFromDisk(MapOptions::Map);
mtv.DeleteFromDisk(MapOptions::Map);
zrh.DeleteFromDisk(MapOptions::Map);
Cleanup({msk, mtv, zrh});
});
{
TestMwmBuilder builder(msk);
TestMwmBuilder builder(msk, feature::DataHeader::country);
builder.AddPOI(m2::PointD(0, 0), "Cafe MTV", "en");
}
{
TestMwmBuilder builder(mtv);
TestMwmBuilder builder(mtv, feature::DataHeader::country);
builder.AddPOI(m2::PointD(10, 0), "MTV", "en");
}
{
TestMwmBuilder builder(zrh);
TestMwmBuilder builder(zrh, feature::DataHeader::country);
builder.AddPOI(m2::PointD(0, 10), "Bar MTV", "en");
}
@ -252,3 +268,83 @@ UNIT_TEST(Retrieval_3Mwms)
TEST_EQUAL(3, callback.GetNumFeatures(), ());
}
}
// This test creates a couple of maps:
// * model map of Moscow, with "Cafe MTV" at the center
// * model map of MTV, with "Cafe Moscow" at the center
// * TestWorld map, with Moscow and MTV
// TestWorld map is needed because locality search works only on world maps.
//
// Then, it tests search engine on following requests:
//
// 1. "Moscow", viewport covers only Moscow - should return two
// results (Moscow city and Cafe Moscow at MTV).
// 2. "MTV", viewport covers only MTV"- should return two results (MTV
// city and Cafe MTV at Moscow).
// 3. "Moscow MTV", viewport covers only MTV - should return MTV cafe
// at Moscow.
// 4. "MTV Moscow", viewport covers only Moscow - should return Moscow
// cafe at MTV.
UNIT_TEST(Retrieval_CafeMTV)
{
classificator::Load();
Platform & platform = GetPlatform();
platform::LocalCountryFile msk(platform.WritableDir(), platform::CountryFile("msk"), 0);
platform::LocalCountryFile mtv(platform.WritableDir(), platform::CountryFile("mtv"), 0);
platform::LocalCountryFile testWorld(platform.WritableDir(), platform::CountryFile("testWorld"), 0);
Cleanup({msk, mtv, testWorld});
MY_SCOPE_GUARD(cleanup, [&]()
{
Cleanup({msk, mtv, testWorld});
});
{
TestMwmBuilder builder(msk, feature::DataHeader::country);
builder.AddCity(m2::PointD(1, 0), "Moscow", "en");
builder.AddPOI(m2::PointD(1, 0), "Cafe MTV", "en");
}
{
TestMwmBuilder builder(mtv, feature::DataHeader::country);
builder.AddCity(m2::PointD(-1, 0), "MTV", "en");
builder.AddPOI(m2::PointD(-1, 0), "Cafe Moscow", "en");
}
{
TestMwmBuilder builder(testWorld, feature::DataHeader::world);
builder.AddCity(m2::PointD(1, 0), "Moscow", "en");
builder.AddCity(m2::PointD(-1, 0), "MTV", "en");
}
TestSearchEngine engine("en");
TEST_EQUAL(MwmSet::RegResult::Success, engine.RegisterMap(msk).second, ());
TEST_EQUAL(MwmSet::RegResult::Success, engine.RegisterMap(mtv).second, ());
TEST_EQUAL(MwmSet::RegResult::Success, engine.RegisterMap(testWorld).second, ());
m2::RectD const moscowViewport(m2::PointD(0.99, -0.1), m2::PointD(1.01, 0.1));
m2::RectD const mtvViewport(m2::PointD(-1.1, -0.1), m2::PointD(-0.99, 0.1));
{
TestSearchRequest request(engine, "Moscow ", "en", search::SearchParams::ALL, moscowViewport);
request.Wait();
TEST_EQUAL(2, request.Results().size(), ());
}
{
TestSearchRequest request(engine, "MTV ", "en", search::SearchParams::ALL, mtvViewport);
request.Wait();
TEST_EQUAL(2, request.Results().size(), ());
}
{
TestSearchRequest request(engine, "Moscow MTV ", "en", search::SearchParams::ALL, mtvViewport);
request.Wait();
TEST_EQUAL(1, request.Results().size(), ());
}
{
TestSearchRequest request(engine, "MTV Moscow ", "en", search::SearchParams::ALL,
moscowViewport);
request.Wait();
TEST_EQUAL(1, request.Results().size(), ());
}
}

View file

@ -7,7 +7,7 @@ TEMPLATE = app
ROOT_DIR = ../..
DEPENDENCIES = generator_tests_support generator routing search search_tests_support storage stats_client indexer \
DEPENDENCIES = search_tests_support generator routing search storage stats_client indexer \
platform geometry coding base tess2 protobuf tomcrypt jansson
DEPENDENCIES += opening_hours \

View file

@ -1,7 +1,6 @@
#include "testing/testing.hpp"
#include "generator/generator_tests_support/test_mwm_builder.hpp"
#include "search/search_tests_support/test_mwm_builder.hpp"
#include "search/search_tests_support/test_search_engine.hpp"
#include "search/search_tests_support/test_search_request.hpp"
@ -61,7 +60,7 @@ UNIT_TEST(GenerateTestMwm_Smoke)
platform::LocalCountryFile & file = scopedFile.GetFile();
{
TestMwmBuilder builder(file);
TestMwmBuilder builder(file, feature::DataHeader::country);
builder.AddPOI(m2::PointD(0, 0), "Wine shop", "en");
builder.AddPOI(m2::PointD(1, 0), "Tequila shop", "en");
builder.AddPOI(m2::PointD(0, 1), "Brandy shop", "en");
@ -78,14 +77,14 @@ UNIT_TEST(GenerateTestMwm_Smoke)
TestFeaturesCount(engine, m2::RectD(m2::PointD(-0.5, -0.5), m2::PointD(0.5, 1.5)), 2);
{
TestSearchRequest request(engine, "wine ", "en",
TestSearchRequest request(engine, "wine ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
request.Wait();
TEST_EQUAL(1, request.Results().size(), ());
}
{
TestSearchRequest request(engine, "shop ", "en",
TestSearchRequest request(engine, "shop ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
request.Wait();
TEST_EQUAL(4, request.Results().size(), ());
@ -99,7 +98,7 @@ UNIT_TEST(GenerateTestMwm_NotPrefixFreeNames)
platform::LocalCountryFile & file = scopedFile.GetFile();
{
TestMwmBuilder builder(file);
TestMwmBuilder builder(file, feature::DataHeader::country);
builder.AddPOI(m2::PointD(0, 0), "a", "en");
builder.AddPOI(m2::PointD(0, 1), "aa", "en");
builder.AddPOI(m2::PointD(1, 1), "aa", "en");
@ -117,19 +116,19 @@ UNIT_TEST(GenerateTestMwm_NotPrefixFreeNames)
TestFeaturesCount(engine, m2::RectD(m2::PointD(0, 0), m2::PointD(2, 2)), 6);
{
TestSearchRequest request(engine, "a ", "en",
TestSearchRequest request(engine, "a ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
request.Wait();
TEST_EQUAL(1, request.Results().size(), ());
}
{
TestSearchRequest request(engine, "aa ", "en",
TestSearchRequest request(engine, "aa ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
request.Wait();
TEST_EQUAL(2, request.Results().size(), ());
}
{
TestSearchRequest request(engine, "aaa ", "en",
TestSearchRequest request(engine, "aaa ", "en", search::SearchParams::IN_VIEWPORT_ONLY,
m2::RectD(m2::PointD(0, 0), m2::PointD(100, 100)));
request.Wait();
TEST_EQUAL(3, request.Results().size(), ());

View file

@ -9,7 +9,9 @@ include($$ROOT_DIR/common.pri)
SOURCES += \
test_search_engine.cpp \
test_search_request.cpp \
test_mwm_builder.cpp \
HEADERS += \
test_search_engine.hpp \
test_search_request.hpp \
test_mwm_builder.hpp \

View file

@ -1,4 +1,4 @@
#include "test_mwm_builder.hpp"
#include "search/search_tests_support/test_mwm_builder.hpp"
#include "indexer/classificator.hpp"
#include "indexer/data_header.hpp"
@ -12,15 +12,17 @@
#include "platform/local_country_file.hpp"
#include "coding/internal/file_data.hpp"
#include "base/logging.hpp"
#include "defines.hpp"
TestMwmBuilder::TestMwmBuilder(platform::LocalCountryFile & file)
namespace search
{
namespace tests_support
{
TestMwmBuilder::TestMwmBuilder(platform::LocalCountryFile & file, feature::DataHeader::MapType type)
: m_file(file),
m_type(type),
m_collector(
make_unique<feature::FeaturesCollector>(file.GetPath(MapOptions::Map) + EXTENSION_TMP)),
m_classificator(classif())
@ -31,53 +33,47 @@ TestMwmBuilder::~TestMwmBuilder()
{
if (m_collector)
Finish();
CHECK(!m_collector, ("Features weren't dumped on disk."));
}
void TestMwmBuilder::AddPOI(m2::PointD const & p, string const & name, string const & lang)
{
CHECK(m_collector, ("It's not possible to add features after call to Finish()."));
FeatureBuilder1 fb;
fb.SetCenter(p);
fb.SetType(m_classificator.GetTypeByPath({"railway", "station"}));
CHECK(fb.AddName(lang, name), ("Can't set feature name:", name, "(", lang, ")"));
CHECK(Add(fb), (fb));
(*m_collector)(fb);
}
bool TestMwmBuilder::Add(FeatureBuilder1 & fb)
void TestMwmBuilder::AddCity(m2::PointD const & p, string const & name, string const & lang)
{
CHECK(m_collector, ("It's not possible to add features after call to Finish()."));
if (fb.PreSerialize() && fb.RemoveInvalidTypes())
{
(*m_collector)(fb);
return true;
}
return false;
FeatureBuilder1 fb;
fb.SetCenter(p);
fb.SetType(m_classificator.GetTypeByPath({"place", "city"}));
fb.SetRank(100);
CHECK(fb.AddName(lang, name), ("Can't set feature name:", name, "(", lang, ")"));
(*m_collector)(fb);
}
void TestMwmBuilder::Finish()
{
string const tmpFilePath = m_collector->GetFilePath();
CHECK(m_collector, ("Finish() already was called."));
m_collector.reset();
feature::GenerateInfo info;
info.m_targetDir = m_file.GetDirectory();
info.m_tmpDir = m_file.GetDirectory();
CHECK(GenerateFinalFeatures(info, m_file.GetCountryFile().GetNameWithoutExt(),
feature::DataHeader::country),
CHECK(GenerateFinalFeatures(info, m_file.GetCountryFile().GetNameWithoutExt(), m_type),
("Can't sort features."));
CHECK(my::DeleteFileX(tmpFilePath), ());
string const mapFilePath = m_file.GetPath(MapOptions::Map);
CHECK(feature::BuildOffsetsTable(mapFilePath), ("Can't build feature offsets table."));
CHECK(indexer::BuildIndexFromDatFile(mapFilePath, mapFilePath), ("Can't build geometry index."));
CHECK(indexer::BuildSearchIndexFromDatFile(mapFilePath, true /* forceRebuild */),
CHECK(feature::BuildOffsetsTable(m_file.GetPath(MapOptions::Map)), ("Can't build feature offsets table."));
CHECK(indexer::BuildIndexFromDatFile(m_file.GetPath(MapOptions::Map),
m_file.GetPath(MapOptions::Map)),
("Can't build geometry index."));
CHECK(indexer::BuildSearchIndexFromDatFile(m_file.GetPath(MapOptions::Map),
true /* forceRebuild */),
("Can't build search index."));
m_file.SyncWithDisk();
}
} // namespace tests_support
} // namespace search

View file

@ -1,13 +1,13 @@
#pragma once
#include "indexer/data_header.hpp"
#include "geometry/point2d.hpp"
#include "std/string.hpp"
#include "std/unique_ptr.hpp"
class Classificator;
class FeatureBuilder1;
namespace feature
{
@ -18,20 +18,28 @@ namespace platform
class LocalCountryFile;
}
namespace search
{
namespace tests_support
{
class TestMwmBuilder
{
public:
TestMwmBuilder(platform::LocalCountryFile & file);
TestMwmBuilder(platform::LocalCountryFile & file, feature::DataHeader::MapType type);
~TestMwmBuilder();
void AddPOI(m2::PointD const & p, string const & name, string const & lang);
bool Add(FeatureBuilder1 & fb);
void AddCity(m2::PointD const & p, string const & name, string const & lang);
void Finish();
private:
platform::LocalCountryFile & m_file;
feature::DataHeader::MapType m_type;
unique_ptr<feature::FeaturesCollector> m_collector;
Classificator const & m_classificator;
};
} // namespace tests_support
} // namespace search

View file

@ -1,7 +1,7 @@
#include "search/search_tests_support/test_search_request.hpp"
#include "search/search_tests_support/test_search_engine.hpp"
#include "search/params.hpp"
#include "search/search_tests_support/test_search_engine.hpp"
#include "base/logging.hpp"
@ -10,8 +10,9 @@ namespace search
namespace tests_support
{
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & query,
string const & locale, m2::RectD const & viewport)
: m_done(false)
string const & locale, search::SearchParams::SearchModeT mode,
m2::RectD const & viewport)
: m_done(false)
{
search::SearchParams params;
params.m_query = query;
@ -20,7 +21,7 @@ TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & q
{
Done(results);
};
params.SetSearchMode(search::SearchParams::IN_VIEWPORT_ONLY);
params.SetSearchMode(mode);
CHECK(engine.Search(params, viewport), ("Can't run search."));
}

View file

@ -2,6 +2,7 @@
#include "geometry/rect2d.hpp"
#include "search/params.hpp"
#include "search/result.hpp"
#include "std/condition_variable.hpp"
@ -22,7 +23,7 @@ class TestSearchRequest
{
public:
TestSearchRequest(TestSearchEngine & engine, string const & query, string const & locale,
m2::RectD const & viewport);
search::SearchParams::SearchModeT mode, m2::RectD const & viewport);
void Wait();