Pekka Paalanen | 46804ca | 2015-03-27 11:55:21 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 DENSO CORPORATION |
| 3 | * Copyright © 2015 Collabora, Ltd. |
| 4 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 5 | * 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 Paalanen | 46804ca | 2015-03-27 11:55:21 +0200 | [diff] [blame] | 12 | * |
Bryce Harrington | 2cc9297 | 2015-06-11 15:39:40 -0700 | [diff] [blame] | 13 | * 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 Paalanen | 46804ca | 2015-03-27 11:55:21 +0200 | [diff] [blame] | 25 | */ |
| 26 | |
| 27 | #include "config.h" |
| 28 | |
| 29 | #include <unistd.h> |
| 30 | #include <signal.h> |
| 31 | #include <string.h> |
| 32 | #include <stdbool.h> |
| 33 | |
Jon Cruz | 4678bab | 2015-06-15 15:37:07 -0700 | [diff] [blame] | 34 | #include "src/compositor.h" |
| 35 | #include "ivi-shell/ivi-layout-export.h" |
Pekka Paalanen | 46804ca | 2015-03-27 11:55:21 +0200 | [diff] [blame] | 36 | |
| 37 | struct test_context { |
| 38 | struct weston_compositor *compositor; |
| 39 | const struct ivi_controller_interface *controller_interface; |
| 40 | }; |
| 41 | |
| 42 | static void |
| 43 | iassert_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 | |
| 65 | static void |
| 66 | test_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 Tanibata | 16ed543 | 2015-06-22 15:33:59 +0900 | [diff] [blame] | 79 | static void |
| 80 | test_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 | |
| 87 | static void |
| 88 | test_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 | |
| 97 | static void |
| 98 | test_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 | |
| 114 | static void |
| 115 | test_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 | |
| 131 | static void |
| 132 | test_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 | |
| 139 | static void |
| 140 | test_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 Paalanen | 46804ca | 2015-03-27 11:55:21 +0200 | [diff] [blame] | 147 | /************************ tests end ********************************/ |
| 148 | |
| 149 | static void |
| 150 | run_internal_tests(void *data) |
| 151 | { |
| 152 | struct test_context *ctx = data; |
| 153 | |
| 154 | test_surface_bad_visibility(ctx); |
Nobuhiko Tanibata | 16ed543 | 2015-06-22 15:33:59 +0900 | [diff] [blame] | 155 | 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 Paalanen | 46804ca | 2015-03-27 11:55:21 +0200 | [diff] [blame] | 161 | |
| 162 | weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS); |
| 163 | free(ctx); |
| 164 | } |
| 165 | |
| 166 | int |
| 167 | controller_module_init(struct weston_compositor *compositor, |
| 168 | int *argc, char *argv[], |
| 169 | const struct ivi_controller_interface *iface, |
| 170 | size_t iface_version); |
| 171 | |
| 172 | WL_EXPORT int |
| 173 | controller_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 | } |