summaryrefslogtreecommitdiff
path: root/src/tests/ecore_con/ecore_con_test_efl_net_ip_address.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric@osg.samsung.com>2018-04-27 16:20:47 -0700
committerCedric BAIL <cedric@osg.samsung.com>2018-05-01 10:39:01 -0700
commitec44120e93fac0c933b99eb1b221c8389299930a (patch)
tree9e289f93fcf4608292aa2934dd2f2ee3a89f9b35 /src/tests/ecore_con/ecore_con_test_efl_net_ip_address.c
parentb1883c7989355e95cd4c826d3c7ecdbbbd257d77 (diff)
ecore_con: migrate efl_net_ip_address_resolve to use Eina_Future.
Diffstat (limited to '')
-rw-r--r--src/tests/ecore_con/ecore_con_test_efl_net_ip_address.c81
1 files changed, 29 insertions, 52 deletions
diff --git a/src/tests/ecore_con/ecore_con_test_efl_net_ip_address.c b/src/tests/ecore_con/ecore_con_test_efl_net_ip_address.c
index a32f6ee6a6..b44bd0bffa 100644
--- a/src/tests/ecore_con/ecore_con_test_efl_net_ip_address.c
+++ b/src/tests/ecore_con/ecore_con_test_efl_net_ip_address.c
@@ -128,51 +128,38 @@ _timeout(void *data,
128 128
129 129
130struct resolve_ctx { 130struct resolve_ctx {
131 Eina_Array *results; 131 Eina_Value *results;
132 Eina_Stringshare *canonical_name; 132 Eina_Stringshare *canonical_name;
133 Eina_Stringshare *request_address; 133 Eina_Stringshare *request_address;
134 Efl_Future *future; 134 Eina_Future *future;
135 Eina_Error err; 135 Eina_Error err;
136}; 136};
137 137
138static void 138static void
139_resolve_cleanup(struct resolve_ctx *ctx) 139_resolve_cleanup(struct resolve_ctx *ctx)
140{ 140{
141 Eina_Array_Iterator it;
142 unsigned int i;
143 const Efl_Net_Ip_Address *o;
144
145 mark_point(); 141 mark_point();
146 142
147 if (ctx->results) 143 if (ctx->results) eina_value_free(ctx->results);
148 { 144 ctx->results = NULL;
149 EINA_ARRAY_ITER_NEXT(ctx->results, i, o, it)
150 efl_unref(o);
151 eina_array_free(ctx->results);
152 ctx->results = NULL;
153 }
154 145
155 ctx->err = 0; 146 ctx->err = 0;
156 eina_stringshare_replace(&ctx->canonical_name, NULL); 147 eina_stringshare_replace(&ctx->canonical_name, NULL);
157 eina_stringshare_replace(&ctx->request_address, NULL); 148 eina_stringshare_replace(&ctx->request_address, NULL);
158 149
159 if (ctx->future) 150 if (ctx->future) eina_future_cancel(ctx->future);
160 { 151 ctx->future = NULL;
161 efl_future_cancel(ctx->future);
162 ctx->future = NULL;
163 }
164} 152}
165 153
166static Eina_Bool 154static Eina_Bool
167_resolve_found(const struct resolve_ctx *ctx, const char *string) 155_resolve_found(const struct resolve_ctx *ctx, const char *string)
168{ 156{
169 Eina_Array_Iterator it;
170 unsigned int i;
171 const Efl_Net_Ip_Address *o; 157 const Efl_Net_Ip_Address *o;
158 unsigned int i, len;
172 159
173 ck_assert_ptr_ne(ctx->results, NULL); 160 ck_assert_ptr_ne(ctx->results, NULL);
174 161
175 EINA_ARRAY_ITER_NEXT(ctx->results, i, o, it) 162 EINA_VALUE_ARRAY_FOREACH(ctx->results, len, i, o)
176 { 163 {
177 if (strcmp(string, efl_net_ip_address_string_get(o)) == 0) 164 if (strcmp(string, efl_net_ip_address_string_get(o)) == 0)
178 return EINA_TRUE; 165 return EINA_TRUE;
@@ -186,8 +173,7 @@ static void
186_assert_found_internal(const char *file, int line, const struct resolve_ctx *ctx, const char *string, Eina_Bool expected, Eina_Error err) 173_assert_found_internal(const char *file, int line, const struct resolve_ctx *ctx, const char *string, Eina_Bool expected, Eina_Error err)
187{ 174{
188 Eina_Bool found; 175 Eina_Bool found;
189 Eina_Array_Iterator it; 176 unsigned int i, len;
190 unsigned int i;
191 const Efl_Net_Ip_Address *o; 177 const Efl_Net_Ip_Address *o;
192 178
193 if (ctx->err != err) 179 if (ctx->err != err)
@@ -206,7 +192,7 @@ _assert_found_internal(const char *file, int line, const struct resolve_ctx *ctx
206 fprintf(stderr, "ERROR: did%s expect '%s' in results:\n", 192 fprintf(stderr, "ERROR: did%s expect '%s' in results:\n",
207 expected ? "" : " NOT", string); 193 expected ? "" : " NOT", string);
208 194
209 EINA_ARRAY_ITER_NEXT(ctx->results, i, o, it) 195 EINA_VALUE_ARRAY_FOREACH(ctx->results, len, i, o)
210 fprintf(stderr, "result %u: %s\n", i, efl_net_ip_address_string_get(o)); 196 fprintf(stderr, "result %u: %s\n", i, efl_net_ip_address_string_get(o));
211 197
212 _ck_assert_failed(file, line, "Failed", 198 _ck_assert_failed(file, line, "Failed",
@@ -216,44 +202,35 @@ _assert_found_internal(const char *file, int line, const struct resolve_ctx *ctx
216 NULL); 202 NULL);
217} 203}
218 204
219static void 205static Eina_Value
220_resolve_done(void *data, const Efl_Event *event) 206_resolve_done(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNUSED)
221{ 207{
222 struct resolve_ctx *ctx = data; 208 struct resolve_ctx *ctx = data;
223 Efl_Future_Event_Success *f = event->info; 209 const Eina_Value_Array desc = { 0 };
224 Efl_Net_Ip_Address_Resolve_Results *r = f->value;
225 Eina_Array_Iterator it;
226 unsigned int i;
227 Efl_Net_Ip_Address *o;
228
229 ck_assert_ptr_eq(ctx->results, NULL);
230 ctx->results = eina_array_new(32);
231
232 ctx->canonical_name = eina_stringshare_ref(r->canonical_name);
233 ctx->request_address = eina_stringshare_ref(r->request_address);
234 210
235 EINA_ARRAY_ITER_NEXT(r->results, i, o, it) 211 mark_point();
236 eina_array_push(ctx->results, efl_ref(o));
237 212
238 ctx->future = NULL; 213 if (eina_value_type_get(&v) == EINA_VALUE_TYPE_ERROR)
239 ecore_main_loop_quit(); 214 {
215 eina_value_error_get(&v, &ctx->err);
216 goto end;
217 }
240 218
241 mark_point(); 219 eina_value_struct_get(&v, "canonical_name", &ctx->canonical_name);
242} 220 eina_value_struct_get(&v, "request_address", &ctx->request_address);
221 eina_value_struct_get(&v, "results", &desc);
243 222
244static void 223 ctx->results = eina_value_new(EINA_VALUE_TYPE_ARRAY);
245_resolve_failed(void *data, const Efl_Event *event) 224 eina_value_pset(ctx->results, &desc);
246{
247 struct resolve_ctx *ctx = data;
248 Efl_Future_Event_Failure *f = event->info;
249 225
250 mark_point(); 226 end:
227 ecore_main_loop_quit();
251 228
252 ctx->err = f->error;
253 ctx->future = NULL; 229 ctx->future = NULL;
254 ecore_main_loop_quit();
255 230
256 mark_point(); 231 mark_point();
232
233 return v;
257} 234}
258 235
259static void 236static void
@@ -262,7 +239,7 @@ _resolve(struct resolve_ctx *ctx, const char *address, int family, int flags)
262 ctx->future = efl_net_ip_address_resolve(EFL_NET_IP_ADDRESS_CLASS, 239 ctx->future = efl_net_ip_address_resolve(EFL_NET_IP_ADDRESS_CLASS,
263 address, family, flags); 240 address, family, flags);
264 ck_assert_ptr_ne(ctx->future, NULL); 241 ck_assert_ptr_ne(ctx->future, NULL);
265 efl_future_then(ctx->future, _resolve_done, _resolve_failed, NULL, ctx); 242 ctx->future = eina_future_then(ctx->future, _resolve_done, ctx);
266 243
267 LOOP_WITH_TIMEOUT(10); 244 LOOP_WITH_TIMEOUT(10);
268} 245}