1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
#include "testing/testing.hpp"
#include "search/search_tests_support/helpers.hpp"
#include "search/search_tests_support/test_results_matching.hpp"
#include "generator/generator_tests_support/test_feature.hpp"
#include "indexer/editable_map_object.hpp"
#include "geometry/point2d.hpp"
#include "coding/string_utf8_multilang.hpp"
#include <memory>
using namespace generator::tests_support;
using namespace search::tests_support;
using namespace search;
using namespace std;
namespace
{
class SearchEditedFeaturesTest : public SearchTest
{
};
UNIT_CLASS_TEST(SearchEditedFeaturesTest, Smoke)
{
TestCity city(m2::PointD(0, 0), "Quahog", "default", 100 /* rank */);
TestPOI cafe(m2::PointD(0, 0), "Bar", "default");
BuildWorld([&](TestMwmBuilder & builder) { builder.Add(city); });
auto const id = BuildCountry("Wonderland", [&](TestMwmBuilder & builder) { builder.Add(cafe); });
FeatureID cafeId(id, 0 /* index */);
{
TRules const rules = {ExactMatch(id, cafe)};
TEST(ResultsMatch("Bar", rules), ());
TEST(ResultsMatch("Drunken", TRules{}), ());
EditFeature(cafeId, [](osm::EditableMapObject & emo) {
emo.SetName("The Drunken Clam", StringUtf8Multilang::kEnglishCode);
});
TEST(ResultsMatch("Bar", rules), ());
TEST(ResultsMatch("Drunken", rules), ());
}
{
TRules const rules = {ExactMatch(id, cafe)};
TEST(ResultsMatch("Wifi", TRules{}), ());
EditFeature(cafeId, [](osm::EditableMapObject & emo) { emo.SetInternet(osm::Internet::Wlan); });
TEST(ResultsMatch("Wifi", rules), ());
TEST(ResultsMatch("wifi bar quahog", rules), ());
}
}
UNIT_CLASS_TEST(SearchEditedFeaturesTest, SearchInViewport)
{
TestCity city(m2::PointD(0, 0), "Canterlot", "default", 100 /* rank */);
TestPOI bakery0(m2::PointD(0, 0), "Bakery 0", "default");
TestPOI cornerPost(m2::PointD(100, 100), "Corner Post", "default");
auto & editor = osm::Editor::Instance();
BuildWorld([&](TestMwmBuilder & builder) { builder.Add(city); });
auto const countryId = BuildCountry("Equestria", [&](TestMwmBuilder & builder) {
builder.Add(bakery0);
builder.Add(cornerPost);
});
auto const tmp1 = TestPOI::AddWithEditor(editor, countryId, "bakery1", {1.0, 1.0});
TestPOI const & bakery1 = tmp1.first;
FeatureID const & id1 = tmp1.second;
auto const tmp2 = TestPOI::AddWithEditor(editor, countryId, "bakery2", {2.0, 2.0});
TestPOI const & bakery2 = tmp2.first;
FeatureID const & id2 = tmp2.second;
auto const tmp3 = TestPOI::AddWithEditor(editor, countryId, "bakery3", {3.0, 3.0});
TestPOI const & bakery3 = tmp3.first;
FeatureID const & id3 = tmp3.second;
UNUSED_VALUE(id2);
SetViewport(m2::RectD(-1.0, -1.0, 4.0, 4.0));
{
TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery1),
ExactMatch(countryId, bakery2), ExactMatch(countryId, bakery3)};
TEST(ResultsMatch("bakery", Mode::Viewport, rules), ());
}
SetViewport(m2::RectD(-2.0, -2.0, -1.0, -1.0));
{
TRules const rules = {};
TEST(ResultsMatch("bakery", Mode::Viewport, rules), ());
}
SetViewport(m2::RectD(-1.0, -1.0, 1.5, 1.5));
{
TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery1)};
TEST(ResultsMatch("bakery", Mode::Viewport, rules), ());
}
SetViewport(m2::RectD(1.5, 1.5, 4.0, 4.0));
{
TRules const rules = {ExactMatch(countryId, bakery2), ExactMatch(countryId, bakery3)};
TEST(ResultsMatch("bakery", Mode::Viewport, rules), ());
}
editor.DeleteFeature(id1);
editor.DeleteFeature(id3);
SetViewport(m2::RectD(-1.0, -1.0, 4.0, 4.0));
{
TRules const rules = {ExactMatch(countryId, bakery0), ExactMatch(countryId, bakery2)};
TEST(ResultsMatch("bakery", Mode::Viewport, rules), ());
}
}
} // namespace
|