Pekka Paalanen | 46804ca | 2015-03-27 11:55:21 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2013 DENSO CORPORATION |
| 3 | * Copyright © 2015 Collabora, Ltd. |
| 4 | * |
| 5 | * Permission to use, copy, modify, distribute, and sell this software and |
| 6 | * its documentation for any purpose is hereby granted without fee, provided |
| 7 | * that the above copyright notice appear in all copies and that both that |
| 8 | * copyright notice and this permission notice appear in supporting |
| 9 | * documentation, and that the name of the copyright holders not be used in |
| 10 | * advertising or publicity pertaining to distribution of the software |
| 11 | * without specific, written prior permission. The copyright holders make |
| 12 | * no representations about the suitability of this software for any |
| 13 | * purpose. It is provided "as is" without express or implied warranty. |
| 14 | * |
| 15 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 16 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 18 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 19 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 20 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 21 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #include "config.h" |
| 25 | |
| 26 | #include <unistd.h> |
| 27 | #include <signal.h> |
| 28 | #include <string.h> |
| 29 | #include <stdbool.h> |
| 30 | |
| 31 | #include "../src/compositor.h" |
| 32 | #include "../ivi-shell/ivi-layout-export.h" |
| 33 | |
| 34 | struct test_context { |
| 35 | struct weston_compositor *compositor; |
| 36 | const struct ivi_controller_interface *controller_interface; |
| 37 | }; |
| 38 | |
| 39 | static void |
| 40 | iassert_fail(const char *cond, const char *file, int line, |
| 41 | const char *func, struct test_context *ctx) |
| 42 | { |
| 43 | weston_log("Assert failure in %s:%d, %s: '%s'\n", |
| 44 | file, line, func, cond); |
| 45 | weston_compositor_exit_with_code(ctx->compositor, EXIT_FAILURE); |
| 46 | } |
| 47 | |
| 48 | #define iassert(cond) ({ \ |
| 49 | bool b_ = (cond); \ |
| 50 | if (!b_) \ |
| 51 | iassert_fail(#cond, __FILE__, __LINE__, __func__, ctx); \ |
| 52 | b_; \ |
| 53 | }) |
| 54 | |
| 55 | /************************ tests begin ******************************/ |
| 56 | |
| 57 | /* |
| 58 | * These are all internal ivi_layout API tests that do not require |
| 59 | * any client objects. |
| 60 | */ |
| 61 | |
| 62 | static void |
| 63 | test_surface_bad_visibility(struct test_context *ctx) |
| 64 | { |
| 65 | const struct ivi_controller_interface *ctl = ctx->controller_interface; |
| 66 | bool visibility; |
| 67 | |
| 68 | iassert(ctl->surface_set_visibility(NULL, true) == IVI_FAILED); |
| 69 | |
| 70 | ctl->commit_changes(); |
| 71 | |
| 72 | visibility = ctl->surface_get_visibility(NULL); |
| 73 | iassert(visibility == false); |
| 74 | } |
| 75 | |
| 76 | /************************ tests end ********************************/ |
| 77 | |
| 78 | static void |
| 79 | run_internal_tests(void *data) |
| 80 | { |
| 81 | struct test_context *ctx = data; |
| 82 | |
| 83 | test_surface_bad_visibility(ctx); |
| 84 | |
| 85 | weston_compositor_exit_with_code(ctx->compositor, EXIT_SUCCESS); |
| 86 | free(ctx); |
| 87 | } |
| 88 | |
| 89 | int |
| 90 | controller_module_init(struct weston_compositor *compositor, |
| 91 | int *argc, char *argv[], |
| 92 | const struct ivi_controller_interface *iface, |
| 93 | size_t iface_version); |
| 94 | |
| 95 | WL_EXPORT int |
| 96 | controller_module_init(struct weston_compositor *compositor, |
| 97 | int *argc, char *argv[], |
| 98 | const struct ivi_controller_interface *iface, |
| 99 | size_t iface_version) |
| 100 | { |
| 101 | struct wl_event_loop *loop; |
| 102 | struct test_context *ctx; |
| 103 | |
| 104 | /* strict check, since this is an internal test module */ |
| 105 | if (iface_version != sizeof(*iface)) { |
| 106 | weston_log("fatal: controller interface mismatch\n"); |
| 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | ctx = zalloc(sizeof(*ctx)); |
| 111 | if (!ctx) |
| 112 | return -1; |
| 113 | |
| 114 | ctx->compositor = compositor; |
| 115 | ctx->controller_interface = iface; |
| 116 | |
| 117 | loop = wl_display_get_event_loop(compositor->wl_display); |
| 118 | wl_event_loop_add_idle(loop, run_internal_tests, ctx); |
| 119 | |
| 120 | return 0; |
| 121 | } |