Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 1 | /* |
Jan Arne Petersen | 4c26518 | 2012-09-09 23:08:30 +0200 | [diff] [blame] | 2 | * Copyright © 2012 Intel Corporation |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 3 | * |
| 4 | * Permission to use, copy, modify, distribute, and sell this software and |
| 5 | * its documentation for any purpose is hereby granted without fee, provided |
| 6 | * that the above copyright notice appear in all copies and that both that |
| 7 | * copyright notice and this permission notice appear in supporting |
| 8 | * documentation, and that the name of the copyright holders not be used in |
| 9 | * advertising or publicity pertaining to distribution of the software |
| 10 | * without specific, written prior permission. The copyright holders make |
| 11 | * no representations about the suitability of this software for any |
| 12 | * purpose. It is provided "as is" without express or implied warranty. |
| 13 | * |
| 14 | * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS |
| 15 | * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 16 | * FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 17 | * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 18 | * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF |
| 19 | * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 20 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 21 | */ |
| 22 | |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 23 | #include <string.h> |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 24 | #include <stdio.h> |
| 25 | #include <linux/input.h> |
| 26 | #include "weston-test-client-helper.h" |
| 27 | #include "../clients/text-client-protocol.h" |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 28 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 29 | struct text_model_state { |
| 30 | int activated; |
| 31 | int deactivated; |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 32 | }; |
| 33 | |
| 34 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 35 | text_model_commit_string(void *data, |
| 36 | struct text_model *text_model, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 37 | uint32_t serial, |
| 38 | const char *text) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 39 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 43 | text_model_preedit_string(void *data, |
| 44 | struct text_model *text_model, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 45 | uint32_t serial, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 46 | const char *text, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 47 | const char *commit) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 48 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 52 | text_model_delete_surrounding_text(void *data, |
| 53 | struct text_model *text_model, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 54 | uint32_t serial, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 55 | int32_t index, |
| 56 | uint32_t length) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 57 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | static void |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 61 | text_model_cursor_position(void *data, |
| 62 | struct text_model *text_model, |
| 63 | uint32_t serial, |
| 64 | int32_t index, |
| 65 | int32_t anchor) |
| 66 | { |
| 67 | } |
| 68 | |
| 69 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 70 | text_model_preedit_styling(void *data, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 71 | struct text_model *text_model, |
| 72 | uint32_t serial, |
| 73 | uint32_t index, |
| 74 | uint32_t length, |
| 75 | uint32_t style) |
| 76 | { |
| 77 | } |
| 78 | |
| 79 | static void |
| 80 | text_model_preedit_cursor(void *data, |
| 81 | struct text_model *text_model, |
| 82 | uint32_t serial, |
| 83 | int32_t index) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 84 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 88 | text_model_modifiers_map(void *data, |
| 89 | struct text_model *text_model, |
| 90 | struct wl_array *map) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 91 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 95 | text_model_keysym(void *data, |
| 96 | struct text_model *text_model, |
| 97 | uint32_t serial, |
| 98 | uint32_t time, |
| 99 | uint32_t sym, |
| 100 | uint32_t state, |
| 101 | uint32_t modifiers) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 102 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 106 | text_model_enter(void *data, |
| 107 | struct text_model *text_model, |
| 108 | struct wl_surface *surface) |
| 109 | |
| 110 | { |
| 111 | struct text_model_state *state = data; |
| 112 | |
| 113 | fprintf(stderr, "%s\n", __FUNCTION__); |
| 114 | |
| 115 | state->activated += 1; |
| 116 | } |
| 117 | |
| 118 | static void |
| 119 | text_model_leave(void *data, |
| 120 | struct text_model *text_model) |
| 121 | { |
| 122 | struct text_model_state *state = data; |
| 123 | |
| 124 | state->deactivated += 1; |
| 125 | } |
| 126 | |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 127 | static void |
| 128 | text_model_input_panel_state(void *data, |
| 129 | struct text_model *text_model, |
| 130 | uint32_t state) |
| 131 | { |
| 132 | } |
| 133 | |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame^] | 134 | static void |
| 135 | text_model_language(void *data, |
| 136 | struct text_model *text_model, |
| 137 | uint32_t serial, |
| 138 | const char *language) |
| 139 | { |
| 140 | } |
| 141 | |
| 142 | static void |
| 143 | text_model_text_direction(void *data, |
| 144 | struct text_model *text_model, |
| 145 | uint32_t serial, |
| 146 | uint32_t direction) |
| 147 | { |
| 148 | } |
| 149 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 150 | static const struct text_model_listener text_model_listener = { |
| 151 | text_model_commit_string, |
| 152 | text_model_preedit_string, |
| 153 | text_model_delete_surrounding_text, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 154 | text_model_cursor_position, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 155 | text_model_preedit_styling, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 156 | text_model_preedit_cursor, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 157 | text_model_modifiers_map, |
| 158 | text_model_keysym, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 159 | text_model_enter, |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 160 | text_model_leave, |
Jan Arne Petersen | ece6b5a | 2013-04-18 16:47:15 +0200 | [diff] [blame^] | 161 | text_model_input_panel_state, |
| 162 | text_model_language, |
| 163 | text_model_text_direction |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 164 | }; |
| 165 | |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 166 | TEST(text_test) |
| 167 | { |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 168 | struct client *client; |
| 169 | struct global *global; |
| 170 | struct text_model_factory *factory; |
| 171 | struct text_model *text_model; |
| 172 | struct text_model_state state; |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 173 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 174 | client = client_create(100, 100, 100, 100); |
| 175 | assert(client); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 176 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 177 | factory = NULL; |
| 178 | wl_list_for_each(global, &client->global_list, link) { |
| 179 | if (strcmp(global->interface, "text_model_factory") == 0) |
| 180 | factory = wl_registry_bind(client->wl_registry, |
| 181 | global->name, |
| 182 | &text_model_factory_interface, 1); |
| 183 | } |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 184 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 185 | assert(factory); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 186 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 187 | memset(&state, 0, sizeof state); |
| 188 | text_model = text_model_factory_create_text_model(factory); |
| 189 | text_model_add_listener(text_model, &text_model_listener, &state); |
| 190 | |
| 191 | /* Make sure our test surface has keyboard focus. */ |
| 192 | wl_test_activate_surface(client->test->wl_test, |
| 193 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 194 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 195 | assert(client->input->keyboard->focus == client->surface); |
| 196 | |
| 197 | /* Activate test model and make sure we get enter event. */ |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 198 | text_model_activate(text_model, 0, client->input->wl_seat, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 199 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 200 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 201 | assert(state.activated == 1 && state.deactivated == 0); |
| 202 | |
| 203 | /* Deactivate test model and make sure we get leave event. */ |
| 204 | text_model_deactivate(text_model, client->input->wl_seat); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 205 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 206 | assert(state.activated == 1 && state.deactivated == 1); |
| 207 | |
| 208 | /* Activate test model again. */ |
Jan Arne Petersen | d5a97ae | 2013-02-19 19:26:55 +0100 | [diff] [blame] | 209 | text_model_activate(text_model, 0, client->input->wl_seat, |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 210 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 211 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 212 | assert(state.activated == 2 && state.deactivated == 1); |
| 213 | |
| 214 | /* Take keyboard focus away and verify we get leave event. */ |
| 215 | wl_test_activate_surface(client->test->wl_test, NULL); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame] | 216 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 217 | assert(state.activated == 2 && state.deactivated == 2); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 218 | } |