summaryrefslogtreecommitdiff
path: root/src/tests/elementary/efl_ui_test_layout.c
blob: 20581d4ae60a24106c2e95a18ca2a69c68a84a4f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#define EFL_NOLEGACY_API_SUPPORT
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif
#define EFL_LAYOUT_CALC_PROTECTED
#include <Efl_Ui.h>
#include "efl_ui_suite.h"

static Eina_Value
_propagated_cb(void *data EINA_UNUSED,
               const Eina_Value v,
               const Eina_Future *dead_future EINA_UNUSED)
{
   ecore_main_loop_quit();

   fprintf(stderr, "delivered '%s'\n", eina_value_to_string(&v));

   return v;
}

EFL_START_TEST(efl_ui_layout_test_property_bind)
{
   char buf[PATH_MAX];
   Evas_Object *win, *ly;
   Efl_Generic_Model *model;
   Eina_Value v;
   Eina_Future *f;
   const char *part_text;
   const char text_value[] = "A random string for elm_layout_property_bind test";

   win = win_add(NULL, "layout", EFL_UI_WIN_TYPE_BASIC);

   ly = efl_add(EFL_UI_LAYOUT_CLASS, win);
   snprintf(buf, sizeof(buf), "%s/objects/test.edj", ELM_TEST_DATA_DIR);
   efl_file_simple_load(ly, buf, "layout");
   efl_gfx_entity_visible_set(ly, EINA_TRUE);

   model = efl_add(EFL_GENERIC_MODEL_CLASS, win);
   ck_assert(!!eina_value_setup(&v, EINA_VALUE_TYPE_STRING));
   ck_assert(!!eina_value_set(&v, text_value));
   f = efl_model_property_set(model, "text_property", &v);
   eina_future_then(f, _propagated_cb, NULL, NULL);

   efl_ui_property_bind(ly, "text", "text_property");
   efl_ui_view_model_set(ly, model);

   ecore_main_loop_begin();

   part_text = efl_text_get(efl_part(ly, "text"));

   ck_assert_str_eq(part_text, text_value);

}
EFL_END_TEST

EFL_START_TEST(efl_ui_layout_test_layout_api_size_min)
{
   Evas_Object *win;
   Eina_Size2D res;

   win = win_add(NULL, "layout", EFL_UI_WIN_TYPE_BASIC);
   /* this is just a test to not get segfaults in those calls */
   Eo *layout = efl_add(EFL_UI_LAYOUT_CLASS, win);
   res = efl_layout_calc_size_min(layout, EINA_SIZE2D(2, 2));
   ck_assert_int_eq(res.w, 2);
   ck_assert_int_eq(res.h, 2);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_layout_test_layout_api_update_hints)
{
   Evas_Object *win;

   win = win_add(NULL, "layout", EFL_UI_WIN_TYPE_BASIC);
   /* this is just a test to not get segfaults in those calls */
   Eo *layout = efl_add(EFL_UI_LAYOUT_CLASS, win);
   efl_layout_calc_auto_update_hints_set(layout, EINA_TRUE);
   ck_assert_int_eq(efl_layout_calc_auto_update_hints_get(layout), EINA_TRUE);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_layout_test_layout_force)
{
   Evas_Object *win;

   win = win_add(NULL, "layout", EFL_UI_WIN_TYPE_BASIC);
   /* this is just a test to not get segfaults in those calls */
   Eo *layout = efl_add(EFL_UI_LAYOUT_CLASS, win);
   efl_layout_calc_force(layout);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_layout_test_layout_theme)
{
   Evas_Object *win;
   const char *klass, *group, *style;

   win = win_add(NULL, "layout", EFL_UI_WIN_TYPE_BASIC);
   Eo *layout = efl_add(EFL_UI_LAYOUT_CLASS, win,
     efl_ui_layout_theme_set(efl_added, "win", "background", NULL)
   );
   efl_ui_layout_theme_get(layout, &klass, &group, &style);
   ck_assert_str_eq(klass, "win");
   ck_assert_str_eq(group, "background");
   ck_assert(!style);
}
EFL_END_TEST

EFL_START_TEST(efl_ui_layout_test_api_ordering)
{
   Evas_Object *win, *box;
   const char text_text[] = "test text";

   win = win_add(NULL, "layout", EFL_UI_WIN_TYPE_BASIC);
   box = efl_add(EFL_UI_BOX_CLASS, win);
   Eo *layout = efl_add(EFL_UI_BUTTON_CLASS, win,
     efl_content_set(efl_added, box),
     efl_text_set(efl_added, text_text)
   );
   ck_assert_ptr_eq(efl_content_get(layout), box);
   ck_assert_str_eq(efl_text_get(layout), text_text);
}
EFL_END_TEST

void efl_ui_test_layout(TCase *tc)
{
   tcase_add_test(tc, efl_ui_layout_test_property_bind);
   tcase_add_test(tc, efl_ui_layout_test_layout_api_size_min);
   tcase_add_test(tc, efl_ui_layout_test_layout_api_update_hints);
   tcase_add_test(tc, efl_ui_layout_test_layout_force);
   tcase_add_test(tc, efl_ui_layout_test_layout_theme);
   tcase_add_test(tc, efl_ui_layout_test_api_ordering);
}