Elementary test.c: Fixed some comments.
[framework/uifw/elementary.git] / src / bin / test.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 /* all tests prototypes */
8 void test_bg_plain(void *data, Evas_Object *obj, void *event_info);
9 void test_bg_image(void *data, Evas_Object *obj, void *event_info);
10 void test_bg_options(void *data, Evas_Object *obj, void *event_info);
11 void test_icon(void *data, Evas_Object *obj, void *event_info);
12 void test_box_vert(void *data, Evas_Object *obj, void *event_info);
13 void test_box_vert2(void *data, Evas_Object *obj, void *event_info);
14 void test_box_horiz(void *data, Evas_Object *obj, void *event_info);
15 void test_box_transition(void *data, Evas_Object *obj, void *event_info);
16 void test_button(void *data, Evas_Object *obj, void *event_info);
17 void test_transit(void *data, Evas_Object *obj, void *event_info);
18 void test_transit2(void *data, Evas_Object *obj, void *event_info);
19 void test_transit3(void *data, Evas_Object *obj, void *event_info);
20 void test_transit4(void *data, Evas_Object *obj, void *event_info);
21 void test_transit5(void *data, Evas_Object *obj, void *event_info);
22 void test_transit6(void *data, Evas_Object *obj, void *event_info);
23 void test_transit7(void *data, Evas_Object *obj, void *event_info);
24 void test_transit8(void *data, Evas_Object *obj, void *event_info);
25 void test_fileselector_button(void *data, Evas_Object *obj, void *event_info);
26 void test_fileselector_entry(void *data, Evas_Object *obj, void *event_info);
27 void test_toggle(void *data, Evas_Object *obj, void *event_info);
28 void test_clock(void *data, Evas_Object *obj, void *event_info);
29 void test_clock2(void *data, Evas_Object *obj, void *event_info);
30 void test_check(void *data, Evas_Object *obj, void *event_info);
31 void test_radio(void *data, Evas_Object *obj, void *event_info);
32 void test_layout(void *data, Evas_Object *obj, void *event_info);
33 void test_hover(void *data, Evas_Object *obj, void *event_info);
34 void test_hover2(void *data, Evas_Object *obj, void *event_info);
35 void test_entry(void *data, Evas_Object *obj, void *event_info);
36 void test_entry_scrolled(void *data, Evas_Object *obj, void *event_info);
37 void test_entry3(void *data, Evas_Object *obj, void *event_info);
38 void test_entry4(void *data, Evas_Object *obj, void *event_info);
39 void test_entry5(void *data, Evas_Object *obj, void *event_info);
40 void test_entry_notepad(void *data, Evas_Object *obj, void *event_info);
41 void test_anchorview(void *data, Evas_Object *obj, void *event_info);
42 void test_anchorblock(void *data, Evas_Object *obj, void *event_info);
43 void test_toolbar(void *data, Evas_Object *obj, void *event_info);
44 void test_toolbar2(void *data, Evas_Object *obj, void *event_info);
45 void test_toolbar3(void *data, Evas_Object *obj, void *event_info);
46 void test_toolbar4(void *data, Evas_Object *obj, void *event_info);
47 void test_toolbar5(void *data, Evas_Object *obj, void *event_info);
48 void test_hoversel(void *data, Evas_Object *obj, void *event_info);
49 void test_list(void *data, Evas_Object *obj, void *event_info);
50 void test_list_horizontal(void *data, Evas_Object *obj, void *event_info);
51 void test_list2(void *data, Evas_Object *obj, void *event_info);
52 void test_list3(void *data, Evas_Object *obj, void *event_info);
53 void test_list4(void *data, Evas_Object *obj, void *event_info);
54 void test_list5(void *data, Evas_Object *obj, void *event_info);
55 void test_inwin(void *data, Evas_Object *obj, void *event_info);
56 void test_inwin2(void *data, Evas_Object *obj, void *event_info);
57 void test_scaling(void *data, Evas_Object *obj, void *event_info);
58 void test_scaling2(void *data, Evas_Object *obj, void *event_info);
59 void test_slider(void *data, Evas_Object *obj, void *event_info);
60 void test_actionslider(void *data, Evas_Object *obj, void *event_info);
61 void test_genlist(void *data, Evas_Object *obj, void *event_info);
62 void test_genlist2(void *data, Evas_Object *obj, void *event_info);
63 void test_genlist3(void *data, Evas_Object *obj, void *event_info);
64 void test_genlist4(void *data, Evas_Object *obj, void *event_info);
65 void test_genlist5(void *data, Evas_Object *obj, void *event_info);
66 void test_genlist6(void *data, Evas_Object *obj, void *event_info);
67 void test_genlist7(void *data, Evas_Object *obj, void *event_info);
68 void test_genlist8(void *data, Evas_Object *obj, void *event_info);
69 void test_genlist9(void *data, Evas_Object *obj, void *event_info);
70 void test_table(void *data, Evas_Object *obj, void *event_info);
71 void test_gengrid(void *data, Evas_Object *obj, void *event_info);
72 void test_gengrid2(void *data, Evas_Object *obj, void *event_info);
73 void test_pager(void *data, Evas_Object *obj, void *event_info);
74 void test_pager_slide(void *data, Evas_Object *obj, void *event_info);
75 void test_win_state(void *data, Evas_Object *obj, void *event_info);
76 void test_win_state2(void *data, Evas_Object *obj, void *event_info);
77 void test_progressbar(void *data, Evas_Object *obj, void *event_info);
78 void test_fileselector(void *data, Evas_Object *obj, void *event_info);
79 void test_separator(void *data, Evas_Object *obj, void *event_info);
80 void test_scroller(void *data, Evas_Object *obj, void *event_info);
81 void test_scroller2(void *data, Evas_Object *obj, void *event_info);
82 void test_spinner(void *data, Evas_Object *obj, void *event_info);
83 void test_index(void *data, Evas_Object *obj, void *event_info);
84 void test_index2(void *data, Evas_Object *obj, void *event_info);
85 void test_photocam(void *data, Evas_Object *obj, void *event_info);
86 void test_photo(void *data, Evas_Object *obj, void *event_info);
87 void test_thumb(void *data, Evas_Object *obj, void *event_info);
88 void test_icon_desktops(void *data, Evas_Object *obj, void *event_info);
89 void test_notify(void *data, Evas_Object *obj, void *event_info);
90 void test_slideshow(void *data, Evas_Object *obj, void *event_info);
91 void test_menu(void *data, Evas_Object *obj, void *event_info);
92 void test_panel(void *data, Evas_Object *obj, void *event_info);
93 void test_panes(void *data, Evas_Object *obj, void *event_info);
94 void test_calendar(void *data, Evas_Object *obj, void *event_info);
95 void test_calendar2(void *data, Evas_Object *obj, void *event_info);
96 void test_map(void *data, Evas_Object *obj, void *event_info);
97 void test_weather(void *data, Evas_Object *obj, void *event_info);
98 void test_flip(void *data, Evas_Object *obj, void *event_info);
99 void test_flip2(void *data, Evas_Object *obj, void *event_info);
100 void test_flip3(void *data, Evas_Object *obj, void *event_info);
101 void test_label(void *data, Evas_Object *obj, void *event_info);
102 void test_conformant(void *data, Evas_Object *obj, void *event_info);
103 void test_conformant2(void *data, Evas_Object *obj, void *event_info);
104 void test_multi(void *data, Evas_Object *obj, void *event_info);
105 void test_floating(void *data, Evas_Object *obj, void *event_info);
106 void test_launcher(void *data, Evas_Object *obj, void *event_info);
107 void test_launcher2(void *data, Evas_Object *obj, void *event_info);
108 void test_launcher3(void *data, Evas_Object *obj, void *event_info);
109 void test_anim(void *data, Evas_Object *obj, void *event_info);
110 void test_tooltip(void *data, Evas_Object *obj, void *event_info);
111 void test_tooltip2(void *data, Evas_Object *obj, void *event_info);
112 void test_cursor(void *data, Evas_Object *obj, void *event_info);
113 void test_cursor2(void *data, Evas_Object *obj, void *event_info);
114 void test_cursor3(void *data, Evas_Object *obj, void *event_info);
115 void test_focus(void *data, Evas_Object *obj, void *event_info);
116 void test_focus2(void *data, Evas_Object *obj, void *event_info);
117 void test_flipselector(void *data, Evas_Object *obj, void *event_info);
118 void test_diskselector(void *data, Evas_Object *obj, void *event_info);
119 void test_colorselector(void *data, Evas_Object *obj, void *event_info);
120 void test_ctxpopup(void *data, Evas_Object *obj, void *event_info);
121 void test_bubble(void *data, Evas_Object *obj, void *event_info);
122 void test_store(void *data, Evas_Object *obj, void *event_info);
123
124 struct elm_test
125 {
126    const char *name;
127    void (*cb)(void *, Evas_Object *, void *);
128 };
129
130 static int
131 elm_test_sort(const void *pa, const void *pb)
132 {
133    const struct elm_test *a = pa, *b = pb;
134    return strcasecmp(a->name, b->name);
135 }
136
137 static void
138 elm_test_add(Eina_List **p_list, const char *name, void (*cb)(void *, Evas_Object *, void *))
139 {
140    struct elm_test *t = malloc(sizeof(struct elm_test));
141    t->name = name;
142    t->cb = cb;
143    *p_list = eina_list_sorted_insert(*p_list, elm_test_sort, t);
144 }
145
146 static void
147 my_win_del(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
148 {
149    /* called when my_win_main is requested to be deleted */
150    elm_exit(); /* exit the program's main loop that runs in elm_run() */
151 }
152
153 static void
154 index_changed(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
155 {
156    elm_list_item_show(event_info);
157 }
158
159 static void
160 _ui_tg_changed(void *data, Evas_Object *obj, void *event_info)
161 {
162    (void) data; (void) event_info;
163    elm_mirrored_set(elm_toggle_state_get(obj));
164 }
165
166
167 static void
168 my_win_main(char *autorun)
169 {
170    Evas_Object *win, *bg, *bx0, *lb, *li, *idx, *fr, *tg;
171    Eina_List *tests, *l;
172    struct elm_test *t;
173
174    /* create an elm window - it returns an evas object. this is a little
175     * special as the object lives in the canvas that is inside the window
176     * so what is returned is really inside the window, but as you manipulate
177     * the evas object returned - the window will respond. elm_win makes sure
178     * of that so you can blindly treat it like any other evas object
179     * pretty much, just as long as you know it has special significance.
180     * the first parameter is a "parent" window - eg for a dialog you want to
181     * have a main window it is related to, here it is NULL meaning there
182     * is no parent. "main" is the name of the window - used by the window
183     * manager for identifying the window uniquely amongst all the windows
184     * within this application (and all instances of the application). the
185     * type is a basic window (the final parameter) */
186    win = elm_win_add(NULL, "main", ELM_WIN_BASIC);
187    /* set the title of the window - this is in the titlebar */
188    elm_win_title_set(win, "Elementary Tests");
189
190    /* set a callback on the window when "delete,request" is emitted as
191     * a callback. when this happens my_win_del() is called and the
192     * data pointer (first param) is passed the final param here (in this
193     * case it is NULL). This is how you can pass specific things to a
194     * callback like objects or data layered on top */
195    evas_object_smart_callback_add(win, "delete,request", my_win_del, NULL);
196
197    /* add a background to our window. this just uses the standard theme set
198     * background. without a background, you could make a window seem
199     * transparent with elm_win_alpha_set(win, 1); for example. if you have
200     * a compositor running this will make the window able to be
201     * semi-transparent and any space not filled by object/widget pixels will
202     * be transparent or translucent based on alpha. if you do not have a
203     * comnpositor running this should fall back to using shaped windows
204     * (which have a mask). both these features will be slow and rely on
205     * a lot more resources, so only use it if you need it. */
206    bg = elm_bg_add(win);
207    /* set weight to 1.0 x 1.0 == expand in both x and y direction */
208    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
209    /* tell the window that this object is to be resized along with the window.
210     * also as a result this object will be one of several objects that
211     * controls the minimum/maximum size of the window */
212    elm_win_resize_object_add(win, bg);
213    /* and show the background */
214    evas_object_show(bg);
215
216    /* add a box layout widget to the window */
217    bx0 = elm_box_add(win);
218    /* allow base box (bx0) to expand in x and y */
219    evas_object_size_hint_weight_set(bx0, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
220    /* tell the window that the box affects window size and also will be
221     * resized when the window is */
222    elm_win_resize_object_add(win, bx0);
223    evas_object_show(bx0);
224
225    fr = elm_frame_add(win);
226    elm_frame_label_set(fr, "Information");
227    elm_box_pack_end(bx0, fr);
228    evas_object_show(fr);
229
230    lb = elm_label_add(win);
231    elm_label_label_set(lb,
232                        "Please select a test from the list below<br>"
233                        "by clicking the test button to show the<br>"
234                        "test window.");
235    elm_frame_content_set(fr, lb);
236    evas_object_show(lb);
237
238    tg = elm_toggle_add(win);
239    elm_toggle_label_set(tg, "UI-Mirroring:");
240    elm_toggle_state_set(tg, elm_mirrored_get());
241    evas_object_smart_callback_add(tg, "changed", _ui_tg_changed, NULL);
242    elm_box_pack_end(bx0, tg);
243    evas_object_show(tg);
244
245    li = elm_list_add(win);
246    elm_list_always_select_mode_set(li, 1);
247    evas_object_size_hint_weight_set(li, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
248    evas_object_size_hint_fill_set(li, EVAS_HINT_FILL, EVAS_HINT_FILL);
249    elm_box_pack_end(bx0, li);
250    evas_object_show(li);
251
252    idx = elm_index_add(win);
253    evas_object_smart_callback_add(idx, "delay,changed", index_changed, NULL);
254    evas_object_size_hint_weight_set(idx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
255    elm_win_resize_object_add(win, idx);
256    evas_object_show(idx);
257
258    tests = NULL;
259 #define ADD_TEST(name_, cb_) elm_test_add(&tests, name_, cb_)
260    ADD_TEST("Bg Plain", test_bg_plain);
261    ADD_TEST("Bg Image", test_bg_image);
262    ADD_TEST("Bg Options", test_bg_options);
263    ADD_TEST("Icon Transparent", test_icon);
264    ADD_TEST("Box Vert", test_box_vert);
265    ADD_TEST("Box Vert 2", test_box_vert2);
266    ADD_TEST("Box Horiz", test_box_horiz);
267    ADD_TEST("Box Transition", test_box_transition);
268    ADD_TEST("Buttons", test_button);
269    ADD_TEST("Transit", test_transit);
270    ADD_TEST("Transit 2", test_transit2);
271    ADD_TEST("Transit 3", test_transit3);
272    ADD_TEST("Transit 4", test_transit4);
273    ADD_TEST("Transit 5", test_transit5);
274    ADD_TEST("Transit 6", test_transit6);
275    ADD_TEST("Transit 7", test_transit7);
276    ADD_TEST("Transit 8", test_transit8);
277    ADD_TEST("File Selector Button", test_fileselector_button);
278    ADD_TEST("File Selector Entry", test_fileselector_entry);
279    ADD_TEST("Toggles", test_toggle);
280    ADD_TEST("Table", test_table);
281    ADD_TEST("Clock", test_clock);
282    ADD_TEST("Clock 2", test_clock2);
283    ADD_TEST("Layout", test_layout);
284    ADD_TEST("Hover", test_hover);
285    ADD_TEST("Hover 2", test_hover2);
286    ADD_TEST("Entry", test_entry);
287    ADD_TEST("Entry Scrolled", test_entry_scrolled);
288    ADD_TEST("Entry 3", test_entry3);
289    ADD_TEST("Entry 4", test_entry4);
290    ADD_TEST("Entry 5", test_entry5);
291    ADD_TEST("Entry Notepad", test_entry_notepad);
292    ADD_TEST("Anchorview", test_anchorview);
293    ADD_TEST("Anchorblock", test_anchorblock);
294    ADD_TEST("Toolbar", test_toolbar);
295    ADD_TEST("Toolbar 2", test_toolbar2);
296    ADD_TEST("Toolbar 3", test_toolbar3);
297    ADD_TEST("Toolbar 4", test_toolbar4);
298    ADD_TEST("Toolbar 5", test_toolbar5);
299    ADD_TEST("Hoversel", test_hoversel);
300    ADD_TEST("List", test_list);
301    ADD_TEST("List - Horizontal", test_list_horizontal);
302    ADD_TEST("List 2", test_list2);
303    ADD_TEST("List 3", test_list3);
304    ADD_TEST("List 4", test_list4);
305    ADD_TEST("List 5", test_list5);
306    ADD_TEST("Inwin", test_inwin);
307    ADD_TEST("Inwin 2", test_inwin2);
308    ADD_TEST("Scaling", test_scaling);
309    ADD_TEST("Scaling 2", test_scaling2);
310    ADD_TEST("Slider", test_slider);
311    ADD_TEST("Actionslider", test_actionslider);
312    ADD_TEST("Genlist", test_genlist);
313    ADD_TEST("Genlist 2", test_genlist2);
314    ADD_TEST("Genlist 3", test_genlist3);
315    ADD_TEST("Genlist 4", test_genlist4);
316    ADD_TEST("Genlist 5", test_genlist5);
317    ADD_TEST("Genlist 7", test_genlist7);
318    ADD_TEST("Genlist Tree", test_genlist6);
319    ADD_TEST("Genlist Group", test_genlist8);
320    ADD_TEST("Genlist Group Tree", test_genlist9);
321    ADD_TEST("GenGrid", test_gengrid);
322    ADD_TEST("GenGrid 2", test_gengrid2);
323    ADD_TEST("Checks", test_check);
324    ADD_TEST("Radios", test_radio);
325    ADD_TEST("Pager", test_pager);
326    ADD_TEST("Pager Slide", test_pager_slide);
327    ADD_TEST("Window States", test_win_state);
328    ADD_TEST("Window States 2", test_win_state2);
329    ADD_TEST("Progressbar", test_progressbar);
330    ADD_TEST("File Selector", test_fileselector);
331    ADD_TEST("Separator", test_separator);
332    ADD_TEST("Scroller", test_scroller);
333    ADD_TEST("Scroller 2", test_scroller2);
334    ADD_TEST("Spinner", test_spinner);
335    ADD_TEST("Index", test_index);
336    ADD_TEST("Index 2", test_index2);
337    ADD_TEST("Photocam", test_photocam);
338    ADD_TEST("Photo", test_photo);
339    ADD_TEST("Thumb", test_thumb);
340    ADD_TEST("Icon Desktops", test_icon_desktops);
341    ADD_TEST("Notify", test_notify);
342    ADD_TEST("Slideshow", test_slideshow);
343    ADD_TEST("Menu", test_menu);
344    ADD_TEST("Panel", test_panel);
345    ADD_TEST("Panes", test_panes);
346    ADD_TEST("Map", test_map);
347    ADD_TEST("Weather", test_weather);
348    ADD_TEST("Flip", test_flip);
349    ADD_TEST("Flip 2", test_flip2);
350    ADD_TEST("Flip 3", test_flip3);
351    ADD_TEST("Label", test_label);
352    ADD_TEST("Conformant", test_conformant);
353    ADD_TEST("Conformant 2", test_conformant2);
354    ADD_TEST("Multi Touch", test_multi);
355    ADD_TEST("Floating Objects", test_floating);
356    ADD_TEST("Launcher", test_launcher);
357    ADD_TEST("Launcher 2", test_launcher2);
358    ADD_TEST("Launcher 3", test_launcher3);
359    ADD_TEST("Animation", test_anim);
360    ADD_TEST("Calendar", test_calendar);
361    ADD_TEST("Calendar 2", test_calendar2);
362    ADD_TEST("Tooltip", test_tooltip);
363    ADD_TEST("Tooltip2", test_tooltip2);
364    ADD_TEST("Cursor", test_cursor);
365    ADD_TEST("Cursor 2", test_cursor2);
366    ADD_TEST("Cursor 3", test_cursor3);
367    ADD_TEST("Focus", test_focus);
368    ADD_TEST("Focus 2", test_focus2);
369    ADD_TEST("Flip Selector", test_flipselector);
370    ADD_TEST("Disk Selector", test_diskselector);
371    ADD_TEST("Color Selector", test_colorselector);
372    ADD_TEST("Ctxpopup", test_ctxpopup);
373    ADD_TEST("Bubble", test_bubble);
374    ADD_TEST("Store", test_store);
375 #undef ADD_TEST
376
377    if (autorun)
378      {
379         EINA_LIST_FOREACH(tests, l, t)
380           if ((t->name) && (t->cb) && (!strcmp(t->name, autorun)))
381             t->cb(NULL, NULL, NULL);
382      }
383
384    if (tests)
385      {
386         char last_letter = 0;
387         EINA_LIST_FREE(tests, t)
388           {
389              Elm_List_Item *it;
390              it = elm_list_item_append(li, t->name, NULL, NULL, t->cb, NULL);
391              if (last_letter != t->name[0])
392                {
393                   char letter[2] = {t->name[0], '\0'};
394                   elm_index_item_append(idx, letter, it);
395                   last_letter = t->name[0];
396                }
397              free(t);
398           }
399         elm_index_item_go(idx, 0);
400      }
401
402    elm_list_go(li);
403
404    /* set an initial window size */
405    evas_object_resize(win, 320, 480);
406    /* show the window */
407    evas_object_show(win);
408 }
409
410 /* this is your elementary main function - it MUST be called IMMEDIATELY
411  * after elm_init() and MUST be passed argc and argv, and MUST be called
412  * elm_main and not be static - must be a visible symbol with EAPI infront */
413 EAPI int
414 elm_main(int argc, char **argv)
415 {
416    char *autorun = NULL;
417
418    /* if called with a single argument try to autorun a test with
419     * the same name as the given param
420     * ex:  elementary_test "Box Vert 2" */
421    if (argc == 2)
422      autorun = argv[1];
423
424    /* put here any init specific to this app like parsing args etc. */
425    my_win_main(autorun); /* create main window */
426    elm_run(); /* and run the program now  and handle all events etc. */
427    /* if the mainloop that elm_run() runs exist - we exit the app */
428    elm_shutdown(); /* clean up and shut down */
429    /* exit code */
430    return 0;
431 }
432 #endif
433 /* all elementary apps should use this. but it should be placed right after
434  * elm_main() */
435 ELM_MAIN()