2 #include "mockclient.h"
3 #include "mockcompositor.h"
4 #include <libds-tizen/input_method.h>
5 #include <input-method-server-protocol.h>
6 #include <input-method-client-protocol.h>
8 #define INPUT_METHOD_VERSION 1
10 class MockInputMethodCompositor : public MockCompositor
13 MockInputMethodCompositor()
14 : MockCompositor(&MockInputMethodCompositor::TestSetup, this)
16 ds_inf("%s : this(%p)", __func__, this);
18 // initialize the flags to check
20 bNewInputMethodContext = false;
23 ~MockInputMethodCompositor()
25 ds_inf("%s : this(%p)", __func__, this);
28 static void TestSetup(void *data)
30 MockInputMethodCompositor *mockComp =
31 static_cast<MockInputMethodCompositor *>(data);
32 Compositor *comp = mockComp->compositor;
34 ds_inf("%s: mockComp(%p)", __func__, mockComp);
36 mockComp->mInputMethod = ds_tizen_input_method_create(comp->display);
39 mockComp->mDestroyListener.notify =
40 MockInputMethodCompositor::DestroyCallback;
41 mockComp->mDestroyListener.parent = mockComp;
42 ds_tizen_input_method_add_destroy_listener(mockComp->mInputMethod,
43 &mockComp->mDestroyListener);
45 // new input method context listener
46 mockComp->mNewInputMethodContextListener.notify =
47 MockInputMethodCompositor::NewInputMethodContextCallback;
48 mockComp->mNewInputMethodContextListener.parent = mockComp;
49 ds_tizen_input_method_add_new_input_method_context_listener(mockComp->mInputMethod,
50 &mockComp->mNewInputMethodContextListener);
53 static void DestroyCallback(struct wl_listener *listener, void *data)
55 ds_inf("%s", __func__);
57 MockInputMethodCompositor *mockComp =
58 reinterpret_cast<DestroyListener *>(listener)->parent;
60 mockComp->bDestroyed = true;
63 static void NewInputMethodContextCallback(struct wl_listener *listener, void *data)
65 ds_inf("%s", __func__);
67 MockInputMethodCompositor *mockComp =
68 reinterpret_cast<NewInputMethodContextListener *>(listener)->parent;
69 struct ds_tizen_input_method_context *context =
70 static_cast<struct ds_tizen_input_method_context *>(data);
72 ds_inf("%s: mockComp(%p), input_method_context(%p)", __func__, mockComp, context);
74 mockComp->mInputMethodContext = context;
75 mockComp->bNewInputMethodContext = true;
78 void CreateInputMethodContext()
80 ds_inf("%s", __func__);
82 ds_tizen_input_method_create_context(mInputMethod);
87 ds_inf("%s", __func__);
89 ds_tizen_input_method_send_activate(mInputMethod, mInputMethodContext);
94 ds_inf("%s", __func__);
96 ds_tizen_input_method_send_deactivate(mInputMethod, mInputMethodContext);
101 bool bNewInputMethodContext;
104 struct ds_tizen_input_method_manager *mInputMethodMgr;
105 struct ds_tizen_input_method *mInputMethod;
106 struct ds_tizen_input_method_context *mInputMethodContext;
108 struct DestroyListener: ::wl_listener {
109 MockInputMethodCompositor *parent;
111 DestroyListener mDestroyListener;
113 struct NewInputMethodContextListener: ::wl_listener {
114 MockInputMethodCompositor *parent;
116 NewInputMethodContextListener mNewInputMethodContextListener;
119 class MockInputMethodClient : public MockClient
122 MockInputMethodClient()
125 compositor_res(nullptr),
126 zwp_input_method(nullptr)
129 MockInputMethodClient(const struct wl_registry_listener *listener)
130 : MockClient(listener, this)
132 ds_inf("%s", __func__);
135 ~MockInputMethodClient()
137 ds_inf("%s", __func__);
140 void SetWlCompositor(struct wl_compositor *global_res)
142 ds_inf("%s", __func__);
144 compositor_res = global_res;
147 struct wl_compositor *GetWlCompositor()
149 ds_inf("%s", __func__);
151 return compositor_res;
154 void SetInputMethod(struct zwp_input_method_v1 *global_res)
156 ds_inf("%s", __func__);
157 zwp_input_method = global_res;
160 struct zwp_input_method_v1 *GetInputMethod()
162 ds_inf("%s", __func__);
164 return zwp_input_method;
172 struct wl_compositor *compositor_res;
173 struct zwp_input_method_v1 *zwp_input_method;
177 client_registry_cb_global(void *data, struct wl_registry *registry,
178 uint32_t name, const char *interface, uint32_t version)
180 ds_inf("%s", __func__);
182 MockInputMethodClient *client = static_cast<MockInputMethodClient *>(data);
183 struct wl_compositor *compositor_res;
184 struct zwp_input_method_v1 *zwp_input_method;
186 if (!strcmp(interface, "wl_compositor")) {
187 compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
188 name, &wl_compositor_interface, 1);
189 if (compositor_res == nullptr) {
190 ds_err("wl_registry_bind() failed. wl_compositor resource.");
193 client->SetWlCompositor(compositor_res);
194 } else if (!strcmp(interface, "zwp_input_method_v1")) {
195 zwp_input_method = (struct zwp_input_method_v1 *)wl_registry_bind(registry,
196 name, &zwp_input_method_v1_interface, INPUT_METHOD_VERSION);
197 if (zwp_input_method == nullptr) {
198 ds_err("wl_registry_bind() failed. zwp_input_method_v1 resource.");
201 client->SetInputMethod(zwp_input_method);
206 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
209 ds_inf("%s", __func__);
211 MockInputMethodClient *client = static_cast<MockInputMethodClient *>(data);
212 struct wl_compositor *compositor_res = client->GetWlCompositor();
213 struct zwp_input_method_v1 *input_method_res = client->GetInputMethod();
215 zwp_input_method_v1_destroy(input_method_res);
216 wl_compositor_destroy(compositor_res);
219 static const struct wl_registry_listener registry_listener = {
220 .global = client_registry_cb_global,
221 .global_remove = client_registry_cb_global_remove
225 im_cb_activate (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
227 ds_inf("%s", __func__);
229 MockInputMethodClient *client = static_cast<MockInputMethodClient *>(data);
230 client->bActivate = true;
233 im_cb_deactivate (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
235 ds_inf("%s", __func__);
237 MockInputMethodClient *client = static_cast<MockInputMethodClient *>(data);
238 client->bDeactivate = true;
241 im_cb_destroy (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
244 im_cb_show_input_panel (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx, uint32_t angle)
247 im_cb_hide_input_panel (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
250 im_cb_open_connection (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
253 im_cb_close_connection (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx)
256 im_cb_set_text_input_id (void *data, struct zwp_input_method_v1 *input_method, struct zwp_input_method_context_v1 *im_ctx, uint32_t text_input_id)
258 static const struct zwp_input_method_v1_listener input_method_cb_listener = {
259 .activate = im_cb_activate,
260 .deactivate = im_cb_deactivate,
262 .destroy = im_cb_destroy,
263 .show_input_panel = im_cb_show_input_panel,
264 .hide_input_panel = im_cb_hide_input_panel,
265 .open_connection = im_cb_open_connection,
266 .close_connection = im_cb_close_connection,
267 .set_text_input_id = im_cb_set_text_input_id,
270 class InputMethodTest : public ::testing::Test
273 void SetUp(void) override;
274 void TearDown(void) override;
276 MockInputMethodCompositor *comp;
277 MockInputMethodClient *client;
278 struct wl_compositor *compositor_res;
279 struct zwp_input_method_v1 *input_method_res;
283 InputMethodTest::SetUp(void)
285 ds_log_init(DS_INF, NULL);
287 ds_inf("%s", __func__);
289 comp = new MockInputMethodCompositor();
290 client = new MockInputMethodClient(®istry_listener);
291 compositor_res = client->GetWlCompositor();
292 input_method_res = client->GetInputMethod();
294 zwp_input_method_v1_add_listener(input_method_res,
295 &input_method_cb_listener, client);
301 InputMethodTest::TearDown(void)
303 ds_inf("%s", __func__);
311 TEST_F(InputMethodTest, Create_P)
316 TEST_F(InputMethodTest, CreateInputMethodContext)
318 comp->CreateInputMethodContext();
321 EXPECT_TRUE(comp->bNewInputMethodContext);
324 TEST_F(InputMethodTest, Ev_Activate)
326 comp->CreateInputMethodContext();
329 comp->SendActivate();
333 EXPECT_TRUE(client->bActivate);
336 TEST_F(InputMethodTest, Ev_Deactivate)
338 comp->CreateInputMethodContext();
341 comp->SendDeactivate();
345 EXPECT_TRUE(client->bDeactivate);