Pekka Paalanen | 827b5d2 | 2016-06-29 11:54:26 +0200 | [diff] [blame^] | 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 "plugin-registry.h" |
| 32 | |
| 33 | static void |
| 34 | dummy_func(void) |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | static const struct my_api { |
| 39 | void (*func1)(void); |
| 40 | void (*func2)(void); |
| 41 | void (*func3)(void); |
| 42 | } my_test_api = { |
| 43 | dummy_func, |
| 44 | dummy_func, |
| 45 | dummy_func, |
| 46 | }; |
| 47 | |
| 48 | #define MY_API_NAME "test_my_api_v1" |
| 49 | |
| 50 | static void |
| 51 | init_tests(struct weston_compositor *compositor) |
| 52 | { |
| 53 | assert(weston_plugin_api_get(compositor, MY_API_NAME, |
| 54 | sizeof(my_test_api)) == NULL); |
| 55 | |
| 56 | assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api, |
| 57 | sizeof(my_test_api)) == 0); |
| 58 | |
| 59 | assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api, |
| 60 | sizeof(my_test_api)) == -2); |
| 61 | |
| 62 | assert(weston_plugin_api_get(compositor, MY_API_NAME, |
| 63 | sizeof(my_test_api)) == &my_test_api); |
| 64 | |
| 65 | assert(weston_plugin_api_register(compositor, "another", &my_test_api, |
| 66 | sizeof(my_test_api)) == 0); |
| 67 | } |
| 68 | |
| 69 | static void |
| 70 | runtime_tests(void *data) |
| 71 | { |
| 72 | struct weston_compositor *compositor = data; |
| 73 | const struct my_api *api; |
| 74 | size_t sz = sizeof(struct my_api); |
| 75 | |
| 76 | assert(weston_plugin_api_get(compositor, MY_API_NAME, sz) == |
| 77 | &my_test_api); |
| 78 | |
| 79 | assert(weston_plugin_api_get(compositor, MY_API_NAME, sz - 4) == |
| 80 | &my_test_api); |
| 81 | |
| 82 | assert(weston_plugin_api_get(compositor, MY_API_NAME, sz + 4) == NULL); |
| 83 | |
| 84 | api = weston_plugin_api_get(compositor, MY_API_NAME, sz); |
| 85 | assert(api && api->func2 == dummy_func); |
| 86 | |
| 87 | wl_display_terminate(compositor->wl_display); |
| 88 | } |
| 89 | |
| 90 | WL_EXPORT int |
| 91 | module_init(struct weston_compositor *compositor, int *argc, char *argv[]) |
| 92 | { |
| 93 | struct wl_event_loop *loop; |
| 94 | |
| 95 | init_tests(compositor); |
| 96 | |
| 97 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 98 | wl_event_loop_add_idle(loop, runtime_tests, compositor); |
| 99 | |
| 100 | return 0; |
| 101 | } |