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 MockInputMethodMgrCompositor : public MockCompositor
13 MockInputMethodMgrCompositor()
14 : MockCompositor(&MockInputMethodMgrCompositor::TestSetup, this)
16 ds_inf("%s : this(%p)", __func__, this);
18 // initialize the flags to check
21 bSetTransientFor = false;
26 ~MockInputMethodMgrCompositor()
28 ds_inf("%s : this(%p)", __func__, this);
31 static void TestSetup(void *data)
33 MockInputMethodMgrCompositor *mockComp =
34 static_cast<MockInputMethodMgrCompositor *>(data);
35 Compositor *comp = mockComp->compositor;
37 ds_inf("%s: mockComp(%p)", __func__, mockComp);
39 mockComp->mInputMethodMgr = ds_tizen_input_method_manager_create(comp->display);
42 mockComp->mDestroyListener.notify =
43 MockInputMethodMgrCompositor::DestroyCallback;
44 mockComp->mDestroyListener.parent = mockComp;
45 ds_tizen_input_method_manager_add_destroy_listener(mockComp->mInputMethodMgr,
46 &mockComp->mDestroyListener);
48 // set_transient_for listener
49 mockComp->mSetTransientForListener.notify =
50 MockInputMethodMgrCompositor::SetTransientForCallback;
51 mockComp->mSetTransientForListener.parent = mockComp;
52 ds_tizen_input_method_manager_add_set_transient_for_listener(mockComp->mInputMethodMgr,
53 &mockComp->mSetTransientForListener);
56 static void DestroyCallback(struct wl_listener *listener, void *data)
58 ds_inf("%s", __func__);
60 MockInputMethodMgrCompositor *mockComp =
61 reinterpret_cast<DestroyListener *>(listener)->parent;
63 mockComp->bDestroyed = true;
66 static void SetTransientForCallback(struct wl_listener *listener, void *data)
68 struct ds_tizen_input_method_manager_event_set_transient_for *event =
69 (struct ds_tizen_input_method_manager_event_set_transient_for *)data;
71 ds_inf("%s", __func__);
73 MockInputMethodMgrCompositor *mockComp =
74 reinterpret_cast<SetTransientForListener *>(listener)->parent;
76 mockComp->bSetTransientFor = true;
77 mockComp->mParentPid = event->pid_parent;
78 mockComp->mChildPid = event->pid_child;
83 bool bSetTransientFor;
88 struct ds_tizen_input_method_manager *mInputMethodMgr;
89 struct DestroyListener: ::wl_listener {
90 MockInputMethodMgrCompositor *parent;
92 DestroyListener mDestroyListener;
94 struct SetTransientForListener: ::wl_listener {
95 MockInputMethodMgrCompositor *parent;
97 SetTransientForListener mSetTransientForListener;
100 class MockInputMethodMgrClient : public MockClient
103 MockInputMethodMgrClient()
105 compositor_res(nullptr),
106 zwp_input_method_manager(nullptr)
109 MockInputMethodMgrClient(const struct wl_registry_listener *listener)
110 : MockClient(listener, this)
112 ds_inf("%s", __func__);
115 ~MockInputMethodMgrClient()
117 ds_inf("%s", __func__);
120 void SetWlCompositor(struct wl_compositor *global_res)
122 ds_inf("%s", __func__);
124 compositor_res = global_res;
127 struct wl_compositor *GetWlCompositor()
129 ds_inf("%s", __func__);
131 return compositor_res;
134 void SetInputMethodMgr(struct zwp_input_method_manager_v1 *global_res)
136 ds_inf("%s", __func__);
137 zwp_input_method_manager = global_res;
140 struct zwp_input_method_manager_v1 *GetInputMethodMgr()
142 ds_inf("%s", __func__);
144 return zwp_input_method_manager;
151 struct wl_compositor *compositor_res;
152 struct zwp_input_method_manager_v1 *zwp_input_method_manager;
156 client_registry_cb_global(void *data, struct wl_registry *registry,
157 uint32_t name, const char *interface, uint32_t version)
159 ds_inf("%s", __func__);
161 MockInputMethodMgrClient *client = static_cast<MockInputMethodMgrClient *>(data);
162 struct wl_compositor *compositor_res;
163 struct zwp_input_method_manager_v1 *zwp_input_method_manager;
165 if (!strcmp(interface, "wl_compositor")) {
166 compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
167 name, &wl_compositor_interface, 1);
168 if (compositor_res == nullptr) {
169 ds_err("wl_registry_bind() failed. wl_compositor resource.");
172 client->SetWlCompositor(compositor_res);
173 } else if (!strcmp(interface, "zwp_input_method_manager_v1")) {
174 zwp_input_method_manager = (struct zwp_input_method_manager_v1 *)wl_registry_bind(registry,
175 name, &zwp_input_method_manager_v1_interface, INPUT_METHOD_VERSION);
176 if (zwp_input_method_manager == nullptr) {
177 ds_err("wl_registry_bind() failed. zwp_input_method_manager_v1 resource.");
180 client->SetInputMethodMgr(zwp_input_method_manager);
185 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
188 ds_inf("%s", __func__);
190 MockInputMethodMgrClient *client = static_cast<MockInputMethodMgrClient *>(data);
191 struct wl_compositor *compositor_res = client->GetWlCompositor();
192 struct zwp_input_method_manager_v1 *input_method_mgr_res = client->GetInputMethodMgr();
194 zwp_input_method_manager_v1_destroy(input_method_mgr_res);
195 wl_compositor_destroy(compositor_res);
198 static const struct wl_registry_listener registry_listener = {
199 .global = client_registry_cb_global,
200 .global_remove = client_registry_cb_global_remove
203 class InputMethodMgrTest : public ::testing::Test
206 void SetUp(void) override;
207 void TearDown(void) override;
209 MockInputMethodMgrCompositor *comp;
210 MockInputMethodMgrClient *client;
211 struct wl_compositor *compositor_res;
212 struct zwp_input_method_manager_v1 *input_method_mgr_res;
216 InputMethodMgrTest::SetUp(void)
218 ds_log_init(DS_INF, NULL);
220 ds_inf("%s", __func__);
222 comp = new MockInputMethodMgrCompositor();
223 client = new MockInputMethodMgrClient(®istry_listener);
224 compositor_res = client->GetWlCompositor();
225 input_method_mgr_res = client->GetInputMethodMgr();
231 InputMethodMgrTest::TearDown(void)
233 ds_inf("%s", __func__);
241 TEST_F(InputMethodMgrTest, Create_P)
246 TEST_F(InputMethodMgrTest, Req_SetTransientFor)
248 uint32_t parent_pid = 123;
249 uint32_t child_pid = 321;
251 zwp_input_method_manager_v1_set_transient_for(input_method_mgr_res, parent_pid, child_pid);
253 EXPECT_TRUE(comp->mParentPid == parent_pid);
254 EXPECT_TRUE(comp->mChildPid == child_pid);