diff --git a/search/search_quality/search_quality_tests/CMakeLists.txt b/search/search_quality/search_quality_tests/CMakeLists.txt index f32ceda90d..d29699e8e9 100644 --- a/search/search_quality/search_quality_tests/CMakeLists.txt +++ b/search/search_quality/search_quality_tests/CMakeLists.txt @@ -1,6 +1,9 @@ project(search_quality_tests) -set(SRC sample_test.cpp) +set(SRC + benchmark_tests.cpp + sample_test.cpp +) omim_add_test(${PROJECT_NAME} ${SRC}) diff --git a/search/search_quality/search_quality_tests/benchmark_tests.cpp b/search/search_quality/search_quality_tests/benchmark_tests.cpp new file mode 100644 index 0000000000..d04bdd6048 --- /dev/null +++ b/search/search_quality/search_quality_tests/benchmark_tests.cpp @@ -0,0 +1,81 @@ +#include "testing/testing.hpp" + +#include "generator/generator_tests_support/test_with_classificator.hpp" + +#include "search/search_tests_support/test_search_engine.hpp" +#include "search/search_tests_support/test_search_request.hpp" + +#include "indexer/classificator_loader.hpp" +#include "indexer/data_source.hpp" + +#include "platform/local_country_file_utils.hpp" + +namespace benchmark_tests +{ +using namespace search; +using namespace std::chrono; + +class DataSourceTestFixture : public generator::tests_support::TestWithClassificator +{ +protected: + FrozenDataSource m_dataSource; + std::unique_ptr m_countryInfo; + +public: + DataSourceTestFixture() + : m_countryInfo(std::make_unique()) + { + using namespace platform; + std::vector localFiles; + FindAllLocalMapsAndCleanup(std::numeric_limits::max() /* latestVersion */, localFiles); + + bool hasWorld = false; + for (auto const & file : localFiles) + { + auto const res = m_dataSource.RegisterMap(file); + TEST_EQUAL(res.second, MwmSet::RegResult::Success, ()); + + auto const & info = res.first.GetInfo(); + TEST_EQUAL(file.GetCountryName(), info->GetCountryName(), ()); + if (file.GetCountryName() == WORLD_FILE_NAME) + { + TEST_EQUAL(info->GetType(), MwmInfo::WORLD, ()); + hasWorld = true; + } + + m_countryInfo->AddCountry({ info->GetCountryName(), info->m_bordersRect }); + } + + TEST(hasWorld, ()); + } +}; + +class SearchBenchmarkFixture : public DataSourceTestFixture +{ + tests_support::TestSearchEngine m_engine; + m2::RectD m_viewport; + +public: + SearchBenchmarkFixture() : m_engine(m_dataSource, std::move(m_countryInfo), {}) + { + } + + void SetCenter(ms::LatLon ll) + { + m_viewport = mercator::MetersToXY(ll.m_lon, ll.m_lat, 1.0E4); + } + + uint64_t Run(std::string const & query) + { + tests_support::TestSearchRequest request(m_engine, query, "en", Mode::Everywhere, m_viewport); + request.Run(); + return request.ResponseTime().count(); + } +}; + +UNIT_CLASS_TEST(SearchBenchmarkFixture, Smoke) +{ + SetCenter({ 50.1052, 8.6868 }); // Frankfurt am Main + LOG(LINFO, (Run("b"))); +} +} // namespace benchmark_tests diff --git a/search/search_quality/search_quality_tests/sample_test.cpp b/search/search_quality/search_quality_tests/sample_test.cpp index 042ef12aae..b7377ab5b0 100644 --- a/search/search_quality/search_quality_tests/sample_test.cpp +++ b/search/search_quality/search_quality_tests/sample_test.cpp @@ -7,6 +7,8 @@ #include #include +namespace sample_test +{ using namespace search; using namespace std; @@ -31,9 +33,9 @@ void SampleTest::Init() m_cuba.m_locale = "en"; m_cuba.m_pos = m2::PointD{37.618706, 99.53730574302003}; m_cuba.m_viewport = {37.1336, 67.1349, 38.0314, 67.7348}; - search::Sample::Result cubaRes; + Sample::Result cubaRes; cubaRes.m_name = strings::MakeUniString("Cuba"); - cubaRes.m_relevance = search::Sample::Result::Relevance::Relevant; + cubaRes.m_relevance = Sample::Result::Relevance::Relevant; cubaRes.m_types.push_back("place-country"); cubaRes.m_pos = {-80.832886, 15.521132748163712}; cubaRes.m_houseNumber = ""; @@ -45,9 +47,9 @@ void SampleTest::Init() m_riga.m_locale = "en"; m_riga.m_pos = m2::PointD{37.65376, 98.51110651930014}; m_riga.m_viewport = {37.5064, 67.0476, 37.7799, 67.304}; - search::Sample::Result rigaRes; + Sample::Result rigaRes; rigaRes.m_name = strings::MakeUniString("Rīga"); - rigaRes.m_relevance = search::Sample::Result::Relevance::Vital; + rigaRes.m_relevance = Sample::Result::Relevance::Vital; rigaRes.m_types.push_back("place-city-capital-2"); rigaRes.m_pos = {24.105186, 107.7819569220319}; rigaRes.m_houseNumber = ""; @@ -174,3 +176,4 @@ UNIT_CLASS_TEST(SampleTest, SerDes) sort(actual.begin(), actual.end()); TEST_EQUAL(expected, actual, ()); } +} // namespace sample_test diff --git a/search/search_tests_support/helpers.cpp b/search/search_tests_support/helpers.cpp index bab0e86257..d5954f3354 100644 --- a/search/search_tests_support/helpers.cpp +++ b/search/search_tests_support/helpers.cpp @@ -7,10 +7,10 @@ #include "geometry/mercator.hpp" #include "geometry/rect2d.hpp" -using namespace std; - namespace search { +using namespace std; + SearchTest::SearchTest() : m_scopedLog(LDEBUG) , m_engine(m_dataSource, make_unique(), Engine::Params{}) diff --git a/search/search_tests_support/test_search_engine.cpp b/search/search_tests_support/test_search_engine.cpp index 19b82ecf81..616a655534 100644 --- a/search/search_tests_support/test_search_engine.cpp +++ b/search/search_tests_support/test_search_engine.cpp @@ -6,12 +6,12 @@ #include -using namespace std; - namespace search { namespace tests_support { +using namespace std; + TestSearchEngine::TestSearchEngine(DataSource & dataSource, unique_ptr infoGetter, Engine::Params const & params) diff --git a/search/search_tests_support/test_search_request.cpp b/search/search_tests_support/test_search_request.cpp index a9e7e8054e..657ca7b99c 100644 --- a/search/search_tests_support/test_search_request.cpp +++ b/search/search_tests_support/test_search_request.cpp @@ -10,13 +10,13 @@ #include -using namespace std::chrono; -using namespace std; - namespace search { namespace tests_support { +using namespace std::chrono; +using namespace std; + TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & query, string const & locale, Mode mode, m2::RectD const & viewport) : m_engine(engine)