summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMykola Solyanko <m.solyanko@samsung.com>2017-12-19 14:41:32 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-12-19 14:42:56 +0900
commitea63f487d33c2371b502dd5e3f31d045acde627e (patch)
treedd16ee84b87a9c5cd1bf85a6db076150ca02feda
parent346e9a190426071a1b15c80554b5e249dfd8d8a2 (diff)
Eldbus: add test suite for eldbus (eldbus_pending_data*)
Summary: add tests for next API: eldbus_pending_data_set() eldbus_pending_data_get() eldbus_pending_data_del() Reviewers: cedric, NikaWhite, myoungwoon, raster, artem.popov Subscribers: jpeg Differential Revision: https://phab.enlightenment.org/D5650
-rw-r--r--src/tests/eldbus/eldbus_test_eldbus_pending_data.c161
1 files changed, 161 insertions, 0 deletions
diff --git a/src/tests/eldbus/eldbus_test_eldbus_pending_data.c b/src/tests/eldbus/eldbus_test_eldbus_pending_data.c
new file mode 100644
index 0000000000..0428535ac4
--- /dev/null
+++ b/src/tests/eldbus/eldbus_test_eldbus_pending_data.c
@@ -0,0 +1,161 @@
1#include <check.h>
2#include <Eldbus.h>
3#include <Ecore.h>
4#include <string.h>
5#include <stdio.h>
6#include <Eina.h>
7
8#include "eldbus_suite.h"
9
10static Eina_Bool is_response_cb = EINA_FALSE;
11
12static Ecore_Timer *timeout = NULL;
13
14static int pending_data_stored = 5;
15const char *pending_key_store = "pending_data";
16
17static Eldbus_Connection *conn = NULL;
18static Eldbus_Object *obj = NULL;
19static Eldbus_Message *message = NULL;
20
21/**
22* @addtogroup eldbus
23* @{
24* @defgroup eldbus_pending_data
25* @li eldbus_pending_data_set()
26* @li eldbus_pending_data_get()
27* @li eldbus_pending_data_del()
28*
29* @precondition
30* @step 1 Initialize ecore with ecore_init()
31* @step 2 Initialize eldbus with eldbus_init()
32*/
33
34static void
35_setup(void)
36{
37 ecore_init();
38 int ret = eldbus_init();
39 ck_assert_int_ge(ret, 1);
40}
41
42static void
43_teardown(void)
44{
45 eldbus_shutdown();
46 ecore_shutdown();
47}
48
49static Eina_Bool
50_ecore_loop_close(void *data EINA_UNUSED)
51{
52 ecore_main_loop_quit();
53
54 return ECORE_CALLBACK_CANCEL;
55}
56
57static void
58_response_message_cb(void *data EINA_UNUSED, const Eldbus_Message *msg EINA_UNUSED, Eldbus_Pending *pending)
59{
60 ck_assert_ptr_ne(NULL, pending);
61
62 int *pending_data_get = eldbus_pending_data_get(pending, pending_key_store);
63
64 ck_assert_ptr_ne(NULL, pending_data_get);
65 ck_assert_int_eq((*pending_data_get), pending_data_stored);
66
67 int *pending_data_del = eldbus_pending_data_del(pending, pending_key_store);
68
69 ck_assert_ptr_ne(NULL, pending_data_del);
70 ck_assert_int_eq((*pending_data_del), pending_data_stored);
71
72 is_response_cb = EINA_TRUE;
73
74 if (timeout != NULL)
75 {
76 ecore_timer_del(timeout);
77 timeout = NULL;
78 }
79
80 ecore_main_loop_quit();
81}
82
83/**
84 * @addtogroup eldbus_pending_data
85 * @{
86 * @objective Positive test case checks if function correctly set, get and delete the data stored
87 * in pending connection object and without segmentation fault.
88 *
89 * @n Input Data:
90 * @li the conn object connection with bus
91 * @li the obj object of the given bus and path
92 * @li the message of the pointer to message strunct a dbus method
93 * @li the pending connection object to store data
94 * @li data that will be stored
95 * @li key that identifies data
96 *
97 * @procedure
98 * @step 1 Call eldbus_connection_get function to get connection object
99 * @step 2 Check returned connection object on NULL.
100 * @step 3 Call eldbus_object_get function to get an object
101 * of the given bus and path.
102 * @step 4 Check returned object on NULL.
103 * @step 5 Call eldbus_object_method_call_new function to call
104 * a dbus method on the object.
105 * @step 6 Check returned message on NULL.
106 * @step 7 Call eldbus_connection_send function to send a message a dbus object with timeout.
107 * @step 8 Check returned pending on NULL.
108 * @step 9 Call eldbus_pending_data_set function to set data in pending connection object.
109 * @step 10 Set timer for preschedule termination of main loop if tested callback wasn't executed.
110 * @step 11 Start of main loop and wait for tested response in callback executing.
111 * @step 12 Check variable if callback executing.
112 * @step 13 Call eldbus_message_unref function to delete message object
113 * @step 14 Call eldbus_object_unref function to delete connection dbus object
114 * @step 15 Call eldbus_connection_unref function to delete connection object
115 *
116 * @passcondition Function should set data without segmentation fault,
117 get and delete valid stored data.
118 * @}
119 */
120
121START_TEST(utc_eldbus_pending_data_p)
122{
123 const char *bus = "org.freedesktop.DBus";
124 const char *path = "/org/freedesktop/DBus";
125 const char *interface = "org.freedesktop.DBus";
126 const char *member = "GetId";
127 const int send_timeout_ms = 500;
128
129 conn = eldbus_connection_get(ELDBUS_CONNECTION_TYPE_SYSTEM);
130 ck_assert_ptr_ne(NULL, conn);
131
132 obj = eldbus_object_get(conn, bus, path);
133 ck_assert_ptr_ne(NULL, obj);
134
135 message = eldbus_object_method_call_new(obj, interface, member);
136 ck_assert_ptr_ne(NULL, message);
137
138 Eldbus_Pending *pending = eldbus_connection_send(conn, message, _response_message_cb, NULL, send_timeout_ms);
139 ck_assert_ptr_ne(NULL, pending);
140
141 eldbus_pending_data_set(pending, pending_key_store, &pending_data_stored);
142
143 timeout = ecore_timer_add(1.5, _ecore_loop_close, NULL);
144 ck_assert_ptr_ne(NULL, timeout);
145
146 ecore_main_loop_begin();
147
148 ck_assert(is_response_cb == EINA_TRUE);
149
150 eldbus_message_unref(message);
151 eldbus_object_unref(obj);
152 eldbus_connection_unref(conn);
153}
154END_TEST
155
156void
157eldbus_test_eldbus_pending_data(TCase *tc)
158{
159 tcase_add_checked_fixture(tc, _setup, _teardown);
160 tcase_add_test(tc, utc_eldbus_pending_data_p);
161}