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

test_search_request.hpp « search_tests_support « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6172716e42d52da45a4690176e55db3cd7dd2066 (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
#pragma once

#include "geometry/rect2d.hpp"

#include "search/result.hpp"
#include "search/search_params.hpp"

#include "base/timer.hpp"

#include <chrono>
#include <condition_variable>
#include <mutex>
#include <string>
#include <vector>

namespace search
{
namespace tests_support
{
class TestSearchEngine;

// This class wraps a search query to a search engine. Note that the
// last token will be handled as a complete token iff it will be
// followed by a space in a query.
class TestSearchRequest
{
public:
  TestSearchRequest(TestSearchEngine & engine, std::string const & query, std::string const & locale,
                    Mode mode, m2::RectD const & viewport);
  TestSearchRequest(TestSearchEngine & engine, SearchParams const & params);

  // Initiates the search and waits for it to finish.
  void Run();

  // Call these functions only after call to Wait().
  std::chrono::steady_clock::duration ResponseTime() const;
  std::vector<search::Result> const & Results() const;

protected:
  TestSearchRequest(TestSearchEngine & engine, std::string const & query, std::string const & locale,
                    Mode mode, m2::RectD const & viewport,
                    SearchParams::OnStarted const & onStarted,
                    SearchParams::OnResults const & onResults);

  // Initiates the search.
  void Start();

  // Waits for the search to finish.
  void Wait();

  void SetUpCallbacks();
  void SetUpResultParams();

  void OnStarted();
  void OnResults(search::Results const & results);

  // Overrides the default onResults callback.
  void SetCustomOnResults(SearchParams::OnResults const & onResults);

  std::condition_variable m_cv;
  mutable std::mutex m_mu;

  std::vector<search::Result> m_results;
  bool m_done = false;

  base::Timer m_timer;
  std::chrono::steady_clock::duration m_startTime;
  std::chrono::steady_clock::duration m_endTime;

  TestSearchEngine & m_engine;
  SearchParams m_params;
};
}  // namespace tests_support
}  // namespace search