| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ | 5 #ifndef REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ |
| 6 #define REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ | 6 #define REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ |
| 7 | 7 |
| 8 #include <cmath> |
| 9 |
| 10 #include "remoting/proto/event.pb.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
| 9 | 12 |
| 10 // This file contains matchers for events. | 13 // This file contains matchers for protocol events. |
| 11 namespace remoting { | 14 namespace remoting { |
| 12 namespace protocol { | 15 namespace protocol { |
| 16 namespace test { |
| 13 | 17 |
| 14 MATCHER_P(TouchEventEqual, expected_event, "Expect touch events equal.") { | 18 MATCHER_P2(EqualsKeyEvent, usb_keycode, pressed, "") { |
| 19 return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && |
| 20 arg.pressed() == pressed; |
| 21 } |
| 22 |
| 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; |
| 27 } |
| 28 |
| 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; |
| 33 } |
| 34 |
| 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(); |
| 39 } |
| 40 |
| 41 MATCHER_P(EqualsTextEvent, text, "") { |
| 42 return arg.text() == text; |
| 43 } |
| 44 |
| 45 MATCHER_P2(EqualsMouseMoveEvent, x, y, "") { |
| 46 return arg.x() == x && arg.y() == y; |
| 47 } |
| 48 |
| 49 MATCHER_P2(EqualsMouseButtonEvent, button, button_down, "") { |
| 50 return arg.button() == button && arg.button_down() == button_down; |
| 51 } |
| 52 |
| 53 MATCHER_P4(EqualsMouseEvent, x, y, button, down, "") { |
| 54 return arg.x() == x && arg.y() == y && arg.button() == button && |
| 55 arg.button_down() == down; |
| 56 } |
| 57 |
| 58 MATCHER_P2(EqualsClipboardEvent, mime_type, data, "") { |
| 59 return arg.mime_type() == mime_type && arg.data() == data; |
| 60 } |
| 61 |
| 62 MATCHER_P(EqualsTouchEvent, expected_event, "") { |
| 15 if (arg.event_type() != expected_event.event_type()) | 63 if (arg.event_type() != expected_event.event_type()) |
| 16 return false; | 64 return false; |
| 17 | 65 |
| 18 if (arg.touch_points().size() != expected_event.touch_points().size()) | 66 if (arg.touch_points().size() != expected_event.touch_points().size()) |
| 19 return false; | 67 return false; |
| 20 | 68 |
| 21 for (int i = 0; i < expected_event.touch_points().size(); ++i) { | 69 for (int i = 0; i < expected_event.touch_points().size(); ++i) { |
| 22 const protocol::TouchEventPoint& expected_point = | 70 const TouchEventPoint& expected_point = expected_event.touch_points(i); |
| 23 expected_event.touch_points(i); | 71 const TouchEventPoint& actual_point = arg.touch_points(i); |
| 24 const protocol::TouchEventPoint& actual_point = arg.touch_points(i); | |
| 25 | 72 |
| 26 const bool equal = expected_point.id() == actual_point.id() && | 73 const bool equal = expected_point.id() == actual_point.id() && |
| 27 expected_point.x() == actual_point.x() && | 74 expected_point.x() == actual_point.x() && |
| 28 expected_point.y() == actual_point.y() && | 75 expected_point.y() == actual_point.y() && |
| 29 expected_point.radius_x() == actual_point.radius_x() && | 76 expected_point.radius_x() == actual_point.radius_x() && |
| 30 expected_point.radius_y() == actual_point.radius_y() && | 77 expected_point.radius_y() == actual_point.radius_y() && |
| 31 expected_point.angle() == actual_point.angle() && | 78 expected_point.angle() == actual_point.angle() && |
| 32 expected_point.pressure() == actual_point.pressure(); | 79 expected_point.pressure() == actual_point.pressure(); |
| 33 if (!equal) | 80 if (!equal) |
| 34 return false; | 81 return false; |
| 35 } | 82 } |
| 36 | 83 |
| 37 return true; | 84 return true; |
| 38 } | 85 } |
| 39 | 86 |
| 40 MATCHER(IsTouchCancelEvent, "expect touch cancel event") { | 87 // If the rounding error for the coordinates checked in TouchPoint* matcher are |
| 41 return arg.event_type() == protocol::TouchEvent::TOUCH_POINT_CANCEL; | 88 // within 1 pixel diff, it is acceptable. |
| 89 const float kTestTouchErrorEpsilon = 1.0f; |
| 90 |
| 91 MATCHER_P(EqualsTouchPointCoordinates, expected_event, "") { |
| 92 if (arg.touch_points().size() != expected_event.touch_points().size()) |
| 93 return false; |
| 94 |
| 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) |
| 99 return false; |
| 100 |
| 101 if (std::abs(expected_point.y() - arg_point.y()) >= kTestTouchErrorEpsilon) |
| 102 return false; |
| 103 } |
| 104 return true; |
| 42 } | 105 } |
| 43 | 106 |
| 107 MATCHER_P(EqualsTouchPointRadii, expected_event, "") { |
| 108 if (arg.touch_points().size() != expected_event.touch_points().size()) |
| 109 return false; |
| 110 |
| 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) { |
| 116 return false; |
| 117 } |
| 118 |
| 119 if (std::abs(expected_point.radius_y() - arg_point.radius_y()) >= |
| 120 kTestTouchErrorEpsilon) { |
| 121 return false; |
| 122 } |
| 123 } |
| 124 return true; |
| 125 } |
| 126 |
| 127 MATCHER_P2(EqualsTouchEventTypeAndId, type, id, "") { |
| 128 if (arg.event_type() != type) |
| 129 return false; |
| 130 |
| 131 if (arg.touch_points().size() != 1) |
| 132 return false; |
| 133 |
| 134 return arg.touch_points(0).id() == id; |
| 135 } |
| 136 |
| 137 } // namespace test |
| 44 } // namespace protocol | 138 } // namespace protocol |
| 45 } // namespace remoting | 139 } // namespace remoting |
| 46 | 140 |
| 47 #endif // REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ | 141 #endif // REMOTING_PROTOCOL_TEST_EVENT_MATCHERS_H_ |
| OLD | NEW |