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
130
131
132
133
134
135
136
137
138
139
140
141
|
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
#define REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
#include <cmath>
#include "remoting/proto/event.pb.h"
#include "testing/gmock/include/gmock/gmock.h"
// This file contains matchers for protocol events.
namespace remoting {
namespace protocol {
namespace test {
MATCHER_P2(EqualsKeyEvent, usb_keycode, pressed, "") {
return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
arg.pressed() == pressed;
}
MATCHER_P2(EqualsKeyEventWithCapsLock, usb_keycode, pressed, "") {
return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
arg.pressed() == pressed &&
arg.lock_states() == KeyEvent::LOCK_STATES_CAPSLOCK;
}
MATCHER_P2(EqualsKeyEventWithNumLock, usb_keycode, pressed, "") {
return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
arg.pressed() == pressed &&
arg.lock_states() == KeyEvent::LOCK_STATES_NUMLOCK;
}
MATCHER_P2(EqualsKeyEventWithoutLockStates, usb_keycode, pressed, "") {
return arg.usb_keycode() == static_cast<uint32>(usb_keycode) &&
arg.pressed() == pressed &&
!arg.has_lock_states();
}
MATCHER_P(EqualsTextEvent, text, "") {
return arg.text() == text;
}
MATCHER_P2(EqualsMouseMoveEvent, x, y, "") {
return arg.x() == x && arg.y() == y;
}
MATCHER_P2(EqualsMouseButtonEvent, button, button_down, "") {
return arg.button() == button && arg.button_down() == button_down;
}
MATCHER_P4(EqualsMouseEvent, x, y, button, down, "") {
return arg.x() == x && arg.y() == y && arg.button() == button &&
arg.button_down() == down;
}
MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") {
return arg.mime_type() == mime_type && arg.data() == data;
}
MATCHER_P(EqualsTouchEvent, expected_event, "") {
if (arg.event_type() != expected_event.event_type())
return false;
if (arg.touch_points().size() != expected_event.touch_points().size())
return false;
for (int i = 0; i < expected_event.touch_points().size(); ++i) {
const TouchEventPoint& expected_point = expected_event.touch_points(i);
const TouchEventPoint& actual_point = arg.touch_points(i);
const bool equal = expected_point.id() == actual_point.id() &&
expected_point.x() == actual_point.x() &&
expected_point.y() == actual_point.y() &&
expected_point.radius_x() == actual_point.radius_x() &&
expected_point.radius_y() == actual_point.radius_y() &&
expected_point.angle() == actual_point.angle() &&
expected_point.pressure() == actual_point.pressure();
if (!equal)
return false;
}
return true;
}
// If the rounding error for the coordinates checked in TouchPoint* matcher are
// within 1 pixel diff, it is acceptable.
const float kTestTouchErrorEpsilon = 1.0f;
MATCHER_P(EqualsTouchPointCoordinates, expected_event, "") {
if (arg.touch_points().size() != expected_event.touch_points().size())
return false;
for (int i = 0; i < expected_event.touch_points().size(); ++i) {
const TouchEventPoint& arg_point = arg.touch_points(i);
const TouchEventPoint& expected_point = expected_event.touch_points(i);
if (std::abs(expected_point.x() - arg_point.x()) >= kTestTouchErrorEpsilon)
return false;
if (std::abs(expected_point.y() - arg_point.y()) >= kTestTouchErrorEpsilon)
return false;
}
return true;
}
MATCHER_P(EqualsTouchPointRadii, expected_event, "") {
if (arg.touch_points().size() != expected_event.touch_points().size())
return false;
for (int i = 0; i < expected_event.touch_points().size(); ++i) {
const TouchEventPoint& arg_point = arg.touch_points(i);
const TouchEventPoint& expected_point = expected_event.touch_points(i);
if (std::abs(expected_point.radius_x() - arg_point.radius_x()) >=
kTestTouchErrorEpsilon) {
return false;
}
if (std::abs(expected_point.radius_y() - arg_point.radius_y()) >=
kTestTouchErrorEpsilon) {
return false;
}
}
return true;
}
MATCHER_P2(EqualsTouchEventTypeAndId, type, id, "") {
if (arg.event_type() != type)
return false;
if (arg.touch_points().size() != 1)
return false;
return arg.touch_points(0).id() == id;
}
} // namespace test
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
|