change wl_signal_emit_mutable into wl_signal_emit
[platform/core/uifw/libds-tizen.git] / tests / tc_text_input.cpp
1 #include "tc_main.h"
2 #include "mockclient.h"
3 #include "mockcompositor.h"
4 #include <libds-tizen/text_input.h>
5 #include <libds/seat.h>
6 #include <text-server-protocol.h>
7 #include <text-client-protocol.h>
8
9 #define TEXT_INPUT_MGR_VERSION 1
10 #define SEAT_VERSION 7
11
12 class MockTextInputCompositor : public MockCompositor
13 {
14 public:
15     MockTextInputCompositor()
16         : MockCompositor(&MockTextInputCompositor::TestSetup, this)
17     {
18         ds_inf("%s : this(%p)", __func__, this);
19
20         // initialize the flags to check
21         bDestroyed = false;
22         bNewTextInput = false;
23         bActivated = false;
24         bReset = false;;
25         bContentType = false;
26         bInvokeAction = false;
27         bCommitState = false;
28         bPreferredLanguage = false;
29     }
30
31     ~MockTextInputCompositor()
32     {
33         ds_inf("%s : this(%p)", __func__, this);
34     }
35
36     static void TestSetup(void *data)
37     {
38         MockTextInputCompositor *mockComp =
39             static_cast<MockTextInputCompositor *>(data);
40         Compositor *comp = mockComp->compositor;
41
42         ds_inf("%s: mockComp(%p)", __func__, mockComp);
43
44         ds_seat_create(comp->display, "seat0"); //for client to be bound to wl_seat_interface
45
46         mockComp->mTextInputMgr = ds_tizen_text_input_manager_create(comp->display);
47
48         // destroy listener
49         mockComp->mDestroyListener.notify =
50             MockTextInputCompositor::DestroyCallback;
51         mockComp->mDestroyListener.parent = mockComp;
52         ds_tizen_text_input_manager_add_destroy_listener(mockComp->mTextInputMgr,
53             &mockComp->mDestroyListener);
54
55         mockComp->mNewTextInputListener.notify =
56             MockTextInputCompositor::NewTextInputCallback;
57         mockComp->mNewTextInputListener.parent = mockComp;
58         ds_tizen_text_input_manager_add_new_text_input_listener(mockComp->mTextInputMgr,
59             &mockComp->mNewTextInputListener);
60     }
61
62     static void DestroyCallback(struct wl_listener *listener, void *data)
63     {
64         ds_inf("%s", __func__);
65
66         MockTextInputCompositor *mockComp =
67             reinterpret_cast<DestroyListener *>(listener)->parent;
68
69         mockComp->bDestroyed = true;
70     }
71
72     static void NewTextInputCallback(struct wl_listener *listener, void *data)
73     {
74         struct ds_tizen_text_input *text_input = (ds_tizen_text_input *)data;
75         ds_inf("%s", __func__);
76
77         MockTextInputCompositor *mockComp =
78             reinterpret_cast<NewTextInputListener *>(listener)->parent;
79
80         mockComp->bNewTextInput = true;
81         mockComp->mTextInput = text_input;
82
83         mockComp->mActivateListener.notify =
84             MockTextInputCompositor::ActivateCallback;
85         mockComp->mActivateListener.parent = mockComp;
86         ds_tizen_text_input_add_activate_listener(mockComp->mTextInput,
87             &mockComp->mActivateListener);
88
89         mockComp->mDeactivateListener.notify =
90             MockTextInputCompositor::DeactivateCallback;
91         mockComp->mDeactivateListener.parent = mockComp;
92         ds_tizen_text_input_add_deactivate_listener(mockComp->mTextInput,
93             &mockComp->mDeactivateListener);
94
95         mockComp->mResetListener.notify =
96             MockTextInputCompositor::ResetCallback;
97         mockComp->mResetListener.parent = mockComp;
98         ds_tizen_text_input_add_reset_listener(mockComp->mTextInput,
99             &mockComp->mResetListener);
100
101         mockComp->mContentTypeListener.notify =
102             MockTextInputCompositor::ContentTypeCallback;
103         mockComp->mContentTypeListener.parent = mockComp;
104         ds_tizen_text_input_add_set_content_type_listener(mockComp->mTextInput,
105             &mockComp->mContentTypeListener);
106
107         mockComp->mInvokeActionListener.notify =
108             MockTextInputCompositor::InvokeActionCallback;
109         mockComp->mInvokeActionListener.parent = mockComp;
110         ds_tizen_text_input_add_invoke_action_listener(mockComp->mTextInput,
111             &mockComp->mInvokeActionListener);
112
113         mockComp->mCommitStateListener.notify =
114             MockTextInputCompositor::CommitStateCallback;
115         mockComp->mCommitStateListener.parent = mockComp;
116         ds_tizen_text_input_add_commit_state_listener(mockComp->mTextInput,
117             &mockComp->mCommitStateListener);
118
119         mockComp->mPreferredLanguageListener.notify =
120             MockTextInputCompositor::PreferredLanguageCallback;
121         mockComp->mPreferredLanguageListener.parent = mockComp;
122         ds_tizen_text_input_add_set_preferred_language_listener(mockComp->mTextInput,
123             &mockComp->mPreferredLanguageListener);
124     }
125
126     static void ActivateCallback(struct wl_listener *listener, void *data)
127     {
128         struct ds_tizen_text_input_event_activate *event = (struct ds_tizen_text_input_event_activate *)data;
129
130         ds_inf("%s", __func__);
131
132         MockTextInputCompositor *mockComp =
133             reinterpret_cast<ActivateListener *>(listener)->parent;
134
135         mockComp->bActivated = true;
136         mockComp->mSeat = event->seat;
137         mockComp->mSurface = event->surface;
138     }
139
140     static void DeactivateCallback(struct wl_listener *listener, void *data)
141     {
142         struct ds_tizen_text_input_event_deactivate *event = (struct ds_tizen_text_input_event_deactivate *)data;
143
144         ds_inf("%s", __func__);
145
146         MockTextInputCompositor *mockComp =
147             reinterpret_cast<DeactivateListener *>(listener)->parent;
148
149         mockComp->bActivated = false;
150         if (mockComp->mSeat == event->seat)
151             mockComp->mSeat = NULL;
152         mockComp->mSurface = NULL;
153     }
154
155
156     static void ResetCallback(struct wl_listener *listener, void *data)
157     {
158         ds_inf("%s", __func__);
159
160         MockTextInputCompositor *mockComp =
161             reinterpret_cast<DeactivateListener *>(listener)->parent;
162
163         mockComp->bReset = true;
164     }
165
166     static void ContentTypeCallback(struct wl_listener *listener, void *data)
167     {
168         ds_inf("%s", __func__);
169
170         MockTextInputCompositor *mockComp =
171             reinterpret_cast<DeactivateListener *>(listener)->parent;
172
173         mockComp->bContentType = true;
174     }
175
176     static void InvokeActionCallback(struct wl_listener *listener, void *data)
177     {
178         ds_inf("%s", __func__);
179
180         MockTextInputCompositor *mockComp =
181             reinterpret_cast<DeactivateListener *>(listener)->parent;
182
183         mockComp->bInvokeAction = true;
184     }
185
186     static void CommitStateCallback(struct wl_listener *listener, void *data)
187     {
188         ds_inf("%s", __func__);
189
190         MockTextInputCompositor *mockComp =
191             reinterpret_cast<DeactivateListener *>(listener)->parent;
192
193         mockComp->bCommitState = true;
194     }
195
196     static void PreferredLanguageCallback(struct wl_listener *listener, void *data)
197     {
198         ds_inf("%s", __func__);
199
200         MockTextInputCompositor *mockComp =
201             reinterpret_cast<DeactivateListener *>(listener)->parent;
202
203         mockComp->bPreferredLanguage = true;
204     }
205
206     void SendEnter()
207     {
208         ds_inf("%s", __func__);
209
210         ds_tizen_text_input_send_enter(mTextInput, mSurface);
211     }
212     void SendLeave()
213     {
214         ds_inf("%s", __func__);
215
216         ds_tizen_text_input_send_leave(mTextInput);
217     }
218     void SendModifiersMap(struct wl_array *map)
219     {
220         ds_inf("%s", __func__);
221
222         ds_tizen_text_input_send_modifiers_map(mTextInput, map);
223     }
224     void SendInputPanelState(uint32_t state)
225     {
226         ds_inf("%s", __func__);
227
228         ds_tizen_text_input_send_input_panel_state(mTextInput, state);
229     }
230     void SendPreeditString(uint32_t serial, const char *text, const char *commit)
231     {
232         ds_inf("%s", __func__);
233
234         ds_tizen_text_input_send_preedit_string(mTextInput, serial, text, commit);
235     }
236     void SendPreeditStyling(uint32_t index, uint32_t length, uint32_t style)
237     {
238         ds_inf("%s", __func__);
239
240         ds_tizen_text_input_send_preedit_styling(mTextInput, index, length, style);
241     }
242     void SendPreeditCursor(uint32_t index)
243     {
244         ds_inf("%s", __func__);
245
246         ds_tizen_text_input_send_preedit_cursor(mTextInput, index);
247     }
248     void SendCommitString(uint32_t serial, const char *text)
249     {
250         ds_inf("%s", __func__);
251
252         ds_tizen_text_input_send_commit_string(mTextInput, serial, text);
253     }
254     void SendCursorPosition(int32_t index, int32_t anchor)
255     {
256         ds_inf("%s", __func__);
257
258         ds_tizen_text_input_send_cursor_position(mTextInput, index, anchor);
259     }
260     void SendDeleteSurroundingText(int32_t index, uint32_t length)
261     {
262         ds_inf("%s", __func__);
263
264         ds_tizen_text_input_send_delete_surrounding_text(mTextInput, index, length);
265     }
266     void SendKeysym(uint32_t serial, uint32_t time, uint32_t sym, uint32_t state,
267     uint32_t modifiers)
268     {
269         ds_inf("%s", __func__);
270
271         ds_tizen_text_input_send_keysym(mTextInput, serial, time, sym, state, modifiers);
272     }
273     void SendLanguage(uint32_t serial, const char *language)
274     {
275         ds_inf("%s", __func__);
276
277         ds_tizen_text_input_send_language(mTextInput, serial, language);
278     }
279     void SendTextDirection(uint32_t serial, uint32_t direction)
280     {
281         ds_inf("%s", __func__);
282
283         ds_tizen_text_input_send_text_direction(mTextInput, serial, direction);
284     }
285
286 public:
287     bool bDestroyed;
288     bool bNewTextInput;
289     bool bActivated;
290
291     bool bReset;
292     bool bContentType;
293     bool bInvokeAction;
294     bool bCommitState;
295     bool bPreferredLanguage;
296
297     struct ds_seat *mSeat;
298     struct ds_surface *mSurface;
299
300 private:
301     struct ds_tizen_text_input_manager *mTextInputMgr;
302     struct ds_tizen_text_input *mTextInput;
303
304     struct DestroyListener: ::wl_listener {
305         MockTextInputCompositor *parent;
306     };
307     DestroyListener mDestroyListener;
308
309     struct NewTextInputListener: ::wl_listener {
310         MockTextInputCompositor *parent;
311     };
312     NewTextInputListener mNewTextInputListener;
313
314     struct ActivateListener: ::wl_listener {
315         MockTextInputCompositor *parent;
316     };
317     ActivateListener mActivateListener;
318
319     struct DeactivateListener: ::wl_listener {
320         MockTextInputCompositor *parent;
321     };
322     DeactivateListener mDeactivateListener;
323
324     struct ResetListener: ::wl_listener {
325         MockTextInputCompositor *parent;
326     };
327     ResetListener mResetListener;
328
329     struct ContentTypeListener: ::wl_listener {
330         MockTextInputCompositor *parent;
331     };
332     ContentTypeListener mContentTypeListener;
333
334     struct InvokeActionListener: ::wl_listener {
335         MockTextInputCompositor *parent;
336     };
337     InvokeActionListener mInvokeActionListener;
338
339     struct CommitStateListener: ::wl_listener {
340         MockTextInputCompositor *parent;
341     };
342     CommitStateListener mCommitStateListener;
343
344     struct PreferredLanguageListener: ::wl_listener {
345         MockTextInputCompositor *parent;
346     };
347     PreferredLanguageListener mPreferredLanguageListener;
348 };
349
350 class MockTextInputClient : public MockClient
351 {
352 public:
353     MockTextInputClient()
354         : bEnter(false),
355           bLeave(false),
356           bCallback(false),
357           compositor_res(nullptr),
358           wl_text_input_manager(nullptr),
359           wl_seat(nullptr)
360     {}
361
362     MockTextInputClient(const struct wl_registry_listener *listener)
363         : MockClient(listener, this)
364     {
365         ds_inf("%s", __func__);
366     }
367
368     ~MockTextInputClient()
369     {
370         ds_inf("%s", __func__);
371     }
372
373     void SetWlCompositor(struct wl_compositor *global_res)
374     {
375         ds_inf("%s", __func__);
376
377         compositor_res = global_res;
378     }
379
380     struct wl_compositor *GetWlCompositor()
381     {
382         ds_inf("%s", __func__);
383
384         return compositor_res;
385     }
386
387     void SetTextInputMgr(struct wl_text_input_manager *global_res)
388     {
389         ds_inf("%s", __func__);
390         wl_text_input_manager = global_res;
391     }
392
393     struct wl_text_input_manager *GetTextInputMgr()
394     {
395         ds_inf("%s", __func__);
396
397         return wl_text_input_manager;
398     }
399
400     void SetSeat(struct wl_seat *global_res)
401     {
402         ds_inf("%s", __func__);
403         wl_seat = global_res;
404     }
405
406     struct wl_seat *GetSeat()
407     {
408         ds_inf("%s", __func__);
409
410         return wl_seat;
411     }
412
413 public:
414     bool bEnter;
415     bool bLeave;
416     bool bCallback;
417
418 private:
419     struct wl_compositor *compositor_res;
420     struct wl_text_input_manager *wl_text_input_manager;
421     struct wl_seat *wl_seat;
422 };
423
424 static void
425 client_registry_cb_global(void *data, struct wl_registry *registry,
426     uint32_t name, const char *interface, uint32_t version)
427 {
428     ds_inf("%s", __func__);
429
430     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
431     struct wl_compositor *compositor_res;
432     struct wl_text_input_manager *wl_text_input_manager;
433     struct wl_seat *wl_seat;
434
435     if (!strcmp(interface, "wl_compositor")) {
436         compositor_res = (struct wl_compositor *)wl_registry_bind(registry,
437             name, &wl_compositor_interface, 1);
438         if (compositor_res == nullptr) {
439             ds_err("wl_registry_bind() failed. wl_compositor resource.");
440             return;
441         }
442         client->SetWlCompositor(compositor_res);
443     } else if (!strcmp(interface, "wl_text_input_manager")) {
444         wl_text_input_manager = (struct wl_text_input_manager *)wl_registry_bind(registry,
445             name, &wl_text_input_manager_interface, TEXT_INPUT_MGR_VERSION);
446         if (wl_text_input_manager == nullptr) {
447             ds_err("wl_registry_bind() failed. wl_text_input_manager resource.");
448             return;
449         }
450         client->SetTextInputMgr(wl_text_input_manager);
451     } else if (!strcmp(interface, "wl_seat")) {
452         wl_seat = (struct wl_seat *)wl_registry_bind(registry,
453             name, &wl_seat_interface, SEAT_VERSION);
454         if (wl_seat == nullptr) {
455             ds_err("wl_registry_bind() failed. wl_seat resource.");
456             return;
457         }
458         client->SetSeat(wl_seat);
459     }
460 }
461
462 static void
463 client_registry_cb_global_remove(void *data, struct wl_registry *registry,
464     uint32_t name)
465 {
466     ds_inf("%s", __func__);
467
468     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
469     struct wl_compositor *compositor_res = client->GetWlCompositor();
470     struct wl_text_input_manager *text_input_mgr_res = client->GetTextInputMgr();
471     struct wl_seat *seat_res = client->GetSeat();
472
473     wl_seat_destroy(seat_res);
474     wl_text_input_manager_destroy(text_input_mgr_res);
475     wl_compositor_destroy(compositor_res);
476 }
477
478 static const struct wl_registry_listener registry_listener = {
479     .global = client_registry_cb_global,
480     .global_remove = client_registry_cb_global_remove
481 };
482
483 static void
484 text_input_cb_enter(void *data, struct wl_text_input *text_input,
485     struct wl_surface    *surface)
486 {
487     ds_inf("%s", __func__);
488     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
489     client->bEnter = true;
490 }
491 static void
492 text_input_cb_leave(void *data, struct wl_text_input *text_input)
493 {
494     ds_inf("%s", __func__);
495     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
496     client->bLeave = true;
497 }
498 static void
499 text_input_cb_modifiers_map(void *data, struct wl_text_input *text_input,
500     struct wl_array *map)
501 {
502     ds_inf("%s", __func__);
503     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
504     client->bCallback = true;
505 }
506 static void
507 text_input_cb_input_panel_state(void *data, struct wl_text_input *text_input,
508     uint32_t state)
509 {
510     ds_inf("%s", __func__);
511     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
512     client->bCallback = true;
513 }
514 static void
515 text_input_cb_preedit_string(void *data, struct wl_text_input *text_input,
516     uint32_t serial, const char *text, const char *commit)
517 {
518     ds_inf("%s", __func__);
519     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
520     client->bCallback = true;
521 }
522 static void
523 text_input_cb_preedit_styling(void *data, struct wl_text_input *text_input,
524     uint32_t index, uint32_t length, uint32_t style)
525 {
526     ds_inf("%s", __func__);
527     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
528     client->bCallback = true;
529 }
530 static void
531 text_input_cb_preedit_cursor(void *data, struct wl_text_input *text_input,
532     int32_t index)
533 {
534     ds_inf("%s", __func__);
535     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
536     client->bCallback = true;
537 }
538 static void
539 text_input_cb_commit_string(void *data, struct wl_text_input *text_input,
540     uint32_t serial, const char *text)
541 {
542     ds_inf("%s", __func__);
543     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
544     client->bCallback = true;
545 }
546 static void
547 text_input_cb_cursor_position(void *data, struct wl_text_input *text_input,
548     int32_t index, int32_t anchor)
549 {
550     ds_inf("%s", __func__);
551     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
552     client->bCallback = true;    
553 }
554 static void
555 text_input_cb_delete_surrounding_text(void *data,
556     struct wl_text_input *text_input, int32_t index, uint32_t length)
557 {
558     ds_inf("%s", __func__);
559     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
560     client->bCallback = true;
561 }
562 static void
563 text_input_cb_keysym(void *data, struct wl_text_input *text_input,
564     uint32_t serial, uint32_t time, uint32_t sym, uint32_t state,
565     uint32_t modifiers)
566 {
567     ds_inf("%s", __func__);
568     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
569     client->bCallback = true;
570 }
571 static void
572 text_input_cb_language(void *data, struct wl_text_input *text_input,
573     uint32_t serial, const char *language)
574 {
575     ds_inf("%s", __func__);
576     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
577     client->bCallback = true;
578 }
579 static void
580 text_input_cb_text_direction(void *data, struct wl_text_input *text_input,
581     uint32_t serial, uint32_t direction)
582 {
583     ds_inf("%s", __func__);
584     MockTextInputClient *client = static_cast<MockTextInputClient *>(data);
585     client->bCallback = true;
586 }
587 //for tizen only
588 static void
589 text_input_cb_selection_region(void                 *data,
590                             struct wl_text_input *text_input,
591                             uint32_t              serial,
592                             int32_t               start,
593                             int32_t               end)
594 {}
595 static void
596 text_input_cb_private_command(void                 *data,
597                            struct wl_text_input *text_input,
598                            uint32_t              serial,
599                            const char           *command)
600 {}
601 static void
602 text_input_cb_input_panel_geometry(void                 *data,
603                                 struct wl_text_input *text_input,
604                                 uint32_t              x,
605                                 uint32_t              y,
606                                 uint32_t              w,
607                                 uint32_t              h)
608 {}
609 static void
610 text_input_cb_input_panel_data(void                 *data,
611                             struct wl_text_input *text_input,
612                             uint32_t              serial,
613                             const char           *input_panel_data,
614                             uint32_t              length)
615 {}
616 static void
617 text_input_cb_get_selection_text (void                 *data,
618                                struct wl_text_input *text_input,
619                                int32_t              fd)
620 {}
621 static void
622 text_input_cb_get_surrounding_text (void                 *data,
623                                  struct wl_text_input *text_input,
624                                  uint32_t              maxlen_before,
625                                  uint32_t              maxlen_after,
626                                  int32_t              fd)
627 {}
628 static void
629 text_input_cb_filter_key_event_done(void                 *data,
630                                  struct wl_text_input *text_input,
631                                  uint32_t              serial,
632                                  uint32_t              state)
633 {}
634 static void
635 text_input_cb_hide_permission(void                 *data,
636                            struct wl_text_input *text_input,
637                            uint32_t              permission)
638 {}
639 static void
640 text_input_cb_recapture_string(void                 *data,
641                             struct wl_text_input *text_input,
642                             uint32_t              serial,
643                             int32_t               index,
644                             uint32_t              length,
645                             const char           *preedit,
646                             const char           *preedit_commit,
647                             const char           *commit)
648 {}
649 static void
650 text_input_cb_input_panel_event(void                 *data,
651                              struct wl_text_input *text_input,
652                              uint32_t              serial,
653                              uint32_t              event_type,
654                              uint32_t              value)
655 {}
656
657 static void
658 text_input_cb_commit_content(void                 *data,
659                           struct wl_text_input *text_input,
660                           uint32_t              serial,
661                           const char           *content,
662                           const char           *description,
663                           const char           *mime_types)
664 {}
665 static const struct wl_text_input_listener text_input_cb_listener =
666 {
667     .enter = text_input_cb_enter,
668     .leave = text_input_cb_leave,
669     .modifiers_map = text_input_cb_modifiers_map,
670     .input_panel_state = text_input_cb_input_panel_state,
671     .preedit_string = text_input_cb_preedit_string,
672     .preedit_styling = text_input_cb_preedit_styling,
673     .preedit_cursor = text_input_cb_preedit_cursor,
674     .commit_string = text_input_cb_commit_string,
675     .cursor_position = text_input_cb_cursor_position,
676     .delete_surrounding_text = text_input_cb_delete_surrounding_text,
677     .keysym = text_input_cb_keysym,
678     .language = text_input_cb_language,
679     .text_direction = text_input_cb_text_direction,
680     //for tizen only
681     .selection_region = text_input_cb_selection_region,
682     .private_command = text_input_cb_private_command,
683     .input_panel_geometry = text_input_cb_input_panel_geometry,
684     .input_panel_data = text_input_cb_input_panel_data,
685     .get_selection_text = text_input_cb_get_selection_text,
686     .get_surrounding_text = text_input_cb_get_surrounding_text,
687     .filter_key_event_done = text_input_cb_filter_key_event_done,
688     .hide_permission = text_input_cb_hide_permission,
689     .recapture_string = text_input_cb_recapture_string,
690     .input_panel_event = text_input_cb_input_panel_event,
691     .commit_content = text_input_cb_commit_content,
692 };
693
694 class TextInputTest : public ::testing::Test
695 {
696 public:
697     void SetUp(void) override;
698     void TearDown(void) override;
699
700     MockTextInputCompositor *comp;
701     MockTextInputClient *client;
702     struct wl_compositor *compositor_res;
703     struct wl_text_input_manager *text_input_mgr_res;
704     struct wl_text_input *text_input_res;
705     struct wl_seat *seat_res;
706 };
707
708 void
709 TextInputTest::SetUp(void)
710 {
711     ds_inf("%s", __func__);
712
713     comp = new MockTextInputCompositor();
714     client = new MockTextInputClient(&registry_listener);
715     compositor_res = client->GetWlCompositor();
716     text_input_mgr_res = client->GetTextInputMgr();
717     seat_res = client->GetSeat();
718
719     text_input_res = wl_text_input_manager_create_text_input(text_input_mgr_res);
720
721     wl_text_input_add_listener(text_input_res,
722         &text_input_cb_listener, client);
723
724     client->RoundTrip();
725 }
726
727 void
728 TextInputTest::TearDown(void)
729 {
730     ds_inf("%s", __func__);
731
732     client->RoundTrip();
733
734     delete client;
735     delete comp;
736 }
737
738 TEST_F(TextInputTest, Create_P)
739 {
740     EXPECT_TRUE(true);
741 }
742
743 TEST_F(TextInputTest, Req_TextInputMgr_CreateTextInput)
744 {
745     EXPECT_TRUE(comp->bNewTextInput);
746     EXPECT_TRUE(text_input_res != NULL);
747 }
748
749 TEST_F(TextInputTest, Req_TextInput_Activate)
750 {
751     struct wl_surface *surface_res;
752
753     surface_res = wl_compositor_create_surface(compositor_res);
754     client->RoundTrip();
755     EXPECT_TRUE(surface_res != NULL);
756     wl_text_input_activate(text_input_res, seat_res, surface_res);
757     client->RoundTrip();
758     EXPECT_TRUE(comp->bActivated);
759     EXPECT_TRUE(comp->mSeat != NULL);
760     EXPECT_TRUE(comp->mSurface != NULL);
761
762     EXPECT_TRUE(client->bEnter);
763 }
764
765 TEST_F(TextInputTest, Req_TextInput_Deactivate)
766 {
767     struct wl_surface *surface_res;
768
769     surface_res = wl_compositor_create_surface(compositor_res);
770     client->RoundTrip();
771     EXPECT_TRUE(surface_res != NULL);
772     wl_text_input_activate(text_input_res, seat_res, surface_res);
773     client->RoundTrip();
774     EXPECT_TRUE(comp->bActivated);
775     EXPECT_TRUE(comp->mSeat != NULL);
776     EXPECT_TRUE(comp->mSurface != NULL);
777
778     EXPECT_TRUE(client->bEnter);
779
780     wl_text_input_deactivate(text_input_res, seat_res);
781     client->RoundTrip();
782     EXPECT_TRUE(comp->bActivated == false);
783     EXPECT_TRUE(comp->mSeat == NULL);
784     EXPECT_TRUE(comp->mSurface == NULL);
785
786     EXPECT_TRUE(client->bLeave);
787 }
788
789 TEST_F(TextInputTest, Req_TextInput_Reset)
790 {
791     wl_text_input_reset(text_input_res);
792     client->RoundTrip();
793     EXPECT_TRUE(comp->bReset);
794 }
795
796 TEST_F(TextInputTest, Req_TextInput_SetContentType)
797 {
798     uint32_t hint = 0, purpose = 0;
799     wl_text_input_set_content_type(text_input_res, hint, purpose);
800     client->RoundTrip();
801     EXPECT_TRUE(comp->bContentType);
802 }
803
804 TEST_F(TextInputTest, Req_TextInput_SetPreferredLanguage)
805 {
806     wl_text_input_set_preferred_language(text_input_res, "en");
807     client->RoundTrip();
808     EXPECT_TRUE(comp->bPreferredLanguage);
809 }
810
811 TEST_F(TextInputTest, Req_TextInput_CommitState)
812 {
813     uint32_t serial = 1;
814
815     wl_text_input_commit_state(text_input_res, serial);
816     client->RoundTrip();
817     EXPECT_TRUE(comp->bCommitState);
818 }
819
820 TEST_F(TextInputTest, Req_TextInput_InvokeAction)
821 {
822     uint32_t button = 0, index = 1;
823     wl_text_input_invoke_action(text_input_res, button, index);
824     client->RoundTrip();
825     EXPECT_TRUE(comp->bInvokeAction);
826 }
827
828 TEST_F(TextInputTest, Ev_TextInput_Enter)
829 {
830     struct wl_surface *surface_res;
831
832     surface_res = wl_compositor_create_surface(compositor_res);
833     client->RoundTrip();
834     EXPECT_TRUE(surface_res != NULL);
835     wl_text_input_activate(text_input_res, seat_res, surface_res);
836     client->RoundTrip();
837
838     EXPECT_TRUE(comp->mSurface != NULL);
839     comp->SendEnter();
840     comp->Process();
841
842     EXPECT_TRUE(client->bEnter);
843 }
844
845 TEST_F(TextInputTest, Ev_TextInput_Leave)
846 {
847     struct wl_surface *surface_res;
848
849     surface_res = wl_compositor_create_surface(compositor_res);
850     client->RoundTrip();
851     EXPECT_TRUE(surface_res != NULL);
852     wl_text_input_activate(text_input_res, seat_res, surface_res);
853     client->RoundTrip();
854
855     EXPECT_TRUE(comp->mSurface != NULL);
856     comp->SendLeave();
857     comp->Process();
858
859     EXPECT_TRUE(client->bLeave);
860 }
861
862 TEST_F(TextInputTest, Ev_TextInput_ModifiersMap)
863 {
864     struct wl_array map_data;
865     int size;
866     void *data;
867     const char *modShift = "Shift", *modControl = "Control", *mod1 = "Mod1";
868
869     wl_array_init(&map_data);
870
871     size = strlen(modShift) + 1;
872     data = wl_array_add(&map_data, size);
873     memcpy(data, modShift, size);
874
875     size = strlen(modControl) + 1;
876     data = wl_array_add(&map_data, size);
877     memcpy(data, modControl, size);
878
879     size = strlen(mod1) + 1;
880     data = wl_array_add(&map_data, size);
881     memcpy(data, mod1, size); 
882
883     comp->SendModifiersMap(&map_data);
884     comp->Process();
885
886     EXPECT_TRUE(client->bCallback);
887 }
888
889 TEST_F(TextInputTest, Ev_TextInput_InputPanelState)
890 {
891     comp->SendInputPanelState(WL_TEXT_INPUT_INPUT_PANEL_STATE_SHOW);
892     comp->Process();
893
894     EXPECT_TRUE(client->bCallback);
895 }
896
897 TEST_F(TextInputTest, Ev_TextInput_PreeditString)
898 {
899     comp->SendPreeditString(1, "", "");
900     comp->Process();
901
902     EXPECT_TRUE(client->bCallback);
903 }
904
905 TEST_F(TextInputTest, Ev_TextInput_PreeditStyling)
906 {
907     comp->SendPreeditStyling(1, 1, 1);
908     comp->Process();
909
910     EXPECT_TRUE(client->bCallback);
911 }
912
913 TEST_F(TextInputTest, Ev_TextInput_PreeditCursor)
914 {
915     comp->SendPreeditCursor(0);
916     comp->Process();
917
918     EXPECT_TRUE(client->bCallback);
919 }
920
921 TEST_F(TextInputTest, Ev_TextInput_CommitString)
922 {
923     comp->SendCommitString(0, "");
924     comp->Process();
925
926     EXPECT_TRUE(client->bCallback);
927 }
928
929 TEST_F(TextInputTest, Ev_TextInput_CursorPosition)
930 {
931     comp->SendCursorPosition(1, 1);
932     comp->Process();
933
934     EXPECT_TRUE(client->bCallback);
935 }
936
937 TEST_F(TextInputTest, Ev_TextInput_DeleteSurroundingText)
938 {
939     comp->SendDeleteSurroundingText(1, 1);
940     comp->Process();
941
942     EXPECT_TRUE(client->bCallback);
943 }
944
945 TEST_F(TextInputTest, Ev_TextInput_Keysym)
946 {
947     comp->SendKeysym(1, 10, 65, 1, 1);
948     comp->Process();
949
950     EXPECT_TRUE(client->bCallback);
951 }
952
953 TEST_F(TextInputTest, Ev_TextInput_Language)
954 {
955     comp->SendLanguage(1, "en_US");
956     comp->Process();
957
958     EXPECT_TRUE(client->bCallback);
959 }
960
961 TEST_F(TextInputTest, Ev_TextInput_TextDirection)
962 {
963     comp->SendTextDirection(1, 1);
964     comp->Process();
965
966     EXPECT_TRUE(client->bCallback);
967 }