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
|
#include "search/search_tests_support/test_search_request.hpp"
#include "search/search_tests_support/test_search_engine.hpp"
#include "geometry/latlon.hpp"
#include "geometry/mercator.hpp"
#include "base/logging.hpp"
namespace search
{
namespace tests_support
{
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & query,
string const & locale, Mode mode, m2::RectD const & viewport)
{
SearchParams params;
params.m_query = query;
params.m_inputLocale = locale;
params.SetMode(mode);
SetUpCallbacks(params);
engine.Search(params, viewport);
}
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, SearchParams params,
m2::RectD const & viewport)
{
SetUpCallbacks(params);
engine.Search(params, viewport);
}
TestSearchRequest::TestSearchRequest(TestSearchEngine & engine, string const & query,
string const & locale, Mode mode, m2::RectD const & viewport,
TOnStarted onStarted, TOnResults onResults)
{
SearchParams params;
params.m_query = query;
params.m_inputLocale = locale;
params.SetMode(mode);
params.m_onStarted = move(onStarted);
params.m_onResults = move(onResults);
engine.Search(params, viewport);
}
void TestSearchRequest::Wait()
{
unique_lock<mutex> lock(m_mu);
m_cv.wait(lock, [this]()
{
return m_done;
});
}
steady_clock::duration TestSearchRequest::ResponseTime() const
{
lock_guard<mutex> lock(m_mu);
CHECK(m_done, ("This function may be called only when request is processed."));
return m_endTime - m_startTime;
}
vector<search::Result> const & TestSearchRequest::Results() const
{
lock_guard<mutex> lock(m_mu);
CHECK(m_done, ("This function may be called only when request is processed."));
return m_results;
}
void TestSearchRequest::SetUpCallbacks(SearchParams & params)
{
params.m_onStarted = bind(&TestSearchRequest::OnStarted, this);
params.m_onResults = bind(&TestSearchRequest::OnResults, this, _1);
}
void TestSearchRequest::OnStarted()
{
lock_guard<mutex> lock(m_mu);
m_startTime = m_timer.TimeElapsed();
}
void TestSearchRequest::OnResults(search::Results const & results)
{
lock_guard<mutex> lock(m_mu);
if (results.IsEndMarker())
{
m_done = true;
m_endTime = m_timer.TimeElapsed();
m_cv.notify_one();
}
else
{
m_results.assign(results.Begin(), results.End());
}
}
} // namespace tests_support
} // namespace search
|