Marius Vlad | 9901730 | 2021-12-06 15:27:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2021 Collabora, Ltd. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining |
| 5 | * a copy of this software and associated documentation files (the |
| 6 | * "Software"), to deal in the Software without restriction, including |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, |
| 8 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 9 | * permit persons to whom the Software is furnished to do so, subject to |
| 10 | * the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the |
| 13 | * next paragraph) shall be included in all copies or substantial |
| 14 | * portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 20 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 21 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 22 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | * SOFTWARE. |
| 24 | */ |
| 25 | #include "config.h" |
| 26 | |
| 27 | #include <unistd.h> |
| 28 | #include <assert.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <stdio.h> |
| 31 | |
| 32 | #include "../shared/signal.h" |
| 33 | #include "weston-test-client-helper.h" |
| 34 | |
| 35 | struct test_surface_state { |
| 36 | struct wl_signal signal_destroy; |
| 37 | struct wl_listener surface_destroy_listener; |
| 38 | }; |
| 39 | |
| 40 | static enum test_result_code |
| 41 | fixture_setup(struct weston_test_harness *harness) |
| 42 | { |
| 43 | return weston_test_harness_execute_standalone(harness); |
| 44 | } |
| 45 | |
| 46 | DECLARE_FIXTURE_SETUP(fixture_setup); |
| 47 | |
| 48 | static void |
| 49 | destroy_test_surface(struct test_surface_state *st) |
| 50 | { |
| 51 | weston_signal_emit_mutable(&st->signal_destroy, st); |
| 52 | } |
| 53 | |
| 54 | static void |
| 55 | notify_test_destroy(struct wl_listener *listener, void *data) |
| 56 | { |
| 57 | struct test_surface_state *st = data; |
| 58 | |
| 59 | wl_list_remove(&st->surface_destroy_listener.link); |
| 60 | free(st); |
| 61 | } |
| 62 | |
| 63 | static struct test_surface_state * |
| 64 | create_surface(void) |
| 65 | { |
| 66 | struct test_surface_state *st = zalloc(sizeof(*st)); |
| 67 | |
| 68 | wl_signal_init(&st->signal_destroy); |
| 69 | return st; |
| 70 | } |
| 71 | |
| 72 | static void |
| 73 | add_destroy_listener(struct test_surface_state *st) |
| 74 | { |
| 75 | st->surface_destroy_listener.notify = notify_test_destroy; |
| 76 | wl_signal_add(&st->signal_destroy, |
| 77 | &st->surface_destroy_listener); |
| 78 | } |
| 79 | |
| 80 | TEST(real_usecase_standalone) |
| 81 | { |
| 82 | struct test_surface_state *st, *st_new; |
| 83 | |
| 84 | st = create_surface(); |
| 85 | add_destroy_listener(st); |
| 86 | |
| 87 | st_new = create_surface(); |
| 88 | add_destroy_listener(st_new); |
| 89 | |
| 90 | destroy_test_surface(st); |
| 91 | } |