2020-08-05 17:12:54 +10:00
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/socket.h>
|
2020-08-19 09:37:04 +10:00
|
|
|
#include "util-munit.h"
|
2020-08-05 17:12:54 +10:00
|
|
|
|
|
|
|
|
#include "libei.h"
|
|
|
|
|
#include "eierpecken.h"
|
|
|
|
|
|
2020-08-19 09:37:04 +10:00
|
|
|
MUNIT_TEST(test_ei_ref_unref)
|
2020-08-05 17:12:54 +10:00
|
|
|
{
|
|
|
|
|
struct ei *ei = ei_new(NULL);
|
|
|
|
|
|
|
|
|
|
struct ei *refd = ei_ref(ei);
|
|
|
|
|
munit_assert_ptr_equal(ei, refd);
|
|
|
|
|
|
|
|
|
|
struct ei *unrefd = ei_unref(ei);
|
|
|
|
|
munit_assert_ptr_null(unrefd);
|
|
|
|
|
unrefd = ei_unref(ei);
|
|
|
|
|
munit_assert_ptr_null(unrefd);
|
|
|
|
|
|
|
|
|
|
/* memleak only shows up in valgrind */
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 10:13:48 +10:00
|
|
|
MUNIT_TEST(test_ei_disconnect_immediately)
|
2020-08-05 17:12:54 +10:00
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
|
|
|
|
|
/* Client is immediately rejected */
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_REJECT_CLIENT);
|
2020-08-19 10:16:47 +10:00
|
|
|
peck_dispatch_until_stable(peck);
|
2020-08-05 17:12:54 +10:00
|
|
|
|
|
|
|
|
/* Expect the client to get a disconnect event */
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
2020-08-19 11:09:55 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *disconnect =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
|
2020-08-05 17:12:54 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 10:13:48 +10:00
|
|
|
MUNIT_TEST(test_ei_disconnect_after_connect)
|
2020-08-05 17:12:54 +10:00
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_eis_client_ struct eis_client *client = NULL;
|
|
|
|
|
|
2020-08-19 10:16:47 +10:00
|
|
|
peck_dispatch_until_stable(peck);
|
2020-08-05 17:12:54 +10:00
|
|
|
|
2020-08-19 11:09:55 +10:00
|
|
|
with_server(peck) {
|
|
|
|
|
eis_dispatch(eis);
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_CLIENT_CONNECT);
|
|
|
|
|
client = eis_client_ref(eis_event_get_client(e));
|
|
|
|
|
eis_client_connect(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *e =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_CONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_client_disconnect(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *e =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MUNIT_TEST(test_ei_disconnect_after_add_before_received)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_eis_client_ struct eis_client *client = NULL;
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_dispatch(eis);
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_CLIENT_CONNECT);
|
|
|
|
|
client = eis_client_ref(eis_event_get_client(e));
|
|
|
|
|
eis_client_connect(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* We have *not* called eis_dispatch, so the device add hasn't been
|
|
|
|
|
* processed by the server yet */
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_client_disconnect(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *removed =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *disconnect =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MUNIT_TEST(test_ei_disconnect_after_add_after_received)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_eis_client_ struct eis_client *client = NULL;
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
2020-08-05 17:12:54 +10:00
|
|
|
with_server(peck) {
|
|
|
|
|
eis_dispatch(eis);
|
2020-09-23 11:17:36 +10:00
|
|
|
_cleanup_eis_event_ struct eis_event *e =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_CLIENT_CONNECT);
|
2020-08-05 17:12:54 +10:00
|
|
|
client = eis_client_ref(eis_event_get_client(e));
|
|
|
|
|
eis_client_connect(client);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 11:09:55 +10:00
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Receive the Added event but don't actually add the device */
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_client_disconnect(client);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 17:12:54 +10:00
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
2020-08-19 11:09:55 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *removed =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *disconnect =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MUNIT_TEST(test_ei_disconnect_after_remove_before_received)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_eis_client_ struct eis_client *client = NULL;
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = NULL;
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_dispatch(eis);
|
2020-09-23 11:17:36 +10:00
|
|
|
_cleanup_eis_event_ struct eis_event *e =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_CLIENT_CONNECT);
|
2020-08-19 11:09:55 +10:00
|
|
|
client = eis_client_ref(eis_event_get_client(e));
|
|
|
|
|
eis_client_connect(client);
|
2020-08-05 17:12:54 +10:00
|
|
|
}
|
|
|
|
|
|
2020-08-19 11:09:55 +10:00
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
device = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* server has the device now */
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *added =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
|
2020-08-19 13:39:32 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *resumed =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_RESUMED);
|
2020-08-19 11:09:55 +10:00
|
|
|
ei_device_remove(device);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 11:39:58 +10:00
|
|
|
/* No server dispatch here so the server isn't aware of the
|
|
|
|
|
* ei_device_remove() call. Disconnect the client, this
|
|
|
|
|
* automatically removes all devices */
|
2020-08-05 17:12:54 +10:00
|
|
|
with_server(peck) {
|
|
|
|
|
eis_client_disconnect(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
2020-09-23 11:39:58 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *removed =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
|
2020-08-19 11:09:55 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *disconnect =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MUNIT_TEST(test_ei_disconnect_after_remove_after_received)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_eis_client_ struct eis_client *client = NULL;
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = NULL;
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_dispatch(eis);
|
2020-09-23 11:17:36 +10:00
|
|
|
_cleanup_eis_event_ struct eis_event *e =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_CLIENT_CONNECT);
|
2020-08-19 11:09:55 +10:00
|
|
|
client = eis_client_ref(eis_event_get_client(e));
|
|
|
|
|
eis_client_connect(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
device = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* server has the device now */
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *added =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
|
2020-08-19 13:39:32 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *resumed =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_RESUMED);
|
2020-08-19 11:09:55 +10:00
|
|
|
ei_device_remove(device);
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 11:39:58 +10:00
|
|
|
/* Dispatch, server is aware of the ei_device_remove() */
|
2020-08-19 11:09:55 +10:00
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_client_disconnect(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
2020-09-23 11:39:58 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *removed =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
|
|
|
|
|
|
2020-08-19 11:09:55 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *disconnect =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DISCONNECT);
|
2020-08-05 17:12:54 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 09:37:04 +10:00
|
|
|
MUNIT_TEST(test_ei_device_basics)
|
2020-08-05 17:12:54 +10:00
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = NULL;
|
|
|
|
|
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
2020-08-19 10:16:47 +10:00
|
|
|
peck_dispatch_until_stable(peck);
|
2020-08-05 17:12:54 +10:00
|
|
|
|
|
|
|
|
/* device creation and getters/setters test */
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
device = ei_device_new(ei);
|
|
|
|
|
munit_assert_not_null(device);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
munit_assert_string_equal(ei_device_get_name(device), __func__);
|
|
|
|
|
|
|
|
|
|
bool success = ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
munit_assert(success);
|
|
|
|
|
munit_assert(ei_device_has_capability(device, EI_DEVICE_CAP_POINTER));
|
|
|
|
|
|
|
|
|
|
/* Add it, but we don't care about whether it worked correctly in this test */
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
|
|
|
|
|
/* Device is immutable after ei_device_add() */
|
|
|
|
|
bool failed_caps = ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
munit_assert(failed_caps == false);
|
|
|
|
|
munit_assert(ei_device_has_capability(device, EI_DEVICE_CAP_POINTER));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Drain both sides, we don't care about the events themselves */
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
peck_drain_eis(eis);
|
|
|
|
|
}
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
peck_drain_ei(ei);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* device is still immutable */
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
bool failed_caps = ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
munit_assert(failed_caps == false);
|
|
|
|
|
munit_assert(ei_device_has_capability(device, EI_DEVICE_CAP_POINTER));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 13:36:15 +10:00
|
|
|
MUNIT_TEST(test_ei_device_set_name)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *d1 = NULL;
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *d2 = NULL;
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *d3 = NULL;
|
|
|
|
|
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_CLIENT);
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
d1 = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(d1, "first device");
|
|
|
|
|
ei_device_configure_capability(d1, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(d1);
|
|
|
|
|
|
|
|
|
|
d2 = ei_device_new(ei);
|
|
|
|
|
munit_assert_not_null(d2);
|
|
|
|
|
ei_device_configure_name(d2, "second device");
|
|
|
|
|
ei_device_configure_capability(d2, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(d2);
|
|
|
|
|
|
|
|
|
|
d3 = ei_device_new(ei);
|
|
|
|
|
munit_assert_not_null(d3);
|
|
|
|
|
ei_device_configure_name(d3, "third device");
|
|
|
|
|
ei_device_configure_capability(d3, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(d3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e1 =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_DEVICE_ADDED);
|
|
|
|
|
|
|
|
|
|
struct eis_device *d1 = eis_event_get_device(e1);
|
|
|
|
|
munit_assert_string_equal(eis_device_get_name(d1), "first device");
|
|
|
|
|
/* change the name */
|
|
|
|
|
eis_device_set_name(d1, "other name");
|
|
|
|
|
munit_assert_string_equal(eis_device_get_name(d1), "other name");
|
|
|
|
|
eis_device_allow_capability(d1, EIS_DEVICE_CAP_POINTER);
|
|
|
|
|
eis_device_connect(d1);
|
|
|
|
|
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e2 =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_DEVICE_ADDED);
|
|
|
|
|
struct eis_device *d2 = eis_event_get_device(e2);
|
|
|
|
|
|
|
|
|
|
munit_assert_string_equal(eis_device_get_name(d2), "second device");
|
|
|
|
|
/* unset the name */
|
|
|
|
|
eis_device_set_name(d2, NULL);
|
|
|
|
|
munit_assert_ptr_null(eis_device_get_name(d2));
|
|
|
|
|
eis_device_allow_capability(d2, EIS_DEVICE_CAP_POINTER);
|
|
|
|
|
eis_device_connect(d2);
|
|
|
|
|
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e3 =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_DEVICE_ADDED);
|
|
|
|
|
struct eis_device *d3 = eis_event_get_device(e3);
|
|
|
|
|
|
|
|
|
|
munit_assert_string_equal(eis_device_get_name(d3), "third device");
|
|
|
|
|
/* leave the name as-is */
|
|
|
|
|
eis_device_allow_capability(d3, EIS_DEVICE_CAP_POINTER);
|
|
|
|
|
eis_device_connect(d3);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *e1 =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
|
|
|
|
|
munit_assert_ptr_equal(d1, ei_event_get_device(e1));
|
|
|
|
|
munit_assert_string_equal(ei_device_get_name(d1), "other name");
|
|
|
|
|
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *e2 =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
|
|
|
|
|
munit_assert_ptr_equal(d2, ei_event_get_device(e2));
|
|
|
|
|
munit_assert_ptr_null(ei_device_get_name(d2));
|
|
|
|
|
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *e3 =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
|
|
|
|
|
munit_assert_ptr_equal(d3, ei_event_get_device(e3));
|
|
|
|
|
munit_assert_string_equal(ei_device_get_name(d3), "third device");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 11:39:58 +10:00
|
|
|
MUNIT_TEST(test_ei_device_add_remove)
|
2020-08-05 17:12:54 +10:00
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
|
2020-08-11 10:51:30 +10:00
|
|
|
with_server(peck) {
|
2020-09-23 11:39:58 +10:00
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_CLIENT);
|
2020-08-11 10:51:30 +10:00
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
peck_drain_ei(ei);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = NULL;
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
device = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 10:16:47 +10:00
|
|
|
peck_dispatch_until_stable(peck);
|
2020-08-05 17:12:54 +10:00
|
|
|
|
2020-09-23 11:39:58 +10:00
|
|
|
_cleanup_eis_device_ struct eis_device *eis_device = NULL;
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *event =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_DEVICE_ADDED);
|
|
|
|
|
|
|
|
|
|
eis_device = eis_device_ref(eis_event_get_device(event));
|
|
|
|
|
eis_device_allow_capability(eis_device, EIS_DEVICE_CAP_POINTER);
|
|
|
|
|
eis_device_connect(eis_device);
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 10:51:30 +10:00
|
|
|
with_client(peck) {
|
2020-09-23 11:39:58 +10:00
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
|
2020-09-23 11:17:36 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *event =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
|
2020-08-05 17:12:54 +10:00
|
|
|
|
2020-08-11 10:51:30 +10:00
|
|
|
struct ei_device *added = ei_event_get_device(event);
|
|
|
|
|
munit_assert_ptr_equal(device, added);
|
|
|
|
|
munit_assert(ei_device_has_capability(added, EI_DEVICE_CAP_POINTER));
|
2020-09-23 11:39:58 +10:00
|
|
|
|
|
|
|
|
ei_device_remove(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *event =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_DEVICE_REMOVED);
|
|
|
|
|
|
|
|
|
|
munit_assert_ptr_equal(eis_event_get_device(event), eis_device);
|
|
|
|
|
eis_device_disconnect(eis_device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *event =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
|
|
|
|
|
|
|
|
|
|
struct ei_device *removed = ei_event_get_device(event);
|
|
|
|
|
munit_assert_ptr_equal(device, removed);
|
2020-08-11 10:51:30 +10:00
|
|
|
}
|
2020-08-05 17:12:54 +10:00
|
|
|
|
2020-09-23 11:39:58 +10:00
|
|
|
|
2020-08-05 17:12:54 +10:00
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-23 11:39:58 +10:00
|
|
|
MUNIT_TEST(test_ei_device_remove_forget_disconnect)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
|
|
|
|
peck_enable_ei_behavior(peck, PECK_EI_BEHAVIOR_AUTODEVICES);
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *d1 = NULL;
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *d2 = NULL;
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
d1 = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(d1, "first");
|
|
|
|
|
ei_device_configure_capability(d1, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(d1);
|
|
|
|
|
|
|
|
|
|
d2 = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(d2, "second");
|
|
|
|
|
ei_device_configure_capability(d2, EI_DEVICE_CAP_KEYBOARD);
|
|
|
|
|
ei_device_add(d2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_NONE);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
/* remove in order d1, d2 */
|
|
|
|
|
ei_device_remove(d1);
|
|
|
|
|
ei_device_remove(d2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
struct eis_event *e1 = NULL;
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
e1 = peck_eis_next_event(eis, EIS_EVENT_DEVICE_REMOVED);
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e2 =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_DEVICE_REMOVED);
|
|
|
|
|
|
|
|
|
|
/* Explicitly disconnect device d2 */
|
|
|
|
|
eis_device_disconnect(eis_event_get_device(e2));
|
|
|
|
|
/* But forget to eis_device_disconnect(d1), happens
|
|
|
|
|
* automatically when the event is unref'd */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *event =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
|
|
|
|
|
|
|
|
|
|
struct ei_device *removed = ei_event_get_device(event);
|
|
|
|
|
munit_assert_ptr_equal(d2, removed);
|
|
|
|
|
peck_assert_no_ei_events(ei);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* unref should trigger eis_device_disconnect() */
|
|
|
|
|
eis_event_unref(e1);
|
|
|
|
|
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *event =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
|
|
|
|
|
|
|
|
|
|
struct ei_device *removed = ei_event_get_device(event);
|
|
|
|
|
munit_assert_ptr_equal(d1, removed);
|
|
|
|
|
peck_assert_no_ei_events(ei);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2020-08-19 09:37:04 +10:00
|
|
|
MUNIT_TEST(test_ei_device_add_drop_caps)
|
2020-08-11 12:37:00 +10:00
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
|
|
|
|
|
/* Device with pointer and keyboard caps but pointer is dropped */
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_DROP_POINTER);
|
|
|
|
|
|
2020-08-19 10:16:47 +10:00
|
|
|
peck_dispatch_until_stable(peck);
|
2020-08-11 12:37:00 +10:00
|
|
|
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = NULL;
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
device = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_KEYBOARD);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
|
|
|
|
|
2020-09-23 11:17:36 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *event =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_ADDED);
|
2020-08-11 12:37:00 +10:00
|
|
|
|
|
|
|
|
struct ei_device *d = ei_event_get_device(event);
|
|
|
|
|
munit_assert_ptr_equal(d, device);
|
|
|
|
|
munit_assert(ei_device_has_capability(d, EI_DEVICE_CAP_KEYBOARD));
|
|
|
|
|
munit_assert(!ei_device_has_capability(d, EI_DEVICE_CAP_POINTER));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-19 09:37:04 +10:00
|
|
|
MUNIT_TEST(test_ei_device_add_zero_caps)
|
2020-08-11 11:29:55 +10:00
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
|
|
|
|
|
/* Device with pointer caps but those caps are rejected -> device
|
|
|
|
|
immediately removed by EIS */
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
2020-08-11 12:37:00 +10:00
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_DROP_POINTER);
|
2020-08-11 11:29:55 +10:00
|
|
|
|
2020-08-19 10:16:47 +10:00
|
|
|
peck_dispatch_until_stable(peck);
|
2020-08-11 11:29:55 +10:00
|
|
|
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = NULL;
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
device = ei_device_new(ei);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
|
|
|
|
|
2020-09-23 11:17:36 +10:00
|
|
|
_cleanup_ei_event_ struct ei_event *event =
|
|
|
|
|
peck_ei_next_event(ei, EI_EVENT_DEVICE_REMOVED);
|
2020-08-11 11:29:55 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 12:02:44 +10:00
|
|
|
MUNIT_TEST(test_ei_device_pointer_rel)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = NULL;
|
|
|
|
|
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
|
|
|
|
peck_enable_ei_behavior(peck, PECK_EI_BEHAVIOR_AUTODEVICES);
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
device = ei_device_new(ei);
|
|
|
|
|
munit_assert_not_null(device);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_device_pointer_motion(device, 1, 2);
|
|
|
|
|
ei_device_pointer_motion(device, 0.3, 1.4);
|
|
|
|
|
ei_device_pointer_motion(device, 100, 200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *first =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_POINTER_MOTION);
|
|
|
|
|
munit_assert_double_equal(eis_event_pointer_get_dx(first), 1.0, 2 /* precision */);
|
|
|
|
|
munit_assert_double_equal(eis_event_pointer_get_dy(first), 2.0, 2 /* precision */);
|
|
|
|
|
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *second =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_POINTER_MOTION);
|
|
|
|
|
munit_assert_double_equal(eis_event_pointer_get_dx(second), 0.3, 2 /* precision */);
|
|
|
|
|
munit_assert_double_equal(eis_event_pointer_get_dy(second), 1.4, 2 /* precision */);
|
|
|
|
|
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *third =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_POINTER_MOTION);
|
|
|
|
|
munit_assert_double_equal(eis_event_pointer_get_dx(third), 100, 2 /* precision */);
|
|
|
|
|
munit_assert_double_equal(eis_event_pointer_get_dy(third), 200, 2 /* precision */);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-22 13:17:54 +10:00
|
|
|
MUNIT_TEST(test_ei_device_pointer_abs)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_ei_device_ struct ei_device *device = NULL;
|
|
|
|
|
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
|
|
|
|
peck_enable_ei_behavior(peck, PECK_EI_BEHAVIOR_AUTODEVICES);
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
device = ei_device_new(ei);
|
|
|
|
|
munit_assert_not_null(device);
|
|
|
|
|
ei_device_configure_name(device, __func__);
|
|
|
|
|
|
|
|
|
|
ei_device_configure_capability(device, EI_DEVICE_CAP_POINTER_ABSOLUTE);
|
|
|
|
|
ei_device_pointer_configure_range(device, 1920, 1200);
|
|
|
|
|
ei_device_add(device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
|
ei_device_pointer_motion_absolute(device, 1 * i , 2 + i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_POINTER_MOTION_ABSOLUTE);
|
|
|
|
|
munit_assert_double_equal(eis_event_pointer_get_absolute_x(e), 1.0 * i, 2 /* precision */);
|
|
|
|
|
munit_assert_double_equal(eis_event_pointer_get_absolute_y(e), 2.0 + i, 2 /* precision */);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
/* outside of pointer range, expect to be discarded */
|
|
|
|
|
ei_device_pointer_motion_absolute(device, 1920, 1200);
|
|
|
|
|
ei_device_pointer_motion_absolute(device, 2000, 1400);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
peck_dispatch_until_stable(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
peck_assert_no_eis_events(eis);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_device_remove(device);
|
|
|
|
|
/* absmotion after remove must not trigger an event */
|
|
|
|
|
ei_device_pointer_motion_absolute(device, 100, 200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
/* Don't auto-handle the removed event */
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_NONE);
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e =
|
|
|
|
|
peck_eis_next_event(eis, EIS_EVENT_DEVICE_REMOVED);
|
|
|
|
|
peck_assert_no_eis_events(eis);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 17:12:54 +10:00
|
|
|
int
|
2020-08-19 09:37:04 +10:00
|
|
|
main(int argc, char **argv)
|
2020-08-05 17:12:54 +10:00
|
|
|
{
|
2020-08-19 09:37:04 +10:00
|
|
|
return munit_tests_run(argc, argv);
|
2020-08-05 17:12:54 +10:00
|
|
|
}
|