summaryrefslogtreecommitdiff
path: root/tests/wayland
diff options
context:
space:
mode:
Diffstat (limited to 'tests/wayland')
-rw-r--r--tests/wayland/test_app_input.c55
-rw-r--r--tests/wayland/test_state.c75
2 files changed, 128 insertions, 2 deletions
diff --git a/tests/wayland/test_app_input.c b/tests/wayland/test_app_input.c
index 2cacb5e..c8c5687 100644
--- a/tests/wayland/test_app_input.c
+++ b/tests/wayland/test_app_input.c
@@ -9,6 +9,8 @@
struct test_state {
int keys;
+ int buttons, motions, resets;
+ int end;
};
static void push_key(struct yasl_surface *s)
@@ -23,10 +25,32 @@ static void push_key(struct yasl_surface *s)
static int on_init(void *ud, struct yasl_display *d)
{
- (void)ud;
+ struct test_state *state = ud;
+ if (state->end) {
+ struct wayland_display *display = (struct wayland_display *)d;
+ if (state->end == 1)
+ display->cbs->quit(display->ud);
+ else
+ display->cbs->lost(display->ud);
+ return YASL_APP_CONTINUE;
+ }
struct yasl_surface *s = yasl_surface_create_toplevel(d,
&(struct yasl_window_spec){ .title = "App Input Test", .size = {64, 64} });
assert(s);
+ struct input_queue *queue = &((struct wayland_surface *)s)->input;
+ input_queue_clear(queue);
+ struct yasl_input_event event = {.surface = s, .kind = YASL_INPUT_MOUSE,
+ .mouse = {.kind = YASL_PTR_PRESS, .device = YASL_PTR_DEV_ERASER,
+ .pos = {12, 34}, .pen = {.pressure = 50000, .tilt_x = -20, .tilt_y = 30}}};
+ assert(input_queue_push(queue, &event));
+ event.mouse.kind = YASL_PTR_MOTION;
+ event.mouse.pos = (struct yasl_vector2i){15, 39};
+ assert(input_queue_push(queue, &event));
+ struct yasl_input_event reset = {.surface = s, .kind = YASL_INPUT_RESET};
+ assert(input_queue_push(queue, &reset));
+ event.mouse.device = YASL_PTR_DEV_PEN;
+ event.mouse.pos = (struct yasl_vector2i){100, 200};
+ assert(input_queue_push(queue, &event));
push_key(s);
push_key(s);
return YASL_APP_CONTINUE;
@@ -35,7 +59,26 @@ static int on_init(void *ud, struct yasl_display *d)
static int on_event(void *ud, const struct yasl_event *ev)
{
struct test_state *state = ud;
- if (ev->type == YASL_EVENT_KEY) {
+ if (ev->type == YASL_EVENT_MOUSE_BUTTON) {
+ assert(ev->mouse_button.device == YASL_PTR_DEV_ERASER);
+ assert(ev->mouse_button.pressed && ev->mouse_button.button == 0);
+ assert(ev->mouse_button.pos.x == 12 && ev->mouse_button.pos.y == 34);
+ assert(ev->mouse_button.pen.pressure == 50000);
+ assert(ev->mouse_button.pen.tilt_x == -20 && ev->mouse_button.pen.tilt_y == 30);
+ state->buttons++;
+ } else if (ev->type == YASL_EVENT_MOUSE_MOTION) {
+ if (!state->motions) {
+ assert(ev->mouse_motion.device == YASL_PTR_DEV_ERASER);
+ assert(ev->mouse_motion.delta.x == 3 && ev->mouse_motion.delta.y == 5);
+ } else {
+ assert(ev->mouse_motion.device == YASL_PTR_DEV_PEN);
+ assert(!ev->mouse_motion.delta.x && !ev->mouse_motion.delta.y);
+ }
+ assert(ev->mouse_motion.pen.pressure == 50000);
+ state->motions++;
+ } else if (ev->type == YASL_EVENT_INPUT_RESET) {
+ state->resets++;
+ } else if (ev->type == YASL_EVENT_KEY) {
state->keys++;
yasl_surface_destroy(ev->surface);
}
@@ -56,5 +99,13 @@ int main(void)
});
assert(res == 0);
assert(state.keys == 1);
+ assert(state.buttons == 1 && state.motions == 2 && state.resets == 1);
+ for (int end = 1; end <= 2; end++) {
+ state = (struct test_state){.end = end};
+ res = yasl_run(&(struct yasl_app_desc){
+ .backend = YASL_BACKEND_WAYLAND, .userdata = &state, .init = on_init,
+ });
+ assert(end == 1 ? res == 0 : res < 0);
+ }
return 0;
}
diff --git a/tests/wayland/test_state.c b/tests/wayland/test_state.c
new file mode 100644
index 0000000..2da26e5
--- /dev/null
+++ b/tests/wayland/test_state.c
@@ -0,0 +1,75 @@
+#include "../../src/platform/wayland/shell.c"
+#include <assert.h>
+
+struct notifications {
+ int count;
+ uint32_t state;
+};
+
+static void state_changed(struct yasl_surface *surface, uint32_t state, void *ud)
+{
+ struct notifications *notifications = ud;
+ assert(yasl_surface_state(surface) == state);
+ notifications->count++;
+ notifications->state = state;
+}
+
+static void configure(struct wayland_surface *surface, uint32_t *states, size_t count)
+{
+ struct wl_array array = {.size = count * sizeof(*states), .data = states};
+ toplevel_configure(surface, NULL, 640, 480, &array);
+ assert(surface->req_width == 640 && surface->req_height == 480);
+}
+
+int main(void)
+{
+ struct notifications notifications = {0};
+ struct wayland_surface surface = {.base.state = YASL_STATE_CSD};
+ wayland_surface_set_callbacks(&surface, &(struct yasl_window_cbs){
+ .state = state_changed}, &notifications);
+ assert(yasl_surface_state(&surface.base) == YASL_STATE_CSD);
+
+ uint32_t fullscreen[] = {XDG_TOPLEVEL_STATE_FULLSCREEN,
+ XDG_TOPLEVEL_STATE_ACTIVATED, XDG_TOPLEVEL_STATE_FULLSCREEN, 31, UINT32_MAX};
+ configure(&surface, fullscreen, sizeof(fullscreen) / sizeof(*fullscreen));
+ assert(notifications.count == 1);
+ assert(notifications.state == (YASL_STATE_CSD | YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED));
+ configure(&surface, fullscreen, sizeof(fullscreen) / sizeof(*fullscreen));
+ assert(notifications.count == 1);
+
+ /* Decoration changes preserve the other flags and do not notify twice. */
+ toplevel_decoration_configure(&surface, NULL, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+ assert(notifications.count == 2);
+ assert(notifications.state == (YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED));
+ toplevel_decoration_configure(&surface, NULL, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+ assert(notifications.count == 2);
+
+ uint32_t maximized[] = {XDG_TOPLEVEL_STATE_MAXIMIZED, XDG_TOPLEVEL_STATE_SUSPENDED};
+ configure(&surface, maximized, sizeof(maximized) / sizeof(*maximized));
+ assert(notifications.count == 3);
+ assert(notifications.state == (YASL_STATE_MAXIMIZED | YASL_STATE_SUSPENDED));
+ toplevel_decoration_configure(&surface, NULL, ZXDG_TOPLEVEL_DECORATION_V1_MODE_CLIENT_SIDE);
+ assert(notifications.count == 4);
+ assert(notifications.state == (YASL_STATE_CSD | YASL_STATE_MAXIMIZED | YASL_STATE_SUSPENDED));
+
+ /* Each tiled edge maps to the same portable flag; changing edges alone
+ * leaves the reported state unchanged. */
+ uint32_t edges[] = {XDG_TOPLEVEL_STATE_TILED_LEFT, XDG_TOPLEVEL_STATE_TILED_RIGHT,
+ XDG_TOPLEVEL_STATE_TILED_TOP, XDG_TOPLEVEL_STATE_TILED_BOTTOM};
+ for (size_t i = 0; i < sizeof(edges) / sizeof(*edges); i++) {
+ configure(&surface, &edges[i], 1);
+ assert(notifications.count == 5);
+ assert(notifications.state == (YASL_STATE_CSD | YASL_STATE_TILED));
+ }
+ configure(&surface, edges, 0);
+ assert(notifications.count == 6);
+ assert(notifications.state == YASL_STATE_CSD);
+
+ /* State still advances when applications have not installed callbacks. */
+ wayland_surface_set_callbacks(&surface, NULL, NULL);
+ configure(&surface, fullscreen, sizeof(fullscreen) / sizeof(*fullscreen));
+ assert(yasl_surface_state(&surface.base) ==
+ (YASL_STATE_CSD | YASL_STATE_FULLSCREEN | YASL_STATE_ACTIVATED));
+ assert(notifications.count == 6);
+ return 0;
+}