2 * Copyright (C) 2016 DENSO CORPORATION
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:
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.
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
30 #include "compositor.h"
31 #include "compositor/weston.h"
32 #include "plugin-registry.h"
39 static const struct my_api {
49 #define MY_API_NAME "test_my_api_v1"
52 init_tests(struct weston_compositor *compositor)
54 assert(weston_plugin_api_get(compositor, MY_API_NAME,
55 sizeof(my_test_api)) == NULL);
57 assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api,
58 sizeof(my_test_api)) == 0);
60 assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api,
61 sizeof(my_test_api)) == -2);
63 assert(weston_plugin_api_get(compositor, MY_API_NAME,
64 sizeof(my_test_api)) == &my_test_api);
66 assert(weston_plugin_api_register(compositor, "another", &my_test_api,
67 sizeof(my_test_api)) == 0);
71 runtime_tests(void *data)
73 struct weston_compositor *compositor = data;
74 const struct my_api *api;
75 size_t sz = sizeof(struct my_api);
77 assert(weston_plugin_api_get(compositor, MY_API_NAME, sz) ==
80 assert(weston_plugin_api_get(compositor, MY_API_NAME, sz - 4) ==
83 assert(weston_plugin_api_get(compositor, MY_API_NAME, sz + 4) == NULL);
85 api = weston_plugin_api_get(compositor, MY_API_NAME, sz);
86 assert(api && api->func2 == dummy_func);
88 wl_display_terminate(compositor->wl_display);
92 wet_module_init(struct weston_compositor *compositor,
93 int *argc, char *argv[])
95 struct wl_event_loop *loop;
97 init_tests(compositor);
99 loop = wl_display_get_event_loop(compositor->wl_display);
100 wl_event_loop_add_idle(loop, runtime_tests, compositor);