1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
6 #define REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_
10 #include "remoting/proto/event.pb.h"
11 #include "testing/gmock/include/gmock/gmock.h"
13 // This file contains matchers for protocol events.
18 MATCHER_P2(EqualsKeyEvent
, usb_keycode
, pressed
, "") {
19 return arg
.usb_keycode() == static_cast<uint32
>(usb_keycode
) &&
20 arg
.pressed() == pressed
;
23 MATCHER_P2(EqualsKeyEventWithCapsLock
, usb_keycode
, pressed
, "") {
24 return arg
.usb_keycode() == static_cast<uint32
>(usb_keycode
) &&
25 arg
.pressed() == pressed
&&
26 arg
.lock_states() == KeyEvent::LOCK_STATES_CAPSLOCK
;
29 MATCHER_P2(EqualsKeyEventWithNumLock
, usb_keycode
, pressed
, "") {
30 return arg
.usb_keycode() == static_cast<uint32
>(usb_keycode
) &&
31 arg
.pressed() == pressed
&&
32 arg
.lock_states() == KeyEvent::LOCK_STATES_NUMLOCK
;
35 MATCHER_P2(EqualsKeyEventWithoutLockStates
, usb_keycode
, pressed
, "") {
36 return arg
.usb_keycode() == static_cast<uint32
>(usb_keycode
) &&
37 arg
.pressed() == pressed
&&
38 !arg
.has_lock_states();
41 MATCHER_P(EqualsTextEvent
, text
, "") {
42 return arg
.text() == text
;
45 MATCHER_P2(EqualsMouseMoveEvent
, x
, y
, "") {
46 return arg
.x() == x
&& arg
.y() == y
;
49 MATCHER_P2(EqualsMouseButtonEvent
, button
, button_down
, "") {
50 return arg
.button() == button
&& arg
.button_down() == button_down
;
53 MATCHER_P4(EqualsMouseEvent
, x
, y
, button
, down
, "") {
54 return arg
.x() == x
&& arg
.y() == y
&& arg
.button() == button
&&
55 arg
.button_down() == down
;
58 MATCHER_P2(EqualsClipboardEvent
, mime_type
, data
, "") {
59 return arg
.mime_type() == mime_type
&& arg
.data() == data
;
62 MATCHER_P(EqualsTouchEvent
, expected_event
, "") {
63 if (arg
.event_type() != expected_event
.event_type())
66 if (arg
.touch_points().size() != expected_event
.touch_points().size())
69 for (int i
= 0; i
< expected_event
.touch_points().size(); ++i
) {
70 const TouchEventPoint
& expected_point
= expected_event
.touch_points(i
);
71 const TouchEventPoint
& actual_point
= arg
.touch_points(i
);
73 const bool equal
= expected_point
.id() == actual_point
.id() &&
74 expected_point
.x() == actual_point
.x() &&
75 expected_point
.y() == actual_point
.y() &&
76 expected_point
.radius_x() == actual_point
.radius_x() &&
77 expected_point
.radius_y() == actual_point
.radius_y() &&
78 expected_point
.angle() == actual_point
.angle() &&
79 expected_point
.pressure() == actual_point
.pressure();
87 // If the rounding error for the coordinates checked in TouchPoint* matcher are
88 // within 1 pixel diff, it is acceptable.
89 const float kTestTouchErrorEpsilon
= 1.0f
;
91 MATCHER_P(EqualsTouchPointCoordinates
, expected_event
, "") {
92 if (arg
.touch_points().size() != expected_event
.touch_points().size())
95 for (int i
= 0; i
< expected_event
.touch_points().size(); ++i
) {
96 const TouchEventPoint
& arg_point
= arg
.touch_points(i
);
97 const TouchEventPoint
& expected_point
= expected_event
.touch_points(i
);
98 if (std::abs(expected_point
.x() - arg_point
.x()) >= kTestTouchErrorEpsilon
)
101 if (std::abs(expected_point
.y() - arg_point
.y()) >= kTestTouchErrorEpsilon
)
107 MATCHER_P(EqualsTouchPointRadii
, expected_event
, "") {
108 if (arg
.touch_points().size() != expected_event
.touch_points().size())
111 for (int i
= 0; i
< expected_event
.touch_points().size(); ++i
) {
112 const TouchEventPoint
& arg_point
= arg
.touch_points(i
);
113 const TouchEventPoint
& expected_point
= expected_event
.touch_points(i
);
114 if (std::abs(expected_point
.radius_x() - arg_point
.radius_x()) >=
115 kTestTouchErrorEpsilon
) {
119 if (std::abs(expected_point
.radius_y() - arg_point
.radius_y()) >=
120 kTestTouchErrorEpsilon
) {
127 MATCHER_P2(EqualsTouchEventTypeAndId
, type
, id
, "") {
128 if (arg
.event_type() != type
)
131 if (arg
.touch_points().size() != 1)
134 return arg
.touch_points(0).id() == id
;
138 } // namespace protocol
139 } // namespace remoting
141 #endif // REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_