summaryrefslogtreecommitdiff
path: root/tests/wayland/test_input.c
blob: 7b91a9df528b30517865df31550cd373bd7aca09 (plain)
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
#include "wayland/internal.h"
#include <assert.h>

static void test_popup_bounds(void)
{
    struct seat seat = {.input_serial = 1};
    struct wayland_display d = {.base.ops = &yasl_wayland_backend, .seats = &seat};
    struct wayland_surface w = {.base.display = &d.base, .conn = &d};
    w.parent = &w;
    w.content.x = w.content.y = 1;
    /* Invalid bounds must be rejected before accessing any protocol object. */
    w.xdg_surface = (struct xdg_surface *)&w;
    w.popup = (struct xdg_popup *)&w;
    struct yasl_popup_spec specs[] = {
        {.size = {100, 100}, .content_offset = {INT_MAX, 0}, .content_size = {1, 0}},
        {.size = {100, 100}, .content_offset = {0, INT_MAX}, .content_size = {0, 1}},
        {.size = {100, 100}, .content_offset = {1, 0}, .content_size = {INT_MAX, 0}},
        {.size = {100, 100}, .content_offset = {0, 1}, .content_size = {0, INT_MAX}},
        {.size = {100, 100}, .anchor = {INT_MIN, 0, 1, 1}},
        {.size = {100, 100}, .anchor = {0, INT_MIN, 1, 1}},
    };
    for (size_t i = 0; i < sizeof(specs) / sizeof(specs[0]); i++) {
        assert(!yasl_surface_create_popup(&w.base, &specs[i]));
        assert(!yasl_surface_popup_reposition(&w.base, &specs[i]));
    }
}

int main(void)
{
    test_popup_bounds();
    struct wayland_surface w = {0};
    struct seat seat = {.ime_focus = &w};
    wayland_surface_set_callbacks(&w, NULL, NULL);
    for (int i = 0; i < 600; i++) {
        char text[32];
        snprintf(text, sizeof(text), "commit-%d", i);
        text_input_listener.commit_string(&seat, NULL, text);
        text_input_listener.done(&seat, NULL, (uint32_t)i);
        assert(!w.ime_commit);
    }
    for (int i = 0; i < 600; i++) {
        char text[32];
        snprintf(text, sizeof(text), "commit-%d", i);
        struct yasl_input_event event;
        assert(wayland_surface_input_poll(&w, &event));
        assert(event.kind == YASL_INPUT_TEXT && event.surface == &w.base);
        assert(strcmp(event.text.text, text) == 0);
    }
    input_queue_clear(&w.input);
    return 0;
}