• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <libweston/libweston.h>
31 #include "compositor/weston.h"
32 #include <libweston/plugin-registry.h>
33 
34 #include "weston-test-runner.h"
35 #include "weston-test-fixture-compositor.h"
36 
37 static enum test_result_code
fixture_setup(struct weston_test_harness * harness)38 fixture_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 }
46 DECLARE_FIXTURE_SETUP(fixture_setup);
47 
48 static void
dummy_func(void)49 dummy_func(void)
50 {
51 }
52 
53 static 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 
65 static void
init_tests(struct weston_compositor * compositor)66 init_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 
PLUGIN_TEST(plugin_registry_test)84 PLUGIN_TEST(plugin_registry_test)
85 {
86 	/* struct weston_compositor *compositor; */
87 	const struct my_api *api;
88 	size_t sz = sizeof(struct my_api);
89 
90 	init_tests(compositor);
91 
92 	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);
102 }
103