Re: [PATCH libinput 3/3] test: Add trackpoint middlebutton scrolling tests

2014-09-18 Thread Hans de Goede
Hi,

On 09/18/2014 03:27 AM, Peter Hutterer wrote:
 On Wed, Sep 17, 2014 at 03:35:32PM +0200, Hans de Goede wrote:
 Signed-off-by: Hans de Goede hdego...@redhat.com
 ---
  test/Makefile.am |   5 +++
  test/litest-trackpoint.c |   2 +-
  test/litest.h|   1 +
  test/trackpoint.c| 100 
 +++
  4 files changed, 107 insertions(+), 1 deletion(-)
  create mode 100644 test/trackpoint.c

 diff --git a/test/Makefile.am b/test/Makefile.am
 index 86859d8..6a68982 100644
 --- a/test/Makefile.am
 +++ b/test/Makefile.am
 @@ -34,6 +34,7 @@ run_tests = \
  test-touch \
  test-log \
  test-touchpad \
 +test-trackpoint \
  test-misc \
  test-keyboard \
  test-device
 @@ -72,6 +73,10 @@ test_touchpad_SOURCES = touchpad.c
  test_touchpad_LDADD = $(TEST_LIBS)
  test_touchpad_LDFLAGS = -no-install
  
 +test_trackpoint_SOURCES = trackpoint.c
 +test_trackpoint_LDADD = $(TEST_LIBS)
 +test_trackpoint_LDFLAGS = -no-install
 +
  test_misc_SOURCES = misc.c
  test_misc_LDADD = $(TEST_LIBS)
  test_misc_LDFLAGS = -no-install
 diff --git a/test/litest-trackpoint.c b/test/litest-trackpoint.c
 index 40b9ed0..01ad34e 100644
 --- a/test/litest-trackpoint.c
 +++ b/test/litest-trackpoint.c
 @@ -56,7 +56,7 @@ static int events[] = {
  
  struct litest_test_device litest_trackpoint_device = {
  .type = LITEST_TRACKPOINT,
 -.features = LITEST_POINTER | LITEST_BUTTON,
 +.features = LITEST_POINTER | LITEST_BUTTON | LITEST_POINTINGSTICK,
  .shortname = trackpoint,
  .setup = litest_trackpoint_setup,
  .interface = interface,
 diff --git a/test/litest.h b/test/litest.h
 index fdf815f..fca6acb 100644
 --- a/test/litest.h
 +++ b/test/litest.h
 @@ -61,6 +61,7 @@ enum litest_device_feature {
  LITEST_APPLE_CLICKPAD = 1  8,
  LITEST_TOPBUTTONPAD = 1  9,
  LITEST_SEMI_MT = 1  10,
 +LITEST_POINTINGSTICK = 1  11,
  };
  
  struct litest_device {
 diff --git a/test/trackpoint.c b/test/trackpoint.c
 new file mode 100644
 index 000..038185b
 --- /dev/null
 +++ b/test/trackpoint.c
 @@ -0,0 +1,100 @@
 +/*
 + * Copyright © 2014 Red Hat, Inc.
 + *
 + * Permission to use, copy, modify, distribute, and sell this software and
 + * its documentation for any purpose is hereby granted without fee, provided
 + * that the above copyright notice appear in all copies and that both that
 + * copyright notice and this permission notice appear in supporting
 + * documentation, and that the name of the copyright holders not be used in
 + * advertising or publicity pertaining to distribution of the software
 + * without specific, written prior permission.  The copyright holders make
 + * no representations about the suitability of this software for any
 + * purpose.  It is provided as is without express or implied warranty.
 + *
 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 + */
 +
 +#include config.h
 +
 +#include check.h
 +#include errno.h
 +#include fcntl.h
 +#include libinput.h
 +#include unistd.h
 +
 +#include libinput-util.h
 +#include litest.h
 +
 +START_TEST(trackpoint_middlebutton)
 +{
 +struct litest_device *dev = litest_current_device();
 +struct libinput *li = dev-libinput;
 +
 +litest_drain_events(li);
 +
 +/* A quick middle button click should get reported normally */
 +litest_button_click(dev, BTN_MIDDLE, 1);
 +litest_button_click(dev, BTN_MIDDLE, 0);
 +
 +litest_assert_button_event(li, BTN_MIDDLE, 1);
 +litest_assert_button_event(li, BTN_MIDDLE, 0);
 +
 +litest_assert_empty_queue(li);
 +}
 +END_TEST
 
 add a test for a middlebutton timeout without trackstick motion please.

See below.

 +
 +static void
 +test_2fg_scroll(struct litest_device *dev, double dx, double dy)
 +{
 +struct libinput *li = dev-libinput;
 +
 +litest_button_click(dev, BTN_MIDDLE, 1);
 +
 +libinput_dispatch(li);
 +msleep(300);
 +libinput_dispatch(li);
 +
 +litest_event(dev, EV_REL, REL_X, dx);
 +litest_event(dev, EV_REL, REL_Y, dy);
 +litest_event(dev, EV_SYN, SYN_REPORT, 0);
 +
 +litest_button_click(dev, BTN_MIDDLE, 0);
 +
 +libinput_dispatch(li);
 +}
 +
 +START_TEST(trackpoint_scroll)
 +{
 +struct litest_device *dev = litest_current_device();
 +struct libinput *li = dev-libinput;
 +
 +litest_drain_events(li);
 +
 +test_2fg_scroll(dev, 1, 6);
 +litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6);
 +test_2fg_scroll(dev, 1, -7);
 +litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 

Re: [PATCH libinput 3/3] test: Add trackpoint middlebutton scrolling tests

2014-09-17 Thread Peter Hutterer
On Wed, Sep 17, 2014 at 03:35:32PM +0200, Hans de Goede wrote:
 Signed-off-by: Hans de Goede hdego...@redhat.com
 ---
  test/Makefile.am |   5 +++
  test/litest-trackpoint.c |   2 +-
  test/litest.h|   1 +
  test/trackpoint.c| 100 
 +++
  4 files changed, 107 insertions(+), 1 deletion(-)
  create mode 100644 test/trackpoint.c
 
 diff --git a/test/Makefile.am b/test/Makefile.am
 index 86859d8..6a68982 100644
 --- a/test/Makefile.am
 +++ b/test/Makefile.am
 @@ -34,6 +34,7 @@ run_tests = \
   test-touch \
   test-log \
   test-touchpad \
 + test-trackpoint \
   test-misc \
   test-keyboard \
   test-device
 @@ -72,6 +73,10 @@ test_touchpad_SOURCES = touchpad.c
  test_touchpad_LDADD = $(TEST_LIBS)
  test_touchpad_LDFLAGS = -no-install
  
 +test_trackpoint_SOURCES = trackpoint.c
 +test_trackpoint_LDADD = $(TEST_LIBS)
 +test_trackpoint_LDFLAGS = -no-install
 +
  test_misc_SOURCES = misc.c
  test_misc_LDADD = $(TEST_LIBS)
  test_misc_LDFLAGS = -no-install
 diff --git a/test/litest-trackpoint.c b/test/litest-trackpoint.c
 index 40b9ed0..01ad34e 100644
 --- a/test/litest-trackpoint.c
 +++ b/test/litest-trackpoint.c
 @@ -56,7 +56,7 @@ static int events[] = {
  
  struct litest_test_device litest_trackpoint_device = {
   .type = LITEST_TRACKPOINT,
 - .features = LITEST_POINTER | LITEST_BUTTON,
 + .features = LITEST_POINTER | LITEST_BUTTON | LITEST_POINTINGSTICK,
   .shortname = trackpoint,
   .setup = litest_trackpoint_setup,
   .interface = interface,
 diff --git a/test/litest.h b/test/litest.h
 index fdf815f..fca6acb 100644
 --- a/test/litest.h
 +++ b/test/litest.h
 @@ -61,6 +61,7 @@ enum litest_device_feature {
   LITEST_APPLE_CLICKPAD = 1  8,
   LITEST_TOPBUTTONPAD = 1  9,
   LITEST_SEMI_MT = 1  10,
 + LITEST_POINTINGSTICK = 1  11,
  };
  
  struct litest_device {
 diff --git a/test/trackpoint.c b/test/trackpoint.c
 new file mode 100644
 index 000..038185b
 --- /dev/null
 +++ b/test/trackpoint.c
 @@ -0,0 +1,100 @@
 +/*
 + * Copyright © 2014 Red Hat, Inc.
 + *
 + * Permission to use, copy, modify, distribute, and sell this software and
 + * its documentation for any purpose is hereby granted without fee, provided
 + * that the above copyright notice appear in all copies and that both that
 + * copyright notice and this permission notice appear in supporting
 + * documentation, and that the name of the copyright holders not be used in
 + * advertising or publicity pertaining to distribution of the software
 + * without specific, written prior permission.  The copyright holders make
 + * no representations about the suitability of this software for any
 + * purpose.  It is provided as is without express or implied warranty.
 + *
 + * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
 + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
 + * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY
 + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
 + * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
 + * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 + */
 +
 +#include config.h
 +
 +#include check.h
 +#include errno.h
 +#include fcntl.h
 +#include libinput.h
 +#include unistd.h
 +
 +#include libinput-util.h
 +#include litest.h
 +
 +START_TEST(trackpoint_middlebutton)
 +{
 + struct litest_device *dev = litest_current_device();
 + struct libinput *li = dev-libinput;
 +
 + litest_drain_events(li);
 +
 + /* A quick middle button click should get reported normally */
 + litest_button_click(dev, BTN_MIDDLE, 1);
 + litest_button_click(dev, BTN_MIDDLE, 0);
 +
 + litest_assert_button_event(li, BTN_MIDDLE, 1);
 + litest_assert_button_event(li, BTN_MIDDLE, 0);
 +
 + litest_assert_empty_queue(li);
 +}
 +END_TEST

add a test for a middlebutton timeout without trackstick motion please.

 +
 +static void
 +test_2fg_scroll(struct litest_device *dev, double dx, double dy)
 +{
 + struct libinput *li = dev-libinput;
 +
 + litest_button_click(dev, BTN_MIDDLE, 1);
 +
 + libinput_dispatch(li);
 + msleep(300);
 + libinput_dispatch(li);
 +
 + litest_event(dev, EV_REL, REL_X, dx);
 + litest_event(dev, EV_REL, REL_Y, dy);
 + litest_event(dev, EV_SYN, SYN_REPORT, 0);
 +
 + litest_button_click(dev, BTN_MIDDLE, 0);
 +
 + libinput_dispatch(li);
 +}
 +
 +START_TEST(trackpoint_scroll)
 +{
 + struct litest_device *dev = litest_current_device();
 + struct libinput *li = dev-libinput;
 +
 + litest_drain_events(li);
 +
 + test_2fg_scroll(dev, 1, 6);
 + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, 6);
 + test_2fg_scroll(dev, 1, -7);
 + litest_assert_scroll(li, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL, -7);
 +