summaryrefslogtreecommitdiffstats
path: root/src/tests/test-interfaces.c
blob: 86f772fc77c29c0c111f5abfac64c49cf9d4ad4b (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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/* PipeWire
 *
 * Copyright © 2019 Wim Taymans
 *
 * 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 <pipewire/pipewire.h>

#define TEST_FUNC(a,b,func)	\
do {				\
	a.func = b.func;	\
	spa_assert_se(SPA_PTRDIFF(&a.func, &a) == SPA_PTRDIFF(&b.func, &b)); \
} while(0)

static void test_core_abi(void)
{
	static const struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_core_events *events,
			void *data);
		int (*hello) (void *object, uint32_t version);
		int (*sync) (void *object, uint32_t id, int seq);
		int (*pong) (void *object, uint32_t id, int seq);
		int (*error) (void *object, uint32_t id, int seq, int res, const char *error);
		struct pw_registry * (*get_registry) (void *object,
				uint32_t version, size_t user_data_size);
		void * (*create_object) (void *object,
				       const char *factory_name,
				       const char *type,
				       uint32_t version,
				       const struct spa_dict *props,
				       size_t user_data_size);
		int (*destroy) (void *object, void *proxy);
	} methods = { PW_VERSION_CORE_METHODS, };
	static const struct {
		uint32_t version;
		void (*info) (void *data, const struct pw_core_info *info);
		void (*done) (void *data, uint32_t id, int seq);
		void (*ping) (void *data, uint32_t id, int seq);
		void (*error) (void *data, uint32_t id, int seq, int res, const char *error);
		void (*remove_id) (void *data, uint32_t id);
		void (*bound_id) (void *data, uint32_t id, uint32_t global_id);
		void (*add_mem) (void *data, uint32_t id, uint32_t type, int fd, uint32_t flags);
		void (*remove_mem) (void *data, uint32_t id);
	} events = { PW_VERSION_CORE_EVENTS, };

	struct pw_core_events e;
	struct pw_core_methods m;

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	TEST_FUNC(m, methods, hello);
	TEST_FUNC(m, methods, sync);
	TEST_FUNC(m, methods, pong);
	TEST_FUNC(m, methods, error);
	TEST_FUNC(m, methods, get_registry);
	TEST_FUNC(m, methods, create_object);
	TEST_FUNC(m, methods, destroy);
	spa_assert_se(PW_VERSION_CORE_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, info);
	TEST_FUNC(e, events, done);
	TEST_FUNC(e, events, ping);
	TEST_FUNC(e, events, error);
	TEST_FUNC(e, events, remove_id);
	TEST_FUNC(e, events, bound_id);
	TEST_FUNC(e, events, add_mem);
	TEST_FUNC(e, events, remove_mem);
	spa_assert_se(PW_VERSION_CORE_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

static void test_registry_abi(void)
{
	struct pw_registry_methods m;
	struct pw_registry_events e;
	struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_registry_events *events,
			void *data);
		void * (*bind) (void *object, uint32_t id, const char *type, uint32_t version,
				size_t user_data_size);
		int (*destroy) (void *object, uint32_t id);
	} methods = { PW_VERSION_REGISTRY_METHODS, };
	struct {
		uint32_t version;
		void (*global) (void *data, uint32_t id,
			uint32_t permissions, const char *type, uint32_t version,
			const struct spa_dict *props);
		void (*global_remove) (void *data, uint32_t id);
	} events = { PW_VERSION_REGISTRY_EVENTS, };

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	TEST_FUNC(m, methods, bind);
	TEST_FUNC(m, methods, destroy);
	spa_assert_se(PW_VERSION_REGISTRY_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, global);
	TEST_FUNC(e, events, global_remove);
	spa_assert_se(PW_VERSION_REGISTRY_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

static void test_module_abi(void)
{
	struct pw_module_methods m;
	struct pw_module_events e;
	struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_module_events *events,
			void *data);
	} methods = { PW_VERSION_MODULE_METHODS, };
	struct {
		uint32_t version;
		void (*info) (void *data, const struct pw_module_info *info);
	} events = { PW_VERSION_MODULE_EVENTS, };

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	spa_assert_se(PW_VERSION_MODULE_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, info);
	spa_assert_se(PW_VERSION_MODULE_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

static void test_device_abi(void)
{
	struct pw_device_methods m;
	struct pw_device_events e;
	struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_device_events *events,
			void *data);
		int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids);
		int (*enum_params) (void *object, int seq, uint32_t id,
			uint32_t start, uint32_t num,
			const struct spa_pod *filter);
		int (*set_param) (void *object, uint32_t id, uint32_t flags,
			const struct spa_pod *param);
	} methods = { PW_VERSION_DEVICE_METHODS, };
	struct {
		uint32_t version;
		void (*info) (void *data, const struct pw_device_info *info);
		void (*param) (void *data, int seq,
			uint32_t id, uint32_t index, uint32_t next,
			const struct spa_pod *param);
	} events = { PW_VERSION_DEVICE_EVENTS, };

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	TEST_FUNC(m, methods, subscribe_params);
	TEST_FUNC(m, methods, enum_params);
	TEST_FUNC(m, methods, set_param);
	spa_assert_se(PW_VERSION_DEVICE_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, info);
	TEST_FUNC(e, events, param);
	spa_assert_se(PW_VERSION_DEVICE_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

static void test_node_abi(void)
{
	struct pw_node_methods m;
	struct pw_node_events e;
	struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_node_events *events,
			void *data);
		int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids);
		int (*enum_params) (void *object, int seq, uint32_t id,
			uint32_t start, uint32_t num, const struct spa_pod *filter);
		int (*set_param) (void *object, uint32_t id, uint32_t flags,
			const struct spa_pod *param);
		int (*send_command) (void *object, const struct spa_command *command);
	} methods = { PW_VERSION_NODE_METHODS, };
	struct {
		uint32_t version;
		void (*info) (void *data, const struct pw_node_info *info);
		void (*param) (void *data, int seq,
			uint32_t id, uint32_t index, uint32_t next,
			const struct spa_pod *param);
	} events = { PW_VERSION_NODE_EVENTS, };

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	TEST_FUNC(m, methods, subscribe_params);
	TEST_FUNC(m, methods, enum_params);
	TEST_FUNC(m, methods, set_param);
	TEST_FUNC(m, methods, send_command);
	spa_assert_se(PW_VERSION_NODE_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, info);
	TEST_FUNC(e, events, param);
	spa_assert_se(PW_VERSION_NODE_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

static void test_port_abi(void)
{
	struct pw_port_methods m;
	struct pw_port_events e;
	struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_port_events *events,
			void *data);
		int (*subscribe_params) (void *object, uint32_t *ids, uint32_t n_ids);
		int (*enum_params) (void *object, int seq, uint32_t id,
			uint32_t start, uint32_t num, const struct spa_pod *filter);
	} methods = { PW_VERSION_PORT_METHODS, };
	struct {
		uint32_t version;
		void (*info) (void *data, const struct pw_port_info *info);
		void (*param) (void *data, int seq,
			uint32_t id, uint32_t index, uint32_t next,
			const struct spa_pod *param);
	} events = { PW_VERSION_PORT_EVENTS, };

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	TEST_FUNC(m, methods, enum_params);
	spa_assert_se(PW_VERSION_PORT_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, info);
	TEST_FUNC(e, events, param);
	spa_assert_se(PW_VERSION_PORT_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

static void test_factory_abi(void)
{
	struct pw_factory_methods m;
	struct pw_factory_events e;
	struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_factory_events *events,
			void *data);
	} methods = { PW_VERSION_FACTORY_METHODS, };
	struct {
		uint32_t version;
		void (*info) (void *data, const struct pw_factory_info *info);
	} events = { PW_VERSION_FACTORY_EVENTS, };

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	spa_assert_se(PW_VERSION_FACTORY_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, info);
	spa_assert_se(PW_VERSION_FACTORY_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

static void test_client_abi(void)
{
	struct pw_client_methods m;
	struct pw_client_events e;
	struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_client_events *events,
			void *data);
		int (*error) (void *object, uint32_t id, int res, const char *error);
		int (*update_properties) (void *object, const struct spa_dict *props);
		int (*get_permissions) (void *object, uint32_t index, uint32_t num);
		int (*update_permissions) (void *object, uint32_t n_permissions,
			const struct pw_permission *permissions);
	} methods = { PW_VERSION_CLIENT_METHODS, };
	struct {
		uint32_t version;
		void (*info) (void *data, const struct pw_client_info *info);
		void (*permissions) (void *data, uint32_t index,
			uint32_t n_permissions, const struct pw_permission *permissions);
	} events = { PW_VERSION_CLIENT_EVENTS, };

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	TEST_FUNC(m, methods, error);
	TEST_FUNC(m, methods, update_properties);
	TEST_FUNC(m, methods, get_permissions);
	TEST_FUNC(m, methods, update_permissions);
	spa_assert_se(PW_VERSION_CLIENT_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, info);
	TEST_FUNC(e, events, permissions);
	spa_assert_se(PW_VERSION_CLIENT_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

static void test_link_abi(void)
{
	struct pw_link_methods m;
	struct pw_link_events e;
	struct {
		uint32_t version;
		int (*add_listener) (void *object,
			struct spa_hook *listener,
			const struct pw_link_events *events,
			void *data);
	} methods = { PW_VERSION_LINK_METHODS, };
	struct {
		uint32_t version;
		void (*info) (void *data, const struct pw_link_info *info);
	} events = { PW_VERSION_LINK_EVENTS, };

	TEST_FUNC(m, methods, version);
	TEST_FUNC(m, methods, add_listener);
	spa_assert_se(PW_VERSION_LINK_METHODS == 0);
	spa_assert_se(sizeof(m) == sizeof(methods));

	TEST_FUNC(e, events, version);
	TEST_FUNC(e, events, info);
	spa_assert_se(PW_VERSION_LINK_EVENTS == 0);
	spa_assert_se(sizeof(e) == sizeof(events));
}

int main(int argc, char *argv[])
{
	pw_init(&argc, &argv);

	test_core_abi();
	test_registry_abi();
	test_module_abi();
	test_device_abi();
	test_node_abi();
	test_port_abi();
	test_factory_abi();
	test_client_abi();
	test_link_abi();

	return 0;
}