Welcome to mirror list, hosted at ThFree Co, Russian Federation.

interactive_search_test.cpp « search_integration_tests « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f344973861f4781fca6b39f39dcb8b4a052a93f8 (plain)
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
#include "testing/testing.hpp"

#include "generator/generator_tests_support/test_feature.hpp"

#include "search/viewport_search_callback.hpp"
#include "search/mode.hpp"
#include "search/search_integration_tests/helpers.hpp"
#include "search/search_tests_support/test_results_matching.hpp"
#include "search/search_tests_support/test_search_request.hpp"

#include "base/macros.hpp"

using namespace generator::tests_support;
using namespace search::tests_support;

using TRules = vector<shared_ptr<MatchingRule>>;

namespace search
{
namespace
{
class TestCafe : public TestPOI
{
public:
  TestCafe(m2::PointD const & center) : TestPOI(center, "cafe", "en")
  {
    SetTypes({{"amenity", "cafe"}});
  }
};

class TestHotel : public TestPOI
{
public:
  TestHotel(m2::PointD const & center) : TestPOI(center, "hotel", "en")
  {
    SetTypes({{"tourism", "hotel"}});
  }
};

class TestDelegate : public ViewportSearchCallback::Delegate
{
public:
  TestDelegate(bool & mode) : m_mode(mode) {}

  // ViewportSearchCallback::Delegate overrides:
  void RunUITask(function<void()> /* fn */) override {}
  void SetHotelDisplacementMode() override { m_mode = true; }
  bool IsViewportSearchActive() const override { return true; }
  void ShowViewportSearchResults(Results const & /* results */) override {}
  void ClearViewportSearchResults() override {}

 private:
  bool & m_mode;
};

class InteractiveSearchRequest : public TestDelegate, public TestSearchRequest
{
public:
  InteractiveSearchRequest(TestSearchEngine & engine, string const & query,
                           m2::RectD const & viewport, bool & mode)
    : TestDelegate(mode)
    , TestSearchRequest(
          engine, query, "en" /* locale */, Mode::Viewport, viewport,
          bind(&InteractiveSearchRequest::OnStarted, this),
          ViewportSearchCallback(static_cast<ViewportSearchCallback::Delegate &>(*this),
                                 bind(&InteractiveSearchRequest::OnResults, this, _1)))
  {
  }
};

class InteractiveSearchTest : public SearchTest
{
};

double const kDX[] = {-0.01, 0, 0, 0.01};
double const kDY[] = {0, -0.01, 0.01, 0};

static_assert(ARRAY_SIZE(kDX) == ARRAY_SIZE(kDY), "Wrong deltas lists");

UNIT_CLASS_TEST(InteractiveSearchTest, Smoke)
{
  m2::PointD const cafesPivot(-1, -1);
  m2::PointD const hotelsPivot(1, 1);

  vector<TestCafe> cafes;
  for (size_t i = 0; i < ARRAY_SIZE(kDX); ++i)
    cafes.emplace_back(m2::Shift(cafesPivot, kDX[i], kDY[i]));

  vector<TestHotel> hotels;
  for (size_t i = 0; i < ARRAY_SIZE(kDX); ++i)
    hotels.emplace_back(m2::Shift(hotelsPivot, kDX[i], kDY[i]));

  auto const id = BuildCountry("Wonderland", [&](TestMwmBuilder & builder) {
    for (auto const & cafe : cafes)
      builder.Add(cafe);
    for (auto const & hotel : hotels)
      builder.Add(hotel);
  });

  {
    bool mode = false;
    InteractiveSearchRequest request(
        m_engine, "cafe", m2::RectD(m2::PointD(-1.5, -1.5), m2::PointD(-0.5, -0.5)), mode);
    request.Wait();

    TRules const rules = {ExactMatch(id, cafes[0]), ExactMatch(id, cafes[1]),
                          ExactMatch(id, cafes[2]), ExactMatch(id, cafes[3])};

    TEST(!mode, ());
    TEST(MatchResults(m_engine, rules, request.Results()), ());
  }

  {
    bool mode = false;
    InteractiveSearchRequest request(m_engine, "hotel",
                                     m2::RectD(m2::PointD(0.5, 0.5), m2::PointD(1.5, 1.5)), mode);
    request.Wait();

    TRules const rules = {ExactMatch(id, hotels[0]), ExactMatch(id, hotels[1]),
                          ExactMatch(id, hotels[2]), ExactMatch(id, hotels[3])};

    TEST(mode, ());
    TEST(MatchResults(m_engine, rules, request.Results()), ());
  }
}
}  // namespace
}  // namespace search