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, |
| 37 | const char *text, |
| 38 | uint32_t index) |
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, |
| 45 | const char *text, |
| 46 | uint32_t index) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 47 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 51 | text_model_delete_surrounding_text(void *data, |
| 52 | struct text_model *text_model, |
| 53 | int32_t index, |
| 54 | uint32_t length) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 55 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 59 | text_model_preedit_styling(void *data, |
| 60 | struct text_model *text_model) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 61 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 65 | text_model_modifiers_map(void *data, |
| 66 | struct text_model *text_model, |
| 67 | struct wl_array *map) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 68 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 72 | text_model_keysym(void *data, |
| 73 | struct text_model *text_model, |
| 74 | uint32_t serial, |
| 75 | uint32_t time, |
| 76 | uint32_t sym, |
| 77 | uint32_t state, |
| 78 | uint32_t modifiers) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 79 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 83 | text_model_selection_replacement(void *data, |
| 84 | struct text_model *text_model) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 85 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static void |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 89 | text_model_direction(void *data, |
| 90 | struct text_model *text_model) |
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_locale(void *data, |
| 96 | struct text_model *text_model) |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 97 | { |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 98 | } |
| 99 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 100 | static void |
| 101 | text_model_enter(void *data, |
| 102 | struct text_model *text_model, |
| 103 | struct wl_surface *surface) |
| 104 | |
| 105 | { |
| 106 | struct text_model_state *state = data; |
| 107 | |
| 108 | fprintf(stderr, "%s\n", __FUNCTION__); |
| 109 | |
| 110 | state->activated += 1; |
| 111 | } |
| 112 | |
| 113 | static void |
| 114 | text_model_leave(void *data, |
| 115 | struct text_model *text_model) |
| 116 | { |
| 117 | struct text_model_state *state = data; |
| 118 | |
| 119 | state->deactivated += 1; |
| 120 | } |
| 121 | |
| 122 | static const struct text_model_listener text_model_listener = { |
| 123 | text_model_commit_string, |
| 124 | text_model_preedit_string, |
| 125 | text_model_delete_surrounding_text, |
| 126 | text_model_preedit_styling, |
| 127 | text_model_modifiers_map, |
| 128 | text_model_keysym, |
| 129 | text_model_selection_replacement, |
| 130 | text_model_direction, |
| 131 | text_model_locale, |
| 132 | text_model_enter, |
| 133 | text_model_leave |
| 134 | }; |
| 135 | |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 136 | TEST(text_test) |
| 137 | { |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 138 | struct client *client; |
| 139 | struct global *global; |
| 140 | struct text_model_factory *factory; |
| 141 | struct text_model *text_model; |
| 142 | struct text_model_state state; |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 143 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 144 | client = client_create(100, 100, 100, 100); |
| 145 | assert(client); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 146 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 147 | factory = NULL; |
| 148 | wl_list_for_each(global, &client->global_list, link) { |
| 149 | if (strcmp(global->interface, "text_model_factory") == 0) |
| 150 | factory = wl_registry_bind(client->wl_registry, |
| 151 | global->name, |
| 152 | &text_model_factory_interface, 1); |
| 153 | } |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 154 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 155 | assert(factory); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 156 | |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 157 | memset(&state, 0, sizeof state); |
| 158 | text_model = text_model_factory_create_text_model(factory); |
| 159 | text_model_add_listener(text_model, &text_model_listener, &state); |
| 160 | |
| 161 | /* Make sure our test surface has keyboard focus. */ |
| 162 | wl_test_activate_surface(client->test->wl_test, |
| 163 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame^] | 164 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 165 | assert(client->input->keyboard->focus == client->surface); |
| 166 | |
| 167 | /* Activate test model and make sure we get enter event. */ |
| 168 | text_model_activate(text_model, client->input->wl_seat, |
| 169 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame^] | 170 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 171 | assert(state.activated == 1 && state.deactivated == 0); |
| 172 | |
| 173 | /* Deactivate test model and make sure we get leave event. */ |
| 174 | text_model_deactivate(text_model, client->input->wl_seat); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame^] | 175 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 176 | assert(state.activated == 1 && state.deactivated == 1); |
| 177 | |
| 178 | /* Activate test model again. */ |
| 179 | text_model_activate(text_model, client->input->wl_seat, |
| 180 | client->surface->wl_surface); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame^] | 181 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 182 | assert(state.activated == 2 && state.deactivated == 1); |
| 183 | |
| 184 | /* Take keyboard focus away and verify we get leave event. */ |
| 185 | wl_test_activate_surface(client->test->wl_test, NULL); |
Pekka Paalanen | f2aa64f | 2012-12-12 14:26:41 +0200 | [diff] [blame^] | 186 | client_roundtrip(client); |
Kristian Høgsberg | 1cb3df4 | 2012-12-11 23:03:56 -0500 | [diff] [blame] | 187 | assert(state.activated == 2 && state.deactivated == 2); |
Jan Arne Petersen | b00e663 | 2012-08-21 18:28:49 +0200 | [diff] [blame] | 188 | } |