summaryrefslogtreecommitdiff
path: root/src/tests/ecore_con
diff options
context:
space:
mode:
authorSrivardhan Hebbar <sri.hebbar@samsung.com>2015-04-15 14:50:03 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-04-15 14:50:06 +0200
commit3d697254b0e8283f74b90ca3ff6900179ddb9b01 (patch)
treec9c176a3e16be4bdc276624a9c84aaed84118bd5 /src/tests/ecore_con
parent2f4dee02e4bb57cccb35403039e703a18a0dbeb2 (diff)
ecore_con: add test cases for ecore_con_eet.
Summary: Added test case for ecore_con_eet. Signed-off-by: Srivardhan Hebbar <sri.hebbar@samsung.com> Reviewers: cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D2347 Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/tests/ecore_con')
-rw-r--r--src/tests/ecore_con/ecore_con_suite.c1
-rw-r--r--src/tests/ecore_con/ecore_con_suite.h1
-rw-r--r--src/tests/ecore_con/ecore_con_test_ecore_con_eet.c173
3 files changed, 175 insertions, 0 deletions
diff --git a/src/tests/ecore_con/ecore_con_suite.c b/src/tests/ecore_con/ecore_con_suite.c
index b695873..331f660 100644
--- a/src/tests/ecore_con/ecore_con_suite.c
+++ b/src/tests/ecore_con/ecore_con_suite.c
@@ -20,6 +20,7 @@ struct _Ecore_Con_Test_Case
20static const Ecore_Con_Test_Case etc[] = { 20static const Ecore_Con_Test_Case etc[] = {
21 { "Ecore_Con", ecore_con_test_ecore_con }, 21 { "Ecore_Con", ecore_con_test_ecore_con },
22 { "Ecore_Con_Url", ecore_con_test_ecore_con_url }, 22 { "Ecore_Con_Url", ecore_con_test_ecore_con_url },
23 { "Ecore_Con_Eet", ecore_con_test_ecore_con_eet },
23 { NULL, NULL } 24 { NULL, NULL }
24}; 25};
25 26
diff --git a/src/tests/ecore_con/ecore_con_suite.h b/src/tests/ecore_con/ecore_con_suite.h
index 9232189..5d18647 100644
--- a/src/tests/ecore_con/ecore_con_suite.h
+++ b/src/tests/ecore_con/ecore_con_suite.h
@@ -5,5 +5,6 @@
5 5
6void ecore_con_test_ecore_con(TCase *tc); 6void ecore_con_test_ecore_con(TCase *tc);
7void ecore_con_test_ecore_con_url(TCase *tc); 7void ecore_con_test_ecore_con_url(TCase *tc);
8void ecore_con_test_ecore_con_eet(TCase *tc);
8 9
9#endif /* _ECORE_CON_SUITE_H */ 10#endif /* _ECORE_CON_SUITE_H */
diff --git a/src/tests/ecore_con/ecore_con_test_ecore_con_eet.c b/src/tests/ecore_con/ecore_con_test_ecore_con_eet.c
new file mode 100644
index 0000000..d981a93
--- /dev/null
+++ b/src/tests/ecore_con/ecore_con_test_ecore_con_eet.c
@@ -0,0 +1,173 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "ecore_con_suite.h"
6
7#include <Eet.h>
8#include <Ecore_Con_Eet.h>
9
10#define TEST_STREAM "test_stream"
11#define SRV_MSG "Server Message"
12#define CLI_MSG "Client Message"
13
14static Eet_Data_Descriptor *_ece_test_descriptor;
15static char eet_data[] = "test_data";
16
17typedef struct
18{
19 int id;
20 char *message;
21}ECE_Test;
22
23static void
24_ece_test_descriptor_init(void)
25{
26 Eet_Data_Descriptor_Class eddc;
27
28 EET_EINA_STREAM_DATA_DESCRIPTOR_CLASS_SET(&eddc, ECE_Test);
29 _ece_test_descriptor = eet_data_descriptor_stream_new(&eddc);
30
31#define ECE_TEST_ADD_BASIC(member, eet_type) \
32 EET_DATA_DESCRIPTOR_ADD_BASIC \
33 (_ece_test_descriptor, ECE_Test, # member, member, eet_type)
34
35 ECE_TEST_ADD_BASIC(id, EET_T_INT);
36 ECE_TEST_ADD_BASIC(message, EET_T_STRING);
37#undef ECE_TEST_ADD_BASIC
38}
39
40static void
41_ece_test_descriptor_shutdown(void)
42{
43 eet_data_descriptor_free(_ece_test_descriptor);
44}
45
46Eina_Bool
47_eet_client_discnct_cb(void *data EINA_UNUSED, Ecore_Con_Reply *reply EINA_UNUSED, Ecore_Con_Client *conn EINA_UNUSED)
48{
49 ecore_main_loop_quit();
50
51 return EINA_FALSE;
52}
53
54Eina_Bool
55_eet_client_cnct_cb(void *data EINA_UNUSED, Ecore_Con_Reply *reply, Ecore_Con_Client *conn EINA_UNUSED)
56{
57 char *ec_eet_data;
58 Ecore_Con_Eet *ec_eet = ecore_con_eet_reply(reply);
59 fail_unless(ec_eet);
60
61 ec_eet_data = ecore_con_eet_data_get(ec_eet);
62 fail_if(strcmp(ec_eet_data, eet_data));
63
64 return EINA_TRUE;
65}
66
67static void
68_eet_data_cb(void *data EINA_UNUSED, Ecore_Con_Reply *reply, const char *protocol_name, void *value)
69{
70 char toSend[] = SRV_MSG;
71 ECE_Test *received = value;
72
73 fprintf(stderr, "id: %d\n message: %s\n",
74 received->id, received->message);
75 fail_if(strcmp(received->message, CLI_MSG));
76 fail_if(received->id != 1);
77
78 ecore_con_eet_raw_send(reply, protocol_name, "message", toSend,
79 strlen(toSend));
80}
81
82Eina_Bool
83_eet_svr_discnct_cb(void *data EINA_UNUSED, Ecore_Con_Reply *reply EINA_UNUSED, Ecore_Con_Client *conn EINA_UNUSED)
84{
85 ecore_main_loop_quit();
86 return EINA_FALSE;
87}
88
89Eina_Bool
90_eet_svr_cnct_cb(void *data EINA_UNUSED, Ecore_Con_Reply *reply, Ecore_Con_Client *conn EINA_UNUSED)
91{
92 ECE_Test toSend = {1, CLI_MSG};
93
94 ecore_con_eet_send(reply, TEST_STREAM, &toSend);
95 return EINA_TRUE;
96}
97
98static void
99_eet_raw_data_cb(void *data EINA_UNUSED, Ecore_Con_Reply *reply EINA_UNUSED, const char *protocol_name EINA_UNUSED, const char *section, void *value, size_t length)
100{
101 fprintf(stderr, "Section: %s\n", section);
102 fprintf(stderr, "Value: %s\n", (char *) value);
103 fail_if(strncmp((char *) value, SRV_MSG, length));
104
105 ecore_main_loop_quit();
106}
107
108START_TEST(ecore_con_test_ecore_con_eet_svr_cl)
109{
110 Ecore_Con_Eet *ece_svr, *ece_cl;
111 Ecore_Con_Server *svr, *cl;
112
113 eina_init();
114 eet_init();
115 ecore_con_init();
116 _ece_test_descriptor_init();
117
118 svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP, "127.0.0.1",
119 8080, NULL);
120 fail_unless(svr);
121
122 ece_svr = ecore_con_eet_server_new(svr);
123 fail_unless(ece_svr);
124
125 ecore_con_eet_data_set(ece_svr, eet_data);
126
127 ecore_con_eet_register(ece_svr, TEST_STREAM, _ece_test_descriptor);
128 ecore_con_eet_data_callback_add(ece_svr, TEST_STREAM, _eet_data_cb,
129 NULL);
130 ecore_con_eet_client_connect_callback_add(ece_svr, _eet_client_cnct_cb,
131 NULL);
132 ecore_con_eet_client_disconnect_callback_add(ece_svr,
133 _eet_client_discnct_cb, NULL);
134
135 cl = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, "127.0.0.1",
136 8080, NULL);
137 fail_unless (cl);
138
139 ece_cl = ecore_con_eet_client_new(cl);
140 fail_unless (ece_cl);
141
142 ecore_con_eet_register(ece_cl, TEST_STREAM, _ece_test_descriptor);
143 ecore_con_eet_raw_data_callback_add(ece_cl, TEST_STREAM,
144 _eet_raw_data_cb, NULL);
145 ecore_con_eet_server_connect_callback_add(ece_cl, _eet_svr_cnct_cb, NULL);
146 ecore_con_eet_server_disconnect_callback_add(ece_cl, _eet_svr_discnct_cb,
147 NULL);
148
149 ecore_main_loop_begin();
150
151 ecore_con_eet_raw_data_callback_del(ece_cl, TEST_STREAM);
152 ecore_con_eet_server_connect_callback_del(ece_cl, _eet_svr_cnct_cb, NULL);
153 ecore_con_eet_server_disconnect_callback_del(ece_cl, _eet_svr_discnct_cb,
154 NULL);
155
156 ecore_con_eet_data_callback_del(ece_svr, TEST_STREAM);
157 ecore_con_eet_client_connect_callback_del(ece_svr, _eet_client_cnct_cb,
158 NULL);
159 ecore_con_eet_client_disconnect_callback_del(ece_svr,
160 _eet_client_discnct_cb, NULL);
161
162 _ece_test_descriptor_shutdown();
163 ecore_con_server_del(cl);
164 ecore_con_server_del(svr);
165 ecore_con_shutdown();
166 eet_shutdown();
167 eina_shutdown();
168}
169END_TEST
170void ecore_con_test_ecore_con_eet(TCase *tc)
171{
172 tcase_add_test(tc, ecore_con_test_ecore_con_eet_svr_cl);
173}