diff options
| author | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 22:12:02 +0300 |
|---|---|---|
| committer | Berke Güzel <wenekar1@gmail.com> | 2026-10-12 22:12:02 +0300 |
| commit | 94c5e361fbb229b0cd6853e2102a7d95f1f358b3 (patch) | |
| tree | 3c0f11af9dcb84dac8067a31a6979acd6dd56fbf /tests/common/test_contracts.c | |
| parent | 08dc9047098d6d96791024ac7d8f5837633673ef (diff) | |
better public interface and doxygen
Diffstat (limited to 'tests/common/test_contracts.c')
| -rw-r--r-- | tests/common/test_contracts.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/common/test_contracts.c b/tests/common/test_contracts.c index 4e22de1..8580dd6 100644 --- a/tests/common/test_contracts.c +++ b/tests/common/test_contracts.c @@ -232,6 +232,97 @@ static void test_scale(void) assert(yasl_scale_to_logical(1, 0) == 0); } +static int popup_calls; +static struct yasl_surface *popup_create(struct yasl_surface *parent, + const struct yasl_popup_spec *spec) +{ + (void)parent; (void)spec; + popup_calls++; + return NULL; /* Backend fails without setting errno. */ +} + +static bool popup_reposition(struct yasl_surface *popup, + const struct yasl_popup_spec *spec) +{ + (void)popup; (void)spec; + popup_calls++; + errno = EBUSY; + return false; +} + +static uint32_t popup_caps(const struct yasl_display *d) +{ (void)d; return YASL_CAP_POPUPS; } + +static int dispatch_failure(struct yasl_display *d, int timeout) +{ (void)d; (void)timeout; return -1; } + +static struct yasl_surface *create_failure(struct yasl_display *d, + const struct yasl_surface_spec *spec, void *device) +{ (void)d; (void)spec; (void)device; return NULL; } + +static int drag_starts; +static bool drag_without_listener(struct yasl_display *d, struct yasl_surface *s, + const struct yasl_drag_image *image, const struct yasl_drag_listener *listener, + void *ud) +{ + (void)d; (void)s; (void)image; (void)ud; + /* Backends may require a table even when no completion callback is needed. */ + assert(listener && !listener->end); + drag_starts++; + return true; +} + +static void test_errors(void) +{ + const struct yasl_backend_ops ops = {.display_caps = popup_caps, + .surface_create_toplevel = create_failure, + .surface_create_popup = popup_create, + .surface_popup_reposition = popup_reposition, + .display_drag_start = drag_without_listener, + .display_dispatch_timeout = dispatch_failure}; + struct yasl_display d = {.ops = &ops}; + struct yasl_surface s = {.display = &d}; + struct yasl_popup_spec spec = {.size = {120, 80}, .anchor = {0, 0, 1, 1}}; + assert(!yasl_surface_create_popup(NULL, &spec) && errno == EINVAL); + assert(!yasl_surface_create_popup(&s, NULL) && errno == EINVAL); + spec.anchor.width = -1; /* Must not reach Wayland's protocol marshaler. */ + assert(!yasl_surface_create_popup(&s, &spec) && errno == EINVAL); + assert(!yasl_surface_popup_reposition(&s, &spec) && errno == EINVAL); + spec.anchor.width = 1; + spec.content_offset.x = INT_MAX; + spec.content_size.x = INT_MAX; + assert(!yasl_surface_create_popup(&s, &spec) && errno == EINVAL); + spec.content_offset.x = spec.content_size.x = 0; + spec.size.x = 32768; + assert(!yasl_surface_create_popup(&s, &spec) && errno == EINVAL); + assert(!popup_calls); + spec.size.x = 120; + errno = ERANGE; + assert(!yasl_surface_create_popup(&s, &spec) && errno == ENODEV); + assert(!yasl_surface_popup_reposition(&s, &spec) && errno == EBUSY); + assert(popup_calls == 2); + const struct yasl_backend_ops unsupported = {0}; + d.ops = &unsupported; + assert(!yasl_surface_create_popup(&s, &spec) && errno == ENOTSUP); + assert(!yasl_surface_popup_reposition(&s, &spec) && errno == ENOTSUP); + assert(yasl_display_dispatch(&d, 0) == -1 && errno == ENOTSUP); + assert(yasl_display_dispatch(NULL, 0) == -1 && errno == EINVAL); + d.ops = &ops; + errno = ERANGE; + assert(yasl_display_dispatch(&d, 0) == -1 && errno == EIO); + struct yasl_surface_spec toplevel = {.size = {120, 80}}; + errno = ERANGE; + assert(!yasl_surface_create_toplevel(&d, &toplevel) && errno == ENODEV); + assert(yasl_display_drag_start(&d, &s, NULL, NULL, NULL)); + struct yasl_drag_image image = {.size = {1, 1}}; + assert(!yasl_display_drag_start(&d, &s, &image, NULL, NULL)); + uint32_t pixel = 0; + image.pixels = &pixel; + image.size.x = INT_MAX; + assert(!yasl_display_drag_start(&d, &s, &image, NULL, NULL)); + assert(drag_starts == 1); +} + int main(void) { test_timing_clock(); @@ -239,5 +330,6 @@ int main(void) test_validation(); test_native(); test_scale(); + test_errors(); return 0; } |
