summaryrefslogtreecommitdiff
path: root/src/tests/edje/edje_test_swallow.c
blob: a0e5b4eb96b0f9335bff6595bafc05089c6b6286 (plain)
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <unistd.h>
#include <stdio.h>

#define EFL_GFX_FILTER_BETA
#define EFL_CANVAS_LAYOUT_BETA

#include "edje_suite.h"

#define EVAS_DATA_DIR TESTS_SRC_DIR "/../../lib/evas"


EFL_START_TEST(edje_test_swallows)
{
   Evas *evas = _setup_evas();
   Evas_Object *ly, *o1, *o2;

   ly = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas);
   fail_unless(edje_object_file_set(ly, test_layout_get("test_swallows.edj"), "test_group"));

   fail_unless(edje_object_part_exists(ly, "swallow"));


   o1 = efl_add(EFL_CANVAS_LAYOUT_CLASS, ly);
   fail_if(!edje_object_part_swallow(ly, "swallow", o1));
   ck_assert_ptr_eq(efl_parent_get(o1), ly);

   edje_object_part_unswallow(ly, o1);
   ck_assert_ptr_eq(efl_parent_get(o1), evas_object_evas_get(o1));

   fail_if(!edje_object_part_swallow(ly, "swallow", o1));
   ck_assert_ptr_eq(efl_parent_get(o1), ly);

   o2 = efl_add(EFL_CANVAS_LAYOUT_CLASS, ly);
   fail_if(!edje_object_part_swallow(ly, "swallow", o2));
   ck_assert_ptr_eq(efl_parent_get(o2), ly);
   /* o1 is deleted at this point. */
   ck_assert_ptr_eq(efl_parent_get(o1), evas_object_evas_get(o1));

}
EFL_END_TEST

EFL_START_TEST(edje_test_swallows_lifetime)
{
   Evas *evas = _setup_evas();
   Evas_Object *ly, *o1;

   ly = edje_object_add(evas);
   fail_unless(edje_object_file_set(ly, test_layout_get("test_swallows.edj"), "test_group"));

   fail_unless(edje_object_part_exists(ly, "swallow"));

   o1 = edje_object_add(evas);
   fail_if(!edje_object_part_swallow(ly, "swallow", o1));

   evas_object_del(ly);
   fail_if(!efl_parent_get(o1));

}
EFL_END_TEST

static void
edje_test_swallows_invalidate_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
{
   ck_assert(data == edje_object_part_swallow_get(obj, "swallow"));
}

EFL_START_TEST(edje_test_swallows_invalidate)
{
   Evas *evas = _setup_evas();
   Evas_Object *ly, *o1;

   ly = edje_object_add(evas);
   fail_unless(edje_object_file_set(ly, test_layout_get("test_swallows.edj"), "test_group"));

   fail_unless(edje_object_part_exists(ly, "swallow"));

   o1 = edje_object_add(evas);
   fail_if(!edje_object_part_swallow(ly, "swallow", o1));

   evas_object_event_callback_add(ly, EVAS_CALLBACK_DEL, edje_test_swallows_invalidate_del, o1);

   evas_object_del(ly);
   fail_if(!efl_parent_get(o1));

}
EFL_END_TEST

EFL_START_TEST(edje_test_swallows_eoapi)
{
   Evas *evas = _setup_evas();
   Evas_Object *ly, *o1, *o2;

   ly = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas);
   fail_unless(edje_object_file_set(ly, test_layout_get("test_swallows.edj"), "test_group"));

   fail_unless(edje_object_part_exists(ly, "swallow"));


   o1 = efl_add(EFL_CANVAS_LAYOUT_CLASS, ly);
   fail_if(!efl_content_set(efl_part(ly, "swallow"), o1));
   ck_assert_ptr_eq(efl_parent_get(o1), ly);

   efl_canvas_layout_content_remove(ly, o1);
   ck_assert_ptr_eq(efl_parent_get(o1), evas_object_evas_get(o1));

   fail_if(!efl_content_set(efl_part(ly, "swallow"), o1));
   ck_assert_ptr_eq(efl_parent_get(o1), ly);

   o2 = efl_add(EFL_CANVAS_LAYOUT_CLASS, ly);
   fail_if(!efl_content_set(efl_part(ly, "swallow"), o2));
   ck_assert_ptr_eq(efl_parent_get(o2), ly);
   /* o1 is deleted at this point. */
   ck_assert_ptr_eq(efl_parent_get(o1), evas_object_evas_get(o1));

}
EFL_END_TEST

EFL_START_TEST(edje_test_swallows_container_api)
{
   Evas *evas = _setup_evas();
   Evas_Object *ly, *o1;

   ly = efl_add(EFL_CANVAS_LAYOUT_CLASS, evas);
   fail_unless(edje_object_file_set(ly, test_layout_get("test_swallows.edj"), "test_group"));

   fail_unless(edje_object_part_exists(ly, "swallow"));

   o1 = efl_add(EFL_CANVAS_LAYOUT_CLASS, ly);
   fail_if(!efl_content_set(efl_part(ly, "swallow"), o1));

   ck_assert_int_eq(efl_content_count(ly), 1);

   {
      Eina_Array *arr = eina_array_new(1);
      Eina_Iterator *iter = efl_content_iterate(ly);
      Eo *content;

      EINA_ITERATOR_FOREACH(iter, content)
        {
           eina_array_push(arr, content);
        }

      ck_assert_int_eq(eina_array_count(arr), 1);
      ck_assert_ptr_eq(eina_array_data_get(arr, 0), o1);
      eina_array_free(arr);
   }

}
EFL_END_TEST

void edje_test_swallow(TCase *tc)
{
   tcase_add_test(tc, edje_test_swallows);
   tcase_add_test(tc, edje_test_swallows_lifetime);
   tcase_add_test(tc, edje_test_swallows_invalidate);
   tcase_add_test(tc, edje_test_swallows_eoapi);
   tcase_add_test(tc, edje_test_swallows_container_api);
}