388b264c690ebbce9daede9f3f4049046355755d
[platform/upstream/enlightenment.git] / src / bin / e_test_helper.c
1 #include "e.h"
2 #include "e_test_helper_intern.h"
3 #include "e_policy_wl.h"
4 #include "e_comp_canvas_intern.h"
5 #include "e_comp_intern.h"
6
7 #define BUS "org.enlightenment.wm"
8 #define PATH "/org/enlightenment/wm"
9 #define IFACE "org.enlightenment.wm.Test"
10
11 #define E_TH_SIGN_WIN_INFO  "usiiiiibbbiibibbbi"
12 #define E_TC_TIMEOUT 10.0
13
14 typedef struct _Test_Helper_Reg_Win
15 {
16    Ecore_Window win;
17    E_Client *ec;
18    int vis;
19    Eina_Bool render_send;
20 } Test_Helper_Reg_Win;
21
22
23 typedef struct _Test_Helper_Data
24 {
25    Eldbus_Connection *conn;
26    Eldbus_Service_Interface *iface;
27    Ecore_Event_Handler *dbus_init_done_h;
28
29    Eina_List *hdlrs;
30    Eina_List *hooks;
31    Eina_List *reg_wins;
32
33    Eina_Bool tc_running;
34    Eina_Bool tc_timer_needs;
35    Ecore_Timer *tc_timer;
36 } Test_Helper_Data;
37
38 static Test_Helper_Data *th_data = NULL;
39
40 static Eina_Bool _e_test_helper_cb_property_get(const Eldbus_Service_Interface *iface, const char *name, Eldbus_Message_Iter *iter, const Eldbus_Message *msg, Eldbus_Message **err);
41
42 static Eldbus_Message *_e_test_helper_cb_testcase_start(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
43 static Eldbus_Message *_e_test_helper_cb_testcase_end(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
44 static Eldbus_Message *_e_test_helper_cb_testcase_timeout_set(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
45 static Eldbus_Message *_e_test_helper_cb_register_window(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
46 static Eldbus_Message *_e_test_helper_cb_deregister_window(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
47 static Eldbus_Message *_e_test_helper_cb_reset_register_window(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
48 static Eldbus_Message *_e_test_helper_cb_change_stack(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
49 static Eldbus_Message *_e_test_helper_cb_activate_window(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
50 static Eldbus_Message *_e_test_helper_cb_change_iconic_state(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
51 static Eldbus_Message *_e_test_helper_cb_set_transient_for(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
52 static Eldbus_Message *_e_test_helper_cb_unset_transient_for(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
53 static Eldbus_Message *_e_test_helper_cb_set_transient_for_below(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
54 static Eldbus_Message *_e_test_helper_cb_set_noti_level(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
55 static Eldbus_Message *_e_test_helper_cb_set_focus_skip(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
56 static Eldbus_Message *_e_test_helper_cb_get_client_info(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg);
57 static Eldbus_Message *_e_test_helper_cb_get_clients(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
58 static Eldbus_Message *_e_test_helper_cb_get_noti_level(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
59 static Eldbus_Message *_e_test_helper_cb_dpms(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
60 static Eldbus_Message *_e_test_helper_cb_ev_freeze(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
61 static Eldbus_Message *_e_test_helper_cb_kill_win(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
62 static Eldbus_Message *_e_test_helper_cb_ev_mouse(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
63 static Eldbus_Message *_e_test_helper_cb_ev_key(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
64 static Eldbus_Message *_e_test_helper_cb_hwc(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
65 static Eldbus_Message *_e_test_helper_cb_zone_rot_change(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
66 static Eldbus_Message *_e_test_helper_cb_zone_rot_get(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
67 static Eldbus_Message *_e_test_helper_cb_set_render_condition(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
68 static Eldbus_Message *_e_test_helper_cb_add_supported_aux_hint(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
69 static Eldbus_Message *_e_test_helper_cb_del_supported_aux_hint(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
70 static Eldbus_Message *_e_test_helper_cb_get_aux_hint(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg);
71 static Eina_Bool _e_test_helper_cb_img_render(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
72 static Eina_Bool _e_test_helper_cb_effect_start(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
73 static Eina_Bool _e_test_helper_cb_effect_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event);
74
75 enum
76 {
77    E_TEST_HELPER_SIGNAL_CHANGE_VISIBILITY = 0,
78    E_TEST_HELPER_SIGNAL_RESTACK,
79    E_TEST_HELPER_SIGNAL_WINDOW_ROTATION_CHANGED,
80    E_TEST_HELPER_SIGNAL_FOCUS_CHANGED,
81    E_TEST_HELPER_SIGNAL_RENDER,
82    E_TEST_HELPER_AUX_HINT_CHANGED,
83    E_TEST_HELPER_SIGNAL_ICONIC_STATE_CHANGED,
84 };
85
86 static const Eldbus_Signal signals[] = {
87      [E_TEST_HELPER_SIGNAL_CHANGE_VISIBILITY] =
88        {
89           "VisibilityChanged",
90           ELDBUS_ARGS({"ub", "window id, visibility"}),
91           0
92        },
93      [E_TEST_HELPER_SIGNAL_RESTACK] =
94        {
95           "StackChanged",
96           ELDBUS_ARGS({"u", "window id was restacked"}),
97           0
98        },
99      [E_TEST_HELPER_SIGNAL_WINDOW_ROTATION_CHANGED] =
100        {
101           "WinRotationChanged",
102           ELDBUS_ARGS({"ui", "a window id was rotated to given angle"}),
103           0
104        },
105      [E_TEST_HELPER_SIGNAL_FOCUS_CHANGED] =
106        {
107           "FocusChanged",
108           ELDBUS_ARGS({"ub", "window id, focus state"}),
109           0
110        },
111      [E_TEST_HELPER_SIGNAL_RENDER] =
112        {
113           "RenderRun",
114           ELDBUS_ARGS({"u", "window id for tracing rendering"}),
115           0
116        },
117      [E_TEST_HELPER_AUX_HINT_CHANGED] =
118        {
119           "AuxHintChanged",
120           ELDBUS_ARGS({"uuss", "window id, aux_hint id, aux_hint key, aux_hint value"}),
121           0
122        },
123      [E_TEST_HELPER_SIGNAL_ICONIC_STATE_CHANGED] =
124        {
125           "IconicStateChanged",
126           ELDBUS_ARGS({"ubb", "window id, iconic state"}),
127           0
128        },
129        { }
130 };
131
132 static const Eldbus_Method methods[] ={
133        {
134           "StartTestCase",
135           NULL,
136           ELDBUS_ARGS({"b", "accept or not"}),
137           _e_test_helper_cb_testcase_start, 0
138        },
139        {
140           "EndTestCase",
141           NULL,
142           ELDBUS_ARGS({"b", "accept or not"}),
143           _e_test_helper_cb_testcase_end, 0
144        },
145        {
146           "SetTestTimeout",
147           ELDBUS_ARGS({"bu", "needs timer and time in millisecond"}),
148           ELDBUS_ARGS({"b", "accept or not"}),
149           _e_test_helper_cb_testcase_timeout_set, 0
150        },
151        {
152           "RegisterWindow",
153           ELDBUS_ARGS({"u", "window id to be registered"}),
154           ELDBUS_ARGS({"b", "accept or not"}),
155           _e_test_helper_cb_register_window, 0
156        },
157        {
158           "DeregisterWindow",
159           ELDBUS_ARGS({"u", "window id to be deregistered"}),
160           ELDBUS_ARGS({"b", "accept or not"}),
161           _e_test_helper_cb_deregister_window, 0
162        },
163        {
164           "ResetRegisterWindow",
165           NULL,
166           ELDBUS_ARGS({"b", "accept or not"}),
167           _e_test_helper_cb_reset_register_window, 0
168        },
169        {
170           "SetWindowStack",
171           ELDBUS_ARGS({"uui", "window id to restack, above or below, stacking type"}),
172           NULL,
173           _e_test_helper_cb_change_stack, 0
174        },
175        {
176           "SetWindowActivate",
177           ELDBUS_ARGS({"u", "window id to activate"}),
178           NULL,
179           _e_test_helper_cb_activate_window, 0
180        },
181        {
182           "SetWindowIconify",
183           ELDBUS_ARGS({"ub", "window id to change iconic state, iconify or uniconify"}),
184           NULL,
185           _e_test_helper_cb_change_iconic_state, 0
186        },
187        {
188           "SetWindowTransientFor",
189           ELDBUS_ARGS({"uu", "child window id to set transient_for, parent window id to set transient_for"}),
190           ELDBUS_ARGS({"b", "accept or not"}),
191           _e_test_helper_cb_set_transient_for, 0
192        },
193        {
194           "UnsetWindowTransientFor",
195           ELDBUS_ARGS({"u", "child window id to set transient_for"}),
196           ELDBUS_ARGS({"b", "accept or not"}),
197           _e_test_helper_cb_unset_transient_for, 0
198        },
199        {
200           "SetWindowTransientForBelow",
201           ELDBUS_ARGS({"uub", "child window id to set transient_for, parent window id to set transient_for, set or unset"}),
202           ELDBUS_ARGS({"b", "accept or not"}),
203           _e_test_helper_cb_set_transient_for_below, 0
204        },
205        {
206           "SetWindowNotiLevel",
207           ELDBUS_ARGS({"ui", "window id to set notification level, notification level"}),
208           NULL,
209           _e_test_helper_cb_set_noti_level, 0
210        },
211        {
212           "SetWindowFocusSkip",
213           ELDBUS_ARGS({"ub", "window id to set focus skip, skip set or skip unset"}),
214           NULL,
215           _e_test_helper_cb_set_focus_skip, 0
216        },
217        {
218           "GetWinInfo",
219           ELDBUS_ARGS({"u", "window id"}),
220           ELDBUS_ARGS({E_TH_SIGN_WIN_INFO, "information of ec"}),
221           _e_test_helper_cb_get_client_info, 0
222        },
223        {
224           "GetWinsInfo",
225           NULL,
226           ELDBUS_ARGS({"ua("E_TH_SIGN_WIN_INFO")", "array of ec"}),
227           _e_test_helper_cb_get_clients, 0
228        },
229        {
230           "GetWindowNotiLevel",
231           ELDBUS_ARGS({"u", "window id to get notification level"}),
232           ELDBUS_ARGS({"i", "notification level"}),
233           _e_test_helper_cb_get_noti_level, 0
234        },
235        {
236           "DPMS",
237           ELDBUS_ARGS({"u", "DPMS 0=off or 1=on"}),
238           ELDBUS_ARGS({"b", "accept or not"}),
239           _e_test_helper_cb_dpms, 0
240        },
241        {
242           "EventFreeze",
243           ELDBUS_ARGS({"u", "0=events will start to be processed or 1=freeze input events processing"}),
244           ELDBUS_ARGS({"b", "accept or not"}),
245           _e_test_helper_cb_ev_freeze, 0
246        },
247        {
248           "RequestKillWin",
249           ELDBUS_ARGS({"s", "window name to kill"}),
250           NULL,
251           _e_test_helper_cb_kill_win, 0
252        },
253        {
254           "EventMouse",
255           ELDBUS_ARGS({"uii", "type 0=down 1=move 2=up, x position, y position"}),
256           ELDBUS_ARGS({"b", "accept or not"}),
257           _e_test_helper_cb_ev_mouse, 0
258        },
259        {
260           "EventKey",
261           ELDBUS_ARGS({"us", "type 0=down 1=up, key name"}),
262           ELDBUS_ARGS({"b", "accept or not"}),
263           _e_test_helper_cb_ev_key, 0
264        },
265        {
266           "HWC",
267           ELDBUS_ARGS({"u", "0=off or 1=on"}),
268           ELDBUS_ARGS({"b", "accept or not"}),
269           _e_test_helper_cb_hwc, 0
270        },
271        {
272           "GetCurrentZoneRotation",
273           NULL,
274           ELDBUS_ARGS({"i", "a angle of current zone"}),
275           _e_test_helper_cb_zone_rot_get, 0,
276        },
277        {
278           "ChangeZoneRotation",
279           ELDBUS_ARGS({"i", "(0, 90, 180, 270) = specific angle, -1 = unknown state"}),
280           ELDBUS_ARGS({"b", "accept or not"}),
281           _e_test_helper_cb_zone_rot_change, 0,
282        },
283        {
284           "RenderTrace",
285           ELDBUS_ARGS({"us", "window id and type of rendering to trace"}),
286           ELDBUS_ARGS({"b", "accept or not"}),
287           _e_test_helper_cb_set_render_condition, 0,
288        },
289        {
290           "AddSupportedAuxHint",
291           ELDBUS_ARGS({"s", "Aux hint string to add supported aux hint"}),
292           ELDBUS_ARGS({"b", "accept or not"}),
293           _e_test_helper_cb_add_supported_aux_hint, 0,
294        },
295        {
296           "DelSupportedAuxHint",
297           ELDBUS_ARGS({"s", "Aux hint string to del supported aux hint"}),
298           ELDBUS_ARGS({"b", "accept or not"}),
299           _e_test_helper_cb_del_supported_aux_hint, 0,
300        },
301        {
302           "GetAuxHint",
303           ELDBUS_ARGS({"us", "window id and Aux hint string to get aux hint data"}),
304           ELDBUS_ARGS({"iss", "id, name, value"}),
305           _e_test_helper_cb_get_aux_hint, 0,
306        },
307        { }
308 };
309
310 static const Eldbus_Property properties[] = {
311        { "Registrant", "au", NULL, NULL, 0 },
312        { }
313 };
314
315 static const Eldbus_Service_Interface_Desc iface_desc = {
316      IFACE, methods, signals, properties, _e_test_helper_cb_property_get, NULL
317 };
318
319 static void
320 _e_test_helper_registrant_clear(void)
321 {
322    Test_Helper_Reg_Win *reg_win = NULL;
323
324    EINA_SAFETY_ON_NULL_RETURN(th_data);
325    EINA_SAFETY_ON_NULL_RETURN(th_data->reg_wins);
326
327    EINA_LIST_FREE(th_data->reg_wins, reg_win)
328      {
329         if (reg_win->ec && reg_win->ec->frame)
330           e_comp_object_render_trace_set(reg_win->ec->frame, EINA_FALSE);
331      }
332 }
333
334 static Eina_Bool
335 _e_test_helper_registrant_remove(Ecore_Window target_win)
336 {
337    Test_Helper_Reg_Win *reg_win = NULL;
338    Eina_List *l = NULL, *ll = NULL;
339    Eina_Bool res = EINA_FALSE;
340
341    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, EINA_FALSE);
342    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data->reg_wins, EINA_FALSE);
343
344    EINA_LIST_FOREACH_SAFE(th_data->reg_wins, l, ll, reg_win)
345      {
346         if (reg_win->win == target_win)
347           {
348              if (reg_win->ec && reg_win->ec->frame)
349                e_comp_object_render_trace_set(reg_win->ec->frame, EINA_FALSE);
350              th_data->reg_wins = eina_list_remove(th_data->reg_wins, reg_win);
351              res = EINA_TRUE;
352           }
353      }
354
355    return res;
356 }
357
358 static void
359 _e_test_helper_message_append_client(Eldbus_Message_Iter *iter, E_Client *ec)
360 {
361    eldbus_message_iter_arguments_append
362       (iter, E_TH_SIGN_WIN_INFO,
363        e_pixmap_res_id_get(ec->pixmap),
364        e_client_util_name_get(ec) ?: "NO NAME",
365
366        /* geometry */
367        ec->x, ec->y, ec->w, ec->h,
368
369        /* layer */
370        evas_object_layer_get(ec->frame),
371
372        /* effect */
373        evas_object_data_get(ec->frame, "effect_running"),
374
375        /* visibility & iconify */
376        ec->visible,
377        evas_object_visible_get(ec->frame),
378        ec->visibility.opaque,
379        ec->visibility.obscured,
380        ec->visibility.skip,
381        ec->iconic ? (e_client_is_iconified_by_client(ec) ? 2 : 1) : 0,
382
383        /* color depth */
384        ec->argb,
385
386        /* focus */
387        ec->focused,
388        evas_object_focus_get(ec->frame),
389
390        /* rotation */
391        ec->e.state.rot.ang.curr);
392 }
393
394 static Eina_Bool
395 _e_test_helper_cb_dbus_init_done(void *data EINA_UNUSED, int type, void *event)
396 {
397    E_DBus_Conn_Init_Done_Event *e = event;
398
399    if ((e->status == E_DBUS_CONN_INIT_SUCCESS) && (e->conn_type == ELDBUS_CONNECTION_TYPE_SYSTEM))
400      {
401         th_data->conn = e_dbus_conn_connection_ref(ELDBUS_CONNECTION_TYPE_SYSTEM);
402
403         if (th_data->conn)
404           th_data->iface = eldbus_service_interface_register(th_data->conn, PATH, &iface_desc);
405      }
406
407    ecore_event_handler_del(th_data->dbus_init_done_h);
408    th_data->dbus_init_done_h = NULL;
409
410    return ECORE_CALLBACK_PASS_ON;
411 }
412
413 static void
414 _e_test_helper_message_append_client_info_by_window_id(Eldbus_Message_Iter *iter, Ecore_Window win)
415 {
416    E_Client *ec;
417
418    ec = e_pixmap_find_client_by_res_id(win);
419    if (!ec)
420      return;
421
422    _e_test_helper_message_append_client(iter, ec);
423 }
424
425 static void
426 _e_test_helper_message_append_clients(Eldbus_Message_Iter *iter)
427 {
428    Eldbus_Message_Iter *array_of_ec;
429    E_Client *ec;
430    Evas_Object *o;
431    E_Comp *comp;
432
433    EINA_SAFETY_ON_NULL_RETURN(th_data);
434
435    if (!(comp = e_comp)) return;
436
437    eldbus_message_iter_arguments_append(iter, "a("E_TH_SIGN_WIN_INFO")", &array_of_ec);
438
439    // append clients.
440    for (o = evas_object_top_get(comp->evas); o; o = evas_object_below_get(o))
441      {
442         Eldbus_Message_Iter* struct_of_ec;
443
444         ec = evas_object_data_get(o, "E_Client");
445         if (!ec) continue;
446         if (e_client_util_ignored_get(ec)) continue;
447
448         eldbus_message_iter_arguments_append(array_of_ec, "("E_TH_SIGN_WIN_INFO")", &struct_of_ec);
449         _e_test_helper_message_append_client(struct_of_ec, ec);
450         eldbus_message_iter_container_close(array_of_ec, struct_of_ec);
451      }
452
453    eldbus_message_iter_container_close(iter, array_of_ec);
454 }
455
456 static void
457 _e_test_helper_restack(Ecore_Window win, Ecore_Window target, int above)
458 {
459    E_Client *ec = NULL, *tec = NULL;
460
461    ec = e_pixmap_find_client_by_res_id(win);
462    tec = e_pixmap_find_client_by_res_id(target);
463
464    if (!ec) return;
465
466    if(!tec)
467      {
468         if (above)
469           {
470              if (ec->parent)
471                e_policy_stack_transient_child_raise(ec);
472
473              e_client_raise(ec);
474           }
475         else
476           {
477              if (ec->parent)
478                e_policy_stack_transient_child_lower(ec);
479
480              e_client_lower(ec);
481           }
482      }
483    else
484      {
485
486         if (above)
487           e_client_stack_above(ec, tec);
488         else
489           e_client_stack_below(ec, tec);
490      }
491 }
492
493 static Eina_Bool
494 _e_test_helper_cb_tc_timeout(void *data)
495 {
496    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, ECORE_CALLBACK_DONE);
497
498    th_data->tc_running = EINA_FALSE;
499    _e_test_helper_registrant_clear();
500
501    if (th_data->tc_timer)
502      {
503         ecore_timer_del(th_data->tc_timer);
504         th_data->tc_timer = NULL;
505      }
506
507    return ECORE_CALLBACK_DONE;
508 }
509
510 /* Signal senders */
511 static void
512 _e_test_helper_send_change_visibility(Ecore_Window win, Eina_Bool vis)
513 {
514    Eldbus_Message *signal;
515
516    EINA_SAFETY_ON_NULL_RETURN(th_data);
517
518    signal = eldbus_service_signal_new(th_data->iface,
519                                       E_TEST_HELPER_SIGNAL_CHANGE_VISIBILITY);
520    eldbus_message_arguments_append(signal, "ub", win, vis);
521    eldbus_service_signal_send(th_data->iface, signal);
522 }
523
524 static void
525 _e_test_helper_send_render(Ecore_Window win)
526 {
527    Eldbus_Message *signal;
528
529    EINA_SAFETY_ON_NULL_RETURN(th_data);
530
531    signal = eldbus_service_signal_new(th_data->iface, E_TEST_HELPER_SIGNAL_RENDER);
532    eldbus_message_arguments_append(signal, "u", win);
533    eldbus_service_signal_send(th_data->iface, signal);
534 }
535
536 static void
537 _e_test_helper_send_aux_hint_change(Ecore_Window win, int hint_id, const char *hint_key, const char *hint_val)
538 {
539    Eldbus_Message *signal;
540
541    EINA_SAFETY_ON_NULL_RETURN(th_data);
542
543    signal = eldbus_service_signal_new(th_data->iface, E_TEST_HELPER_AUX_HINT_CHANGED);
544    eldbus_message_arguments_append(signal, "uuss", win, hint_id, hint_key, hint_val);
545    eldbus_service_signal_send(th_data->iface, signal);
546 }
547
548 static Test_Helper_Reg_Win *
549 _e_test_helper_find_win_on_reg_list(Ecore_Window win)
550 {
551    Eina_List *l = NULL;
552    Test_Helper_Reg_Win *reg_win = NULL;
553
554    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, NULL);
555    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data->reg_wins, NULL);
556
557    EINA_LIST_FOREACH(th_data->reg_wins, l, reg_win)
558      {
559         if (reg_win->win == win)
560           return reg_win;
561      }
562
563    return NULL;
564 }
565
566 /* Method Handlers */
567 static Eldbus_Message *
568 _e_test_helper_cb_testcase_start(const Eldbus_Service_Interface *iface EINA_UNUSED,
569                                  const Eldbus_Message *msg)
570 {
571    Eldbus_Message *reply;
572    Eina_Bool res = EINA_FALSE;
573
574    reply = eldbus_message_method_return_new(msg);
575
576    if (th_data)
577      {
578         if (th_data->tc_timer)
579           ecore_timer_del(th_data->tc_timer);
580
581         if (th_data->tc_timer_needs)
582           th_data->tc_timer = ecore_timer_add(E_TC_TIMEOUT, _e_test_helper_cb_tc_timeout, NULL);
583         res = th_data->tc_running = EINA_TRUE;
584      }
585
586    eldbus_message_arguments_append(reply, "b", res);
587
588    return reply;
589 }
590
591 static Eldbus_Message *
592 _e_test_helper_cb_testcase_end(const Eldbus_Service_Interface *iface EINA_UNUSED,
593                                const Eldbus_Message *msg)
594 {
595    Eldbus_Message *reply;
596    Eina_Bool res = EINA_FALSE;
597
598    reply = eldbus_message_method_return_new(msg);
599
600    if (th_data)
601      {
602         if (th_data->tc_timer)
603           {
604              ecore_timer_del(th_data->tc_timer);
605              th_data->tc_timer = NULL;
606           }
607         th_data->tc_running = EINA_FALSE;
608         res = EINA_TRUE;
609      }
610
611    eldbus_message_arguments_append(reply, "b", res);
612
613    return reply;
614 }
615
616 static Eldbus_Message *
617 _e_test_helper_cb_testcase_timeout_set(const Eldbus_Service_Interface *iface EINA_UNUSED,
618                                        const Eldbus_Message *msg)
619 {
620    Eldbus_Message *reply;
621    Eina_Bool res = EINA_FALSE;
622    Eina_Bool set = EINA_TRUE;
623    uint32_t timeout = E_TC_TIMEOUT;
624
625    reply = eldbus_message_method_return_new(msg);
626
627    if (!eldbus_message_arguments_get(msg, "bu", &set, &timeout))
628      {
629         ERR("Error on eldbus_message_arguments_get()\n");
630         goto err;
631      }
632
633    if (th_data)
634      {
635         if (set != th_data->tc_timer_needs)
636           {
637              th_data->tc_timer_needs = set;
638              if (!set)
639                ecore_timer_del(th_data->tc_timer);
640           }
641
642         if (timeout > 0)
643           {
644              if (th_data->tc_timer)
645                ecore_timer_del(th_data->tc_timer);
646
647              if (th_data->tc_timer_needs)
648                th_data->tc_timer = ecore_timer_add(timeout, _e_test_helper_cb_tc_timeout, NULL);
649           }
650         res = EINA_TRUE;
651      }
652
653    eldbus_message_arguments_append(reply, "b", res);
654
655    return reply;
656
657 err:
658    eldbus_message_arguments_append(reply, "b", EINA_FALSE);
659    return reply;
660 }
661
662 static Eldbus_Message *
663 _e_test_helper_cb_register_window(const Eldbus_Service_Interface *iface EINA_UNUSED,
664                                   const Eldbus_Message *msg)
665 {
666    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
667    Ecore_Window id;
668    Test_Helper_Reg_Win *new_win = NULL;
669
670    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
671
672    if (!eldbus_message_arguments_get(msg, "u", &id))
673      {
674         ERR("Error on eldbus_message_arguments_get()\n");
675         goto err;
676      }
677
678    new_win = E_NEW(Test_Helper_Reg_Win, 1);
679    EINA_SAFETY_ON_NULL_GOTO(new_win, err);
680
681    new_win->win = id;
682    new_win->ec = e_pixmap_find_client_by_res_id(id);
683
684    th_data->reg_wins = eina_list_append(th_data->reg_wins, new_win);
685    eldbus_message_arguments_append(reply, "b", EINA_TRUE);
686
687    return reply;
688
689 err:
690    eldbus_message_arguments_append(reply, "b", EINA_FALSE);
691    return reply;
692 }
693
694 static Eldbus_Message *
695 _e_test_helper_cb_dpms(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
696 {
697    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
698    Eina_Bool accept = EINA_FALSE;
699    unsigned int dpms;
700
701    if (!eldbus_message_arguments_get(msg, "u", &dpms))
702      {
703         ERR("Error on eldbus_message_arguments_get()\n");
704         return reply;
705      }
706
707    /* TODO */
708    switch (dpms)
709      {
710       case 0:
711          /* dpms off */
712          accept = EINA_TRUE;
713          break;
714       case 1:
715          /* dpms on */
716          accept = EINA_TRUE;
717          break;
718       default:
719          break;
720      }
721
722    eldbus_message_arguments_append(reply, "b", accept);
723
724    return reply;
725 }
726
727 static Eldbus_Message *
728 _e_test_helper_cb_ev_freeze(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
729 {
730    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
731    Eina_Bool accept = EINA_TRUE;
732    unsigned int freeze;
733
734    if (!eldbus_message_arguments_get(msg, "u", &freeze))
735      {
736         ERR("Error on eldbus_message_arguments_get()\n");
737         return reply;
738      }
739
740    switch (freeze)
741      {
742       case 0: e_comp_all_thaw(); break;
743       case 1: e_comp_all_freeze(); break;
744       default: accept = EINA_FALSE; break;
745      }
746
747    eldbus_message_arguments_append(reply, "b", accept);
748
749    return reply;
750 }
751
752 static Eldbus_Message *
753 _e_test_helper_cb_kill_win(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
754 {
755    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
756    E_Client *ec = NULL;
757    Evas_Object *o = NULL;
758    char *win_name = NULL;
759
760    if (!eldbus_message_arguments_get(msg, "s", &win_name))
761      {
762         ERR("Error on eldbus_message_arguments_get()\n");
763         return reply;
764      }
765
766    for (o = evas_object_top_get(e_comp->evas); o; o = evas_object_below_get(o))
767      {
768         const char *ec_name = NULL;
769         ec = evas_object_data_get(o, "E_Client");
770         if (!ec) continue;
771         if (e_client_util_ignored_get(ec)) continue;
772
773         ec_name = e_client_util_name_get(ec) ?: "NO NAME";
774
775         if (e_util_strcmp(ec_name, win_name)) continue;
776         ELOGF("E_TEST_HELPER", "Window killed by request(ec: %s)", ec, ec? ec->icccm.name : "NO NAME");
777         e_client_act_kill_begin(ec);
778      }
779
780    return reply;
781 }
782
783 static Eldbus_Message *
784 _e_test_helper_cb_ev_mouse(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
785 {
786    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
787    Eina_Bool accept = EINA_TRUE;
788    Ecore_Event_Mouse_Button *ev = NULL;
789    unsigned int type;
790    int x, y;
791
792    if (!eldbus_message_arguments_get(msg, "uii", &type, &x, &y))
793      {
794         ERR("Error on eldbus_message_arguments_get()\n");
795         return reply;
796      }
797
798    ev = E_NEW(Ecore_Event_Mouse_Button, 1);
799    EINA_SAFETY_ON_NULL_RETURN_VAL(ev, reply);
800
801    ev->timestamp = (unsigned int)(ecore_time_unix_get() * (double)1000);
802    ev->same_screen = 1;
803    ev->x = ev->root.x = x;
804    ev->y = ev->root.y = y;
805    ev->buttons = 1;
806
807    switch (type)
808      {
809       case 0: ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); break;
810       case 1: ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL); break;
811       case 2: ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); break;
812       default: accept = EINA_FALSE; break;
813      }
814
815    eldbus_message_arguments_append(reply, "b", accept);
816
817    if (!accept)
818      E_FREE(ev);
819
820    return reply;
821 }
822
823 static int
824 _e_test_helper_key_event_add(char *key_name, unsigned int type)
825 {
826    int res;
827    char *device_identifier = NULL;
828
829    EINA_SAFETY_ON_NULL_RETURN_VAL(key_name, EINA_FALSE);
830    EINA_SAFETY_ON_NULL_RETURN_VAL(e_devicemgr, EINA_FALSE);
831    EINA_SAFETY_ON_NULL_RETURN_VAL(e_devicemgr->last_device_kbd, EINA_FALSE);
832
833    device_identifier = (char *)e_devicemgr->last_device_kbd->identifier;
834
835    EINA_SAFETY_ON_NULL_RETURN_VAL(device_identifier, EINA_FALSE);
836
837    res = e_devicemgr_inputgen_key_event_add(key_name, (Eina_Bool)type, device_identifier);
838
839    if (res)
840      {
841         ERR("[E_Test_Helper] Failed on generating key event ! (key_name=%s, type=%d)\n", key_name, type);
842         return EINA_FALSE;
843      }
844
845    return EINA_TRUE;
846 }
847
848 static Eldbus_Message *
849 _e_test_helper_cb_ev_key(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
850 {
851    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
852    Eina_Bool accept = EINA_FALSE;
853    unsigned int type;
854    char *key;
855
856    if (!eldbus_message_arguments_get(msg, "us", &type, &key))
857      {
858         ERR("Error on eldbus_message_arguments_get()\n");
859         return reply;
860      }
861
862    /* TODO */
863    switch (type)
864      {
865       case 0:
866          /* key down */
867       case 1:
868          /* key up */
869          accept = _e_test_helper_key_event_add(key, type);
870          break;
871       default:
872          break;
873      }
874
875    eldbus_message_arguments_append(reply, "b", accept);
876
877    return reply;
878 }
879
880 static Eldbus_Message *
881 _e_test_helper_cb_hwc(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
882 {
883    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
884    Eina_Bool r, accept = EINA_FALSE;
885    unsigned int on;
886
887    r = eldbus_message_arguments_get(msg, "u", &on);
888    EINA_SAFETY_ON_FALSE_RETURN_VAL(r, reply);
889
890    if (e_comp->hwc)
891      {
892         switch (on)
893           {
894            case 0: accept = EINA_TRUE; e_comp_hwc_deactive_set(EINA_TRUE); break;
895            case 1: accept = EINA_TRUE; e_comp_hwc_deactive_set(EINA_FALSE); break;
896            default: break;
897           }
898      }
899
900    eldbus_message_arguments_append(reply, "b", accept);
901
902    return reply;
903 }
904
905 static void
906 _e_test_helper_event_zone_rot_change_free(void *data EINA_UNUSED, void *event)
907 {
908    E_Event_Info_Rotation_Message *ev = event;
909
910    e_object_unref(E_OBJECT(ev->zone));
911    free(ev);
912 }
913
914
915 static Eldbus_Message *
916 _e_test_helper_cb_zone_rot_change(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
917 {
918    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
919    E_Event_Info_Rotation_Message *ev;
920    E_Zone *zone;
921    Eina_Bool r, accept = EINA_FALSE;
922    int rot;
923
924    r = eldbus_message_arguments_get(msg, "i", &rot);
925    EINA_SAFETY_ON_FALSE_GOTO(r, end);
926
927    if ((rot < 0) || (rot > 270) || ((rot % 90) != 0))
928      goto end;
929
930    zone = e_zone_current_get();
931    if (!zone)
932      goto end;
933
934    ev = E_NEW(E_Event_Info_Rotation_Message, 1);
935    if (EINA_UNLIKELY(!ev))
936      {
937         ERR("Failed to allocate 'E_Event_Info_Rotation_Message'");
938         goto end;
939      }
940
941    e_object_ref(E_OBJECT(zone));
942    ev->zone = zone;
943    ev->message = E_INFO_ROTATION_MESSAGE_SET;
944    ev->rotation = rot;
945    ecore_event_add(E_EVENT_INFO_ROTATION_MESSAGE, ev, _e_test_helper_event_zone_rot_change_free, NULL);
946
947    accept = EINA_TRUE;
948
949 end:
950    eldbus_message_arguments_append(reply, "b", accept);
951
952    return reply;
953 }
954
955 static Eldbus_Message *
956 _e_test_helper_cb_zone_rot_get(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
957 {
958    E_Zone *zone;
959    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
960    Eina_Bool r;
961    int rot = -1;
962
963    r = eldbus_message_arguments_get(msg, "i", &rot);
964    EINA_SAFETY_ON_FALSE_GOTO(r, end);
965
966    if ((rot < 0) || (rot > 270) || ((rot % 90) != 0))
967      goto end;
968
969    zone = e_zone_current_get();
970    if (!zone)
971      goto end;
972
973    eldbus_message_arguments_append(reply, "b", zone->rot.curr);
974 end:
975    return reply;
976 }
977
978 static Eldbus_Message *
979 _e_test_helper_cb_deregister_window(const Eldbus_Service_Interface *iface EINA_UNUSED,
980                                     const Eldbus_Message *msg)
981 {
982    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
983    Ecore_Window id;
984    Eina_Bool res = EINA_FALSE;
985
986    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
987
988    if (!eldbus_message_arguments_get(msg, "u", &id))
989      {
990         ERR("Error on eldbus_message_arguments_get()\n");
991         return reply;
992      }
993
994    res = _e_test_helper_registrant_remove(id);
995    eldbus_message_arguments_append(reply, "b", res);
996
997    return reply;
998 }
999
1000 static Eldbus_Message *
1001 _e_test_helper_cb_reset_register_window(const Eldbus_Service_Interface *iface EINA_UNUSED,
1002                                         const Eldbus_Message *msg)
1003 {
1004    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1005
1006    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
1007
1008    _e_test_helper_registrant_clear();
1009
1010    eldbus_message_arguments_append(reply, "b", EINA_TRUE);
1011
1012    return reply;
1013 }
1014
1015 static Eldbus_Message*
1016 _e_test_helper_cb_change_stack(const Eldbus_Service_Interface *iface EINA_UNUSED,
1017                                const Eldbus_Message *msg)
1018 {
1019    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1020    Ecore_Window win, target;
1021    int above = -1;
1022
1023    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
1024
1025    if (!eldbus_message_arguments_get(msg, "uui", &win, &target, &above))
1026      {
1027         ERR("error on eldbus_message_arguments_get()\n");
1028         return reply;
1029      }
1030
1031    if ((win) && (above != -1))
1032      _e_test_helper_restack(win, target, above);
1033
1034    return reply;
1035 }
1036
1037 static Eldbus_Message*
1038 _e_test_helper_cb_activate_window(const Eldbus_Service_Interface *iface EINA_UNUSED,
1039                                   const Eldbus_Message *msg)
1040 {
1041    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1042    Ecore_Window win = 0x0;
1043    E_Client *ec = NULL;
1044
1045    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
1046
1047    if (!eldbus_message_arguments_get(msg, "u", &win))
1048      {
1049         ERR("error on eldbus_message_arguments_get()\n");
1050         return reply;
1051      }
1052
1053    if (win)
1054      {
1055         ec = e_pixmap_find_client_by_res_id(win);
1056         e_policy_wl_activate(ec);
1057      }
1058
1059    return reply;
1060 }
1061
1062 static Eldbus_Message*
1063 _e_test_helper_cb_change_iconic_state(const Eldbus_Service_Interface *iface EINA_UNUSED,
1064                                       const Eldbus_Message *msg)
1065 {
1066    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1067    Ecore_Window win = 0x0;
1068    Eina_Bool iconic = EINA_FALSE;
1069    E_Client *ec = NULL;
1070
1071    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
1072
1073    if (!eldbus_message_arguments_get(msg, "ub", &win, &iconic))
1074      {
1075         ERR("error on eldbus_message_arguments_get()\n");
1076         return reply;
1077      }
1078
1079    if (win)
1080      {
1081         ec = e_pixmap_find_client_by_res_id(win);
1082         if (iconic)
1083           e_policy_wl_iconify(ec);
1084         else
1085           e_policy_wl_uniconify(ec);
1086      }
1087
1088    return reply;
1089 }
1090
1091 static Eldbus_Message*
1092 _e_test_helper_cb_set_transient_for(const Eldbus_Service_Interface *iface EINA_UNUSED,
1093                                     const Eldbus_Message *msg)
1094 {
1095    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1096    Ecore_Window parent = 0x0, child = 0x0;
1097    E_Client *ec = NULL, *pec = NULL;
1098    Eina_Bool accept = EINA_FALSE;
1099
1100    EINA_SAFETY_ON_NULL_GOTO(th_data, fin);
1101
1102    if (!eldbus_message_arguments_get(msg, "uu", &child, &parent))
1103      {
1104         ERR("error on eldbus_message_arguments_get()\n");
1105         goto fin;
1106      }
1107
1108    if (parent && child)
1109      {
1110         pec = e_pixmap_find_client_by_res_id(parent);
1111         EINA_SAFETY_ON_NULL_GOTO(pec, fin);
1112
1113         ec = e_pixmap_find_client_by_res_id(child);
1114         EINA_SAFETY_ON_NULL_GOTO(ec, fin);
1115
1116         e_policy_stack_transient_for_set(ec, pec);
1117         accept = EINA_TRUE;
1118      }
1119
1120 fin:
1121    eldbus_message_arguments_append(reply, "b", accept);
1122    return reply;
1123 }
1124
1125 static Eldbus_Message*
1126 _e_test_helper_cb_unset_transient_for(const Eldbus_Service_Interface *iface EINA_UNUSED,
1127                                       const Eldbus_Message *msg)
1128 {
1129    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1130    Ecore_Window child = 0x0;
1131    E_Client *ec = NULL;
1132    Eina_Bool accept = EINA_FALSE;
1133
1134    EINA_SAFETY_ON_NULL_GOTO(th_data, fin);
1135
1136    if (!eldbus_message_arguments_get(msg, "u", &child))
1137      {
1138         ERR("error on eldbus_message_arguments_get()\n");
1139         goto fin;
1140      }
1141
1142    if (child)
1143      {
1144         ec = e_pixmap_find_client_by_res_id(child);
1145         EINA_SAFETY_ON_NULL_GOTO(ec, fin);
1146
1147         e_policy_stack_transient_for_set(ec, NULL);
1148         accept = EINA_TRUE;
1149      }
1150
1151 fin:
1152    eldbus_message_arguments_append(reply, "b", accept);
1153    return reply;
1154 }
1155
1156 static Eldbus_Message*
1157 _e_test_helper_cb_set_transient_for_below(const Eldbus_Service_Interface *iface EINA_UNUSED,
1158                                           const Eldbus_Message *msg)
1159 {
1160    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1161    Ecore_Window parent = 0x0, child = 0x0;
1162    E_Client *ec = NULL, *pec = NULL;
1163    Eina_Bool set = EINA_FALSE;
1164    Eina_Bool accept = EINA_FALSE;
1165
1166    EINA_SAFETY_ON_NULL_GOTO(th_data, fin);
1167
1168    if (!eldbus_message_arguments_get(msg, "uub", &child, &parent, &set))
1169      {
1170         ERR("error on eldbus_message_arguments_get()\n");
1171         goto fin;
1172      }
1173
1174    if (parent && child)
1175      {
1176         pec = e_pixmap_find_client_by_res_id(parent);
1177         EINA_SAFETY_ON_NULL_GOTO(pec, fin);
1178
1179         ec = e_pixmap_find_client_by_res_id(child);
1180         EINA_SAFETY_ON_NULL_GOTO(ec, fin);
1181
1182         if (set)
1183           {
1184              e_policy_stack_transient_for_below_set(ec, pec, EINA_TRUE);
1185              accept = EINA_TRUE;
1186           }
1187         else
1188           {
1189              e_policy_stack_transient_for_below_set(ec, NULL, EINA_TRUE);
1190              accept = EINA_TRUE;
1191           }
1192      }
1193
1194 fin:
1195    eldbus_message_arguments_append(reply, "b", accept);
1196    return reply;
1197 }
1198
1199 static Eldbus_Message*
1200 _e_test_helper_cb_set_noti_level(const Eldbus_Service_Interface *iface EINA_UNUSED,
1201                                  const Eldbus_Message *msg)
1202 {
1203    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1204    Ecore_Window win = 0x0;
1205    int layer = 0;
1206    E_Client *ec = NULL;
1207
1208    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
1209
1210    if (!eldbus_message_arguments_get(msg, "ui", &win, &layer))
1211      {
1212         ERR("error on eldbus_message_arguments_get()\n");
1213         return reply;
1214      }
1215
1216    if (win)
1217      {
1218         ec = e_pixmap_find_client_by_res_id(win);
1219         if (!ec) return reply;
1220
1221         e_client_layer_set(ec, layer);
1222      }
1223
1224    return reply;
1225 }
1226
1227 static Eldbus_Message*
1228 _e_test_helper_cb_set_focus_skip(const Eldbus_Service_Interface *iface EINA_UNUSED,
1229                                  const Eldbus_Message *msg)
1230 {
1231    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1232    Ecore_Window win = 0x0;
1233    Eina_Bool skip_set = EINA_FALSE;
1234    E_Client *ec = NULL;
1235
1236    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
1237
1238    if (!eldbus_message_arguments_get(msg, "ub", &win, &skip_set))
1239      {
1240         ERR("error on eldbus_message_arguments_get()\n");
1241         return reply;
1242      }
1243
1244    if (win)
1245      {
1246         ec = e_pixmap_find_client_by_res_id(win);
1247         if (!ec) return reply;
1248
1249         ec->icccm.accepts_focus = ec->icccm.take_focus = !skip_set;
1250         ec->changes.accepts_focus = 1;
1251         ec->changed = 1;
1252      }
1253
1254    return reply;
1255 }
1256
1257 static Eldbus_Message *
1258 _e_test_helper_cb_get_client_info(const Eldbus_Service_Interface *iface EINA_UNUSED,
1259                                   const Eldbus_Message *msg)
1260 {
1261    Eldbus_Message *reply;
1262    Ecore_Window win;
1263
1264    reply = eldbus_message_method_return_new(msg);
1265    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, reply);
1266
1267    if (!eldbus_message_arguments_get(msg, "u", &win))
1268      {
1269         ERR("error getting window ID");
1270         return reply;
1271      }
1272
1273    _e_test_helper_message_append_client_info_by_window_id(eldbus_message_iter_get(reply), win);
1274
1275    return reply;
1276 }
1277
1278 static Eldbus_Message *
1279 _e_test_helper_cb_get_clients(const Eldbus_Service_Interface *iface EINA_UNUSED,
1280                               const Eldbus_Message *msg)
1281 {
1282    Eldbus_Message *reply;
1283
1284    reply = eldbus_message_method_return_new(msg);
1285    _e_test_helper_message_append_clients(eldbus_message_iter_get(reply));
1286
1287    return reply;
1288 }
1289
1290 static Eldbus_Message *
1291 _e_test_helper_cb_get_noti_level(const Eldbus_Service_Interface *iface EINA_UNUSED,
1292                                  const Eldbus_Message *msg)
1293 {
1294    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1295    Ecore_Window win = 0x0;
1296    E_Client *ec = NULL;
1297    int layer = -1;
1298
1299    if (!eldbus_message_arguments_get(msg, "u", &win))
1300      {
1301         ERR("error on eldbus_message_arguments_get()\n");
1302         goto fin;
1303      }
1304
1305    ec = e_pixmap_find_client_by_res_id(win);
1306    if (!ec) goto fin;
1307
1308    layer = ec->layer;
1309
1310 fin:
1311    eldbus_message_arguments_append(reply, "i", layer);
1312    return reply;
1313 }
1314
1315 static Eina_Bool
1316 _e_test_helper_cb_visibility_change(void *data EINA_UNUSED,
1317                                     int type EINA_UNUSED,
1318                                     void *event)
1319 {
1320    E_Client *ec;
1321    Ecore_Window win = 0;
1322    E_Event_Client *ev = event;
1323    Test_Helper_Reg_Win *reg_win = NULL;
1324
1325    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, ECORE_CALLBACK_PASS_ON);
1326    if (!th_data->tc_running) return ECORE_CALLBACK_PASS_ON;
1327
1328    ec = ev->ec;
1329    win = e_pixmap_res_id_get(ec->pixmap);
1330    reg_win = _e_test_helper_find_win_on_reg_list(win);
1331
1332    if (reg_win == NULL) return ECORE_CALLBACK_PASS_ON;
1333
1334    if (reg_win->vis != !ec->visibility.obscured)
1335      _e_test_helper_send_change_visibility(win, !ec->visibility.obscured);
1336
1337    reg_win->vis = !ec->visibility.obscured;
1338
1339    return ECORE_CALLBACK_PASS_ON;
1340 }
1341
1342 static Eina_Bool
1343 _e_test_helper_cb_client_remove(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1344 {
1345    E_Client *ec;
1346    E_Event_Client *ev = event;
1347    Ecore_Window win = 0;
1348
1349    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, ECORE_CALLBACK_PASS_ON);
1350
1351    ec = ev->ec;
1352    if (ec && ec->pixmap)
1353      win = e_pixmap_res_id_get(ec->pixmap);
1354
1355    if (win <= 0) return ECORE_CALLBACK_PASS_ON;
1356
1357    _e_test_helper_registrant_remove(win);
1358
1359    return ECORE_CALLBACK_PASS_ON;
1360 }
1361
1362 static Eina_Bool
1363 _e_test_helper_cb_client_restack(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1364 {
1365    E_Event_Client *ev = event;
1366    E_Client *ec;
1367    Eldbus_Message *sig;
1368    Ecore_Window win;
1369
1370    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, ECORE_CALLBACK_PASS_ON);
1371    if (!th_data->tc_running) return ECORE_CALLBACK_PASS_ON;
1372
1373    ec = ev->ec;
1374
1375    win = e_pixmap_res_id_get(ec->pixmap);
1376    if (!_e_test_helper_find_win_on_reg_list(win)) return ECORE_CALLBACK_PASS_ON;
1377
1378    if (win)
1379      {
1380         sig = eldbus_service_signal_new(th_data->iface, E_TEST_HELPER_SIGNAL_RESTACK);
1381         eldbus_message_arguments_append(sig, "u", win);
1382         eldbus_service_signal_send(th_data->iface, sig);
1383      }
1384
1385    return ECORE_CALLBACK_PASS_ON;
1386 }
1387
1388 static Eina_Bool
1389 _e_test_helper_cb_client_rotation_end(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1390 {
1391    E_Event_Client *ev = event;
1392    E_Client *ec;
1393    Eldbus_Message *sig;
1394    Ecore_Window win;
1395    int rot;
1396
1397    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, ECORE_CALLBACK_PASS_ON);
1398    if (!th_data->tc_running) return ECORE_CALLBACK_PASS_ON;
1399
1400    ec = ev->ec;
1401
1402    win = e_pixmap_res_id_get(ec->pixmap);
1403    if (!_e_test_helper_find_win_on_reg_list(win)) return ECORE_CALLBACK_PASS_ON;
1404
1405    rot = ec->e.state.rot.ang.curr;
1406
1407    if (win)
1408      {
1409         sig = eldbus_service_signal_new(th_data->iface, E_TEST_HELPER_SIGNAL_WINDOW_ROTATION_CHANGED);
1410         eldbus_message_arguments_append(sig, "ui", win, rot);
1411         eldbus_service_signal_send(th_data->iface, sig);
1412      }
1413
1414    return ECORE_CALLBACK_PASS_ON;
1415 }
1416
1417 static Eina_Bool
1418 _e_test_helper_cb_client_focus_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1419 {
1420    E_Event_Client *ev = event;
1421    E_Client *ec = NULL;
1422    Eldbus_Message *sig = NULL;
1423    Ecore_Window win = 0;
1424
1425    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, ECORE_CALLBACK_PASS_ON);
1426    if (!th_data->tc_running) return ECORE_CALLBACK_PASS_ON;
1427
1428    ec = ev->ec;
1429
1430    win = e_pixmap_res_id_get(ec->pixmap);
1431    if (!_e_test_helper_find_win_on_reg_list(win)) return ECORE_CALLBACK_PASS_ON;
1432
1433    if (win)
1434      {
1435         sig = eldbus_service_signal_new(th_data->iface, E_TEST_HELPER_SIGNAL_FOCUS_CHANGED);
1436         eldbus_message_arguments_append(sig, "ub", win, ec->focused);
1437         eldbus_service_signal_send(th_data->iface, sig);
1438      }
1439
1440    return ECORE_CALLBACK_PASS_ON;
1441 }
1442
1443 static Eina_Bool
1444 _e_test_helper_cb_property_get(const Eldbus_Service_Interface *iface EINA_UNUSED, const char *name, Eldbus_Message_Iter *iter, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Message **err EINA_UNUSED)
1445 {
1446    EINA_SAFETY_ON_NULL_RETURN_VAL(th_data, EINA_FALSE);
1447
1448    Eldbus_Message_Iter *arr_of_win = NULL;
1449    Test_Helper_Reg_Win *reg_win = NULL;
1450    Eina_List *l = NULL;
1451
1452    if (!e_util_strcmp(name, "Registrant"))
1453      {
1454         arr_of_win = eldbus_message_iter_container_new(iter, 'a', "u");
1455
1456         EINA_LIST_FOREACH(th_data->reg_wins, l, reg_win)
1457           {
1458              eldbus_message_iter_basic_append(arr_of_win, 'u', reg_win->win);
1459           }
1460         eldbus_message_iter_container_close(iter, arr_of_win);
1461      }
1462
1463    return EINA_TRUE;
1464 }
1465
1466 static Eldbus_Message *
1467 _e_test_helper_cb_set_render_condition(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
1468 {
1469    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1470    Ecore_Window win = 0x0;
1471    Eina_Bool accept = EINA_FALSE;
1472    char *cond;
1473
1474    if (!eldbus_message_arguments_get(msg, "us", &win, &cond))
1475      {
1476         ERR("error on eldbus_message_arguments_get()\n");
1477         goto fin;
1478      }
1479
1480    // a window should be registered for tracing, otherwise reply accept FALSE
1481    if (!th_data) goto fin;
1482    if (!th_data->tc_running) goto fin;
1483    if (!th_data->reg_wins) goto fin;
1484    if (!_e_test_helper_find_win_on_reg_list(win)) goto fin;
1485
1486    // tracning condition on and off depending on "cond" string.
1487    if (!e_util_strcmp(cond, "effect"))
1488      {
1489         E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_COMP_OBJECT_EFFECT_START,
1490                               _e_test_helper_cb_effect_start, NULL);
1491         E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_COMP_OBJECT_EFFECT_END,
1492                               _e_test_helper_cb_effect_end, NULL);
1493         accept = EINA_TRUE;
1494      }
1495
1496 fin:
1497    eldbus_message_arguments_append(reply, "b", accept);
1498
1499    return reply;
1500 }
1501
1502 static Eldbus_Message *
1503 _e_test_helper_cb_add_supported_aux_hint(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
1504 {
1505    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1506    Eina_Bool accept = EINA_FALSE;
1507    const Eina_List *supported_list = NULL;
1508    char *hint;
1509
1510    if (!eldbus_message_arguments_get(msg, "s", &hint))
1511      {
1512         ERR("error on eldbus_message_arguments_get()\n");
1513         goto fin;
1514      }
1515
1516    if (!th_data) goto fin;
1517    if (!th_data->tc_running) goto fin;
1518
1519    supported_list = e_hints_aux_hint_supported_add(hint);
1520
1521    if (eina_list_data_find(supported_list, hint))
1522      accept = EINA_TRUE;
1523
1524 fin:
1525    eldbus_message_arguments_append(reply, "b", accept);
1526
1527    return reply;
1528 }
1529
1530 static Eldbus_Message *
1531 _e_test_helper_cb_del_supported_aux_hint(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
1532 {
1533    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1534    Eina_Bool accept = EINA_FALSE;
1535    const Eina_List *supported_list = NULL;
1536    char *hint;
1537
1538    if (!eldbus_message_arguments_get(msg, "s", &hint))
1539      {
1540         ERR("error on eldbus_message_arguments_get()\n");
1541         goto fin;
1542      }
1543
1544    if (!th_data) goto fin;
1545    if (!th_data->tc_running) goto fin;
1546
1547    supported_list = e_hints_aux_hint_supported_del(hint);
1548
1549    if (eina_list_data_find(supported_list, hint))
1550      accept = EINA_TRUE;
1551
1552 fin:
1553    eldbus_message_arguments_append(reply, "b", accept);
1554
1555    return reply;
1556 }
1557
1558 static Eldbus_Message *
1559 _e_test_helper_cb_get_aux_hint(const Eldbus_Service_Interface *iface, const Eldbus_Message *msg)
1560 {
1561    Eldbus_Message *reply = eldbus_message_method_return_new(msg);
1562    Ecore_Window win = 0x0;
1563    Test_Helper_Reg_Win *reg_win = NULL;
1564    E_Comp_Wl_Aux_Hint *ecah;
1565    E_Client *ec;
1566    Eina_List *l;
1567
1568    int id = -1;
1569    const char *hint = NULL, *val = NULL;
1570
1571    if (!eldbus_message_arguments_get(msg, "us", &win, &hint))
1572      {
1573         ERR("error on eldbus_message_arguments_get()\n");
1574         goto fin;
1575      }
1576
1577    if (!th_data) goto fin;
1578    if (!th_data->tc_running) goto fin;
1579    if (!th_data->reg_wins) goto fin;
1580    if (!(reg_win = _e_test_helper_find_win_on_reg_list(win))) goto fin;
1581    if (!(ec = reg_win->ec)) goto fin;
1582
1583    EINA_LIST_REVERSE_FOREACH(ec->comp_data->aux_hint.hints, l, ecah)
1584      {
1585         if ((!ecah->deleted) &&
1586             (!e_util_strcmp(ecah->hint, hint)))
1587           {
1588              id = ecah->id;
1589              hint = ecah->hint;
1590              val = ecah->val;
1591              break;
1592           }
1593      }
1594
1595 fin:
1596    eldbus_message_arguments_append(reply, "iss", id, hint, val);
1597
1598    return reply;
1599 }
1600
1601 static Eina_Bool
1602 _e_test_helper_cb_img_render(void *data EINA_UNUSED,
1603                              int type EINA_UNUSED,
1604                              void *event)
1605 {
1606    E_Client *ec;
1607    E_Event_Comp_Object *ev = event;
1608    Ecore_Window win = 0;
1609    Test_Helper_Reg_Win *reg_win = NULL;
1610
1611    if (!(ec = evas_object_data_get(ev->comp_object, "E_Client")))
1612      return ECORE_CALLBACK_DONE;
1613
1614    // a window should be registered for tracing
1615    if (!th_data) return ECORE_CALLBACK_DONE;
1616    if (!th_data->tc_running) return ECORE_CALLBACK_DONE;
1617    if (!th_data->reg_wins) return ECORE_CALLBACK_DONE;
1618
1619    win = e_pixmap_res_id_get(ec->pixmap);
1620    reg_win = _e_test_helper_find_win_on_reg_list(win);
1621
1622    if (reg_win && reg_win->render_send)
1623      _e_test_helper_send_render(win);
1624
1625    return ECORE_CALLBACK_DONE;
1626 }
1627
1628 static Eina_Bool
1629 _e_test_helper_cb_effect_start(void *data EINA_UNUSED,
1630                                int type EINA_UNUSED,
1631                                void *event)
1632 {
1633    E_Client *ec;
1634    E_Event_Comp_Object *ev = event;
1635    Ecore_Window win = 0;
1636    Test_Helper_Reg_Win *reg_win = NULL;
1637
1638    if (!(ec = evas_object_data_get(ev->comp_object, "E_Client")))
1639      return ECORE_CALLBACK_DONE;
1640
1641    // a window should be registered for tracing
1642    if (!th_data) return ECORE_CALLBACK_DONE;
1643    if (!th_data->tc_running) return ECORE_CALLBACK_DONE;
1644    if (!th_data->reg_wins) return ECORE_CALLBACK_DONE;
1645
1646    win = e_pixmap_res_id_get(ec->pixmap);
1647    reg_win = _e_test_helper_find_win_on_reg_list(win);
1648
1649    if (reg_win && ec && ec->frame)
1650      {
1651         reg_win->render_send = EINA_TRUE;
1652         e_comp_object_render_trace_set(ec->frame, EINA_TRUE);
1653         e_pixmap_image_refresh(ec->pixmap);
1654         e_comp_object_dirty(ec->frame);
1655      }
1656
1657    return ECORE_CALLBACK_DONE;
1658 }
1659
1660 static Eina_Bool
1661 _e_test_helper_cb_effect_end(void *data EINA_UNUSED,
1662                              int type EINA_UNUSED,
1663                              void *event)
1664 {
1665    E_Client *ec;
1666    E_Event_Comp_Object *ev = event;
1667    Ecore_Window win = 0;
1668    Test_Helper_Reg_Win *reg_win = NULL;
1669
1670    ec = evas_object_data_get(ev->comp_object, "E_Client");
1671    EINA_SAFETY_ON_NULL_RETURN_VAL(ec, ECORE_CALLBACK_DONE);
1672
1673    // a window should be registered for tracing
1674    if (!th_data) return ECORE_CALLBACK_DONE;
1675    if (!th_data->tc_running) return ECORE_CALLBACK_DONE;
1676    if (!th_data->reg_wins) return ECORE_CALLBACK_DONE;
1677
1678    win = e_pixmap_res_id_get(ec->pixmap);
1679    reg_win = _e_test_helper_find_win_on_reg_list(win);
1680
1681    if (reg_win && ec->frame)
1682      {
1683         e_comp_object_render_trace_set(ec->frame, EINA_FALSE);
1684         reg_win->render_send = EINA_FALSE;
1685      }
1686
1687    return ECORE_CALLBACK_DONE;
1688 }
1689
1690 static void
1691 _e_test_helper_hook_cb_client_aux_hint_change(void *data EINA_UNUSED, E_Client *ec)
1692 {
1693    Ecore_Window win = 0;
1694    E_Comp_Wl_Client_Data *cdata = e_client_cdata_get(ec);
1695    Eina_List *l, *ll;
1696    E_Comp_Wl_Aux_Hint *hint;
1697
1698    EINA_SAFETY_ON_NULL_RETURN(th_data);
1699    if (!th_data->tc_running) return;
1700
1701    win = e_pixmap_res_id_get(ec->pixmap);
1702    if (!_e_test_helper_find_win_on_reg_list(win)) return;
1703
1704    if (win)
1705      {
1706         EINA_LIST_FOREACH_SAFE(cdata->aux_hint.hints, l, ll, hint)
1707           {
1708              if (hint->changed)
1709                {
1710                   _e_test_helper_send_aux_hint_change(win, hint->id, hint->hint, hint->val);
1711                }
1712           }
1713      }
1714 }
1715
1716 static Eina_Bool
1717 _e_test_helper_cb_client_iconic_state_changed(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
1718 {
1719    E_Event_Client *ev = event;
1720    E_Client *ec;
1721    Eldbus_Message *sig;
1722    Ecore_Window win;
1723
1724    if (!th_data->tc_running) return ECORE_CALLBACK_PASS_ON;
1725
1726    ec = ev->ec;
1727    if (!ec) return ECORE_CALLBACK_PASS_ON;
1728
1729    win = e_pixmap_res_id_get(ec->pixmap);
1730    if (!win) return ECORE_CALLBACK_PASS_ON;
1731
1732    if (!_e_test_helper_find_win_on_reg_list(win)) return ECORE_CALLBACK_PASS_ON;
1733
1734    sig = eldbus_service_signal_new(th_data->iface, E_TEST_HELPER_SIGNAL_ICONIC_STATE_CHANGED);
1735    eldbus_message_arguments_append(sig, "ubb", win, ec->iconic, e_client_is_iconified_by_client(ec));
1736    eldbus_service_signal_send(th_data->iface, sig);
1737
1738    return ECORE_CALLBACK_PASS_ON;
1739 }
1740
1741 /* externally accessible functions */
1742 EINTERN int
1743 e_test_helper_init(void)
1744 {
1745    Eina_Bool res = EINA_FALSE;
1746
1747    EINA_SAFETY_ON_TRUE_GOTO((e_dbus_conn_init() <= 0), err);
1748
1749    th_data = E_NEW(Test_Helper_Data, 1);
1750    EINA_SAFETY_ON_NULL_GOTO(th_data, err);
1751
1752    th_data->dbus_init_done_h = ecore_event_handler_add(E_EVENT_DBUS_CONN_INIT_DONE, _e_test_helper_cb_dbus_init_done, NULL);
1753    EINA_SAFETY_ON_NULL_GOTO(th_data->dbus_init_done_h, err);
1754
1755    res = e_dbus_conn_dbus_init(ELDBUS_CONNECTION_TYPE_SYSTEM);
1756    EINA_SAFETY_ON_FALSE_GOTO(res, err);
1757
1758    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_CLIENT_VISIBILITY_CHANGE,
1759                          _e_test_helper_cb_visibility_change, NULL);
1760    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_CLIENT_REMOVE,
1761                          _e_test_helper_cb_client_remove, NULL);
1762    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_CLIENT_STACK,
1763                         _e_test_helper_cb_client_restack, NULL);
1764    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_CLIENT_ROTATION_CHANGE_END,
1765                          _e_test_helper_cb_client_rotation_end, NULL);
1766    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_CLIENT_FOCUS_IN,
1767                          _e_test_helper_cb_client_focus_changed, NULL);
1768    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_CLIENT_FOCUS_OUT,
1769                          _e_test_helper_cb_client_focus_changed, NULL);
1770    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_COMP_OBJECT_IMG_RENDER,
1771                           _e_test_helper_cb_img_render, NULL);
1772    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_CLIENT_ICONIFY,
1773                           _e_test_helper_cb_client_iconic_state_changed, NULL);
1774    E_LIST_HANDLER_APPEND(th_data->hdlrs, E_EVENT_CLIENT_UNICONIFY,
1775                           _e_test_helper_cb_client_iconic_state_changed, NULL);
1776
1777    E_LIST_HOOK_APPEND(th_data->hooks, E_CLIENT_HOOK_AUX_HINT_CHANGE,
1778                       _e_test_helper_hook_cb_client_aux_hint_change, NULL);
1779
1780    return 1;
1781
1782 err:
1783    e_test_helper_shutdown();
1784    return 0;
1785 }
1786
1787 EINTERN int
1788 e_test_helper_shutdown(void)
1789 {
1790    if (th_data)
1791      {
1792         E_FREE_LIST(th_data->hdlrs, ecore_event_handler_del);
1793
1794         _e_test_helper_registrant_clear();
1795
1796         if (th_data->tc_timer)
1797           {
1798              ecore_timer_del(th_data->tc_timer);
1799              th_data->tc_timer = NULL;
1800           }
1801
1802         if (th_data->dbus_init_done_h)
1803           {
1804              ecore_event_handler_del(th_data->dbus_init_done_h);
1805              th_data->dbus_init_done_h = NULL;
1806           }
1807
1808         if (th_data->conn)
1809           {
1810              if (th_data->iface)
1811                eldbus_service_interface_unregister(th_data->iface);
1812
1813              e_dbus_conn_connection_unref(th_data->conn);
1814              th_data->conn = NULL;
1815           }
1816
1817         e_dbus_conn_shutdown();
1818
1819         E_FREE(th_data);
1820      }
1821
1822    return 1;
1823 }