blob: 85de5f8a2b297e42791c3c31de17fb38255e9476 [file] [log] [blame]
Pekka Paalanen827b5d22016-06-29 11:54:26 +02001/*
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
Pekka Paalanen3d5d9472019-03-28 16:28:47 +020030#include <libweston/libweston.h>
Quentin Glidic3d7ca3b2016-12-02 14:20:35 +010031#include "compositor/weston.h"
Pekka Paalanen27b377f2019-03-29 17:07:34 +020032#include <libweston/plugin-registry.h>
Pekka Paalanen827b5d22016-06-29 11:54:26 +020033
Pekka Paalanenbabb3b32019-11-01 14:02:15 +020034#include "weston-test-runner.h"
35#include "weston-test-fixture-compositor.h"
36
37static enum test_result_code
38fixture_setup(struct weston_test_harness *harness)
39{
40 struct compositor_setup setup;
41
42 compositor_setup_defaults(&setup);
43
44 return weston_test_harness_execute_as_plugin(harness, &setup);
45}
46DECLARE_FIXTURE_SETUP(fixture_setup);
47
Pekka Paalanen827b5d22016-06-29 11:54:26 +020048static void
49dummy_func(void)
50{
51}
52
53static const struct my_api {
54 void (*func1)(void);
55 void (*func2)(void);
56 void (*func3)(void);
57} my_test_api = {
58 dummy_func,
59 dummy_func,
60 dummy_func,
61};
62
63#define MY_API_NAME "test_my_api_v1"
64
65static void
66init_tests(struct weston_compositor *compositor)
67{
68 assert(weston_plugin_api_get(compositor, MY_API_NAME,
69 sizeof(my_test_api)) == NULL);
70
71 assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api,
72 sizeof(my_test_api)) == 0);
73
74 assert(weston_plugin_api_register(compositor, MY_API_NAME, &my_test_api,
75 sizeof(my_test_api)) == -2);
76
77 assert(weston_plugin_api_get(compositor, MY_API_NAME,
78 sizeof(my_test_api)) == &my_test_api);
79
80 assert(weston_plugin_api_register(compositor, "another", &my_test_api,
81 sizeof(my_test_api)) == 0);
82}
83
Pekka Paalanenbabb3b32019-11-01 14:02:15 +020084PLUGIN_TEST(plugin_registry_test)
Pekka Paalanen827b5d22016-06-29 11:54:26 +020085{
Pekka Paalanenbabb3b32019-11-01 14:02:15 +020086 /* struct weston_compositor *compositor; */
Pekka Paalanen827b5d22016-06-29 11:54:26 +020087 const struct my_api *api;
88 size_t sz = sizeof(struct my_api);
89
Pekka Paalanenbabb3b32019-11-01 14:02:15 +020090 init_tests(compositor);
91
Pekka Paalanen827b5d22016-06-29 11:54:26 +020092 assert(weston_plugin_api_get(compositor, MY_API_NAME, sz) ==
93 &my_test_api);
94
95 assert(weston_plugin_api_get(compositor, MY_API_NAME, sz - 4) ==
96 &my_test_api);
97
98 assert(weston_plugin_api_get(compositor, MY_API_NAME, sz + 4) == NULL);
99
100 api = weston_plugin_api_get(compositor, MY_API_NAME, sz);
101 assert(api && api->func2 == dummy_func);
Pekka Paalanen827b5d22016-06-29 11:54:26 +0200102}