blob: 0a747307ab979fe902c5b4141d1bbe123a2fb4ac [file] [log] [blame]
Marius Vladee571672021-12-09 13:35:54 +02001/*
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 "../shared/shell-utils.h"
34#include "weston-test-client-helper.h"
35#include "weston-test-fixture-compositor.h"
36
37struct test_output {
38 struct weston_compositor *compositor;
39 struct weston_output *output;
40 struct wl_listener output_destroy_listener;
41 struct weston_view *view;
42};
43
44static enum test_result_code
45fixture_setup(struct weston_test_harness *harness)
46{
47 struct compositor_setup setup;
48
49 compositor_setup_defaults(&setup);
50 setup.shell = SHELL_TEST_DESKTOP;
51
52 return weston_test_harness_execute_as_plugin(harness, &setup);
53}
54
55DECLARE_FIXTURE_SETUP(fixture_setup);
56
57static void
58output_destroy(struct test_output *t_output)
59{
60 t_output->output = NULL;
61 t_output->output_destroy_listener.notify = NULL;
62
63 if (t_output->view)
64 weston_surface_destroy(t_output->view->surface);
65
66 wl_list_remove(&t_output->output_destroy_listener.link);
67 free(t_output);
68}
69
70static void
71notify_output_destroy(struct wl_listener *listener, void *data)
72{
73 struct test_output *t_output =
74 container_of(listener, struct test_output, output_destroy_listener);
75
76 output_destroy(t_output);
77}
78
79static void
80output_create_view(struct test_output *t_output)
81{
82 struct weston_solid_color_surface solid_surface = {};
83
84 solid_surface.r = 0.5;
85 solid_surface.g = 0.5;
86 solid_surface.b = 0.5;
87
88 solid_surface.get_label = NULL;
89 solid_surface.surface_committed = NULL;
90 solid_surface.surface_private = NULL;
91
92 t_output->view =
93 create_solid_color_surface(t_output->compositor,
94 &solid_surface, 0, 0, 320, 240);
95 weston_view_set_output(t_output->view, t_output->output);
96
97 /* weston_compositor_remove_output() has to be patched with
98 * weston_signal_emit_mutable() to avoid signal corruption */
99 weston_output_destroy(t_output->output);
100}
101
102static void
103output_create(struct weston_output *output)
104{
105 struct test_output *t_output;
106
107 t_output = zalloc(sizeof *t_output);
108 if (t_output == NULL)
109 return;
110
111 t_output->output = output;
112 t_output->compositor = output->compositor;
113
114 t_output->output_destroy_listener.notify = notify_output_destroy;
115 wl_signal_add(&t_output->output->destroy_signal,
116 &t_output->output_destroy_listener);
117
118 output_create_view(t_output);
119}
120
121static void
122create_outputs(struct weston_compositor *compositor)
123{
124 struct weston_output *output, *output_next;
125
126 wl_list_for_each_safe(output, output_next, &compositor->output_list, link)
127 output_create(output);
128}
129
130PLUGIN_TEST(real_usecase_one)
131{
132 create_outputs(compositor);
133}