blob: 0b1e144f93182a24e5b8ce26dddebf08da96eb02 [file] [log] [blame]
Pekka Paalanen46804ca2015-03-27 11:55:21 +02001/*
2 * Copyright © 2013 DENSO CORPORATION
3 * Copyright © 2015 Collabora, Ltd.
4 *
Bryce Harrington2cc92972015-06-11 15:39:40 -07005 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
Pekka Paalanen46804ca2015-03-27 11:55:21 +020012 *
Bryce Harrington2cc92972015-06-11 15:39:40 -070013 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
21 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
22 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
Pekka Paalanen46804ca2015-03-27 11:55:21 +020025 */
26
27#include "config.h"
28
29#include <unistd.h>
30#include <signal.h>
31#include <string.h>
32#include <stdbool.h>
33
34#include "../src/compositor.h"
35#include "../ivi-shell/ivi-layout-export.h"
36
37struct test_context {
38 struct weston_compositor *compositor;
39 const struct ivi_controller_interface *controller_interface;
40};
41
42static void
43iassert_fail(const char *cond, const char *file, int line,
44 const char *func, struct test_context *ctx)
45{
46 weston_log("Assert failure in %s:%d, %s: '%s'\n",
47 file, line, func, cond);
48 weston_compositor_exit_with_code(ctx->compositor, EXIT_FAILURE);
49}
50
51#define iassert(cond) ({ \
52 bool b_ = (cond); \
53 if (!b_) \
54 iassert_fail(#cond, __FILE__, __LINE__, __func__, ctx); \
55 b_; \
56})
57
58/************************ tests begin ******************************/
59
60/*
61 * These are all internal ivi_layout API tests that do not require
62 * any client objects.
63 */
64
65static void
66test_surface_bad_visibility(struct test_context *ctx)
67{
68 const struct ivi_controller_interface *ctl = ctx->controller_interface;
69 bool visibility;
70
71 iassert(ctl->surface_set_visibility(NULL, true) == IVI_FAILED);
72
73 ctl->commit_changes();
74
75 visibility = ctl->surface_get_visibility(NULL);
76 iassert(visibility == false);
77}
78
79/************************ tests end ********************************/
80
81static void
82run_internal_tests(void *data)
83{
84 struct test_context *ctx = data;
85
86 test_surface_bad_visibility(ctx);
87
88 weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS);
89 free(ctx);
90}
91
92int
93controller_module_init(struct weston_compositor *compositor,
94 int *argc, char *argv[],
95 const struct ivi_controller_interface *iface,
96 size_t iface_version);
97
98WL_EXPORT int
99controller_module_init(struct weston_compositor *compositor,
100 int *argc, char *argv[],
101 const struct ivi_controller_interface *iface,
102 size_t iface_version)
103{
104 struct wl_event_loop *loop;
105 struct test_context *ctx;
106
107 /* strict check, since this is an internal test module */
108 if (iface_version != sizeof(*iface)) {
109 weston_log("fatal: controller interface mismatch\n");
110 return -1;
111 }
112
113 ctx = zalloc(sizeof(*ctx));
114 if (!ctx)
115 return -1;
116
117 ctx->compositor = compositor;
118 ctx->controller_interface = iface;
119
120 loop = wl_display_get_event_loop(compositor->wl_display);
121 wl_event_loop_add_idle(loop, run_internal_tests, ctx);
122
123 return 0;
124}