diff --git a/generator/generator_tests_support/generator_tests_support.pro b/generator/generator_tests_support/generator_tests_support.pro new file mode 100644 index 0000000000..380dc89064 --- /dev/null +++ b/generator/generator_tests_support/generator_tests_support.pro @@ -0,0 +1,15 @@ +TARGET = generator_tests_support +TEMPLATE = lib +CONFIG += staticlib warn_on + +ROOT_DIR = ../.. + +include($$ROOT_DIR/common.pri) + +SOURCES += \ + test_feature.cpp \ + test_mwm_builder.cpp \ + +HEADERS += \ + test_feature.hpp \ + test_mwm_builder.hpp \ diff --git a/search/search_tests_support/test_feature.cpp b/generator/generator_tests_support/test_feature.cpp similarity index 98% rename from search/search_tests_support/test_feature.cpp rename to generator/generator_tests_support/test_feature.cpp index 83b8ca6bdf..54c89fa575 100644 --- a/search/search_tests_support/test_feature.cpp +++ b/generator/generator_tests_support/test_feature.cpp @@ -1,4 +1,4 @@ -#include "search/search_tests_support/test_feature.hpp" +#include "generator/generator_tests_support/test_feature.hpp" #include "generator/feature_builder.hpp" @@ -15,7 +15,7 @@ #include "std/atomic.hpp" #include "std/sstream.hpp" -namespace search +namespace generator { namespace tests_support { @@ -265,4 +265,4 @@ string TestPark::ToString() const string DebugPrint(TestFeature const & feature) { return feature.ToString(); } } // namespace tests_support -} // namespace search +} // namespace generator diff --git a/search/search_tests_support/test_feature.hpp b/generator/generator_tests_support/test_feature.hpp similarity index 98% rename from search/search_tests_support/test_feature.hpp rename to generator/generator_tests_support/test_feature.hpp index b038998a1e..fb345505ed 100644 --- a/search/search_tests_support/test_feature.hpp +++ b/generator/generator_tests_support/test_feature.hpp @@ -8,7 +8,7 @@ class FeatureBuilder1; class FeatureType; -namespace search +namespace generator { namespace tests_support { @@ -140,4 +140,4 @@ private: string DebugPrint(TestFeature const & feature); } // namespace tests_support -} // namespace search +} // namespace generator diff --git a/search/search_tests_support/test_mwm_builder.cpp b/generator/generator_tests_support/test_mwm_builder.cpp similarity index 92% rename from search/search_tests_support/test_mwm_builder.cpp rename to generator/generator_tests_support/test_mwm_builder.cpp index adbbc4b015..19ce627f6a 100644 --- a/search/search_tests_support/test_mwm_builder.cpp +++ b/generator/generator_tests_support/test_mwm_builder.cpp @@ -1,10 +1,9 @@ -#include "search/search_tests_support/test_mwm_builder.hpp" - -#include "search/search_tests_support/test_feature.hpp" +#include "generator/generator_tests_support/test_mwm_builder.hpp" #include "generator/feature_builder.hpp" #include "generator/feature_generator.hpp" #include "generator/feature_sorter.hpp" +#include "generator/generator_tests_support/test_feature.hpp" #include "generator/search_index_builder.hpp" #include "indexer/data_header.hpp" @@ -20,7 +19,7 @@ #include "defines.hpp" -namespace search +namespace generator { namespace tests_support { @@ -87,4 +86,4 @@ void TestMwmBuilder::Finish() m_file.SyncWithDisk(); } } // namespace tests_support -} // namespace search +} // namespace generator diff --git a/search/search_tests_support/test_mwm_builder.hpp b/generator/generator_tests_support/test_mwm_builder.hpp similarity index 93% rename from search/search_tests_support/test_mwm_builder.hpp rename to generator/generator_tests_support/test_mwm_builder.hpp index 1dc9ad3a5f..948999a5da 100644 --- a/search/search_tests_support/test_mwm_builder.hpp +++ b/generator/generator_tests_support/test_mwm_builder.hpp @@ -14,7 +14,7 @@ class LocalCountryFile; } class FeatureBuilder1; -namespace search +namespace generator { namespace tests_support { @@ -38,4 +38,4 @@ private: unique_ptr m_collector; }; } // namespace tests_support -} // namespace search +} // namespace generator diff --git a/omim.pro b/omim.pro index 40a755630e..3a4a0ea76a 100644 --- a/omim.pro +++ b/omim.pro @@ -68,6 +68,12 @@ SUBDIRS = 3party base coding geometry editor indexer routing search qt.depends = $$SUBDIRS SUBDIRS *= benchmark_tool mapshot qt + } + + CONFIG(desktop) { + # Desktop-only support library, used in tests and search quality tools. + generator_tests_support.subdir = generator/generator_tests_support + SUBDIRS *= generator_tests_support } CONFIG(desktop) { @@ -77,14 +83,15 @@ SUBDIRS = 3party base coding geometry editor indexer routing search search_quality.subdir = search/search_quality search_quality.depends = $$SUBDIRS + SUBDIRS *= search_quality search_quality_tool.subdir = search/search_quality/search_quality_tool - search_quality_tool.depends = $$SUBDIRS search_quality + search_quality_tool.depends = $$SUBDIRS features_collector_tool.subdir = search/search_quality/features_collector_tool - features_collector_tool.depends = $$SUBDIRS search_quality + features_collector_tool.depends = $$SUBDIRS - SUBDIRS *= search_quality search_quality_tool features_collector_tool + SUBDIRS *= search_quality_tool features_collector_tool } CONFIG(desktop):!CONFIG(no-tests) { @@ -130,7 +137,7 @@ SUBDIRS = 3party base coding geometry editor indexer routing search # storage_tests.depends should be set to |3party base coding geometry platform storage indexer stats| # as it was before. storage_tests.subdir = storage/storage_tests - storage_tests.depends = $$MapDepLibs + storage_tests.depends = $$MapDepLibs generator_tests_support generator SUBDIRS *= storage_tests storage_integration_tests.subdir = storage/storage_integration_tests @@ -166,15 +173,16 @@ SUBDIRS = 3party base coding geometry editor indexer routing search SUBDIRS *= pedestrian_routing_tests search_tests_support.subdir = search/search_tests_support - search_tests_support.depends = $$MapDepLibs generator + search_tests_support.depends = $$MapDepLibs SUBDIRS *= search_tests_support search_integration_tests.subdir = search/search_integration_tests - search_integration_tests.depends = $$MapDepLibs search_tests_support generator + search_integration_tests.depends = $$MapDepLibs search_tests_support \ + generator_tests_support generator SUBDIRS *= search_integration_tests search_quality_tests.subdir = search/search_quality/search_quality_tests - search_quality_tests.depends = $$MapDepLibs generator search_quality search_tests_support + search_quality_tests.depends = $$MapDepLibs search_quality search_tests_support SUBDIRS *= search_quality_tests generator_tests.subdir = generator/generator_tests diff --git a/search/search_integration_tests/generate_tests.cpp b/search/search_integration_tests/generate_tests.cpp index ebe32538d3..f6a756b157 100644 --- a/search/search_integration_tests/generate_tests.cpp +++ b/search/search_integration_tests/generate_tests.cpp @@ -1,6 +1,6 @@ #include "testing/testing.hpp" -#include "search/search_tests_support/test_mwm_builder.hpp" +#include "generator/generator_tests_support/test_mwm_builder.hpp" #include "generator/feature_builder.hpp" #include "generator/osm_element.hpp" @@ -16,7 +16,7 @@ namespace { -using TBuilder = search::tests_support::TestMwmBuilder; +using TBuilder = generator::tests_support::TestMwmBuilder; void MakeFeature(TBuilder & builder, pair const & tag, m2::PointD const & pt) { diff --git a/search/search_integration_tests/helpers.hpp b/search/search_integration_tests/helpers.hpp index 5e3ffc32aa..c2d128d3e1 100644 --- a/search/search_integration_tests/helpers.hpp +++ b/search/search_integration_tests/helpers.hpp @@ -1,9 +1,10 @@ #pragma once -#include "search/search_tests_support/test_mwm_builder.hpp" #include "search/search_tests_support/test_results_matching.hpp" #include "search/search_tests_support/test_search_engine.hpp" +#include "generator/generator_tests_support/test_mwm_builder.hpp" + #include "storage/country_decl.hpp" #include "storage/country_info_getter.hpp" @@ -56,7 +57,7 @@ public: Cleanup(file); { - tests_support::TestMwmBuilder builder(file, type); + generator::tests_support::TestMwmBuilder builder(file, type); fn(builder); } diff --git a/search/search_integration_tests/search_integration_tests.pro b/search/search_integration_tests/search_integration_tests.pro index 5bfa36ff81..8b10e50c53 100644 --- a/search/search_integration_tests/search_integration_tests.pro +++ b/search/search_integration_tests/search_integration_tests.pro @@ -7,11 +7,9 @@ TEMPLATE = app ROOT_DIR = ../.. -DEPENDENCIES = search_tests_support generator routing search storage stats_client indexer \ - platform editor geometry coding base tess2 protobuf tomcrypt jansson succinct pugixml - -DEPENDENCIES += opening_hours \ - +DEPENDENCIES = search_tests_support generator_tests_support generator routing search storage \ + stats_client indexer platform editor geometry coding base tess2 protobuf \ + tomcrypt jansson succinct pugixml opening_hours include($$ROOT_DIR/common.pri) diff --git a/search/search_integration_tests/search_query_v2_test.cpp b/search/search_integration_tests/search_query_v2_test.cpp index 6ffe1db56e..eacd9af05e 100644 --- a/search/search_integration_tests/search_query_v2_test.cpp +++ b/search/search_integration_tests/search_query_v2_test.cpp @@ -2,12 +2,13 @@ #include "search/retrieval.hpp" #include "search/search_integration_tests/helpers.hpp" -#include "search/search_tests_support/test_feature.hpp" -#include "search/search_tests_support/test_mwm_builder.hpp" #include "search/search_tests_support/test_results_matching.hpp" #include "search/search_tests_support/test_search_request.hpp" #include "search/v2/token_slice.hpp" +#include "generator/generator_tests_support/test_feature.hpp" +#include "generator/generator_tests_support/test_mwm_builder.hpp" + #include "indexer/feature.hpp" #include "indexer/index.hpp" @@ -19,6 +20,7 @@ #include "std/shared_ptr.hpp" #include "std/vector.hpp" +using namespace generator::tests_support; using namespace search::tests_support; using namespace search::v2; diff --git a/search/search_integration_tests/smoke_test.cpp b/search/search_integration_tests/smoke_test.cpp index b2bbe5c135..0ece6f1cf0 100644 --- a/search/search_integration_tests/smoke_test.cpp +++ b/search/search_integration_tests/smoke_test.cpp @@ -1,17 +1,19 @@ #include "testing/testing.hpp" #include "search/search_integration_tests/helpers.hpp" -#include "search/search_tests_support/test_feature.hpp" -#include "search/search_tests_support/test_mwm_builder.hpp" #include "search/search_tests_support/test_results_matching.hpp" #include "search/search_tests_support/test_search_request.hpp" +#include "generator/generator_tests_support/test_feature.hpp" +#include "generator/generator_tests_support/test_mwm_builder.hpp" + #include "geometry/point2d.hpp" #include "geometry/rect2d.hpp" #include "std/shared_ptr.hpp" #include "std/vector.hpp" +using namespace generator::tests_support; using namespace search::tests_support; using TRules = vector>; diff --git a/search/search_query.cpp b/search/search_query.cpp index 9c90c5e62f..8c933ecb21 100644 --- a/search/search_query.cpp +++ b/search/search_query.cpp @@ -622,7 +622,9 @@ class PreResult2Maker info.m_nameScore = v2::NAME_SCORE_ZERO; - v2::TokenSliceNoCategories slice(m_params, preInfo.m_startToken, preInfo.m_endToken); + v2::TokenSlice slice(m_params, preInfo.m_startToken, preInfo.m_endToken); + v2::TokenSliceNoCategories sliceNoCategories(m_params, preInfo.m_startToken, + preInfo.m_endToken); for (auto const & lang : m_params.m_langs) { @@ -633,10 +635,11 @@ class PreResult2Maker SplitUniString(NormalizeAndSimplifyString(name), MakeBackInsertFunctor(tokens), Delimiters()); UpdateNameScore(tokens, slice, info.m_nameScore, info.m_nameCoverage); + UpdateNameScore(tokens, sliceNoCategories, info.m_nameScore, info.m_nameCoverage); } if (info.m_searchType == v2::SearchModel::SEARCH_TYPE_BUILDING) - UpdateNameScore(ft.GetHouseNumber(), slice, info.m_nameScore); + UpdateNameScore(ft.GetHouseNumber(), sliceNoCategories, info.m_nameScore); } uint8_t NormalizeRank(uint8_t rank, v2::SearchModel::SearchType type, m2::PointD const & center, diff --git a/search/search_tests_support/search_tests_support.pro b/search/search_tests_support/search_tests_support.pro index 8a8c23b824..080bb3ba51 100644 --- a/search/search_tests_support/search_tests_support.pro +++ b/search/search_tests_support/search_tests_support.pro @@ -7,15 +7,11 @@ ROOT_DIR = ../.. include($$ROOT_DIR/common.pri) SOURCES += \ - test_feature.cpp \ - test_mwm_builder.cpp \ test_results_matching.cpp \ test_search_engine.cpp \ test_search_request.cpp \ HEADERS += \ - test_feature.hpp \ - test_mwm_builder.hpp \ test_results_matching.hpp \ test_search_engine.hpp \ test_search_request.hpp \ diff --git a/search/search_tests_support/test_results_matching.cpp b/search/search_tests_support/test_results_matching.cpp index dde87f4674..34d8a3e1b9 100644 --- a/search/search_tests_support/test_results_matching.cpp +++ b/search/search_tests_support/test_results_matching.cpp @@ -1,12 +1,14 @@ #include "search/search_tests_support/test_results_matching.hpp" -#include "search/search_tests_support/test_feature.hpp" +#include "generator/generator_tests_support/test_feature.hpp" #include "indexer/feature_decl.hpp" #include "indexer/index.hpp" #include "std/sstream.hpp" +using namespace generator::tests_support; + namespace search { namespace tests_support diff --git a/search/search_tests_support/test_results_matching.hpp b/search/search_tests_support/test_results_matching.hpp index 5ddb1be1bd..24505d369e 100644 --- a/search/search_tests_support/test_results_matching.hpp +++ b/search/search_tests_support/test_results_matching.hpp @@ -11,12 +11,18 @@ class FeatureType; class Index; -namespace search +namespace generator { namespace tests_support { class TestFeature; +} +} +namespace search +{ +namespace tests_support +{ class MatchingRule { public: @@ -29,7 +35,7 @@ public: class ExactMatchingRule : public MatchingRule { public: - ExactMatchingRule(MwmSet::MwmId const & mwmId, TestFeature & feature); + ExactMatchingRule(MwmSet::MwmId const & mwmId, generator::tests_support::TestFeature & feature); // MatchingRule overrides: bool Matches(FeatureType const & feature) const override; @@ -37,7 +43,7 @@ public: private: MwmSet::MwmId m_mwmId; - TestFeature & m_feature; + generator::tests_support::TestFeature & m_feature; }; class AlternativesMatchingRule : public MatchingRule diff --git a/search/v2/token_slice.cpp b/search/v2/token_slice.cpp index ac3c99ead4..3a9ad561a9 100644 --- a/search/v2/token_slice.cpp +++ b/search/v2/token_slice.cpp @@ -1,9 +1,29 @@ #include "search/v2/token_slice.hpp" +#include "std/sstream.hpp" + namespace search { namespace v2 { +namespace +{ +template +string SliceToString(string const & name, TSlice const & slice) +{ + ostringstream os; + os << name << " ["; + for (size_t i = 0; i < slice.Size(); ++i) + { + os << DebugPrint(slice.Get(i)); + if (i + 1 != slice.Size()) + os << ", "; + } + os << "]"; + return os.str(); +} +} // namespace + TokenSlice::TokenSlice(SearchQueryParams const & params, size_t startToken, size_t endToken) : m_params(params), m_offset(startToken), m_size(endToken - startToken) { @@ -37,5 +57,15 @@ TokenSliceNoCategories::TokenSliceNoCategories(SearchQueryParams const & params, m_indexes.push_back(i); } } + +string DebugPrint(TokenSlice const & slice) +{ + return SliceToString("TokenSlice", slice); +} + +string DebugPrint(TokenSliceNoCategories const & slice) +{ + return SliceToString("TokenSliceNoCategories", slice); +} } // namespace v2 } // namespace search diff --git a/search/v2/token_slice.hpp b/search/v2/token_slice.hpp index 66124a0d25..c8cc856d8c 100644 --- a/search/v2/token_slice.hpp +++ b/search/v2/token_slice.hpp @@ -5,6 +5,7 @@ #include "base/assert.hpp" #include "std/cstdint.hpp" +#include "std/string.hpp" #include "std/vector.hpp" namespace search @@ -65,5 +66,9 @@ private: SearchQueryParams const & m_params; vector m_indexes; }; + +string DebugPrint(TokenSlice const & slice); + +string DebugPrint(TokenSliceNoCategories const & slice); } // namespace v2 } // namespace search diff --git a/storage/storage_tests/storage_tests.cpp b/storage/storage_tests/storage_tests.cpp index 31849335af..bf1529a16b 100644 --- a/storage/storage_tests/storage_tests.cpp +++ b/storage/storage_tests/storage_tests.cpp @@ -12,6 +12,11 @@ #include "storage/storage_integration_tests/test_defines.hpp" +#if defined(OMIM_OS_DESKTOP) +#include "generator/generator_tests_support/test_mwm_builder.hpp" +#endif // defined(OMIM_OS_DESKTOP) + +#include "indexer/classificator_loader.hpp" #include "indexer/indexer_tests/test_mwm_set.hpp" #include "platform/country_file.hpp" @@ -44,11 +49,13 @@ #include "std/unique_ptr.hpp" #include "std/vector.hpp" +using namespace generator::tests_support; +using namespace platform::tests_support; using namespace platform; namespace storage { -string const kMapTestDir = string("map-tests"); +string const kMapTestDir = "map-tests"; namespace { @@ -1372,52 +1379,46 @@ UNIT_TEST(StorageTest_GetNodeAttrsSingleMwm) TEST(!nodeAttrs.m_present, ()); } +#if defined(OMIM_OS_DESKTOP) UNIT_TEST(StorageTest_GetUpdateInfoSingleMwm) { - string const kFakeMwmDir = "1"; + classificator::Load(); WritableDirChanger writableDirChanger(kMapTestDir); - - string const kFakeMwmPath = my::JoinFoldersToPath(GetPlatform().WritableDir(), kFakeMwmDir); - GetPlatform().MkDir(kFakeMwmPath); - - // First 150 bytes of http://direct.mapswithme.com/direct/160315/Norway_Bouvet Island.mwm - unsigned char const kMwmData[] = - {0xA5,0x35,0x00,0x00,0x00,0x00,0x00,0x00,0x4D,0x57,0x4D,0x00,0x07,0xAA,0xBB - ,0x9B,0xB7,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x1B,0x82,0x8C,0xD8,0x9C,0xFB - ,0xB4,0xA0,0x0C,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0x18,0xAA,0xD5,0xAA,0xD5 - ,0xAA,0xD5,0x8A,0x1A,0x04,0x0A,0x0C,0x0E,0x11,0x00,0x04,0x07,0x40,0x13,0xF0 - ,0x00,0x00,0x00,0x00,0x0F,0x21,0xBE,0x01,0x6A,0xF0,0xB5,0x90,0xE3,0xB2,0x98 - ,0x02,0x00,0x00,0x00,0x00,0x0C,0x40,0xF9,0x01,0xF0,0xD1,0x01,0xC1,0x03,0xE2 - ,0x04,0x95,0x05,0x9D,0x01,0x48,0x5D,0x8F,0x01,0x80,0x42,0x6F,0x75,0x76,0x65 - ,0x74,0xC3,0xB8,0x79,0x61,0x86,0x42,0x6F,0x75,0x76,0x65,0x74,0x69,0x6E,0x73 - ,0x65,0x6C,0x81,0x42,0x6F,0x75,0x76,0x65,0x74,0x20,0x49,0x73,0x6C,0x61,0x6E - ,0x64,0x95,0x49,0x73,0x6C,0x61,0x20,0x42,0x6F,0x75,0x76,0x65,0x74,0x83,0xC3 - }; - static_assert(150 == sizeof(kMwmData), "Incorrect data size"); - + + Platform & platform = GetPlatform(); + + string const kVersion1Dir = my::JoinFoldersToPath(platform.WritableDir(), "1"); + platform.MkDir(kVersion1Dir); + + LocalCountryFile country1(kVersion1Dir, CountryFile("OutdatedCountry1"), 1); + LocalCountryFile country2(kVersion1Dir, CountryFile("OutdatedCountry2"), 1); + { - FileWriter file(my::JoinFoldersToPath(GetPlatform().WritableDir(), "OutdatedCountry1.mwm")); - file.Write(kMwmData, sizeof(kMwmData)); + TestMwmBuilder builder(country1, feature::DataHeader::country); } { - FileWriter file(my::JoinFoldersToPath(GetPlatform().WritableDir(), "OutdatedCountry2.mwm")); - file.Write(kMwmData, sizeof(kMwmData)); + TestMwmBuilder builder(country2, feature::DataHeader::country); } - + Storage storage(kSingleMwmCountriesTxt, make_unique()); storage.RegisterAllLocalMaps(); + country1.SyncWithDisk(); + country2.SyncWithDisk(); + auto const country1Size = country1.GetSize(MapOptions::Map); + auto const country2Size = country2.GetSize(MapOptions::Map); + Storage::UpdateInfo updateInfo; storage.GetUpdateInfo("OutdatedCountry1", updateInfo); TEST_EQUAL(updateInfo.m_numberOfMwmFilesToUpdate, 1, ()); TEST_EQUAL(updateInfo.m_totalUpdateSizeInBytes, 50, ()); - TEST_EQUAL(updateInfo.m_sizeDifference, -100, ()); + TEST_EQUAL(updateInfo.m_sizeDifference, 50 - country1Size, ()); storage.GetUpdateInfo("OutdatedCountry2", updateInfo); TEST_EQUAL(updateInfo.m_numberOfMwmFilesToUpdate, 1, ()); TEST_EQUAL(updateInfo.m_totalUpdateSizeInBytes, 1000, ()); - TEST_EQUAL(updateInfo.m_sizeDifference, 850, ()); + TEST_EQUAL(updateInfo.m_sizeDifference, 1000 - country2Size, ()); storage.GetUpdateInfo("Abkhazia", updateInfo); TEST_EQUAL(updateInfo.m_numberOfMwmFilesToUpdate, 0, ()); @@ -1434,8 +1435,9 @@ UNIT_TEST(StorageTest_GetUpdateInfoSingleMwm) storage.GetUpdateInfo(storage.GetRootId(), updateInfo); TEST_EQUAL(updateInfo.m_numberOfMwmFilesToUpdate, 2, ()); TEST_EQUAL(updateInfo.m_totalUpdateSizeInBytes, 1050, ()); - TEST_EQUAL(updateInfo.m_sizeDifference, 750, ()); + TEST_EQUAL(updateInfo.m_sizeDifference, (1000 + 50) - (country1Size + country2Size), ()); } +#endif // defined(OMIM_OS_DESKTOP) UNIT_TEST(StorageTest_ParseStatus) { diff --git a/storage/storage_tests/storage_tests.pro b/storage/storage_tests/storage_tests.pro index 1366ac456d..6535fc5ccc 100644 --- a/storage/storage_tests/storage_tests.pro +++ b/storage/storage_tests/storage_tests.pro @@ -6,9 +6,15 @@ CONFIG -= app_bundle TEMPLATE = app ROOT_DIR = ../.. -DEPENDENCIES = map drape_frontend routing search storage indexer drape platform_tests_support platform editor opening_hours geometry \ - coding base freetype expat fribidi tomcrypt jansson protobuf osrm stats_client \ - minizip succinct pugixml oauthcpp + +macx*|win32*|linux* { +DEPENDENCIES = generator_tests_support generator +} + +DEPENDENCIES *= drape_frontend map routing \ + search storage indexer drape platform_tests_support platform editor opening_hours geometry \ + coding base freetype expat fribidi tomcrypt jansson tess2 protobuf osrm stats_client \ + minizip succinct pugixml oauthcpp include($$ROOT_DIR/common.pri)