mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-05 04:20:13 +01:00
test: check the tablet pressure values with a helper function
Makes the code a bit easier to read. Adds precision to some tests, slightly loosens precision in some other tests but that shouldn't matter here. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
684ac6b0c2
commit
24cf215f54
1 changed files with 22 additions and 104 deletions
|
|
@ -3808,18 +3808,26 @@ START_TEST(tablet_calibration_set_matrix)
|
|||
}
|
||||
END_TEST
|
||||
|
||||
static void
|
||||
assert_pressure(struct libinput *li, enum libinput_event_type type, double expected_pressure)
|
||||
{
|
||||
struct libinput_event *event = libinput_get_event(li);
|
||||
struct libinput_event_tablet_tool *tev = litest_is_tablet_event(event, type);
|
||||
double pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
ck_assert_double_eq_tol(pressure, expected_pressure, 0.01);
|
||||
libinput_event_destroy(event);
|
||||
}
|
||||
|
||||
START_TEST(tablet_pressure_offset_set)
|
||||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_event_tablet_tool *tev;
|
||||
struct axis_replacement axes[] = {
|
||||
{ ABS_DISTANCE, 70 },
|
||||
{ ABS_PRESSURE, 20 },
|
||||
{ -1, -1 },
|
||||
};
|
||||
double pressure;
|
||||
|
||||
/* This activates the pressure offset */
|
||||
litest_tablet_proximity_in(dev, 5, 100, axes);
|
||||
|
|
@ -3845,30 +3853,16 @@ START_TEST(tablet_pressure_offset_set)
|
|||
litest_tablet_motion(dev, 70, 70, axes);
|
||||
libinput_dispatch(li);
|
||||
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS);
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
|
||||
/* we can't actually get a real 0.0 because that would trigger a tip
|
||||
up. but it's close enough to zero. */
|
||||
ck_assert_double_lt(pressure, 0.01);
|
||||
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.01);
|
||||
litest_drain_events(li);
|
||||
|
||||
litest_axis_set_value(axes, ABS_PRESSURE, 21);
|
||||
litest_tablet_motion(dev, 70, 70, axes);
|
||||
|
||||
libinput_dispatch(li);
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS);
|
||||
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
|
||||
ck_assert_double_lt(pressure, 0.015);
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.015);
|
||||
|
||||
|
||||
/* Make sure we can reach the upper range too */
|
||||
|
|
@ -3876,14 +3870,7 @@ START_TEST(tablet_pressure_offset_set)
|
|||
litest_tablet_motion(dev, 70, 70, axes);
|
||||
|
||||
libinput_dispatch(li);
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS);
|
||||
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
|
||||
ck_assert_double_ge(pressure, 1.0);
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 1.0);
|
||||
|
||||
/* Tablet motion at offset should trigger tip up. Use
|
||||
* the litest motion helper here to avoid false positives caused by
|
||||
|
|
@ -3902,14 +3889,11 @@ START_TEST(tablet_pressure_offset_decrease)
|
|||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_event_tablet_tool *tev;
|
||||
struct axis_replacement axes[] = {
|
||||
{ ABS_DISTANCE, 70 },
|
||||
{ ABS_PRESSURE, 20 },
|
||||
{ -1, -1 },
|
||||
};
|
||||
double pressure;
|
||||
|
||||
/* offset 20 on prox in */
|
||||
litest_tablet_proximity_in(dev, 5, 100, axes);
|
||||
|
|
@ -3924,13 +3908,7 @@ START_TEST(tablet_pressure_offset_decrease)
|
|||
|
||||
litest_tablet_proximity_in(dev, 5, 100, axes);
|
||||
libinput_dispatch(li);
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
ck_assert_double_eq(pressure, 0.0);
|
||||
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.0);
|
||||
litest_drain_events(li);
|
||||
|
||||
/* trigger the pressure threshold */
|
||||
|
|
@ -3938,18 +3916,11 @@ START_TEST(tablet_pressure_offset_decrease)
|
|||
litest_tablet_tip_down(dev, 70, 70, axes);
|
||||
libinput_dispatch(li);
|
||||
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP);
|
||||
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
|
||||
/* offset 10 + lower threshold of ~1% of original range,
|
||||
* value 15 is 5% over original range but with the above taken into
|
||||
* account it's closer to 5% into the remaining effective 89% range
|
||||
*/
|
||||
ck_assert_double_eq_tol(pressure, 0.05, 0.01);
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.05);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
@ -3957,14 +3928,11 @@ START_TEST(tablet_pressure_offset_increase)
|
|||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_event_tablet_tool *tev;
|
||||
struct axis_replacement axes[] = {
|
||||
{ ABS_DISTANCE, 70 },
|
||||
{ ABS_PRESSURE, 20 },
|
||||
{ -1, -1 },
|
||||
};
|
||||
double pressure;
|
||||
|
||||
/* offset 20 on first prox in */
|
||||
litest_tablet_proximity_in(dev, 5, 100, axes);
|
||||
|
|
@ -3986,17 +3954,11 @@ START_TEST(tablet_pressure_offset_increase)
|
|||
litest_tablet_motion(dev, 70, 70, axes);
|
||||
libinput_dispatch(li);
|
||||
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_AXIS);
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
|
||||
/* offset 20 + lower threshold of 1% of original range,
|
||||
* value 30 is 5% over original range but with the above taken into
|
||||
* account it's closer to 12% into the remaining effective 79% range
|
||||
*/
|
||||
ck_assert_double_eq_tol(pressure, 0.12, 0.01);
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.12);
|
||||
|
||||
litest_drain_events(li);
|
||||
|
||||
|
|
@ -4004,14 +3966,7 @@ START_TEST(tablet_pressure_offset_increase)
|
|||
litest_tablet_motion(dev, 70, 70, axes);
|
||||
libinput_dispatch(li);
|
||||
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_TIP);
|
||||
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
|
||||
ck_assert_double_eq(pressure, 0.0);
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_TIP, 0.0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
@ -4019,14 +3974,11 @@ START_TEST(tablet_pressure_min_max)
|
|||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_event_tablet_tool *tev;
|
||||
struct axis_replacement axes[] = {
|
||||
{ ABS_DISTANCE, 10 },
|
||||
{ ABS_PRESSURE, 0 },
|
||||
{ -1, -1 },
|
||||
};
|
||||
double p;
|
||||
|
||||
if (!libevdev_has_event_code(dev->evdev, EV_ABS, ABS_PRESSURE))
|
||||
return;
|
||||
|
|
@ -4040,12 +3992,7 @@ START_TEST(tablet_pressure_min_max)
|
|||
litest_axis_set_value(axes, ABS_PRESSURE, 1.1);
|
||||
litest_tablet_motion(dev, 5, 50, axes);
|
||||
libinput_dispatch(li);
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS);
|
||||
ck_assert(libinput_event_tablet_tool_pressure_has_changed(tev));
|
||||
p = libinput_event_tablet_tool_get_pressure(tev);
|
||||
ck_assert_double_ge(p, 0.0);
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.0);
|
||||
|
||||
/* skip over pressure-based tip down */
|
||||
litest_axis_set_value(axes, ABS_PRESSURE, 90);
|
||||
|
|
@ -4062,11 +4009,7 @@ START_TEST(tablet_pressure_min_max)
|
|||
|
||||
litest_tablet_motion(dev, 5, 50, axes);
|
||||
libinput_dispatch(li);
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS);
|
||||
p = libinput_event_tablet_tool_get_pressure(tev);
|
||||
ck_assert_double_ge(p, 1.0);
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 1.0);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
@ -4121,14 +4064,11 @@ START_TEST(tablet_pressure_offset_exceed_threshold)
|
|||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_event_tablet_tool *tev;
|
||||
struct axis_replacement axes[] = {
|
||||
{ ABS_DISTANCE, 70 },
|
||||
{ ABS_PRESSURE, 30 },
|
||||
{ -1, -1 },
|
||||
};
|
||||
double pressure;
|
||||
int warning_triggered = 0;
|
||||
struct litest_user_data *user_data = libinput_get_user_data(li);
|
||||
|
||||
|
|
@ -4139,12 +4079,7 @@ START_TEST(tablet_pressure_offset_exceed_threshold)
|
|||
libinput_log_set_handler(li, pressure_threshold_warning);
|
||||
litest_tablet_proximity_in(dev, 5, 100, axes);
|
||||
libinput_dispatch(li);
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
ck_assert_double_gt(pressure, 0.0);
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.30);
|
||||
|
||||
ck_assert_int_eq(warning_triggered, 1);
|
||||
litest_restore_log_handler(li);
|
||||
|
|
@ -4155,14 +4090,11 @@ START_TEST(tablet_pressure_offset_none_for_zero_distance)
|
|||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_event_tablet_tool *tev;
|
||||
struct axis_replacement axes[] = {
|
||||
{ ABS_DISTANCE, 0 },
|
||||
{ ABS_PRESSURE, 20 },
|
||||
{ -1, -1 },
|
||||
};
|
||||
double pressure;
|
||||
|
||||
litest_drain_events(li);
|
||||
|
||||
|
|
@ -4174,13 +4106,7 @@ START_TEST(tablet_pressure_offset_none_for_zero_distance)
|
|||
litest_pop_event_frame(dev);
|
||||
libinput_dispatch(li);
|
||||
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event,
|
||||
LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY);
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
ck_assert_double_gt(pressure, 0.0);
|
||||
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY, 0.20);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
@ -4188,14 +4114,11 @@ START_TEST(tablet_pressure_offset_none_for_small_distance)
|
|||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
struct libinput_event_tablet_tool *tev;
|
||||
struct axis_replacement axes[] = {
|
||||
{ ABS_DISTANCE, 20 },
|
||||
{ ABS_PRESSURE, 20 },
|
||||
{ -1, -1 },
|
||||
};
|
||||
double pressure;
|
||||
|
||||
/* stylus too close to the tablet on the proximity in, ignore any
|
||||
* pressure offset */
|
||||
|
|
@ -4212,12 +4135,7 @@ START_TEST(tablet_pressure_offset_none_for_small_distance)
|
|||
litest_tablet_motion(dev, 70, 70, axes);
|
||||
libinput_dispatch(li);
|
||||
|
||||
event = libinput_get_event(li);
|
||||
tev = litest_is_tablet_event(event, LIBINPUT_EVENT_TABLET_TOOL_AXIS);
|
||||
pressure = libinput_event_tablet_tool_get_pressure(tev);
|
||||
ck_assert_double_gt(pressure, 0.0);
|
||||
|
||||
libinput_event_destroy(event);
|
||||
assert_pressure(li, LIBINPUT_EVENT_TABLET_TOOL_AXIS, 0.20);
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue