event-test.c 4.78 KB
Newer Older
1 2
/*
 * Copyright © 2012 Intel Corporation
3
 * Copyright © 2013 Collabora, Ltd.
4
 *
5 6 7 8 9 10 11
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
12
 *
13 14 15 16 17 18 19 20 21 22 23 24
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial
 * portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
25 26
 */

27 28
#include "config.h"

29
#include "weston-test-client-helper.h"
Pekka Paalanen's avatar
Pekka Paalanen committed
30 31 32 33 34 35 36 37 38 39 40 41
#include "weston-test-fixture-compositor.h"

static enum test_result_code
fixture_setup(struct weston_test_harness *harness)
{
	struct compositor_setup setup;

	compositor_setup_defaults(&setup);

	return weston_test_harness_execute_as_client(harness, &setup);
}
DECLARE_FIXTURE_SETUP(fixture_setup);
42

43 44 45 46 47
static int
output_contains_client(struct client *client)
{
	struct output *output = client->output;
	struct surface *surface = client->surface;
48

49 50 51 52
	return !(output->x >= surface->x + surface->width
		|| output->x + output->width <= surface->x
		|| output->y >= surface->y + surface->height
		|| output->y + output->height <= surface->y);
53 54
}

55
static void
56
check_client_move(struct client *client, int x, int y)
57
{
58 59 60 61 62 63 64
	move_client(client, x, y);

	if (output_contains_client(client)) {
		assert(client->surface->output == client->output);
	} else {
		assert(client->surface->output == NULL);
	}
65 66
}

67
TEST(test_surface_output)
68
{
69 70 71
	struct client *client;
	int x, y;

72
	client = create_client_and_test_surface(100, 100, 100, 100);
73
	assert(client);
74

75
	assert(output_contains_client(client));
76

77 78 79 80
	/* not visible */
	x = 0;
	y = -client->surface->height;
	check_client_move(client, x, y);
81

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	/* visible */
	check_client_move(client, x, ++y);

	/* not visible */
	x = -client->surface->width;
	y = 0;
	check_client_move(client, x, y);

	/* visible */
	check_client_move(client, ++x, y);

	/* not visible */
	x = client->output->width;
	y = 0;
	check_client_move(client, x, y);

	/* visible */
	check_client_move(client, --x, y);
	assert(output_contains_client(client));

	/* not visible */
	x = 0;
	y = client->output->height;
	check_client_move(client, x, y);
	assert(!output_contains_client(client));

	/* visible */
	check_client_move(client, x, --y);
	assert(output_contains_client(client));
111
}
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128

static void
buffer_release_handler(void *data, struct wl_buffer *buffer)
{
	int *released = data;

	*released = 1;
}

static struct wl_buffer_listener buffer_listener = {
	buffer_release_handler
};

TEST(buffer_release)
{
	struct client *client;
	struct wl_surface *surface;
129 130 131
	struct buffer *buf1;
	struct buffer *buf2;
	struct buffer *buf3;
132 133 134 135 136
	int buf1_released = 0;
	int buf2_released = 0;
	int buf3_released = 0;
	int frame;

137
	client = create_client_and_test_surface(100, 100, 100, 100);
138 139 140
	assert(client);
	surface = client->surface->wl_surface;

141 142
	buf1 = create_shm_buffer_a8r8g8b8(client, 100, 100);
	wl_buffer_add_listener(buf1->proxy, &buffer_listener, &buf1_released);
143

144 145
	buf2 = create_shm_buffer_a8r8g8b8(client, 100, 100);
	wl_buffer_add_listener(buf2->proxy, &buffer_listener, &buf2_released);
146

147 148
	buf3 = create_shm_buffer_a8r8g8b8(client, 100, 100);
	wl_buffer_add_listener(buf3->proxy, &buffer_listener, &buf3_released);
149 150 151 152 153 154

	/*
	 * buf1 must never be released, since it is replaced before
	 * it is committed, therefore it never becomes busy.
	 */

155 156
	wl_surface_attach(surface, buf1->proxy, 0, 0);
	wl_surface_attach(surface, buf2->proxy, 0, 0);
157 158 159 160 161 162 163
	frame_callback_set(surface, &frame);
	wl_surface_commit(surface);
	frame_callback_wait(client, &frame);
	assert(buf1_released == 0);
	/* buf2 may or may not be released */
	assert(buf3_released == 0);

164
	wl_surface_attach(surface, buf3->proxy, 0, 0);
165 166 167 168 169 170 171
	frame_callback_set(surface, &frame);
	wl_surface_commit(surface);
	frame_callback_wait(client, &frame);
	assert(buf1_released == 0);
	assert(buf2_released == 1);
	/* buf3 may or may not be released */

172
	wl_surface_attach(surface, client->surface->buffer->proxy, 0, 0);
173 174 175 176 177 178 179
	frame_callback_set(surface, &frame);
	wl_surface_commit(surface);
	frame_callback_wait(client, &frame);
	assert(buf1_released == 0);
	assert(buf2_released == 1);
	assert(buf3_released == 1);
}