2 #include "mockclient.h"
3 #include "mockcompositor.h"
4 #include <libds-tizen/input_method.h>
5 #include <input-method-client-protocol.h>
7 #define INPUT_METHOD_VERSION 1
9 class MockInputMethodMgrCompositor : public MockCompositor
12 MockInputMethodMgrCompositor()
13 : MockCompositor(&MockInputMethodMgrCompositor::TestSetup, this)
15 ds_inf("%s : this(%p)", __func__, this);
17 // initialize the flags to check
20 bSetTransientFor = false;
25 ~MockInputMethodMgrCompositor()
27 ds_inf("%s : this(%p)", __func__, this);
30 static void TestSetup(void *data)
32 MockInputMethodMgrCompositor *mockComp =
33 static_cast<MockInputMethodMgrCompositor *>(data);
34 Compositor *comp = mockComp->compositor;
36 ds_inf("%s: mockComp(%p)", __func__, mockComp);
38 mockComp->mInputMethodMgr = ds_tizen_input_method_manager_create(comp->display);
41 mockComp->mDestroyListener.notify =
42 MockInputMethodMgrCompositor::DestroyCallback;
43 mockComp->mDestroyListener.parent = mockComp;
44 ds_tizen_input_method_manager_add_destroy_listener(mockComp->mInputMethodMgr,
45 &mockComp->mDestroyListener);
47 // set_transient_for listener
48 mockComp->mSetTransientForListener.notify =
49 MockInputMethodMgrCompositor::SetTransientForCallback;
50 mockComp->mSetTransientForListener.parent = mockComp;
51 ds_tizen_input_method_manager_add_set_transient_for_listener(mockComp->mInputMethodMgr,
52 &mockComp->mSetTransientForListener);
55 static void DestroyCallback(struct wl_listener *listener, void *data)
57 ds_inf("%s", __func__);
59 MockInputMethodMgrCompositor *mockComp =
60 reinterpret_cast<DestroyListener *>(listener)->parent;
62 mockComp->bDestroyed = true;
65 static void SetTransientForCallback(struct wl_listener *listener, void *data)
67 struct ds_tizen_input_method_manager_event_set_transient_for *event =
68 (struct ds_tizen_input_method_manager_event_set_transient_for *)data;
70 ds_inf("%s", __func__);
72 MockInputMethodMgrCompositor *mockComp =
73 reinterpret_cast<SetTransientForListener *>(listener)->parent;
75 mockComp->bSetTransientFor = true;
76 mockComp->mParentPid = event->pid_parent;
77 mockComp->mChildPid = event->pid_child;
82 bool bSetTransientFor;
87 struct ds_tizen_input_method_manager *mInputMethodMgr;
88 struct DestroyListener: ::wl_listener {
89 MockInputMethodMgrCompositor *parent;
91 DestroyListener mDestroyListener;
93 struct SetTransientForListener: ::wl_listener {
94 MockInputMethodMgrCompositor *parent;
96 SetTransientForListener mSetTransientForListener;
99 class MockInputMethodMgrClient : public MockClient
102 MockInputMethodMgrClient()
104 compositor_res(nullptr),
105 zwp_input_method_manager(nullptr)
108 MockInputMethodMgrClient(const struct wl_registry_listener *listener)
109 : MockClient(listener, this)
111 ds_inf("%s", __func__);
114 ~MockInputMethodMgrClient()
116 ds_inf("%s", __func__);
119 void SetWlCompositor(struct wl_compositor *global_res)
121 ds_inf("%s", __func__);
123 compositor_res = global_res;
126 struct wl_compositor *GetWlCompositor()
128 ds_inf("%s", __func__);
130 return compositor_res;
133 void SetInputMethodMgr(struct zwp_input_method_manager_v1 *global_res)
135 ds_inf("%s", __func__);
136 zwp_input_method_manager = global_res;
139 struct zwp_input_method_manager_v1 *GetInputMethodMgr()
141 ds_inf("%s", __func__);
143 return zwp_input_method_manager;
150 struct wl_compositor *compositor_res;
151 struct zwp_input_method_manager_v1 *zwp_input_method_manager;
155 client_registry_cb_global(void *data, struct wl_registry *registry,
156 uint32_t name, const char *interface, uint32_t version)
158 ds_inf("%s", __func__);
160 MockInputMethodMgrClient *client = static_cast<MockInputMethodMgrClient *>(data);
161 struct wl_compositor *compositor_res;
162 struct zwp_input_method_manager_v1 *zwp_input_method_manager;
164 if (!strcmp(interface, "wl_compositor")) {
165 compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
166 name, &wl_compositor_interface, 1);
167 if (compositor_res == nullptr) {
168 ds_err("wl_registry_bind() failed. wl_compositor resource.");
171 client->SetWlCompositor(compositor_res);
172 } else if (!strcmp(interface, "zwp_input_method_manager_v1")) {
173 zwp_input_method_manager = (struct zwp_input_method_manager_v1 *)wl_registry_bind(registry,
174 name, &zwp_input_method_manager_v1_interface, INPUT_METHOD_VERSION);
175 if (zwp_input_method_manager == nullptr) {
176 ds_err("wl_registry_bind() failed. zwp_input_method_manager_v1 resource.");
179 client->SetInputMethodMgr(zwp_input_method_manager);
184 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
187 ds_inf("%s", __func__);
189 MockInputMethodMgrClient *client = static_cast<MockInputMethodMgrClient *>(data);
190 struct wl_compositor *compositor_res = client->GetWlCompositor();
191 struct zwp_input_method_manager_v1 *input_method_mgr_res = client->GetInputMethodMgr();
193 zwp_input_method_manager_v1_destroy(input_method_mgr_res);
194 wl_compositor_destroy(compositor_res);
197 static const struct wl_registry_listener registry_listener = {
198 .global = client_registry_cb_global,
199 .global_remove = client_registry_cb_global_remove
202 class InputMethodMgrTest : public ::testing::Test
205 void SetUp(void) override;
206 void TearDown(void) override;
208 MockInputMethodMgrCompositor *comp;
209 MockInputMethodMgrClient *client;
210 struct wl_compositor *compositor_res;
211 struct zwp_input_method_manager_v1 *input_method_mgr_res;
215 InputMethodMgrTest::SetUp(void)
217 ds_log_init(DS_INF, NULL);
219 ds_inf("%s", __func__);
221 comp = new MockInputMethodMgrCompositor();
222 client = new MockInputMethodMgrClient(®istry_listener);
223 compositor_res = client->GetWlCompositor();
224 input_method_mgr_res = client->GetInputMethodMgr();
230 InputMethodMgrTest::TearDown(void)
232 ds_inf("%s", __func__);
240 TEST_F(InputMethodMgrTest, Create_P)
245 TEST_F(InputMethodMgrTest, Req_SetTransientFor)
247 uint32_t parent_pid = 123;
248 uint32_t child_pid = 321;
250 zwp_input_method_manager_v1_set_transient_for(input_method_mgr_res, parent_pid, child_pid);
252 EXPECT_TRUE(comp->mParentPid == parent_pid);
253 EXPECT_TRUE(comp->mChildPid == child_pid);