tests: add test_seat_release() for symmetry
[platform/upstream/weston.git] / tests / plugin-registry-test.c
1 /*
2  * Copyright (C) 2016 DENSO CORPORATION
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
26 #include "config.h"
27
28 #include <assert.h>
29
30 #include "compositor.h"
31 #include "compositor/weston.h"
32 #include "plugin-registry.h"
33
34 static void
35 dummy_func(void)
36 {
37 }
38
39 static const struct my_api {
40         void (*func1)(void);
41         void (*func2)(void);
42         void (*func3)(void);
43 } my_test_api = {
44         dummy_func,
45         dummy_func,
46         dummy_func,
47 };
48
49 #define MY_API_NAME "test_my_api_v1"
50
51 static void
52 init_tests(struct weston_compositor *compositor)
53 {
54         assert(weston_plugin_api_get(compositor, MY_API_NAME,
55                                      sizeof(my_test_api)) == NULL);
56
57         assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api,
58                                           sizeof(my_test_api)) == 0);
59
60         assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api,
61                                           sizeof(my_test_api)) == -2);
62
63         assert(weston_plugin_api_get(compositor, MY_API_NAME,
64                                      sizeof(my_test_api)) == &my_test_api);
65
66         assert(weston_plugin_api_register(compositor, "another", &my_test_api,
67                                           sizeof(my_test_api)) == 0);
68 }
69
70 static void
71 runtime_tests(void *data)
72 {
73         struct weston_compositor *compositor = data;
74         const struct my_api *api;
75         size_t sz = sizeof(struct my_api);
76
77         assert(weston_plugin_api_get(compositor, MY_API_NAME, sz) ==
78                                      &my_test_api);
79
80         assert(weston_plugin_api_get(compositor, MY_API_NAME, sz - 4) ==
81                                      &my_test_api);
82
83         assert(weston_plugin_api_get(compositor, MY_API_NAME, sz + 4) == NULL);
84
85         api = weston_plugin_api_get(compositor, MY_API_NAME, sz);
86         assert(api && api->func2 == dummy_func);
87
88         wl_display_terminate(compositor->wl_display);
89 }
90
91 WL_EXPORT int
92 wet_module_init(struct weston_compositor *compositor,
93                 int *argc, char *argv[])
94 {
95         struct wl_event_loop *loop;
96
97         init_tests(compositor);
98
99         loop = wl_display_get_event_loop(compositor->wl_display);
100         wl_event_loop_add_idle(loop, runtime_tests, compositor);
101
102         return 0;
103 }