[PATCH weston 6/8] tests: Add test for pointer axis events

Alexandros Frantzis alexandros.frantzis at collabora.com
Mon Dec 4 13:34:06 UTC 2017


Add test to verify the server correctly emits pointer axis events.  This
requires updating the weston-test protocol with a new request for
pointer axis events.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis at collabora.com>
---
 protocol/weston-test.xml          |  7 +++++++
 tests/pointer-test.c              | 28 ++++++++++++++++++++++++++++
 tests/weston-test-client-helper.c | 13 ++++++++++++-
 tests/weston-test-client-helper.h |  4 ++++
 tests/weston-test.c               | 20 ++++++++++++++++++++
 5 files changed, 71 insertions(+), 1 deletion(-)

diff --git a/protocol/weston-test.xml b/protocol/weston-test.xml
index ae3349ed..a4a7ad4e 100644
--- a/protocol/weston-test.xml
+++ b/protocol/weston-test.xml
@@ -53,6 +53,13 @@
       <arg name="button" type="int"/>
       <arg name="state" type="uint"/>
     </request>
+    <request name="send_axis">
+      <arg name="tv_sec_hi" type="uint"/>
+      <arg name="tv_sec_lo" type="uint"/>
+      <arg name="tv_nsec" type="uint"/>
+      <arg name="axis" type="uint"/>
+      <arg name="value" type="fixed"/>
+    </request>
     <request name="activate_surface">
       <arg name="surface" type="object" interface="wl_surface" allow-null="true"/>
     </request>
diff --git a/tests/pointer-test.c b/tests/pointer-test.c
index c241fa1d..b0eb6f6f 100644
--- a/tests/pointer-test.c
+++ b/tests/pointer-test.c
@@ -58,6 +58,18 @@ send_button(struct client *client, const struct timespec *time,
 	client_roundtrip(client);
 }
 
+static void
+send_axis(struct client *client, const struct timespec *time, uint32_t axis,
+	  double value)
+{
+	uint32_t tv_sec_hi, tv_sec_lo, tv_nsec;
+
+	timespec_to_proto(time, &tv_sec_hi, &tv_sec_lo, &tv_nsec);
+	weston_test_send_axis(client->test->weston_test, tv_sec_hi, tv_sec_lo,
+			      tv_nsec, axis, wl_fixed_from_double(value));
+	client_roundtrip(client);
+}
+
 static void
 check_pointer(struct client *client, int x, int y)
 {
@@ -355,3 +367,19 @@ TEST(pointer_button_events)
 	assert(pointer->state == WL_POINTER_BUTTON_STATE_RELEASED);
 	assert(pointer->button_time == timespec_to_msec(&t2));
 }
+
+TEST(pointer_axis_events)
+{
+	struct client *client = create_client_with_pointer_focus(100, 100,
+								 100, 100);
+	struct pointer *pointer = client->input->pointer;
+
+	send_axis(client, &t1, 1, 1.0);
+	assert(pointer->axis == 1);
+	assert(pointer->axis_value == 1.0);
+	assert(pointer->axis_time == timespec_to_msec(&t1));
+
+	send_axis(client, &t2, 2, 0.0);
+	assert(pointer->axis == 2);
+	assert(pointer->axis_stop_time == timespec_to_msec(&t2));
+}
diff --git a/tests/weston-test-client-helper.c b/tests/weston-test-client-helper.c
index 108fecfb..92def14d 100644
--- a/tests/weston-test-client-helper.c
+++ b/tests/weston-test-client-helper.c
@@ -179,6 +179,12 @@ static void
 pointer_handle_axis(void *data, struct wl_pointer *wl_pointer,
 		    uint32_t time, uint32_t axis, wl_fixed_t value)
 {
+	struct pointer *pointer = data;
+
+	pointer->axis = axis;
+	pointer->axis_value = wl_fixed_to_double(value);
+	pointer->axis_time = time;
+
 	fprintf(stderr, "test-client: got pointer axis %u %f\n",
 		axis, wl_fixed_to_double(value));
 }
@@ -200,7 +206,12 @@ static void
 pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer,
 			 uint32_t time, uint32_t axis)
 {
-	fprintf(stderr, "test-client: got pointer axis stop\n");
+	struct pointer *pointer = data;
+
+	pointer->axis = axis;
+	pointer->axis_stop_time = time;
+
+	fprintf(stderr, "test-client: got pointer axis stop %u\n", axis);
 }
 
 static void
diff --git a/tests/weston-test-client-helper.h b/tests/weston-test-client-helper.h
index 08817242..1b4d83c7 100644
--- a/tests/weston-test-client-helper.h
+++ b/tests/weston-test-client-helper.h
@@ -90,8 +90,12 @@ struct pointer {
 	int y;
 	uint32_t button;
 	uint32_t state;
+	uint32_t axis;
+	double axis_value;
 	uint32_t motion_time;
 	uint32_t button_time;
+	double axis_time;
+	double axis_stop_time;
 };
 
 struct keyboard {
diff --git a/tests/weston-test.c b/tests/weston-test.c
index 1799de92..bb1a4cd4 100644
--- a/tests/weston-test.c
+++ b/tests/weston-test.c
@@ -183,6 +183,25 @@ send_button(struct wl_client *client, struct wl_resource *resource,
 	notify_button(seat, &time, button, state);
 }
 
+static void
+send_axis(struct wl_client *client, struct wl_resource *resource,
+	  uint32_t tv_sec_hi, uint32_t tv_sec_lo, uint32_t tv_nsec,
+	  uint32_t axis, wl_fixed_t value)
+{
+	struct weston_test *test = wl_resource_get_user_data(resource);
+	struct weston_seat *seat = get_seat(test);
+	struct timespec time;
+	struct weston_pointer_axis_event axis_event;
+
+	timespec_from_proto(&time, tv_sec_hi, tv_sec_lo, tv_nsec);
+	axis_event.axis = axis;
+	axis_event.value = wl_fixed_to_double(value);
+	axis_event.has_discrete = false;
+	axis_event.discrete = 0;
+
+	notify_axis(seat, &time, &axis_event);
+}
+
 static void
 activate_surface(struct wl_client *client, struct wl_resource *resource,
 		 struct wl_resource *surface_resource)
@@ -503,6 +522,7 @@ static const struct weston_test_interface test_implementation = {
 	move_surface,
 	move_pointer,
 	send_button,
+	send_axis,
 	activate_surface,
 	send_key,
 	device_release,
-- 
2.14.1



More information about the wayland-devel mailing list