Index: remoting/protocol/test_event_matchers.h |
diff --git a/remoting/protocol/test_event_matchers.h b/remoting/protocol/test_event_matchers.h |
index 18a6fc34479d79f1bf047de0d83fa755eb50fa06..6316fc0a123004c7b2d9e23b16139403ea8ff2f5 100644 |
--- a/remoting/protocol/test_event_matchers.h |
+++ b/remoting/protocol/test_event_matchers.h |
@@ -5,13 +5,65 @@ |
#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 events. |
namespace remoting { |
namespace protocol { |
Wez
2015/03/12 00:13:58
I'd recommend putting these in a test namespace, e
Rintaro Kuroiwa
2015/03/12 18:51:27
Done.
|
-MATCHER_P(TouchEventEqual, expected_event, "Expect touch events equal.") { |
+MATCHER_P2(EqualsUsbEvent, usb_keycode, pressed, "") { |
Wez
2015/03/12 00:13:58
These should be EqualsKeyEvent, since we no longer
Rintaro Kuroiwa
2015/03/12 18:51:27
Done.
|
+ return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && |
+ arg.pressed() == pressed; |
+} |
+ |
+MATCHER_P2(EqualsUsbEventWithCapsLock, usb_keycode, pressed, "") { |
+ return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && |
+ arg.pressed() == pressed && |
+ // |lock_states| is hardcoded to LOCK_STATES_CAPSLOCK in all key |
+ // events. |
Wez
2015/03/12 00:13:58
You mean in all tests, here and below?
Rintaro Kuroiwa
2015/03/12 18:51:27
Oops, this is me trying to be smart about keeping
|
+ arg.lock_states() == KeyEvent::LOCK_STATES_CAPSLOCK; |
+} |
+ |
+MATCHER_P2(EqualsUsbEventWithNumLock, usb_keycode, pressed, "") { |
+ return arg.usb_keycode() == static_cast<uint32>(usb_keycode) && |
+ arg.pressed() == pressed && |
+ // |lock_states| is hardcoded to LOCK_STATES_NUMLOCK in all key events. |
+ arg.lock_states() == KeyEvent::LOCK_STATES_NUMLOCK; |
+} |
+ |
+// Verify the usb key code and the "pressed" state. |
+// Also verify that the event doesn't have |lock_states| set. |
+MATCHER_P2(EqualsUsbEventWithoutLockStates, 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; |
@@ -19,9 +71,8 @@ MATCHER_P(TouchEventEqual, expected_event, "Expect touch events equal.") { |
return false; |
for (int i = 0; i < expected_event.touch_points().size(); ++i) { |
- const protocol::TouchEventPoint& expected_point = |
- expected_event.touch_points(i); |
- const protocol::TouchEventPoint& actual_point = arg.touch_points(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() && |
@@ -37,8 +88,55 @@ MATCHER_P(TouchEventEqual, expected_event, "Expect touch events equal.") { |
return true; |
} |
-MATCHER(IsTouchCancelEvent, "expect touch cancel event") { |
- return arg.event_type() == protocol::TouchEvent::TOUCH_POINT_CANCEL; |
+// 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; |
+ |
+ // Expect only one touch point. |
+ if (arg.touch_points().size() != 1) |
+ return false; |
+ |
+ return arg.touch_points(0).id() == id; |
} |
} // namespace protocol |