summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMykola Solyanko <m.solyanko@samsung.com>2017-12-13 09:51:41 -0800
committerCedric BAIL <cedric@osg.samsung.com>2017-12-13 10:27:48 -0800
commit750e45e287d9b1046c49fcbd0c25423abe16a35b (patch)
tree4e9b5cb17d17544d5f884863c5c657f5494fa715 /src
parent6f38e42f8e8a876186752f1e82f95e4373090bab (diff)
eldbus: add test suite for eldbus_proxy*
Summary: add tests for next API: eldbus_proxy_get() eldbus_proxy_interface_get() eldbus_proxy_object_get() eldbus_proxy_call() eldbus_proxy_ref() eldbus_proxy_unref() eldbus_proxy_send() eldbus_proxy_method_call_new() eldbus_proxy_send_and_block eldbus_proxy_send_and_block() eldbus_proxy_data_set() eldbus_proxy_data_get() eldbus_proxy_data_del() Reviewers: cedric, NikaWhite, myoungwoon, raster, artem.popov Reviewed By: cedric Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D5644 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile_Eldbus.am1
-rw-r--r--src/tests/eldbus/CMakeLists.txt1
-rw-r--r--src/tests/eldbus/eldbus_suite.c1
-rw-r--r--src/tests/eldbus/eldbus_suite.h2
-rw-r--r--src/tests/eldbus/eldbus_test_eldbus_proxy.c419
5 files changed, 423 insertions, 1 deletions
diff --git a/src/Makefile_Eldbus.am b/src/Makefile_Eldbus.am
index c612b3cac1..99831d55b5 100644
--- a/src/Makefile_Eldbus.am
+++ b/src/Makefile_Eldbus.am
@@ -134,6 +134,7 @@ tests/eldbus/eldbus_test_eldbus_model_signal.c \
134tests/eldbus/eldbus_test_eldbus_object.c \ 134tests/eldbus/eldbus_test_eldbus_object.c \
135tests/eldbus/eldbus_test_eldbus_message.c \ 135tests/eldbus/eldbus_test_eldbus_message.c \
136tests/eldbus/eldbus_test_eldbus_signal_handler.c \ 136tests/eldbus/eldbus_test_eldbus_signal_handler.c \
137tests/eldbus/eldbus_test_eldbus_proxy.c \
137tests/eldbus/eldbus_test_fake_server_eldbus_model_proxy.c \ 138tests/eldbus/eldbus_test_fake_server_eldbus_model_proxy.c \
138tests/eldbus/eldbus_fake_server.c \ 139tests/eldbus/eldbus_fake_server.c \
139tests/eldbus/eldbus_suite.h 140tests/eldbus/eldbus_suite.h
diff --git a/src/tests/eldbus/CMakeLists.txt b/src/tests/eldbus/CMakeLists.txt
index 10f03d1f67..9150863654 100644
--- a/src/tests/eldbus/CMakeLists.txt
+++ b/src/tests/eldbus/CMakeLists.txt
@@ -14,6 +14,7 @@ set(SOURCES
14 eldbus_test_eldbus_object.c 14 eldbus_test_eldbus_object.c
15 eldbus_test_eldbus_message.c 15 eldbus_test_eldbus_message.c
16 eldbus_test_eldbus_signal_handler.c 16 eldbus_test_eldbus_signal_handler.c
17 eldbus_test_eldbus_proxy.c
17 eldbus_test_fake_server_eldbus_model_proxy.c 18 eldbus_test_fake_server_eldbus_model_proxy.c
18) 19)
19 20
diff --git a/src/tests/eldbus/eldbus_suite.c b/src/tests/eldbus/eldbus_suite.c
index 1e6fbc9909..9515e477f6 100644
--- a/src/tests/eldbus/eldbus_suite.c
+++ b/src/tests/eldbus/eldbus_suite.c
@@ -17,6 +17,7 @@ static const Efl_Test_Case etc[] = {
17 { "eldbus_test_eldbus_object", eldbus_test_eldbus_object }, 17 { "eldbus_test_eldbus_object", eldbus_test_eldbus_object },
18 { "eldbus_test_eldbus_message", eldbus_test_eldbus_message }, 18 { "eldbus_test_eldbus_message", eldbus_test_eldbus_message },
19 { "eldbus_test_eldbus_signal_handler", eldbus_test_eldbus_signal_handler }, 19 { "eldbus_test_eldbus_signal_handler", eldbus_test_eldbus_signal_handler },
20 { "eldbus_test_eldbus_proxy", eldbus_test_eldbus_proxy },
20 { NULL, NULL } 21 { NULL, NULL }
21}; 22};
22 23
diff --git a/src/tests/eldbus/eldbus_suite.h b/src/tests/eldbus/eldbus_suite.h
index dd26ce5fa3..7c0aa40af3 100644
--- a/src/tests/eldbus/eldbus_suite.h
+++ b/src/tests/eldbus/eldbus_suite.h
@@ -14,5 +14,5 @@ void eldbus_test_eldbus_model_signal(TCase *tc);
14void eldbus_test_eldbus_object(TCase *tc); 14void eldbus_test_eldbus_object(TCase *tc);
15void eldbus_test_eldbus_message(TCase *tc); 15void eldbus_test_eldbus_message(TCase *tc);
16void eldbus_test_eldbus_signal_handler(TCase *tc); 16void eldbus_test_eldbus_signal_handler(TCase *tc);
17 17void eldbus_test_eldbus_proxy(TCase *tc);
18#endif 18#endif
diff --git a/src/tests/eldbus/eldbus_test_eldbus_proxy.c b/src/tests/eldbus/eldbus_test_eldbus_proxy.c
new file mode 100644
index 0000000000..2fdf06f3eb
--- /dev/null
+++ b/src/tests/eldbus/eldbus_test_eldbus_proxy.c
@@ -0,0 +1,419 @@
1#include <check.h>
2#include <Eldbus.h>
3#include <Ecore.h>
4#include <string.h>
5#include <Eina.h>
6
7#include "eldbus_suite.h"
8
9static Eina_Bool is_success = EINA_FALSE;
10
11static Ecore_Timer *timeout = NULL;
12
13static const char *empty_string = "";
14
15static const char *bus = "org.freedesktop.DBus";
16static const char *interface = "org.freedesktop.DBus";
17static const char *path = "/org/freedesktop/DBus";
18static const char *method_name = "GetId";
19
20static int cb_data = 5;
21
22#define DATA_KEY "proxy_data"
23
24static int proxy_data_stored = 5;
25
26/**
27* @addtogroup eldbus
28* @{
29* @defgroup eldbus_proxy
30*
31* @preconditio
32* @step 1 Initialize ecore with ecore_init()
33* @step 2 Initialize eldbus with eldbus_init()
34*/
35
36static void
37_setup(void)
38{
39 ecore_init();
40 int ret = eldbus_init();
41 ck_assert_int_ge(ret, 1);
42}
43
44static void
45_teardown(void)
46{
47 eldbus_shutdown();
48 ecore_shutdown();
49}
50
51static Eina_Bool
52_ecore_loop_close(void *data EINA_UNUSED)
53{
54 ecore_main_loop_quit();
55
56 return ECORE_CALLBACK_CANCEL;
57}
58
59static void
60_proxy_message_cb(void *data, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
61{
62 if (timeout != NULL)
63 {
64 ecore_timer_del(timeout);
65 timeout = NULL;
66 }
67
68 const char *errname, *errmsg;
69 int *user_data = data;
70
71 if ((user_data) && (*user_data == cb_data))
72 {
73 if (!eldbus_message_error_get(msg, &errname, &errmsg))
74 {
75 char *txt = NULL;
76 if (eldbus_message_arguments_get(msg, "s", &txt))
77 {
78 if ((txt) && strcmp(txt, empty_string))
79 is_success = EINA_TRUE;
80 }
81 }
82 }
83
84 ecore_main_loop_quit();
85}
86
87/**
88 * @addtogroup eldbus_proxy
89 * @{
90 * @defgroup eldbus_proxy_info_get_call
91 * @li eldbus_proxy_get()
92 * @li eldbus_proxy_interface_get()
93 * @li eldbus_proxy_object_get()
94 * @li eldbus_proxy_call()
95 * @li eldbus_proxy_ref()
96 * @li eldbus_proxy_unref()
97 * @{
98 * @objective Positive test case checks if function get a proxy of the
99 * following interface name in a Eldbus_Object, get the interface name associated with a proxy object.
100 * Get the DBus object associated with a proxy object. Call the method and get valid response in callback function.
101 * Without segmentation fault.
102 *
103 * @n Input Data:
104 * @li the conn object connection with bus
105 * @li the obj Eldbus_Object object of the given bus and path.
106 *
107 * @procedure
108 * @step 1 Call eldbus_connection_get function to get connection object.
109 * @step 2 Check returned connection object on NULL.
110 * @step 3 Call eldbus_object_get function to get an object of the given bus and path.
111 * @step 4 Check returned object on NULL.
112 * @step 5 Call eldbus_proxy_get function to get a proxy of the following interface name.
113 * @step 6 Check returned proxy object on NULL.
114 * @step 7 Call eldbus_proxy_object_get function to get the dbus object associated with a proxy object.
115 * @step 8 Check if returned object is equal to obj Eldbus_Object.
116 * @step 9 Call eldbus_proxy_interface_get function to get valid string and check on expected string.
117 * @step 10 Call eldbus_proxy_ref function to increase proxy reference.
118 * @step 11 Check two objects on the same adress.
119 * @step 12 Call eldbus_object_unref function to decrease proxy reference.
120 * @step 13 Call eldbus_proxy_interface_get function to check the proxy object is still correct.
121 * @step 14 Call eldbus_proxy_call function to call a method in proxy.
122 * @step 15 Check returned pending object on NULL.
123 * @step 16 Set timer for preschedule termination of main loop if tested callback wasn't executed.
124 * @step 17 Start of main loop and wait for tested response in callback executing.
125 * @step 18 Check static variable named is_success.
126 * If is equal EINA_TRUE, that callback was executed and method send valid message response.
127 * @step 19 Call eldbus_proxy_unref function to delete proxy object
128 * @step 20 Call eldbus_object_unref function to delete connection dbus object
129 * @step 21 Call eldbus_connection_unref function to delete connection object
130 *
131 * @passcondition Function should get valid expected proxy information about connection dbus object.
132 * Variables named is_success must equals EINA_TRUE. Without segmentation fault.
133 * @}
134 * @}
135 */
136
137START_TEST(utc_eldbus_proxy_info_get_call_p)
138{
139 is_success = EINA_FALSE;
140
141 Eldbus_Connection *conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
142 ck_assert_ptr_ne(NULL, conn);
143
144 Eldbus_Object *obj = eldbus_object_get(conn, bus, path);
145 ck_assert_ptr_ne(NULL, obj);
146
147 Eldbus_Proxy *proxy = eldbus_proxy_get(obj, interface);
148 ck_assert_ptr_ne(NULL, proxy);
149
150 Eldbus_Object *proxy_obj = eldbus_proxy_object_get(proxy);
151 ck_assert_ptr_eq(proxy_obj, obj);
152
153 ck_assert_str_eq(interface, eldbus_proxy_interface_get(proxy));
154
155 Eldbus_Proxy *proxy_ref = eldbus_proxy_ref(proxy);
156 ck_assert_ptr_eq(proxy_ref, proxy);
157
158 eldbus_proxy_unref(proxy_ref);
159
160 ck_assert(eldbus_proxy_interface_get(proxy) != NULL);
161
162 Eldbus_Pending *pending = eldbus_proxy_call(proxy, method_name, _proxy_message_cb, &cb_data, -1, empty_string);
163 ck_assert_ptr_ne(NULL, pending);
164
165 timeout = ecore_timer_add(1.5, _ecore_loop_close, NULL);
166 ck_assert_ptr_ne(NULL, timeout);
167
168 ecore_main_loop_begin();
169
170 ck_assert_msg(is_success, "Method GetId is not call");
171
172 eldbus_proxy_unref(proxy);
173 eldbus_object_unref(obj);
174 eldbus_connection_unref(conn);
175}
176END_TEST
177
178/**
179 * @addtogroup eldbus_proxy
180 * @{
181 * @defgroup eldbus_proxy_send_call
182 * @li eldbus_proxy_send()
183 * @li eldbus_proxy_method_call_new()
184 * @{
185 * @objective Positive test case checks if function call the method
186 * on the proxy object and get valid response in callback function. Without segmentation fault.
187 *
188 * @n Input Data:
189 * @li the conn object connection with bus
190 * @li the obj Eldbus_Object object of the given bus and path.
191 * @li the proxy object associated with dbus object.
192 *
193 * @procedure
194 * @step 1 Call eldbus_connection_get function to get connection object.
195 * @step 2 Check returned connection object on NULL.
196 * @step 3 Call eldbus_object_get function to get an object of the given bus and path.
197 * @step 4 Check returned object on NULL.
198 * @step 5 Call eldbus_proxy_get function to get a proxy of the following interface name.
199 * @step 6 Check returned proxy object on NULL.
200 * @step 7 Call eldbus_proxy_method_call_new function to constructs a new message
201 * to invoke a method on a remote interface.
202 * @step 8 Check returned message object on NULL.
203 * @step 9 Call eldbus_proxy_send function to send a message.
204 * @step 10 Check returned pending object on NULL.
205 * @step 11 Set timer for preschedule termination of main loop if tested callback wasn't executed.
206 * @step 12 Start of main loop and wait for tested response in callback executing.
207 * @step 13 Check static variable named is_success.
208 * If is equal EINA_TRUE, that callback was executed and method send valid message response.
209 * @step 14 Call eldbus_message_unref function to delete message object
210 * @step 15 Call eldbus_proxy_unref function to delete proxy object
211 * @step 16 Call eldbus_object_unref function to delete connection dbus object
212 * @step 17 Call eldbus_connection_unref function to delete connection object
213 *
214 * @passcondition Variables named is_success must equals EINA_TRUE. Without segmentation fault.
215 * @}
216 * @}
217 */
218
219START_TEST(utc_eldbus_proxy_send_call_p)
220{
221 is_success = EINA_FALSE;
222
223 Eldbus_Connection *conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
224 ck_assert_ptr_ne(NULL, conn);
225
226 Eldbus_Object *obj = eldbus_object_get(conn, bus, path);
227 ck_assert_ptr_ne(NULL, obj);
228
229 Eldbus_Proxy *proxy = eldbus_proxy_get(obj, interface);
230 ck_assert_ptr_ne(NULL, proxy);
231
232 Eldbus_Message *msg = eldbus_proxy_method_call_new(proxy, method_name);
233 ck_assert_ptr_ne(NULL, msg);
234
235 Eldbus_Pending *pending = eldbus_proxy_send(proxy, msg, _proxy_message_cb, &cb_data, -1);
236 ck_assert_ptr_ne(NULL, pending);
237
238 timeout = ecore_timer_add(1.5, _ecore_loop_close, NULL);
239 ck_assert_ptr_ne(NULL, timeout);
240
241 ecore_main_loop_begin();
242
243 ck_assert_msg(is_success, "Method GetId is not call");
244
245 eldbus_message_unref(msg);
246 eldbus_proxy_unref(proxy);
247 eldbus_object_unref(obj);
248 eldbus_connection_unref(conn);
249}
250END_TEST
251
252/**
253 * @addtogroup eldbus_proxy
254 * @{
255 * @defgroup eldbus_proxy_send_and_block eldbus_proxy_send_and_block()
256 * @{
257 * @objective Positive test case checks if function send a message and block while waiting for the reply
258 * and get valid response in return message object. Without segmentation fault.
259 *
260 * @n Input Data:
261 * @li the conn object connection with bus
262 * @li the obj Eldbus_Object object of the given bus and path.
263 * @li the proxy object associated with dbus object.
264 *
265 * @procedure
266 * @step 1 Call eldbus_connection_get function to get connection object.
267 * @step 2 Check returned connection object on NULL.
268 * @step 3 Call eldbus_object_get function to get an object of the given bus and path.
269 * @step 4 Check returned object on NULL.
270 * @step 5 Call eldbus_proxy_get function to get a proxy of the following interface name.
271 * @step 6 Check returned proxy object on NULL.
272 * @step 7 Call eldbus_proxy_method_call_new function to constructs a new message
273 * to invoke a method on a remote interface.
274 * @step 8 Check returned message object on NULL.
275 * @step 9 Call eldbus_proxy_send_and_block function to send a message
276 * and block while waiting for the reply.
277 * @step 10 Check returned reply message object on expected value.
278 * @step 11 Call eldbus_message_unref function to delete reply message object
279 * @step 12 Call eldbus_message_unref function to delete message object
280 * @step 13 Call eldbus_proxy_unref function to delete proxy object
281 * @step 14 Call eldbus_object_unref function to delete connection dbus object
282 * @step 15 Call eldbus_connection_unref function to delete connection object
283 *
284 * @passcondition Function should send a message and block while waiting
285 * for returned expected reply message object. Without segmentation fault.
286 * @}
287 * @}
288 */
289
290START_TEST(utc_eldbus_proxy_send_and_block_p)
291{
292 const int timeout = 1000;
293 is_success = EINA_FALSE;
294 const char *errname, *errmsg;
295 char *text_reply = NULL;
296
297 Eldbus_Connection *conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
298 ck_assert_ptr_ne(NULL, conn);
299
300 Eldbus_Object *obj = eldbus_object_get(conn, bus, path);
301 ck_assert_ptr_ne(NULL, obj);
302
303 Eldbus_Proxy *proxy = eldbus_proxy_get(obj, interface);
304 ck_assert_ptr_ne(NULL, proxy);
305
306 Eldbus_Message *msg = eldbus_proxy_method_call_new(proxy, method_name);
307 ck_assert_ptr_ne(NULL, msg);
308
309 Eldbus_Message *message_reply = eldbus_proxy_send_and_block(proxy, msg, timeout);
310 ck_assert_ptr_ne(NULL, message_reply);
311
312 //eldbus_message_error_get(message_reply, &errname, &errmsg)
313 ck_assert(eldbus_message_error_get(message_reply, &errname, &errmsg) == EINA_FALSE);
314
315 ck_assert(eldbus_message_arguments_get(message_reply, "s", &text_reply) == EINA_TRUE);
316
317 if (text_reply)
318 printf("is reply message is not null\n");
319 else
320 printf("is reply message is null\n");
321
322 printf("message %s\n", text_reply);
323
324 ck_assert_ptr_ne(NULL, text_reply);
325
326 ck_assert_str_ne(text_reply, empty_string);
327
328 eldbus_message_unref(message_reply);
329 eldbus_message_unref(msg);
330 eldbus_proxy_unref(proxy);
331 eldbus_object_unref(obj);
332 eldbus_connection_unref(conn);
333}
334END_TEST
335
336/**
337 * @addtogroup eldbus_proxy
338 * @{
339 * @defgroup eldbus_proxy_data
340 * @li eldbus_proxy_data_set()
341 * @li eldbus_proxy_data_get()
342 * @li eldbus_proxy_data_del()
343 * @{
344 * @objective Positive test case checks if function correctly set, get and delete the data stored
345 * in proxy object and without segmentation fault.
346 *
347 * @n Input Data:
348 * @li the conn object connection with bus
349 * @li the obj Eldbus_Object object of the given bus and path.
350 * @li the proxy object associated with dbus object.
351 *
352 * @procedure
353 * @step 1 Call eldbus_connection_get function to get connection object.
354 * @step 2 Check returned connection object on NULL.
355 * @step 3 Call eldbus_object_get function to get an object of the given bus and path.
356 * @step 4 Check returned object on NULL.
357 * @step 5 Call eldbus_proxy_get function to get a proxy of the following interface name.
358 * @step 6 Check returned proxy object on NULL.
359 * @step 7 Call eldbus_proxy_data_set function to set data in proxy object.
360 * @step 8 Call eldbus_proxy_data_get function to get data stored.
361 * @step 9 Check returned data on NULL and correct value.
362 * @step 10 Call eldbus_proxy_data_del function to delete data stored.
363 * @step 11 Check returned data on NULL and correct value.
364 * @step 12 Call eldbus_proxy_data_get function to get data stored.
365 * @step 13 Check returned data on not equal NULL.
366 * @step 14 Call eldbus_proxy_unref function to delete proxy object
367 * @step 15 Call eldbus_object_unref function to delete connection dbus object
368 * @step 16 Call eldbus_connection_unref function to delete connection object
369 *
370 * @passcondition Function should set data without segmentation fault,
371 * get and delete valid stored data.
372 * @}
373 * @}
374 */
375
376START_TEST(utc_eldbus_proxy_data_p)
377{
378 is_success = EINA_FALSE;
379
380 Eldbus_Connection *conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
381 ck_assert_ptr_ne(NULL, conn);
382
383 Eldbus_Object *obj = eldbus_object_get(conn, bus, path);
384 ck_assert_ptr_ne(NULL, obj);
385
386 Eldbus_Proxy *proxy = eldbus_proxy_get(obj, interface);
387 ck_assert_ptr_ne(NULL, proxy);
388
389 eldbus_proxy_data_set(proxy, DATA_KEY, &proxy_data_stored);
390
391 int *proxy_data_get = eldbus_proxy_data_get(proxy, DATA_KEY);
392 ck_assert_ptr_ne(NULL, proxy_data_get);
393 ck_assert_int_eq((*proxy_data_get), proxy_data_stored);
394
395 int *proxy_data_del = eldbus_proxy_data_del(proxy, DATA_KEY);
396 ck_assert_ptr_ne(NULL, proxy_data_del);
397 ck_assert_int_eq((*proxy_data_del), proxy_data_stored);
398
399 int *proxy_data_null = eldbus_proxy_data_get(proxy, DATA_KEY);
400 ck_assert_ptr_eq(NULL, proxy_data_null);
401
402 eldbus_proxy_unref(proxy);
403 eldbus_object_unref(obj);
404 eldbus_connection_unref(conn);
405}
406END_TEST
407
408/**
409 *@}
410 */
411void
412eldbus_test_eldbus_proxy(TCase *tc)
413{
414 tcase_add_checked_fixture(tc, _setup, _teardown);
415 tcase_add_test(tc, utc_eldbus_proxy_info_get_call_p);
416 tcase_add_test(tc, utc_eldbus_proxy_send_call_p);
417 tcase_add_test(tc, utc_eldbus_proxy_send_and_block_p);
418 tcase_add_test(tc, utc_eldbus_proxy_data_p);
419} \ No newline at end of file