2013-06-05 15:31:00 +10:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 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 <linux/input.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <limits.h>
|
2013-07-03 14:51:02 +10:00
|
|
|
#include <fcntl.h>
|
2013-06-05 15:31:00 +10:00
|
|
|
|
2013-06-29 17:57:31 +10:00
|
|
|
#include "test-common.h"
|
2013-06-05 15:31:00 +10:00
|
|
|
|
|
|
|
|
static int evbits[] = {
|
|
|
|
|
EV_SYN, EV_KEY, EV_REL, EV_ABS, EV_MSC,
|
|
|
|
|
EV_SW, EV_LED, EV_SND, EV_FF,
|
|
|
|
|
/* Intentionally skipping these, they're different
|
|
|
|
|
* EV_PWR, EV_FF_STATUS, EV_REP, */
|
|
|
|
|
-1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
START_TEST(test_has_ev_bit)
|
|
|
|
|
{
|
|
|
|
|
int *evbit = evbits;
|
|
|
|
|
|
|
|
|
|
while(*evbit != -1) {
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int i, rc;
|
|
|
|
|
|
2013-07-29 13:38:28 +10:00
|
|
|
if (*evbit == EV_ABS) {
|
|
|
|
|
struct input_absinfo abs = { ABS_X, 0, 2, 0, 0, 0};
|
|
|
|
|
rc = test_create_abs_device(&uidev, &dev,
|
|
|
|
|
1, &abs,
|
|
|
|
|
-1);
|
|
|
|
|
} else
|
|
|
|
|
rc = test_create_device(&uidev, &dev,
|
2013-06-29 18:19:50 +10:00
|
|
|
*evbit, 0,
|
|
|
|
|
-1);
|
|
|
|
|
ck_assert_msg(rc == 0, "%s: Failed to create device with: %s",
|
2013-06-05 15:31:00 +10:00
|
|
|
libevdev_get_event_type_name(*evbit),
|
|
|
|
|
strerror(-rc));
|
|
|
|
|
|
|
|
|
|
ck_assert_msg(libevdev_has_event_type(dev, EV_SYN), "for event type %d\n", *evbit);
|
|
|
|
|
ck_assert_msg(libevdev_has_event_type(dev, *evbit), "for event type %d\n", *evbit);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i <= EV_MAX; i++) {
|
|
|
|
|
if (i == EV_SYN || i == *evbit)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
ck_assert_msg(!libevdev_has_event_type(dev, i), "for event type %d\n", i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
|
|
|
|
|
evbit++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_ev_bit_limits)
|
|
|
|
|
{
|
|
|
|
|
int *evbit = evbits;
|
|
|
|
|
|
|
|
|
|
while(*evbit != -1) {
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc;
|
|
|
|
|
|
2013-07-29 13:38:28 +10:00
|
|
|
if (*evbit == EV_ABS) {
|
|
|
|
|
struct input_absinfo abs = { ABS_X, 0, 2, 0, 0, 0};
|
|
|
|
|
rc = test_create_abs_device(&uidev, &dev,
|
|
|
|
|
1, &abs,
|
|
|
|
|
-1);
|
|
|
|
|
} else
|
|
|
|
|
rc = test_create_device(&uidev, &dev,
|
|
|
|
|
*evbit, 0,
|
|
|
|
|
-1);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-05 15:31:00 +10:00
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_has_event_type(dev, EV_MAX + 1), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_has_event_type(dev, INT_MAX), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_has_event_type(dev, UINT_MAX), 0);
|
|
|
|
|
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
|
|
|
|
|
evbit++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_event_codes)
|
|
|
|
|
{
|
|
|
|
|
int *evbit = evbits;
|
|
|
|
|
|
|
|
|
|
while(*evbit != -1) {
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc;
|
|
|
|
|
int code, max;
|
|
|
|
|
if (*evbit == EV_SYN) {
|
|
|
|
|
evbit++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
max = libevdev_get_event_type_max(*evbit);
|
|
|
|
|
|
|
|
|
|
for (code = 1; code < max; code += 10) {
|
2013-07-29 13:38:28 +10:00
|
|
|
if (*evbit == EV_ABS) {
|
|
|
|
|
struct input_absinfo abs = { code, 0, 2, 0, 0, 0};
|
|
|
|
|
rc = test_create_abs_device(&uidev, &dev,
|
|
|
|
|
1, &abs,
|
|
|
|
|
-1);
|
|
|
|
|
} else
|
|
|
|
|
rc = test_create_device(&uidev, &dev,
|
|
|
|
|
*evbit, code,
|
|
|
|
|
-1);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-05 15:31:00 +10:00
|
|
|
|
|
|
|
|
ck_assert_msg(libevdev_has_event_type(dev, *evbit), "for event type %d\n", *evbit);
|
|
|
|
|
ck_assert_msg(libevdev_has_event_code(dev, *evbit, code), "for type %d code %d", *evbit, code);
|
2013-06-27 10:22:47 +10:00
|
|
|
ck_assert_msg(libevdev_has_event_code(dev, EV_SYN, SYN_REPORT), "for EV_SYN");
|
|
|
|
|
/* always false */
|
|
|
|
|
ck_assert_msg(!libevdev_has_event_code(dev, EV_PWR, 0), "for EV_PWR");
|
2013-06-05 15:31:00 +10:00
|
|
|
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
evbit++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_event_code_limits)
|
|
|
|
|
{
|
|
|
|
|
int *evbit = evbits;
|
|
|
|
|
|
|
|
|
|
while(*evbit != -1) {
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc;
|
|
|
|
|
int max;
|
|
|
|
|
|
|
|
|
|
if (*evbit == EV_SYN) {
|
|
|
|
|
evbit++;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
max = libevdev_get_event_type_max(*evbit);
|
|
|
|
|
ck_assert(max != -1);
|
|
|
|
|
|
2013-07-29 13:38:28 +10:00
|
|
|
if (*evbit == EV_ABS) {
|
|
|
|
|
struct input_absinfo abs = { ABS_X, 0, 2, 0, 0, 0};
|
|
|
|
|
rc = test_create_abs_device(&uidev, &dev,
|
|
|
|
|
1, &abs,
|
|
|
|
|
-1);
|
|
|
|
|
} else
|
|
|
|
|
rc = test_create_device(&uidev, &dev,
|
|
|
|
|
*evbit, 1,
|
|
|
|
|
-1);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-05 15:31:00 +10:00
|
|
|
|
|
|
|
|
ck_assert_msg(!libevdev_has_event_code(dev, *evbit, max), "for type %d code %d", *evbit, max);
|
|
|
|
|
ck_assert_msg(!libevdev_has_event_code(dev, *evbit, INT_MAX), "for type %d code %d", *evbit, INT_MAX);
|
|
|
|
|
ck_assert_msg(!libevdev_has_event_code(dev, *evbit, UINT_MAX), "for type %d code %d", *evbit, UINT_MAX);
|
|
|
|
|
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
|
|
|
|
|
evbit++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_ev_rep)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
/* EV_REP is special, it's always fully set if set at all,
|
|
|
|
|
can't test this through uinput though */
|
2013-07-05 09:08:04 +10:00
|
|
|
rc = uinput_device_new_with_events(&uidev, TEST_DEVICE_NAME, DEFAULT_IDS,
|
2013-06-05 15:31:00 +10:00
|
|
|
EV_REP, 0,
|
|
|
|
|
-1);
|
|
|
|
|
ck_assert_int_eq(rc, -EINVAL);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_ev_rep_values)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc;
|
|
|
|
|
int delay = 0xab, period = 0xbc;
|
|
|
|
|
|
|
|
|
|
/* EV_REP is special, it's always fully set if set at all, can't set
|
|
|
|
|
it through uinput though. */
|
2013-06-29 18:19:50 +10:00
|
|
|
rc = test_create_device(&uidev, &dev, -1);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-05 15:31:00 +10:00
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_get_repeat(dev, NULL, NULL), -1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_repeat(dev, &delay, NULL), -1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_repeat(dev, NULL, &period), -1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_repeat(dev, &delay, &period), -1);
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(delay, 0xab);
|
|
|
|
|
ck_assert_int_eq(period, 0xbc);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
2013-06-28 13:13:55 +10:00
|
|
|
libevdev_free(dev);
|
2013-06-05 15:31:00 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-06-27 10:37:21 +10:00
|
|
|
START_TEST(test_input_props)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
2013-07-11 09:09:14 +10:00
|
|
|
int rc, i;
|
2013-07-29 13:38:28 +10:00
|
|
|
struct input_absinfo abs = {0, 0, 2, 0, 0};
|
2013-07-11 09:09:14 +10:00
|
|
|
|
|
|
|
|
uidev = uinput_device_new(TEST_DEVICE_NAME);
|
2013-07-29 13:38:28 +10:00
|
|
|
rc = uinput_device_set_abs_bit(uidev, ABS_X, &abs);
|
2013-07-11 09:09:14 +10:00
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
uinput_device_set_prop(uidev, INPUT_PROP_DIRECT);
|
|
|
|
|
uinput_device_set_prop(uidev, INPUT_PROP_BUTTONPAD);
|
|
|
|
|
rc = uinput_device_create(uidev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
2013-06-27 10:37:21 +10:00
|
|
|
|
2013-07-11 09:09:14 +10:00
|
|
|
rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-27 10:37:21 +10:00
|
|
|
|
2013-07-11 09:09:14 +10:00
|
|
|
|
|
|
|
|
for (i = 0; i < INPUT_PROP_MAX; i++) {
|
|
|
|
|
if (i == INPUT_PROP_DIRECT || i == INPUT_PROP_BUTTONPAD)
|
|
|
|
|
ck_assert_int_eq(libevdev_has_property(dev, i), 1);
|
|
|
|
|
else
|
|
|
|
|
ck_assert_int_eq(libevdev_has_property(dev, i), 0);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-27 10:37:21 +10:00
|
|
|
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_MAX + 1), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_MAX), 0);
|
2013-06-28 13:13:55 +10:00
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
2013-06-27 10:37:21 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-07-29 15:34:37 +10:00
|
|
|
START_TEST(test_set_input_props)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc, fd;
|
2013-07-29 13:38:28 +10:00
|
|
|
struct input_absinfo abs = {0, 0, 2, 0, 0};
|
2013-07-29 15:34:37 +10:00
|
|
|
|
|
|
|
|
dev = libevdev_new();
|
|
|
|
|
ck_assert_int_eq(libevdev_enable_property(dev, INPUT_PROP_MAX + 1), -1);
|
|
|
|
|
ck_assert_int_eq(libevdev_enable_property(dev, INPUT_PROP_DIRECT), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_enable_property(dev, INPUT_PROP_BUTTONPAD), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_DIRECT), 1);
|
|
|
|
|
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_BUTTONPAD), 1);
|
|
|
|
|
|
|
|
|
|
uidev = uinput_device_new(TEST_DEVICE_NAME);
|
2013-07-29 13:38:28 +10:00
|
|
|
rc = uinput_device_set_abs_bit(uidev, ABS_X, &abs);
|
2013-07-29 15:34:37 +10:00
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
uinput_device_set_prop(uidev, INPUT_PROP_BUTTONPAD);
|
|
|
|
|
rc = uinput_device_create(uidev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
|
|
|
|
|
|
|
|
|
fd = uinput_device_get_fd(uidev);
|
|
|
|
|
rc = libevdev_set_fd(dev, fd);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_DIRECT), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_has_property(dev, INPUT_PROP_BUTTONPAD), 1);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-07-03 14:51:02 +10:00
|
|
|
START_TEST(test_slot_init_value)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device *uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc;
|
|
|
|
|
const int nabs = 6;
|
|
|
|
|
int i;
|
|
|
|
|
int fd;
|
2013-07-29 13:38:28 +10:00
|
|
|
struct input_absinfo abs[] = { { ABS_X, 0, 1000 },
|
|
|
|
|
{ ABS_Y, 0, 1000 },
|
|
|
|
|
{ ABS_MT_POSITION_X, 0, 1000 },
|
|
|
|
|
{ ABS_MT_POSITION_Y, 0, 1000 },
|
|
|
|
|
{ ABS_MT_TRACKING_ID, -1, 2 },
|
|
|
|
|
{ ABS_MT_SLOT, 0, 1 }};
|
2013-07-03 14:51:02 +10:00
|
|
|
|
2013-07-05 09:08:04 +10:00
|
|
|
uidev = uinput_device_new(TEST_DEVICE_NAME);
|
2013-07-03 14:51:02 +10:00
|
|
|
|
|
|
|
|
for (i = 0; i < nabs; i++) {
|
|
|
|
|
rc = uinput_device_set_abs_bit(uidev, abs[i].value, &abs[i]);
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rc = uinput_device_create(uidev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
|
|
|
|
|
|
|
|
|
fd = uinput_device_get_fd(uidev);
|
|
|
|
|
rc = fcntl(fd, F_SETFL, O_NONBLOCK);
|
|
|
|
|
ck_assert_msg(rc == 0, "fcntl failed: %s", strerror(errno));
|
|
|
|
|
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, 0);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_X, 100);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_Y, 500);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_MT_POSITION_X, 100);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_MT_POSITION_Y, 500);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, 1);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_MT_SLOT, 1);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_X, 1);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_Y, 5);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_MT_POSITION_X, 1);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_MT_POSITION_Y, 5);
|
|
|
|
|
uinput_device_event(uidev, EV_ABS, ABS_MT_TRACKING_ID, 2);
|
|
|
|
|
uinput_device_event(uidev, EV_SYN, SYN_REPORT, 0);
|
|
|
|
|
|
|
|
|
|
rc = libevdev_new_from_fd(fd, &dev);
|
|
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_get_current_slot(dev), 1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_X), 100);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_slot_value(dev, 0, ABS_MT_POSITION_Y), 500);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_X), 1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_slot_value(dev, 1, ABS_MT_POSITION_Y), 5);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-06-27 10:29:11 +10:00
|
|
|
START_TEST(test_no_slots)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc;
|
2013-07-29 13:38:28 +10:00
|
|
|
struct input_absinfo abs[] = { { ABS_X, 0, 2 },
|
|
|
|
|
{ ABS_Y, 0, 2 },
|
|
|
|
|
{ ABS_MT_POSITION_X, 0, 2 },
|
|
|
|
|
{ ABS_MT_POSITION_Y, 0, 2 }};
|
|
|
|
|
|
|
|
|
|
rc = test_create_abs_device(&uidev, &dev, 4, abs,
|
|
|
|
|
-1);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-27 10:29:11 +10:00
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_get_num_slots(dev), -1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_current_slot(dev), -1);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
2013-06-28 13:13:55 +10:00
|
|
|
libevdev_free(dev);
|
2013-06-27 10:29:11 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_slot_number)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc;
|
2013-07-29 13:38:28 +10:00
|
|
|
const int nslots = 4;
|
|
|
|
|
struct input_absinfo abs[] = { { ABS_X, 0, 2 },
|
|
|
|
|
{ ABS_Y, 0, 2 },
|
|
|
|
|
{ ABS_MT_POSITION_X, 0, 2 },
|
|
|
|
|
{ ABS_MT_POSITION_Y, 0, 2 },
|
|
|
|
|
{ ABS_MT_SLOT, 0, nslots - 1 }};
|
|
|
|
|
|
|
|
|
|
rc = test_create_abs_device(&uidev, &dev, 5, abs,
|
|
|
|
|
-1);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to uinput device: %s", strerror(-rc));
|
2013-06-27 10:29:11 +10:00
|
|
|
|
2013-07-29 13:38:28 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_num_slots(dev), nslots);
|
2013-06-27 10:29:11 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_current_slot(dev), 0);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
2013-06-28 13:13:55 +10:00
|
|
|
libevdev_free(dev);
|
2013-06-27 10:29:11 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
|
2013-06-05 15:31:00 +10:00
|
|
|
START_TEST(test_device_name)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
struct input_id ids = {1, 2, 3, 4};
|
|
|
|
|
const char *str;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
dev = libevdev_new();
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_name(dev);
|
|
|
|
|
ck_assert(str != NULL);
|
|
|
|
|
ck_assert_int_eq(strlen(str), 0);
|
|
|
|
|
|
2013-07-05 09:08:04 +10:00
|
|
|
rc = uinput_device_new_with_events(&uidev, TEST_DEVICE_NAME, &ids,
|
2013-07-29 13:34:48 +10:00
|
|
|
EV_REL, REL_X,
|
2013-06-05 15:31:00 +10:00
|
|
|
-1);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
|
|
|
|
rc = libevdev_set_fd(dev, uinput_device_get_fd(uidev));
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));;
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_name(dev);
|
2013-07-05 09:08:04 +10:00
|
|
|
ck_assert_int_eq(strcmp(str, TEST_DEVICE_NAME), 0);
|
2013-06-05 15:31:00 +10:00
|
|
|
|
|
|
|
|
str = libevdev_get_phys(dev);
|
|
|
|
|
ck_assert(str == NULL);
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_uniq(dev);
|
|
|
|
|
ck_assert(str == NULL);
|
|
|
|
|
|
2013-08-01 13:22:07 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_id_bustype(dev), ids.bustype);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_vendor(dev), ids.vendor);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_product(dev), ids.product);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_version(dev), ids.version);
|
2013-06-05 15:31:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_driver_version(dev), EV_VERSION);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
2013-06-28 13:13:55 +10:00
|
|
|
libevdev_free(dev);
|
2013-06-05 15:31:00 +10:00
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-07-25 16:11:04 +10:00
|
|
|
START_TEST(test_device_set_name)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
struct input_id ids = {1, 2, 3, 4};
|
|
|
|
|
const char *str;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
dev = libevdev_new();
|
|
|
|
|
|
|
|
|
|
libevdev_set_name(dev, "the name");
|
|
|
|
|
libevdev_set_phys(dev, "the phys");
|
|
|
|
|
libevdev_set_uniq(dev, "the uniq");
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_name(dev);
|
|
|
|
|
ck_assert(str != NULL);
|
|
|
|
|
ck_assert_int_eq(strcmp(str, "the name"), 0);
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_phys(dev);
|
|
|
|
|
ck_assert(str != NULL);
|
|
|
|
|
ck_assert_int_eq(strcmp(str, "the phys"), 0);
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_uniq(dev);
|
|
|
|
|
ck_assert(str != NULL);
|
|
|
|
|
ck_assert_int_eq(strcmp(str, "the uniq"), 0);
|
|
|
|
|
|
|
|
|
|
rc = uinput_device_new_with_events(&uidev, TEST_DEVICE_NAME, &ids,
|
2013-07-29 13:34:48 +10:00
|
|
|
EV_REL, REL_X,
|
2013-07-25 16:11:04 +10:00
|
|
|
-1);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
|
|
|
|
rc = libevdev_set_fd(dev, uinput_device_get_fd(uidev));
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));;
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_name(dev);
|
|
|
|
|
ck_assert_int_eq(strcmp(str, TEST_DEVICE_NAME), 0);
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_phys(dev);
|
|
|
|
|
ck_assert(str == NULL);
|
|
|
|
|
|
|
|
|
|
str = libevdev_get_uniq(dev);
|
|
|
|
|
ck_assert(str == NULL);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-07-25 16:21:32 +10:00
|
|
|
START_TEST(test_device_set_ids)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
struct input_id ids = {1, 2, 3, 4};
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
dev = libevdev_new();
|
|
|
|
|
|
|
|
|
|
libevdev_set_id_product(dev, 10);
|
|
|
|
|
libevdev_set_id_vendor(dev, 20);
|
|
|
|
|
libevdev_set_id_bustype(dev, 30);
|
|
|
|
|
libevdev_set_id_version(dev, 40);
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_product(dev), 10);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_vendor(dev), 20);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_bustype(dev), 30);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_version(dev), 40);
|
|
|
|
|
|
|
|
|
|
rc = uinput_device_new_with_events(&uidev, TEST_DEVICE_NAME, &ids,
|
2013-07-29 13:34:48 +10:00
|
|
|
EV_REL, REL_X,
|
2013-07-25 16:21:32 +10:00
|
|
|
-1);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
|
|
|
|
rc = libevdev_set_fd(dev, uinput_device_get_fd(uidev));
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));;
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_bustype(dev), ids.bustype);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_vendor(dev), ids.vendor);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_product(dev), ids.product);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_id_version(dev), ids.version);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-07-01 09:32:02 +10:00
|
|
|
START_TEST(test_device_get_abs_info)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
struct input_absinfo abs;
|
|
|
|
|
const struct input_absinfo *a;
|
|
|
|
|
int rc;
|
|
|
|
|
|
2013-07-05 09:08:04 +10:00
|
|
|
uidev = uinput_device_new(TEST_DEVICE_NAME);
|
2013-07-01 09:32:02 +10:00
|
|
|
ck_assert(uidev != NULL);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
abs.minimum = 0;
|
|
|
|
|
abs.maximum = 1000;
|
|
|
|
|
abs.fuzz = 1;
|
|
|
|
|
abs.flat = 2;
|
2013-07-05 08:45:48 +10:00
|
|
|
abs.resolution = 3;
|
2013-07-01 09:32:02 +10:00
|
|
|
abs.value = 0;
|
|
|
|
|
|
|
|
|
|
uinput_device_set_abs_bit(uidev, ABS_X, &abs);
|
|
|
|
|
uinput_device_set_abs_bit(uidev, ABS_MT_POSITION_X, &abs);
|
|
|
|
|
|
|
|
|
|
abs.minimum = -500;
|
|
|
|
|
abs.maximum = 500;
|
|
|
|
|
abs.fuzz = 10;
|
|
|
|
|
abs.flat = 20;
|
2013-07-05 08:45:48 +10:00
|
|
|
abs.resolution = 30;
|
2013-07-01 09:32:02 +10:00
|
|
|
abs.value = 0;
|
|
|
|
|
|
|
|
|
|
uinput_device_set_abs_bit(uidev, ABS_Y, &abs);
|
|
|
|
|
uinput_device_set_abs_bit(uidev, ABS_MT_POSITION_Y, &abs);
|
|
|
|
|
|
|
|
|
|
rc = uinput_device_create(uidev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
|
|
|
|
|
|
|
|
|
rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));;
|
|
|
|
|
|
2013-07-30 11:25:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_MAX + 1), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_MAX + 1), 0);
|
2013-07-01 09:32:02 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_MAX + 1), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_MAX + 1), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_MAX + 1), 0);
|
|
|
|
|
ck_assert(!libevdev_get_abs_info(dev, ABS_MAX + 1));
|
|
|
|
|
|
2013-07-30 11:25:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_X), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_X), 1000);
|
2013-07-01 09:32:02 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_X), 1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_X), 2);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_X), 3);
|
2013-07-01 09:32:02 +10:00
|
|
|
a = libevdev_get_abs_info(dev, ABS_X);
|
|
|
|
|
ck_assert(a != NULL);
|
|
|
|
|
ck_assert_int_eq(a->minimum, 0);
|
|
|
|
|
ck_assert_int_eq(a->maximum, 1000);
|
|
|
|
|
ck_assert_int_eq(a->fuzz, 1);
|
|
|
|
|
ck_assert_int_eq(a->flat, 2);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(a->resolution, 3);
|
2013-07-01 09:32:02 +10:00
|
|
|
|
2013-07-30 11:25:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_MT_POSITION_X), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_MT_POSITION_X), 1000);
|
2013-07-01 09:32:02 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_MT_POSITION_X), 1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_MT_POSITION_X), 2);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_MT_POSITION_X), 3);
|
2013-07-01 09:32:02 +10:00
|
|
|
a = libevdev_get_abs_info(dev, ABS_MT_POSITION_X);
|
|
|
|
|
ck_assert(a != NULL);
|
|
|
|
|
ck_assert_int_eq(a->minimum, 0);
|
|
|
|
|
ck_assert_int_eq(a->maximum, 1000);
|
|
|
|
|
ck_assert_int_eq(a->fuzz, 1);
|
|
|
|
|
ck_assert_int_eq(a->flat, 2);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(a->resolution, 3);
|
2013-07-01 09:32:02 +10:00
|
|
|
|
2013-07-30 11:25:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_Y), -500);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_Y), 500);
|
2013-07-01 09:32:02 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_Y), 10);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_Y), 20);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_Y), 30);
|
2013-07-01 09:32:02 +10:00
|
|
|
a = libevdev_get_abs_info(dev, ABS_Y);
|
|
|
|
|
ck_assert(a != NULL);
|
|
|
|
|
ck_assert_int_eq(a->minimum, -500);
|
|
|
|
|
ck_assert_int_eq(a->maximum, 500);
|
|
|
|
|
ck_assert_int_eq(a->fuzz, 10);
|
|
|
|
|
ck_assert_int_eq(a->flat, 20);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(a->resolution, 30);
|
2013-07-01 09:32:02 +10:00
|
|
|
|
2013-07-30 11:25:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_MT_POSITION_Y), -500);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_MT_POSITION_Y), 500);
|
2013-07-01 09:32:02 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_MT_POSITION_Y), 10);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_MT_POSITION_Y), 20);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_MT_POSITION_Y), 30);
|
2013-07-01 09:32:02 +10:00
|
|
|
a = libevdev_get_abs_info(dev, ABS_MT_POSITION_Y);
|
|
|
|
|
ck_assert(a != NULL);
|
|
|
|
|
ck_assert_int_eq(a->minimum, -500);
|
|
|
|
|
ck_assert_int_eq(a->maximum, 500);
|
|
|
|
|
ck_assert_int_eq(a->fuzz, 10);
|
|
|
|
|
ck_assert_int_eq(a->flat, 20);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(a->resolution, 30);
|
2013-07-01 09:32:02 +10:00
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-07-24 15:52:02 +10:00
|
|
|
START_TEST(test_device_set_abs)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
struct input_absinfo abs[2];
|
|
|
|
|
struct input_absinfo a;
|
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
memset(abs, 0, sizeof(abs));
|
|
|
|
|
abs[0].value = ABS_X;
|
|
|
|
|
abs[0].maximum = 1000;
|
|
|
|
|
|
|
|
|
|
abs[1].value = ABS_Y;
|
|
|
|
|
abs[1].maximum = 1000;
|
|
|
|
|
|
|
|
|
|
rc = test_create_abs_device(&uidev, &dev,
|
|
|
|
|
2, abs,
|
|
|
|
|
EV_SYN,
|
|
|
|
|
-1);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
|
|
|
|
|
|
|
|
|
libevdev_set_abs_minimum(dev, ABS_X, 1);
|
|
|
|
|
libevdev_set_abs_minimum(dev, ABS_Y, 5);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_X), 1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_Y), 5);
|
|
|
|
|
|
|
|
|
|
libevdev_set_abs_maximum(dev, ABS_X, 3000);
|
|
|
|
|
libevdev_set_abs_maximum(dev, ABS_Y, 5000);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_X), 3000);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_Y), 5000);
|
|
|
|
|
|
|
|
|
|
libevdev_set_abs_fuzz(dev, ABS_X, 3);
|
|
|
|
|
libevdev_set_abs_fuzz(dev, ABS_Y, 5);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_X), 3);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_Y), 5);
|
|
|
|
|
|
|
|
|
|
libevdev_set_abs_flat(dev, ABS_X, 8);
|
|
|
|
|
libevdev_set_abs_flat(dev, ABS_Y, 15);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_X), 8);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_Y), 15);
|
|
|
|
|
|
|
|
|
|
libevdev_set_abs_resolution(dev, ABS_X, 80);
|
|
|
|
|
libevdev_set_abs_resolution(dev, ABS_Y, 150);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_X), 80);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_Y), 150);
|
|
|
|
|
|
|
|
|
|
a.minimum = 10;
|
|
|
|
|
a.maximum = 100;
|
|
|
|
|
a.fuzz = 13;
|
|
|
|
|
a.flat = 1;
|
|
|
|
|
a.resolution = 16;
|
|
|
|
|
|
|
|
|
|
libevdev_set_abs_info(dev, ABS_X, &a);
|
|
|
|
|
ck_assert_int_eq(memcmp(&a, libevdev_get_abs_info(dev, ABS_X), sizeof(a)), 0);
|
|
|
|
|
|
|
|
|
|
libevdev_set_abs_minimum(dev, ABS_Z, 10);
|
|
|
|
|
ck_assert_int_eq(libevdev_has_event_code(dev, EV_ABS, ABS_Z), 0);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
|
2013-06-29 17:28:49 +10:00
|
|
|
START_TEST(test_device_enable_bit)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev, *dev2;
|
2013-07-29 13:38:28 +10:00
|
|
|
struct input_absinfo abs = {ABS_X, 0, 2};
|
2013-06-29 17:28:49 +10:00
|
|
|
int rc;
|
|
|
|
|
|
2013-07-29 13:38:28 +10:00
|
|
|
rc = test_create_abs_device(&uidev, &dev, 1, &abs,
|
|
|
|
|
-1);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-29 17:28:49 +10:00
|
|
|
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev, EV_ABS, ABS_Y));
|
|
|
|
|
ck_assert(!libevdev_has_event_type(dev, EV_REL));
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev, EV_REL, REL_X));
|
|
|
|
|
|
|
|
|
|
abs.minimum = 0;
|
|
|
|
|
abs.maximum = 100;
|
|
|
|
|
abs.fuzz = 1;
|
|
|
|
|
abs.flat = 2;
|
|
|
|
|
abs.resolution = 3;
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_ABS, ABS_Y, &abs), 0);
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev, EV_ABS, ABS_Y));
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_enable_event_type(dev, EV_REL), 0);
|
|
|
|
|
ck_assert(libevdev_has_event_type(dev, EV_REL));
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev, EV_REL, REL_X));
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_REL, REL_X, NULL), 0);
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev, EV_REL, REL_X));
|
|
|
|
|
|
|
|
|
|
/* make sure kernel device is unchanged */
|
|
|
|
|
rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev2);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev2, EV_ABS, ABS_X));
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev2, EV_ABS, ABS_Y));
|
|
|
|
|
ck_assert(!libevdev_has_event_type(dev2, EV_REL));
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev2, EV_REL, REL_X));
|
|
|
|
|
libevdev_free(dev2);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_device_enable_bit_invalid)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
2013-07-29 13:38:28 +10:00
|
|
|
struct input_absinfo abs = {ABS_X, 0, 1};
|
2013-06-29 17:28:49 +10:00
|
|
|
int rc;
|
|
|
|
|
|
2013-07-29 13:38:28 +10:00
|
|
|
rc = test_create_abs_device(&uidev, &dev, 1, &abs,
|
|
|
|
|
-1);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-29 17:28:49 +10:00
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_ABS, ABS_MAX + 1, &abs), -1);
|
2013-07-01 08:42:29 +10:00
|
|
|
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_MAX + 1, ABS_MAX + 1, &abs), -1);
|
2013-06-29 17:28:49 +10:00
|
|
|
ck_assert_int_eq(libevdev_enable_event_type(dev, EV_MAX + 1), -1);
|
|
|
|
|
|
2013-07-26 16:53:04 +10:00
|
|
|
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_ABS, ABS_Y, NULL), -1);
|
2013-07-29 11:46:01 +10:00
|
|
|
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_REP, REP_DELAY, NULL), -1);
|
2013-07-29 14:35:52 +10:00
|
|
|
ck_assert_int_eq(libevdev_enable_event_code(dev, EV_REL, REL_X, &abs), -1);
|
2013-07-26 16:53:04 +10:00
|
|
|
|
2013-06-29 17:28:49 +10:00
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_device_disable_bit)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev, *dev2;
|
|
|
|
|
int rc;
|
2013-07-29 13:38:28 +10:00
|
|
|
struct input_absinfo abs[2] = {{ABS_X, 0, 1}, {ABS_Y, 0, 1}};
|
2013-06-29 17:28:49 +10:00
|
|
|
|
2013-07-29 13:38:28 +10:00
|
|
|
rc = test_create_abs_device(&uidev, &dev,
|
|
|
|
|
2, abs,
|
|
|
|
|
EV_REL, REL_X,
|
|
|
|
|
EV_REL, REL_Y,
|
|
|
|
|
-1);
|
2013-06-29 18:19:50 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
2013-06-29 17:28:49 +10:00
|
|
|
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev, EV_ABS, ABS_X));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev, EV_ABS, ABS_Y));
|
|
|
|
|
ck_assert(libevdev_has_event_type(dev, EV_REL));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev, EV_REL, REL_X));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev, EV_REL, REL_Y));
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_disable_event_code(dev, EV_ABS, ABS_Y), 0);
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev, EV_ABS, ABS_Y));
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_disable_event_code(dev, EV_REL, REL_X), 0);
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev, EV_REL, REL_X));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev, EV_REL, REL_Y));
|
|
|
|
|
ck_assert(libevdev_has_event_type(dev, EV_REL));
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_disable_event_type(dev, EV_REL), 0);
|
|
|
|
|
ck_assert(!libevdev_has_event_type(dev, EV_REL));
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev, EV_REL, REL_X));
|
|
|
|
|
ck_assert(!libevdev_has_event_code(dev, EV_REL, REL_Y));
|
|
|
|
|
|
|
|
|
|
/* make sure kernel device is unchanged */
|
|
|
|
|
rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev2);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev2, EV_ABS, ABS_X));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev2, EV_ABS, ABS_Y));
|
|
|
|
|
ck_assert(libevdev_has_event_type(dev2, EV_REL));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev2, EV_REL, REL_X));
|
|
|
|
|
ck_assert(libevdev_has_event_code(dev2, EV_REL, REL_Y));
|
|
|
|
|
libevdev_free(dev2);
|
|
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
|
|
|
|
START_TEST(test_device_disable_bit_invalid)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
int rc;
|
2013-07-29 13:38:28 +10:00
|
|
|
struct input_absinfo abs = {ABS_X, 0, 1};
|
2013-06-29 17:28:49 +10:00
|
|
|
|
2013-07-29 13:38:28 +10:00
|
|
|
rc = test_create_abs_device(&uidev, &dev, 1, &abs, -1);
|
2013-06-29 17:28:49 +10:00
|
|
|
ck_assert_msg(rc == 0, "Failed to create uinput device: %s", strerror(-rc));
|
|
|
|
|
|
|
|
|
|
ck_assert_int_eq(libevdev_disable_event_code(dev, EV_ABS, ABS_MAX + 1), -1);
|
2013-07-01 08:42:29 +10:00
|
|
|
ck_assert_int_eq(libevdev_disable_event_code(dev, EV_MAX + 1, ABS_MAX + 1), -1);
|
2013-06-29 17:28:49 +10:00
|
|
|
ck_assert_int_eq(libevdev_disable_event_type(dev, EV_MAX + 1), -1);
|
2013-07-01 10:08:02 +10:00
|
|
|
ck_assert_int_eq(libevdev_disable_event_type(dev, EV_SYN), -1);
|
2013-06-29 17:28:49 +10:00
|
|
|
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-07-01 09:44:47 +10:00
|
|
|
START_TEST(test_device_kernel_change_axis)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev, *dev2;
|
|
|
|
|
struct input_absinfo abs;
|
|
|
|
|
int rc;
|
|
|
|
|
|
2013-07-05 09:08:04 +10:00
|
|
|
uidev = uinput_device_new(TEST_DEVICE_NAME);
|
2013-07-01 09:44:47 +10:00
|
|
|
ck_assert(uidev != NULL);
|
|
|
|
|
|
|
|
|
|
abs.minimum = 0;
|
|
|
|
|
abs.maximum = 1000;
|
|
|
|
|
abs.fuzz = 1;
|
|
|
|
|
abs.flat = 2;
|
2013-07-05 08:45:48 +10:00
|
|
|
abs.resolution = 3;
|
2013-07-01 09:44:47 +10:00
|
|
|
abs.value = 0;
|
|
|
|
|
|
|
|
|
|
uinput_device_set_abs_bit(uidev, ABS_X, &abs);
|
|
|
|
|
|
|
|
|
|
rc = uinput_device_create(uidev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
|
|
|
|
|
|
|
|
|
rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));;
|
|
|
|
|
|
2013-07-30 11:25:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_X), 0);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_X), 1000);
|
2013-07-01 09:44:47 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_X), 1);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_X), 2);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_X), 3);
|
2013-07-01 09:44:47 +10:00
|
|
|
|
|
|
|
|
abs.minimum = 500;
|
|
|
|
|
abs.maximum = 5000;
|
|
|
|
|
abs.fuzz = 10;
|
|
|
|
|
abs.flat = 20;
|
2013-07-05 08:45:48 +10:00
|
|
|
abs.resolution = 30;
|
2013-08-09 13:47:00 +10:00
|
|
|
rc = libevdev_kernel_set_abs_info(dev, ABS_X, &abs);
|
2013-07-01 09:44:47 +10:00
|
|
|
ck_assert_int_eq(rc, 0);
|
|
|
|
|
|
2013-07-30 11:25:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev, ABS_X), 500);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev, ABS_X), 5000);
|
2013-07-01 09:44:47 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev, ABS_X), 10);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev, ABS_X), 20);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev, ABS_X), 30);
|
2013-07-01 09:44:47 +10:00
|
|
|
|
|
|
|
|
/* make sure kernel device is changed */
|
|
|
|
|
rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev2);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));
|
2013-07-30 11:25:00 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_minimum(dev2, ABS_X), 500);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_maximum(dev2, ABS_X), 5000);
|
2013-07-01 09:44:47 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_fuzz(dev2, ABS_X), 10);
|
|
|
|
|
ck_assert_int_eq(libevdev_get_abs_flat(dev2, ABS_X), 20);
|
2013-07-05 08:45:48 +10:00
|
|
|
ck_assert_int_eq(libevdev_get_abs_resolution(dev2, ABS_X), 30);
|
2013-07-01 09:44:47 +10:00
|
|
|
libevdev_free(dev2);
|
|
|
|
|
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-07-01 13:34:21 +10:00
|
|
|
START_TEST(test_device_kernel_change_axis_invalid)
|
|
|
|
|
{
|
|
|
|
|
struct uinput_device* uidev;
|
|
|
|
|
struct libevdev *dev;
|
|
|
|
|
struct input_absinfo abs;
|
|
|
|
|
int rc;
|
|
|
|
|
|
2013-07-05 09:08:04 +10:00
|
|
|
uidev = uinput_device_new(TEST_DEVICE_NAME);
|
2013-07-01 13:34:21 +10:00
|
|
|
ck_assert(uidev != NULL);
|
|
|
|
|
|
|
|
|
|
abs.minimum = 0;
|
|
|
|
|
abs.maximum = 1000;
|
|
|
|
|
abs.fuzz = 1;
|
|
|
|
|
abs.flat = 2;
|
|
|
|
|
/* abs.resolution = 3; FIXME: can't test resolution */
|
|
|
|
|
abs.value = 0;
|
|
|
|
|
|
|
|
|
|
uinput_device_set_abs_bit(uidev, ABS_X, &abs);
|
|
|
|
|
|
|
|
|
|
rc = uinput_device_create(uidev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to create device: %s", strerror(-rc));
|
|
|
|
|
|
|
|
|
|
rc = libevdev_new_from_fd(uinput_device_get_fd(uidev), &dev);
|
|
|
|
|
ck_assert_msg(rc == 0, "Failed to init device: %s", strerror(-rc));;
|
|
|
|
|
|
2013-08-09 13:47:00 +10:00
|
|
|
rc = libevdev_kernel_set_abs_info(dev, ABS_MAX + 1, &abs);
|
2013-07-01 13:34:21 +10:00
|
|
|
ck_assert_int_eq(rc, -EINVAL);
|
|
|
|
|
|
|
|
|
|
libevdev_free(dev);
|
|
|
|
|
uinput_device_free(uidev);
|
|
|
|
|
}
|
|
|
|
|
END_TEST
|
|
|
|
|
|
2013-06-05 15:31:00 +10:00
|
|
|
Suite *
|
|
|
|
|
libevdev_has_event_test(void)
|
|
|
|
|
{
|
|
|
|
|
Suite *s = suite_create("libevdev_has_event tests");
|
|
|
|
|
|
|
|
|
|
TCase *tc = tcase_create("event type");
|
|
|
|
|
tcase_add_test(tc, test_ev_bit_limits);
|
|
|
|
|
tcase_add_test(tc, test_has_ev_bit);
|
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
|
|
tc = tcase_create("event codes");
|
|
|
|
|
tcase_add_test(tc, test_event_codes);
|
|
|
|
|
tcase_add_test(tc, test_event_code_limits);
|
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
|
|
|
|
tc = tcase_create("ev_rep");
|
|
|
|
|
tcase_add_test(tc, test_ev_rep);
|
|
|
|
|
tcase_add_test(tc, test_ev_rep_values);
|
|
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
2013-06-27 10:37:21 +10:00
|
|
|
tc = tcase_create("input properties");
|
|
|
|
|
tcase_add_test(tc, test_input_props);
|
2013-07-29 15:34:37 +10:00
|
|
|
tcase_add_test(tc, test_set_input_props);
|
2013-06-27 10:37:21 +10:00
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
2013-06-27 10:29:11 +10:00
|
|
|
tc = tcase_create("multitouch info");
|
|
|
|
|
tcase_add_test(tc, test_no_slots);
|
|
|
|
|
tcase_add_test(tc, test_slot_number);
|
2013-07-03 14:51:02 +10:00
|
|
|
tcase_add_test(tc, test_slot_init_value);
|
2013-06-27 10:29:11 +10:00
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
2013-06-05 15:31:00 +10:00
|
|
|
tc = tcase_create("device info");
|
|
|
|
|
tcase_add_test(tc, test_device_name);
|
2013-07-25 16:11:04 +10:00
|
|
|
tcase_add_test(tc, test_device_set_name);
|
2013-07-25 16:21:32 +10:00
|
|
|
tcase_add_test(tc, test_device_set_ids);
|
2013-07-01 09:32:02 +10:00
|
|
|
tcase_add_test(tc, test_device_get_abs_info);
|
2013-06-05 15:31:00 +10:00
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
2013-06-29 17:28:49 +10:00
|
|
|
tc = tcase_create("device bit manipulation");
|
2013-07-24 15:52:02 +10:00
|
|
|
tcase_add_test(tc, test_device_set_abs);
|
2013-06-29 17:28:49 +10:00
|
|
|
tcase_add_test(tc, test_device_enable_bit);
|
|
|
|
|
tcase_add_test(tc, test_device_enable_bit_invalid);
|
|
|
|
|
tcase_add_test(tc, test_device_disable_bit);
|
|
|
|
|
tcase_add_test(tc, test_device_disable_bit_invalid);
|
2013-07-01 09:44:47 +10:00
|
|
|
tcase_add_test(tc, test_device_kernel_change_axis);
|
2013-07-01 13:34:21 +10:00
|
|
|
tcase_add_test(tc, test_device_kernel_change_axis_invalid);
|
2013-06-29 17:28:49 +10:00
|
|
|
suite_add_tcase(s, tc);
|
|
|
|
|
|
2013-06-05 15:31:00 +10:00
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|