summaryrefslogtreecommitdiff
path: root/src/tests/eldbus/eldbus_test_eldbus_model_method.c
blob: 51ed4afc34a59fa996999b8c66e8263719c236bb (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
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdbool.h>

#include <Eina.h>
#include <Ecore.h>
#include <Eldbus_Model.h>

#include "eldbus_fake_server.h"
#include "eldbus_test_eldbus_model.h"
#include "eldbus_suite.h"

#define ARGUMENT_A "arg0"
#define ARGUMENT_B "arg1"
#define ARGUMENT_RESULT "arg2"

static Eo *fake_server_object = NULL;
static Eo *fake_server_proxy = NULL;
static Eldbus_Service_Interface *fake_server = NULL;
static Fake_Server_Data fake_server_data = {0};
static Eo *method = NULL;

static void
_setup(void)
{
   check_init();

   fake_server = fake_server_start(&fake_server_data);

   fake_server_object = eo_add(ELDBUS_MODEL_OBJECT_CLASS, NULL, eldbus_model_object_constructor(eoid, ELDBUS_CONNECTION_TYPE_SESSION, NULL, EINA_FALSE, FAKE_SERVER_BUS, FAKE_SERVER_PATH));
   ck_assert_ptr_ne(NULL, fake_server_object);

   efl_model_load_and_wait_for_load_status(fake_server_object, EFL_MODEL_LOAD_STATUS_LOADED);

   fake_server_proxy = eldbus_model_proxy_from_object_get(fake_server_object, FAKE_SERVER_INTERFACE);
   ck_assert_ptr_ne(NULL, fake_server_proxy);

   efl_model_load_and_wait_for_load_status(fake_server_proxy, EFL_MODEL_LOAD_STATUS_LOADED);

   method = eldbus_model_method_from_proxy_get(fake_server_proxy, FAKE_SERVER_SUM_METHOD_NAME);
   ck_assert_ptr_ne(NULL, method);

   efl_model_load_and_wait_for_load_status(method, EFL_MODEL_LOAD_STATUS_LOADED);
}

static void
_teardown(void)
{
   eo_unref(fake_server_object);

   fake_server_stop(fake_server);

   check_shutdown();
}

START_TEST(load_status_get)
{
   check_efl_model_load_status_get(method, EFL_MODEL_LOAD_STATUS_LOADED);
}
END_TEST

START_TEST(properties_get)
{
   Eina_Array *properties = NULL;
   Efl_Model_Load_Status status;
   status = efl_model_properties_get(method, &properties);
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_LOADED, status);
   ck_assert_ptr_ne(NULL, properties);

   const unsigned int expected_properties_count = 3; // a, b and result arguments of 'sum' method
   const unsigned int actual_properties_count = eina_array_count(properties);
   ck_assert_int_eq(expected_properties_count, actual_properties_count);
}
END_TEST

START_TEST(property_get)
{
   // Input only property returns error
   Eina_Value const* dummy;
   Efl_Model_Load_Status status;
   status = efl_model_property_get(method, ARGUMENT_A, &dummy);
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_ERROR, status);

   status = efl_model_property_get(method, ARGUMENT_RESULT, &dummy);
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_LOADED, status);

   // Nonexistent property returns error
   status = efl_model_property_get(method, "nonexistent", &dummy);
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_ERROR, status);
}
END_TEST

START_TEST(property_set)
{
   // Output argument returns error
   Eina_Value dummy = {0};
   Efl_Model_Load_Status status;
   status = efl_model_property_set(method, ARGUMENT_RESULT, &dummy);
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_ERROR, status);
}
END_TEST

static void
_test_method_children_count(Eo *efl_model)
{
   check_efl_model_children_count_eq(efl_model, 0);
}

START_TEST(children_count)
{
   _test_method_children_count(method);
}
END_TEST

START_TEST(children_slice_get)
{
   Eina_Accessor *accessor;
   Efl_Model_Load_Status status;
   status = efl_model_children_slice_get(method, 1, 1, &accessor);
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_LOADED, status);
   ck_assert_ptr_eq(NULL, accessor);
}
END_TEST

static void
_check_unload(void)
{
   check_efl_model_load_status_get(method, EFL_MODEL_LOAD_STATUS_LOADED);
   efl_model_unload(method);
   check_efl_model_load_status_get(method, EFL_MODEL_LOAD_STATUS_UNLOADED);

   check_efl_model_children_count_eq(method, 0);
}

START_TEST(unload)
{
   _check_unload();
}
END_TEST

START_TEST(properties_load)
{
   _check_unload();

   efl_model_properties_load(method);
   efl_model_wait_for_load_status(method, EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES);

   check_efl_model_load_status_get(method, EFL_MODEL_LOAD_STATUS_LOADED_PROPERTIES);
}
END_TEST

START_TEST(children_load)
{
   _check_unload();

   efl_model_children_load(method);
   efl_model_wait_for_load_status(method, EFL_MODEL_LOAD_STATUS_LOADED_CHILDREN);

   check_efl_model_load_status_get(method, EFL_MODEL_LOAD_STATUS_LOADED_CHILDREN);

   _test_method_children_count(method);
}
END_TEST

START_TEST(child_add)
{
   Eo *child;
   child = efl_model_child_add(method);
   ck_assert_ptr_eq(NULL, child);
}
END_TEST

START_TEST(child_del)
{
   // efl_model_child_del always returns ERROR
   Eo *child = NULL;
   Efl_Model_Load_Status status;
   status = efl_model_child_del(method, child);
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_ERROR, status);
}
END_TEST

START_TEST(call)
{
   check_efl_model_property_int_set(method, ARGUMENT_A, 12345678);
   check_efl_model_property_int_set(method, ARGUMENT_B, 87654321);

   Efl_Model_Load_Status status;
   status = eldbus_model_method_call(method);
   ck_assert_int_eq(EFL_MODEL_LOAD_STATUS_LOADED, status);

   efl_model_wait_for_event(method, ELDBUS_MODEL_METHOD_EVENT_SUCCESSFUL_CALL);

   check_efl_model_property_int_eq(method, ARGUMENT_RESULT, 99999999);
}
END_TEST

void eldbus_test_eldbus_model_method(TCase *tc)
{
   tcase_add_checked_fixture(tc, _setup, _teardown);
   tcase_add_test(tc, load_status_get);
   tcase_add_test(tc, properties_get);
   tcase_add_test(tc, property_get);
   tcase_add_test(tc, property_set);
   tcase_add_test(tc, children_count);
   tcase_add_test(tc, children_slice_get);
   tcase_add_test(tc, unload);
   tcase_add_test(tc, properties_load);
   tcase_add_test(tc, children_load);
   tcase_add_test(tc, child_add);
   tcase_add_test(tc, child_del);
   tcase_add_test(tc, call);
}