blob: 3b9d6b9bfadd8cd2d7539acd33af788eadcf4de3 [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
Jon Cruz4678bab2015-06-15 15:37:07 -070034#include "src/compositor.h"
35#include "ivi-shell/ivi-layout-export.h"
Pekka Paalanen46804ca2015-03-27 11:55:21 +020036
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
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +090079static void
80test_surface_bad_destination_rectangle(struct test_context *ctx)
81{
82 const struct ivi_controller_interface *ctl = ctx->controller_interface;
83
84 iassert(ctl->surface_set_destination_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
85}
86
87static void
88test_surface_bad_orientation(struct test_context *ctx)
89{
90 const struct ivi_controller_interface *ctl = ctx->controller_interface;
91
92 iassert(ctl->surface_set_orientation(NULL, WL_OUTPUT_TRANSFORM_90) == IVI_FAILED);
93
94 iassert(ctl->surface_get_orientation(NULL) == WL_OUTPUT_TRANSFORM_NORMAL);
95}
96
97static void
98test_surface_bad_dimension(struct test_context *ctx)
99{
100 const struct ivi_controller_interface *ctl = ctx->controller_interface;
101 struct ivi_layout_surface *ivisurf = NULL;
102 int32_t dest_width;
103 int32_t dest_height;
104
105 iassert(ctl->surface_set_dimension(NULL, 200, 300) == IVI_FAILED);
106
107 ctl->commit_changes();
108
109 iassert(ctl->surface_get_dimension(NULL, &dest_width, &dest_height) == IVI_FAILED);
110 iassert(ctl->surface_get_dimension(ivisurf, NULL, &dest_height) == IVI_FAILED);
111 iassert(ctl->surface_get_dimension(ivisurf, &dest_width, NULL) == IVI_FAILED);
112}
113
114static void
115test_surface_bad_position(struct test_context *ctx)
116{
117 const struct ivi_controller_interface *ctl = ctx->controller_interface;
118 struct ivi_layout_surface *ivisurf = NULL;
119 int32_t dest_x;
120 int32_t dest_y;
121
122 iassert(ctl->surface_set_position(NULL, 20, 30) == IVI_FAILED);
123
124 ctl->commit_changes();
125
126 iassert(ctl->surface_get_position(NULL, &dest_x, &dest_y) == IVI_FAILED);
127 iassert(ctl->surface_get_position(ivisurf, NULL, &dest_y) == IVI_FAILED);
128 iassert(ctl->surface_get_position(ivisurf, &dest_x, NULL) == IVI_FAILED);
129}
130
131static void
132test_surface_bad_source_rectangle(struct test_context *ctx)
133{
134 const struct ivi_controller_interface *ctl = ctx->controller_interface;
135
136 iassert(ctl->surface_set_source_rectangle(NULL, 20, 30, 200, 300) == IVI_FAILED);
137}
138
139static void
140test_surface_bad_properties(struct test_context *ctx)
141{
142 const struct ivi_controller_interface *ctl = ctx->controller_interface;
143
144 iassert(ctl->get_properties_of_surface(NULL) == NULL);
145}
146
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200147/************************ tests end ********************************/
148
149static void
150run_internal_tests(void *data)
151{
152 struct test_context *ctx = data;
153
154 test_surface_bad_visibility(ctx);
Nobuhiko Tanibata16ed5432015-06-22 15:33:59 +0900155 test_surface_bad_destination_rectangle(ctx);
156 test_surface_bad_orientation(ctx);
157 test_surface_bad_dimension(ctx);
158 test_surface_bad_position(ctx);
159 test_surface_bad_source_rectangle(ctx);
160 test_surface_bad_properties(ctx);
Pekka Paalanen46804ca2015-03-27 11:55:21 +0200161
162 weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS);
163 free(ctx);
164}
165
166int
167controller_module_init(struct weston_compositor *compositor,
168 int *argc, char *argv[],
169 const struct ivi_controller_interface *iface,
170 size_t iface_version);
171
172WL_EXPORT int
173controller_module_init(struct weston_compositor *compositor,
174 int *argc, char *argv[],
175 const struct ivi_controller_interface *iface,
176 size_t iface_version)
177{
178 struct wl_event_loop *loop;
179 struct test_context *ctx;
180
181 /* strict check, since this is an internal test module */
182 if (iface_version != sizeof(*iface)) {
183 weston_log("fatal: controller interface mismatch\n");
184 return -1;
185 }
186
187 ctx = zalloc(sizeof(*ctx));
188 if (!ctx)
189 return -1;
190
191 ctx->compositor = compositor;
192 ctx->controller_interface = iface;
193
194 loop = wl_display_get_event_loop(compositor->wl_display);
195 wl_event_loop_add_idle(loop, run_internal_tests, ctx);
196
197 return 0;
198}