summaryrefslogtreecommitdiff
path: root/src/tests/elementary/efl_ui_test_radio_group.c
blob: 4c515bf1406918c3730762e5ba6d29a147f18ed3 (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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
#ifdef HAVE_CONFIG_H
# include "elementary_config.h"
#endif

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

static Eo *win, *radio_group;

int state_values = 0;

typedef struct {
   int called;
   int value;
} Group_Changed_Called;

Group_Changed_Called changed_evt;

#define RESET_EVT \
  changed_evt.called = 0; \
  changed_evt.value = 200000000;

#define EXPECT_EVT(c, v) \
  ck_assert_int_eq(changed_evt.called, c); \
  ck_assert_int_eq(changed_evt.value, v);

static void
_group_value_changed_cb(void *data EINA_UNUSED, const Efl_Event *ev)
{
   changed_evt.called ++;
   changed_evt.value = *((int*)ev->info);
}

static void
check_setup()
{
   win = win_add();
   radio_group = efl_new(EFL_UI_RADIO_GROUP_IMPL_CLASS, NULL);
   efl_event_callback_add(radio_group, EFL_UI_RADIO_GROUP_EVENT_VALUE_CHANGED, _group_value_changed_cb, NULL);
}

static void
check_teardown()
{
   efl_unref(radio_group);
   if (win)
     {
        efl_del(win);
        win = NULL;
     }
}

static Eo*
radio(void)
{
   state_values += 1;
   return efl_add(EFL_UI_RADIO_CLASS, win, efl_ui_radio_state_value_set(efl_added, state_values));
}

EFL_START_TEST(active_selected_value_setting)
{
   Eo *r1 = radio();
   Eo *r2 = radio();

   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, r1);
   efl_ui_radio_group_register(radio_group, r2);

   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);

   RESET_EVT
   efl_ui_radio_group_selected_value_set(radio_group, 1);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r1);
   ck_assert_int_eq(efl_ui_check_selected_get(r1), EINA_TRUE);
   ck_assert_int_eq(efl_ui_check_selected_get(r2), EINA_FALSE);
   EXPECT_EVT(1,1);

   RESET_EVT
   efl_ui_radio_group_selected_object_set(radio_group, r2);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 2);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r2);
   ck_assert_int_eq(efl_ui_check_selected_get(r1), EINA_FALSE);
   ck_assert_int_eq(efl_ui_check_selected_get(r2), EINA_TRUE);
   EXPECT_EVT(1,2);
}
EFL_END_TEST

EFL_START_TEST(active_selection_setting)
{
   Eo *r1 = radio();
   Eo *r2 = radio();

   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, r1);
   efl_ui_radio_group_register(radio_group, r2);

   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);

   RESET_EVT
   efl_ui_radio_group_selected_object_set(radio_group, r1);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r1);
   ck_assert_int_eq(efl_ui_check_selected_get(r1), EINA_TRUE);
   ck_assert_int_eq(efl_ui_check_selected_get(r2), EINA_FALSE);
   EXPECT_EVT(1,1);

   RESET_EVT
   efl_ui_radio_group_selected_object_set(radio_group, r2);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 2);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r2);
   ck_assert_int_eq(efl_ui_check_selected_get(r1), EINA_FALSE);
   ck_assert_int_eq(efl_ui_check_selected_get(r2), EINA_TRUE);
   EXPECT_EVT(1,2);
}
EFL_END_TEST

EFL_START_TEST(active_selection_object_setting)
{
   Eo *r = radio();
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, r);
   efl_ui_radio_group_register(radio_group, radio());

   RESET_EVT
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
   efl_ui_check_selected_set(r, EINA_TRUE);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r);
   EXPECT_EVT(1,1);
}
EFL_END_TEST

EFL_START_TEST(unregister_setted)
{
   Eo *r = radio();
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, r);
   efl_ui_radio_group_register(radio_group, radio());

   RESET_EVT
   efl_ui_radio_group_selected_object_set(radio_group, r);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r);
   EXPECT_EVT(1,1);
   RESET_EVT
   efl_ui_radio_group_unregister(radio_group, r);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
   EXPECT_EVT(1,-1);
}
EFL_END_TEST

