1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
/* The public event queue must retain FIFO order and discard events targeted
* at a surface when that surface is destroyed. Native input is injected
* through the backend queue, without requiring a compositor. */
#include "yasl/yasl.h"
#include "common/backend.h"
#include <assert.h>
#include <string.h>
static struct input_queue *surface_queue(struct yasl_surface *s)
{
return &s->input;
}
static const struct yasl_private_backend_ops test_ops = {
.surface_input_queue = surface_queue,
};
static void setup(struct yasl_private_display *display, struct yasl_surface *surface)
{
*display = (struct yasl_private_display){.ops = &test_ops};
*surface = (struct yasl_surface){.display = display, .scale_120 = 120};
assert(yasl_private_events_open(display));
assert(yasl_private_events_register(surface));
}
static void destroy_surface(struct yasl_surface *surface)
{
yasl_private_events_unregister(surface);
input_queue_clear(&surface->input);
}
static void test_fifo_and_destroy(void)
{
struct yasl_private_display display;
struct yasl_surface surface;
setup(&display, &surface);
assert(input_queue_push(&surface.input, &(struct yasl_private_event){
.type = YASL_PRIVATE_EVENT_KEY,
.surface = &surface,
.key = {.key = YASL_KEY_A, .action = YASL_KEY_PRESS},
}));
assert(input_queue_push(&surface.input, &(struct yasl_private_event){
.type = YASL_PRIVATE_EVENT_TEXT,
.surface = &surface,
.text = {.data = "hello", .len = 5},
}));
struct yasl_private_event event;
assert(yasl_private_display_poll_event(&display, &event));
assert(event.type == YASL_PRIVATE_EVENT_KEY && event.key.key == YASL_KEY_A);
assert(yasl_private_display_poll_event(&display, &event));
assert(event.type == YASL_PRIVATE_EVENT_TEXT && event.text.len == 5);
assert(!strcmp(event.text.data, "hello"));
/* Queue multiple events, then destroy the target before consumption. */
assert(input_queue_push(&surface.input, &(struct yasl_private_event){
.type = YASL_PRIVATE_EVENT_KEY, .surface = &surface,
.key = {.key = YASL_KEY_B, .action = YASL_KEY_PRESS},
}));
assert(input_queue_push(&surface.input, &(struct yasl_private_event){
.type = YASL_PRIVATE_EVENT_TEXT, .surface = &surface,
.text = {.data = "discard", .len = 7},
}));
destroy_surface(&surface);
assert(!yasl_private_display_poll_event(&display, &event));
yasl_private_events_close(&display);
/* Public event names remain the event stream consumed by applications. */
assert(YASL_EVENT_KEY != YASL_EVENT_TEXT);
}
int main(void)
{
test_fifo_and_destroy();
return 0;
}
|