2020-08-05 17:12:54 +10:00
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <munit.h>
|
|
|
|
|
|
|
|
|
|
#include "libei.h"
|
|
|
|
|
#include "eierpecken.h"
|
|
|
|
|
|
|
|
|
|
static MunitResult
|
|
|
|
|
test_ei_ref_unref(const MunitParameter params[], void *user_data)
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MunitResult
|
|
|
|
|
test_ei_reject(const MunitParameter params[], void *user_data)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
|
|
|
|
|
/* Client is immediately rejected */
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_REJECT_CLIENT);
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
|
|
|
|
|
/* Expect the client to get a disconnect event */
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *e = ei_get_event(ei);
|
|
|
|
|
munit_assert_ptr_not_null(e);
|
|
|
|
|
munit_assert_int(ei_event_get_type(e), ==, EI_EVENT_DISCONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MunitResult
|
|
|
|
|
test_ei_reject_after_connect(const MunitParameter params[], void *user_data)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
_cleanup_eis_client_ struct eis_client *client = NULL;
|
|
|
|
|
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_dispatch(eis);
|
|
|
|
|
_cleanup_eis_event_ struct eis_event *e = eis_get_event(eis);
|
|
|
|
|
munit_assert_ptr_not_null(e);
|
|
|
|
|
munit_assert_int(eis_event_get_type(e), ==, 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 = ei_get_event(ei);
|
|
|
|
|
munit_assert_ptr_not_null(e);
|
|
|
|
|
munit_assert_int(ei_event_get_type(e), ==, EI_EVENT_CONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_server(peck) {
|
|
|
|
|
eis_client_disconnect(client);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
with_client(peck) {
|
|
|
|
|
ei_dispatch(ei);
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *e = ei_get_event(ei);
|
|
|
|
|
munit_assert_ptr_not_null(e);
|
|
|
|
|
munit_assert_int(ei_event_get_type(e), ==, EI_EVENT_DISCONNECT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MunitResult
|
|
|
|
|
test_ei_device_basics(const MunitParameter params[], void *user_data)
|
|
|
|
|
{
|
|
|
|
|
_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_dispatch_eis(peck);
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static MunitResult
|
|
|
|
|
test_ei_device_add(const MunitParameter params[], void *user_data)
|
|
|
|
|
{
|
|
|
|
|
_cleanup_peck_ struct peck *peck = peck_new();
|
|
|
|
|
|
2020-08-11 10:51:30 +10:00
|
|
|
with_server(peck) {
|
|
|
|
|
peck_enable_eis_behavior(peck, PECK_EIS_BEHAVIOR_ACCEPT_ALL);
|
|
|
|
|
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-05 17:12:54 +10:00
|
|
|
peck_dispatch_eis(peck);
|
2020-08-11 10:51:30 +10:00
|
|
|
peck_dispatch_ei(peck);
|
2020-08-05 17:12:54 +10:00
|
|
|
|
2020-08-11 10:51:30 +10:00
|
|
|
with_client(peck) {
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *event = ei_get_event(ei);
|
|
|
|
|
munit_assert_ptr_not_null(event);
|
|
|
|
|
munit_assert_int(ei_event_get_type(event), ==, 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-08-05 17:12:54 +10:00
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-11 12:37:00 +10:00
|
|
|
static MunitResult
|
|
|
|
|
test_ei_device_add_drop_caps(const MunitParameter params[], void *user_data)
|
|
|
|
|
{
|
|
|
|
|
_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);
|
|
|
|
|
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
|
|
|
|
|
_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);
|
|
|
|
|
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *event = ei_get_event(ei);
|
|
|
|
|
munit_assert_ptr_not_null(event);
|
|
|
|
|
munit_assert_int(ei_event_get_type(event), ==, EI_EVENT_DEVICE_ADDED);
|
|
|
|
|
|
|
|
|
|
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-11 11:29:55 +10:00
|
|
|
static MunitResult
|
|
|
|
|
test_ei_device_add_zero_caps(const MunitParameter params[], void *user_data)
|
|
|
|
|
{
|
|
|
|
|
_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
|
|
|
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
peck_dispatch_eis(peck);
|
|
|
|
|
peck_dispatch_ei(peck);
|
|
|
|
|
|
|
|
|
|
_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);
|
|
|
|
|
|
|
|
|
|
_cleanup_ei_event_ struct ei_event *event = ei_get_event(ei);
|
|
|
|
|
munit_assert_ptr_not_null(event);
|
|
|
|
|
munit_assert_int(ei_event_get_type(event), ==, EI_EVENT_DEVICE_REMOVED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return MUNIT_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-05 17:12:54 +10:00
|
|
|
static MunitTest ei_tests[] = {
|
|
|
|
|
{ .name = "/ei/ref", .test = test_ei_ref_unref },
|
|
|
|
|
{ .name = "/ei/reject", .test = test_ei_reject },
|
|
|
|
|
{ .name = "/ei/reject_after_connect", .test = test_ei_reject_after_connect },
|
|
|
|
|
{ .name = "/device/basics", .test = test_ei_device_basics },
|
|
|
|
|
{ .name = "/device/add", .test = test_ei_device_add },
|
2020-08-11 12:37:00 +10:00
|
|
|
{ .name = "/device/add_drop_caps", .test = test_ei_device_add_drop_caps },
|
2020-08-11 11:29:55 +10:00
|
|
|
{ .name = "/device/add_zero_caps", .test = test_ei_device_add_zero_caps },
|
2020-08-05 17:12:54 +10:00
|
|
|
};
|
|
|
|
|
|
2020-08-12 14:36:10 +10:00
|
|
|
static const MunitSuite ei_suite = {
|
2020-08-05 17:12:54 +10:00
|
|
|
"/ei",
|
|
|
|
|
ei_tests,
|
|
|
|
|
NULL,
|
|
|
|
|
1,
|
|
|
|
|
MUNIT_SUITE_OPTION_NONE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char* argv[MUNIT_ARRAY_PARAM(argc + 1)])
|
|
|
|
|
{
|
2020-08-12 14:36:10 +10:00
|
|
|
return munit_suite_main(&ei_suite, NULL, argc, argv);
|
2020-08-05 17:12:54 +10:00
|
|
|
}
|