EFL_START_TEST(delete_setted)
{
   Eo *r = radio();
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, r);
   efl_ui_radio_group_register(radio_group, radio());
   RESET_EVT
   efl_ui_radio_group_selected_object_set(radio_group, r);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r);
   EXPECT_EVT(1,1);
   RESET_EVT
   efl_del(r);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
   EXPECT_EVT(1,-1);
}
EFL_END_TEST

EFL_START_TEST(external_setting)
{
   Eo *r = radio();
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, radio());
   efl_ui_radio_group_register(radio_group, r);
   efl_ui_radio_group_register(radio_group, radio());
   RESET_EVT
   efl_ui_check_selected_set(r, EINA_TRUE);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), 1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), r);
   EXPECT_EVT(1,1);
   RESET_EVT
   efl_ui_check_selected_set(r, EINA_FALSE);
   ck_assert_int_eq(efl_ui_radio_group_selected_value_get(radio_group), -1);
   ck_assert_ptr_eq(efl_ui_radio_group_selected_object_get(radio_group), NULL);
   EXPECT_EVT(1,-1);
}
EFL_END_TEST

EFL_START_TEST(pairwise_different_error)
{
   Eo *r = radio();
   Eo *r1 = radio();
   Eo *r2 = radio();
   efl_ui_radio_state_value_set(r, -1);
   efl_ui_radio_state_value_set(r1, 14);
   efl_ui_radio_state_value_set(r2, 14);
   EXPECT_ERROR_START;
   efl_ui_radio_group_register(radio_group, r);
   EXPECT_ERROR_END;
   efl_ui_radio_group_register(radio_group, r1);
   EXPECT_ERROR_START;
   efl_ui_radio_group_register(radio_group, r2);
   EXPECT_ERROR_END;
}
EFL_END_TEST

EFL_START_TEST(group_double_registeration)
{
   Eo *r = radio();
   efl_ui_radio_group_register(radio_group, r);
   EXPECT_ERROR_START;
   efl_ui_radio_group_register(radio_group, r);
   EXPECT_ERROR_END;
}
EFL_END_TEST

EFL_START_TEST(group_registeration_in_two_groups)
{
   Eo *radio_group2 = efl_new(EFL_UI_RADIO_GROUP_IMPL_CLASS, NULL);
   Eo *r = radio();
   efl_ui_radio_group_register(radio_group, r);
   EXPECT_ERROR_START;
   efl_ui_radio_group_register(radio_group2, r);
   EXPECT_ERROR_END;
}
EFL_END_TEST

EFL_START_TEST(group_invalid_value)
{
   Eo *radio_group2 = efl_new(EFL_UI_RADIO_GROUP_IMPL_CLASS, NULL);
   Eo *r = radio();
   efl_ui_radio_group_register(radio_group, r);
   EXPECT_ERROR_START;
   efl_ui_radio_group_selected_value_set(radio_group2, 1000);
   EXPECT_ERROR_END;
}
EFL_END_TEST

void efl_ui_test_radio_group(TCase *tc)
{
   tcase_add_checked_fixture(tc, fail_on_errors_setup, fail_on_errors_teardown);
   tcase_add_checked_fixture(tc, check_setup, check_teardown);
   tcase_add_test(tc, active_selected_value_setting);
   tcase_add_test(tc, active_selection_setting);
   tcase_add_test(tc, active_selection_object_setting);
   tcase_add_test(tc, pairwise_different_error);
   tcase_add_test(tc, group_double_registeration);
   tcase_add_test(tc, group_registeration_in_two_groups);
   tcase_add_test(tc, unregister_setted);
   tcase_add_test(tc, external_setting);
   tcase_add_test(tc, delete_setted);
   tcase_add_test(tc, group_invalid_value);
}