summaryrefslogtreecommitdiff
path: root/tests/ivi_layout-test.c
blob: ba0387be68bee9340bca7ed21cc5319a5b1ac79f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/*
 * Copyright © 2015 Collabora, Ltd.
 *
 * 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:
 *
 * 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.
 */

#include "config.h"

#include <stdio.h>
#include <string.h>

#include "shared/helpers.h"
#include "weston-test-client-helper.h"
#include "ivi-application-client-protocol.h"
#include "ivi-test.h"

struct runner {
	struct client *client;
	struct weston_test_runner *test_runner;
	int done;
};

static void
runner_finished_handler(void *data, struct weston_test_runner *test_runner)
{
	struct runner *runner = data;

	runner->done = 1;
}

static const struct weston_test_runner_listener test_runner_listener = {
	runner_finished_handler
};

static struct runner *
client_create_runner(struct client *client)
{
	struct runner *runner;
	struct global *g;
	struct global *global_runner = NULL;

	runner = xzalloc(sizeof(*runner));
	runner->client = client;

	wl_list_for_each(g, &client->global_list, link) {
		if (strcmp(g->interface, "weston_test_runner"))
			continue;

		if (global_runner)
			assert(0 && "multiple weston_test_runner objects");

		global_runner = g;
	}

	assert(global_runner && "no weston_test_runner found");
	assert(global_runner->version == 1);

	runner->test_runner = wl_registry_bind(client->wl_registry,
					       global_runner->name,
					       &weston_test_runner_interface,
					       1);
	assert(runner->test_runner);

	weston_test_runner_add_listener(runner->test_runner,
					&test_runner_listener, runner);

	return runner;
}

static void
runner_destroy(struct runner *runner)
{
	weston_test_runner_destroy(runner->test_runner);
	client_roundtrip(runner->client);
	free(runner);
}

static void
runner_run(struct runner *runner, const char *test_name)
{
	fprintf(stderr, "weston_test_runner.run(\"%s\")\n", test_name);

	runner->done = 0;
	weston_test_runner_run(runner->test_runner, test_name);

	while (!runner->done) {
		if (wl_display_dispatch(runner->client->wl_display) < 0)
			assert(0 && "runner wait");
	}
}

static struct ivi_application *
get_ivi_application(struct client *client)
{
	struct global *g;
	struct global *global_iviapp = NULL;
	static struct ivi_application *iviapp;

	if (iviapp)
		return iviapp;

	wl_list_for_each(g, &client->global_list, link) {
		if (strcmp(g->interface, "ivi_application"))
			continue;

		if (global_iviapp)
			assert(0 && "multiple ivi_application objects");

		global_iviapp = g;
	}

	assert(global_iviapp && "no ivi_application found");

	assert(global_iviapp->version == 1);

	iviapp = wl_registry_bind(client->wl_registry, global_iviapp->name,
				  &ivi_application_interface, 1);
	assert(iviapp);

	return iviapp;
}

struct ivi_window {
	struct wl_surface *wl_surface;
	struct ivi_surface *ivi_surface;
	uint32_t ivi_id;
};

static struct ivi_window *
client_create_ivi_window(struct client *client, uint32_t ivi_id)
{
	struct ivi_application *iviapp;
	struct ivi_window *wnd;

	iviapp = get_ivi_application(client);

	wnd = xzalloc(sizeof(*wnd));
	wnd->wl_surface = wl_compositor_create_surface(client->wl_compositor);
	wnd->ivi_surface = ivi_application_surface_create(iviapp, ivi_id,
							  wnd->wl_surface);
	wnd->ivi_id = ivi_id;

	return wnd;
}

static void
ivi_window_destroy(struct ivi_window *wnd)
{
	ivi_surface_destroy(wnd->ivi_surface);
	wl_surface_destroy(wnd->wl_surface);
	free(wnd);
}

/******************************** tests ********************************/

/*
 * This is a test program, launched by ivi_layout-test-plugin.c. Each TEST()
 * is forked and exec'd as usual with the weston-test-runner framework.
 *
 * These tests make use of weston_test_runner global interface exposed by
 * ivi_layout-test-plugin.c. This allows these tests to trigger compositor-side
 * checks.
 *
 * See ivi_layout-test-plugin.c for further details.
 */

/**
 * RUNNER_TEST() names are defined in ivi_layout-test-plugin.c.
 * Each RUNNER_TEST name listed here uses the same simple initial client setup.
 */
const char * const basic_test_names[] = {
	"surface_visibility",
	"surface_opacity",
	"surface_orientation",
	"surface_dimension",
	"surface_position",
	"surface_destination_rectangle",
	"surface_source_rectangle",
};

TEST_P(ivi_layout_runner, basic_test_names)
{
	/* an element from basic_test_names */
	const char * const *test_name = data;
	struct client *client;
	struct runner *runner;
	struct ivi_window *wnd;

	client = create_client();
	runner = client_create_runner(client);

	wnd = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));

	runner_run(runner, *test_name);

	ivi_window_destroy(wnd);
	runner_destroy(runner);
}

TEST(ivi_layout_surface_create)
{
	struct client *client;
	struct runner *runner;
	struct ivi_window *winds[2];

	client = create_client();
	runner = client_create_runner(client);

	winds[0] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(0));
	winds[1] = client_create_ivi_window(client, IVI_TEST_SURFACE_ID(1));

	runner_run(runner, "surface_create_p1");

	ivi_window_destroy(winds[0]);

	runner_run(runner, "surface_create_p2");

	ivi_window_destroy(winds[1]);
	runner_destroy(runner);
}