summaryrefslogtreecommitdiff
path: root/src/tests/elementary/spec/efl_test_content.c
blob: 98c3b369eba47c45d7783b670236966122175787 (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
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

#include <Efl_Ui.h>
#include "efl_ui_spec_suite.h"
#include "suite_helpers.h"

/* spec-meta-start
      {"test-interface":"Efl.Content",
       "test-widgets": ["Efl.Ui.Button", "Efl.Ui.Frame", "Efl.Ui.Grid_Default_Item",
                   "Efl.Ui.List_Default_Item", "Efl.Ui.List_Placeholder_Item",
                   "Efl.Ui.Navigation_Layout", "Efl.Ui.Panel", "Efl.Ui.Progressbar",
                   "Efl.Ui.Radio", "Efl.Ui.Popup", "Efl.Ui.Tab_Page", "Efl.Ui.Scroller"]}

   spec-meta-end */

EFL_START_TEST(content_set_get)
{
   Efl_Ui_Widget *w = create_test_widget();

   ck_assert_int_eq(efl_content_set(widget, w), EINA_TRUE);
   ck_assert_ptr_eq(efl_ui_widget_parent_get(w), widget);
   ck_assert_ptr_eq(efl_content_get(widget), w);

   EXPECT_ERROR_START;
   ck_assert_int_eq(efl_content_set(widget, (void*)0x1), EINA_FALSE);
   EXPECT_ERROR_END;
   ck_assert_ptr_eq(efl_content_get(widget), NULL);

   ck_assert_int_eq(efl_alive_get(w), EINA_FALSE);
}
EFL_END_TEST

EFL_START_TEST(content_set_get2)
{
   Efl_Ui_Widget *w = create_test_widget();

   ck_assert_int_eq(efl_content_set(widget, w), EINA_TRUE);
   ck_assert_ptr_eq(efl_ui_widget_parent_get(w), widget);
   ck_assert_ptr_eq(efl_content_get(widget), w);

   ck_assert_int_eq(efl_content_set(widget, NULL), EINA_TRUE);
   ck_assert_int_eq(efl_alive_get(w), EINA_FALSE);
   ck_assert_ptr_eq(efl_content_get(widget), NULL);

   efl_del(widget);
}
EFL_END_TEST


EFL_START_TEST(content_unset)
{
   Efl_Ui_Widget *w = create_test_widget();

   ck_assert_int_eq(efl_content_set(widget, w), EINA_TRUE);
   ck_assert_ptr_eq(efl_content_unset(widget), w);
   ck_assert_ptr_eq(efl_content_get(widget), NULL);

   efl_del(widget);
   ck_assert_int_eq(efl_alive_get(w), EINA_TRUE);
}
EFL_END_TEST

EFL_START_TEST(content_lifetime1)
{
   Efl_Ui_Widget *w1 = create_test_widget();

   efl_wref_add(w1, &w1);
   ck_assert_int_eq(efl_content_set(widget, w1), EINA_TRUE);
   efl_del(widget);
   ck_assert_ptr_eq(w1, NULL);
}
EFL_END_TEST

EFL_START_TEST(content_lifetime2)
{
   Efl_Ui_Widget *w1 = create_test_widget(), *w2 = create_test_widget();

   efl_wref_add(w2, &w2);
   efl_wref_add(w1, &w1);

   ck_assert_int_eq(efl_content_set(widget, w1), EINA_TRUE);
   ck_assert_int_eq(efl_content_set(widget, w2), EINA_TRUE);
   ck_assert_ptr_eq(w1, NULL);
   efl_del(widget);
   ck_assert_ptr_eq(w2, NULL);
}
EFL_END_TEST

EFL_START_TEST(content_lifetime3)
{
   Efl_Ui_Widget *w1 = create_test_widget();
   Eina_Bool content_changed_event = EINA_FALSE;

   ck_assert_int_eq(efl_content_set(widget, w1), EINA_TRUE);
   efl_test_container_expect_evt_content_added(widget, EFL_CONTENT_EVENT_CONTENT_CHANGED, &content_changed_event, NULL);
   efl_del(w1);
   ck_assert_int_eq(content_changed_event, EINA_TRUE);
   ck_assert_ptr_eq(efl_content_get(widget), NULL);
}
EFL_END_TEST

EFL_START_TEST(content_event)
{
   Efl_Ui_Widget *w1 = create_test_widget(), *w2 = create_test_widget();
   Eina_Bool content_changed_event;

   content_changed_event = EINA_FALSE;
   efl_test_container_expect_evt_content_added(widget, EFL_CONTENT_EVENT_CONTENT_CHANGED, &content_changed_event, w1);
   ck_assert_int_eq(efl_content_set(widget, w1), EINA_TRUE);
   ck_assert_int_eq(content_changed_event, EINA_TRUE);

   content_changed_event = EINA_FALSE;
   efl_test_container_expect_evt_content_added(widget, EFL_CONTENT_EVENT_CONTENT_CHANGED, &content_changed_event, w2);
   ck_assert_int_eq(efl_content_set(widget, w2), EINA_TRUE);
   ck_assert_int_eq(content_changed_event, EINA_TRUE);
}
EFL_END_TEST

void
efl_content_behavior_test(TCase *tc)
{
   tcase_add_test(tc, content_set_get);
   tcase_add_test(tc, content_set_get2);
   tcase_add_test(tc, content_lifetime1);
   tcase_add_test(tc, content_lifetime2);
   tcase_add_test(tc, content_lifetime3);
   tcase_add_test(tc, content_unset);
   tcase_add_test(tc, content_event);
}