5 #define E_CONNMAN_I_KNOW_THIS_API_IS_SUBJECT_TO_CHANGE 1
6 #include "connman0_7x/E_Connman.h"
10 #define DBG(...) EINA_LOG_DBG(__VA_ARGS__)
11 #define INF(...) EINA_LOG_INFO(__VA_ARGS__)
12 #define WRN(...) EINA_LOG_WARN(__VA_ARGS__)
13 #define ERR(...) EINA_LOG_ERR(__VA_ARGS__)
15 static int success = 0;
16 static int failure = 0;
17 static Ecore_Timer *exiter = NULL;
20 _test_string_get(E_Connman_Element *element, const char *name, Eina_Bool (*func)(const E_Connman_Element *element, const char **value))
25 INF("BEGIN: testing string get %s of element %s...", name, element->path);
26 ret = func(element, &value);
28 INF("SUCCESS: testing string get %s of element %s: %s",
29 name, element->path, value);
31 WRN("FAILURE: testing string get %s of element %s",
38 _test_string_array_get(E_Connman_Element *element, const char *name, Eina_Bool (*func)(const E_Connman_Element *element, unsigned int *count, const char ***value))
44 INF("BEGIN: testing string array get %s of element %s...",
46 ret = func(element, &count, &value);
49 INF("SUCCESS: testing string array get %s of element %s: %p[%u]",
50 name, element->path, value, count);
53 WRN("FAILURE: testing string get %s of element %s",
60 _test_bool_get(E_Connman_Element *element, const char *name, Eina_Bool (*func)(const E_Connman_Element *element, Eina_Bool *value))
64 INF("BEGIN: testing Eina_Bool get %s of element %s...", name, element->path);
65 ret = func(element, &value);
67 INF("SUCCESS: testing Eina_Bool get %s of element %s: %hhu",
68 name, element->path, value);
70 WRN("FAILURE: testing Eina_Bool get %s of element %s",
77 _test_uchar_get(E_Connman_Element *element, const char *name, Eina_Bool (*func)(const E_Connman_Element *element, unsigned char *value))
82 INF("BEGIN: testing uchar get %s of element %s...", name, element->path);
83 ret = func(element, &value);
85 INF("SUCCESS: testing uchar get %s of element %s: %hhu",
86 name, element->path, value);
88 WRN("FAILURE: testing uchar get %s of element %s",
95 _test_ushort_get(E_Connman_Element *element, const char *name, Eina_Bool (*func)(const E_Connman_Element *element, unsigned short *value))
100 INF("BEGIN: testing ushort get %s of element %s...", name, element->path);
101 ret = func(element, &value);
103 INF("SUCCESS: testing ushort get %s of element %s: %hu",
104 name, element->path, value);
106 WRN("FAILURE: testing ushort get %s of element %s",
107 name, element->path);
113 _test_uchar_array_get(E_Connman_Element *element, const char *name, Eina_Bool (*func)(const E_Connman_Element *element, unsigned int *count, unsigned char **value))
115 unsigned char *value;
119 INF("BEGIN: testing uchar array get %s of element %s...",
120 name, element->path);
121 ret = func(element, &count, &value);
124 INF("SUCCESS: testing uchar array get %s of element %s: %p[%u]",
125 name, element->path, value, count);
129 WRN("FAILURE: testing uchar array get %s of element %s",
130 name, element->path);
136 _test_element_get(E_Connman_Element *element, const char *name, Eina_Bool (*func)(const E_Connman_Element *element, E_Connman_Element **value))
138 E_Connman_Element *value;
141 INF("BEGIN: testing element get %s of element %s...", name, element->path);
142 ret = func(element, &value);
144 INF("SUCCESS: testing element get %s of element %s: %p",
145 name, element->path, value);
147 WRN("FAILURE: testing element get %s of element %s",
148 name, element->path);
154 _test_elements_get(E_Connman_Element *element, const char *name, Eina_Bool (*func)(const E_Connman_Element *element, unsigned int *count, E_Connman_Element ***elements))
156 E_Connman_Element **value;
160 INF("BEGIN: testing elements get %s of element %s...",
161 name, element->path);
162 ret = func(element, &count, &value);
165 INF("SUCCESS: testing elements get %s of element %s: %p",
166 name, element->path, value);
170 WRN("FAILURE: testing elements get %s of element %s",
171 name, element->path);
177 _test_element_get_global(const char *name, Eina_Bool (*func)(E_Connman_Element **value))
179 E_Connman_Element *value;
182 INF("BEGIN: testing element get %s", name);
185 INF("SUCCESS: testing element get %s: %p", name, value);
187 WRN("FAILURE: testing element get %s", name);
193 _test_elements_get_global(const char *name, Eina_Bool (*func)(unsigned int *count, E_Connman_Element ***elements))
195 E_Connman_Element **value;
199 INF("BEGIN: testing elements get %s", name);
200 ret = func(&count, &value);
203 INF("SUCCESS: testing elements get %s: %p", name, value);
207 WRN("FAILURE: testing elements get %s", name);
213 _test_string_get_global(const char *name, Eina_Bool (*func)(const char **value))
218 INF("BEGIN: testing string get %s...", name);
221 INF("SUCCESS: testing string get %s: %s", name, value);
223 WRN("FAILURE: testing string get %s", name);
229 _test_bool_get_global(const char *name, Eina_Bool (*func)(Eina_Bool *value))
231 Eina_Bool value, ret;
233 INF("BEGIN: testing Eina_Bool get %s...", name);
236 INF("SUCCESS: testing Eina_Bool get %s: %hhu", name, value);
238 WRN("FAILURE: testing Eina_Bool get %s", name);
244 _test_strings_get_global(const char *name, Eina_Bool (*func)(unsigned int *count, const char ***elements))
250 INF("BEGIN: testing strings get %s", name);
251 ret = func(&count, &value);
254 INF("SUCCESS: testing strings get %s: %p", name, value);
258 WRN("FAILURE: testing strings get %s", name);
268 TEST_DESC_TYPE_STRING_GET,
269 TEST_DESC_TYPE_STRING_ARRAY_GET,
270 TEST_DESC_TYPE_BOOL_GET,
271 TEST_DESC_TYPE_UCHAR_GET,
272 TEST_DESC_TYPE_USHORT_GET,
273 TEST_DESC_TYPE_UCHAR_ARRAY_GET,
274 TEST_DESC_TYPE_ELEMENT_GET,
275 TEST_DESC_TYPE_ELEMENTS_GET,
276 TEST_DESC_TYPE_ELEMENT_GET_GLOBAL,
277 TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL,
278 TEST_DESC_TYPE_STRING_GET_GLOBAL,
279 TEST_DESC_TYPE_BOOL_GET_GLOBAL,
280 TEST_DESC_TYPE_STRINGS_GET_GLOBAL,
284 Eina_Bool (*string_get)(const E_Connman_Element *element, const char **value);
285 Eina_Bool (*string_array_get)(const E_Connman_Element *element, unsigned int *count, const char ***value);
286 Eina_Bool (*bool_get)(const E_Connman_Element *element, Eina_Bool *value);
287 Eina_Bool (*uchar_get)(const E_Connman_Element *element, unsigned char *value);
288 Eina_Bool (*ushort_get)(const E_Connman_Element *element, unsigned short*value);
289 Eina_Bool (*uchar_array_get)(const E_Connman_Element *element, unsigned int *count, unsigned char **value);
290 Eina_Bool (*element_get)(const E_Connman_Element *element, E_Connman_Element **value);
291 Eina_Bool (*elements_get)(const E_Connman_Element *element, unsigned int *count, E_Connman_Element ***elements);
292 Eina_Bool (*element_get_global)(E_Connman_Element **element);
293 Eina_Bool (*elements_get_global)(unsigned int *count, E_Connman_Element ***elements);
294 Eina_Bool (*string_get_global)(const char **value);
295 Eina_Bool (*bool_get_global)(Eina_Bool *value);
296 Eina_Bool (*strings_get_global)(unsigned int *count, const char ***strings);
302 #define TEST_DESC_STRING_GET(_func, may_fail) \
303 {#_func, TEST_DESC_TYPE_STRING_GET, .func.string_get=_func, may_fail}
304 #define TEST_DESC_STRING_ARRAY_GET(_func, may_fail) \
305 {#_func, TEST_DESC_TYPE_STRING_ARRAY_GET, .func.string_array_get=_func, may_fail}
306 #define TEST_DESC_BOOL_GET(_func, may_fail) \
307 {#_func, TEST_DESC_TYPE_BOOL_GET, .func.bool_get=_func, may_fail}
308 #define TEST_DESC_UCHAR_GET(_func, may_fail) \
309 {#_func, TEST_DESC_TYPE_UCHAR_GET, .func.uchar_get=_func, may_fail}
310 #define TEST_DESC_USHORT_GET(_func, may_fail) \
311 {#_func, TEST_DESC_TYPE_USHORT_GET, .func.ushort_get=_func, may_fail}
312 #define TEST_DESC_UCHAR_ARRAY_GET(_func, may_fail) \
313 {#_func, TEST_DESC_TYPE_UCHAR_ARRAY_GET, .func.uchar_array_get=_func, may_fail}
314 #define TEST_DESC_ELEMENT_GET(_func, may_fail) \
315 {#_func, TEST_DESC_TYPE_ELEMENT_GET, .func.element_get=_func, may_fail}
316 #define TEST_DESC_ELEMENTS_GET(_func, may_fail) \
317 {#_func, TEST_DESC_TYPE_ELEMENTS_GET, .func.elements_get=_func, may_fail}
318 #define TEST_DESC_ELEMENT_GET_GLOBAL(_func, may_fail) \
319 {#_func, TEST_DESC_TYPE_ELEMENT_GET_GLOBAL, .func.element_get_global=_func, may_fail}
320 #define TEST_DESC_ELEMENTS_GET_GLOBAL(_func, may_fail) \
321 {#_func, TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL, .func.elements_get_global=_func, may_fail}
322 #define TEST_DESC_STRING_GET_GLOBAL(_func, may_fail) \
323 {#_func, TEST_DESC_TYPE_STRING_GET_GLOBAL, .func.string_get_global=_func, may_fail}
324 #define TEST_DESC_BOOL_GET_GLOBAL(_func, may_fail) \
325 {#_func, TEST_DESC_TYPE_BOOL_GET_GLOBAL, .func.bool_get_global=_func, may_fail}
326 #define TEST_DESC_STRINGS_GET_GLOBAL(_func, may_fail) \
327 {#_func, TEST_DESC_TYPE_STRINGS_GET_GLOBAL, .func.strings_get_global=_func, may_fail}
328 #define TEST_DESC_SENTINEL {NULL, TEST_DESC_TYPE_LAST, .func.dummy=NULL}
331 _test_element(E_Connman_Element *element, const struct test_desc *test_descs)
333 const struct test_desc *itr;
334 int total, ok = 0, fail = 0;
335 Eina_Bool ret = EINA_TRUE;
337 for (itr = test_descs; itr->type != TEST_DESC_TYPE_LAST; itr++)
343 case TEST_DESC_TYPE_STRING_GET:
344 r = _test_string_get(element, itr->name, itr->func.string_get);
346 case TEST_DESC_TYPE_STRING_ARRAY_GET:
347 r = _test_string_array_get
348 (element, itr->name, itr->func.string_array_get);
350 case TEST_DESC_TYPE_BOOL_GET:
351 r = _test_bool_get(element, itr->name, itr->func.bool_get);
353 case TEST_DESC_TYPE_UCHAR_GET:
354 r = _test_uchar_get(element, itr->name, itr->func.uchar_get);
356 case TEST_DESC_TYPE_USHORT_GET:
357 r = _test_ushort_get(element, itr->name, itr->func.ushort_get);
359 case TEST_DESC_TYPE_UCHAR_ARRAY_GET:
360 r = _test_uchar_array_get
361 (element, itr->name, itr->func.uchar_array_get);
363 case TEST_DESC_TYPE_ELEMENT_GET:
364 r = _test_element_get
365 (element, itr->name, itr->func.element_get);
367 case TEST_DESC_TYPE_ELEMENTS_GET:
368 r = _test_elements_get
369 (element, itr->name, itr->func.elements_get);
371 case TEST_DESC_TYPE_ELEMENT_GET_GLOBAL:
372 r = _test_element_get_global
373 (itr->name, itr->func.element_get_global);
375 case TEST_DESC_TYPE_ELEMENTS_GET_GLOBAL:
376 r = _test_elements_get_global
377 (itr->name, itr->func.elements_get_global);
379 case TEST_DESC_TYPE_STRING_GET_GLOBAL:
380 r = _test_string_get_global
381 (itr->name, itr->func.string_get_global);
383 case TEST_DESC_TYPE_BOOL_GET_GLOBAL:
384 r = _test_bool_get_global
385 (itr->name, itr->func.bool_get_global);
387 case TEST_DESC_TYPE_STRINGS_GET_GLOBAL:
388 r = _test_strings_get_global
389 (itr->name, itr->func.strings_get_global);
392 ERR("unknown test type %d (%s)", itr->type, itr->name);
397 if (r || itr->may_fail)
401 ERR("test failed %s, element %s [%s]",
402 itr->name, element->path, element->interface);
408 total = ok + failure;
413 INF("no tests for %s [%s]", element->path, element->interface);
417 INF("testing %s success: %d, failure: %d: %d%% [%s]",
418 element->path, ok, fail, (ok * 100) / total,
424 static const struct test_desc test_desc_manager[] = {
425 TEST_DESC_STRING_GET_GLOBAL(e_connman_manager_state_get, 0),
426 TEST_DESC_BOOL_GET_GLOBAL(e_connman_manager_offline_mode_get, 0),
427 //TEST_DESC_STRING_SET_GLOBAL(e_connman_manager_request_scan, 0),
428 //TEST_DESC_BOOL_SET_GLOBAL(e_connman_manager_offline_mode_set, 0),
429 TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_profiles_get, 0),
430 TEST_DESC_ELEMENTS_GET_GLOBAL(e_connman_manager_services_get, 1),
431 TEST_DESC_STRING_GET_GLOBAL(e_connman_manager_technology_default_get, 0),
432 TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_available_get, 0),
433 TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_enabled_get, 0),
434 TEST_DESC_STRINGS_GET_GLOBAL(e_connman_manager_technologies_connected_get, 0),
435 TEST_DESC_ELEMENT_GET_GLOBAL(e_connman_manager_profile_active_get, 0),
439 static const struct test_desc test_desc_profile[] = {
440 TEST_DESC_STRING_GET(e_connman_profile_name_get, 1),
441 //TEST_DESC_STRING_SET(e_connman_profile_name_set, 1),
442 TEST_DESC_BOOL_GET(e_connman_profile_offline_mode_get, 0),
443 //TEST_DESC_BOOL_SET(e_connman_profile_offline_mode_set, 0),
444 TEST_DESC_ELEMENTS_GET(e_connman_profile_services_get, 1),
448 static const struct test_desc test_desc_service[] = {
449 /* TODO: need to check exactly what properties may fail */
450 TEST_DESC_STRING_GET(e_connman_service_state_get, 1),
451 TEST_DESC_STRING_GET(e_connman_service_error_get, 1),
452 TEST_DESC_STRING_GET(e_connman_service_name_get, 0),
453 TEST_DESC_STRING_GET(e_connman_service_type_get, 0),
454 TEST_DESC_STRING_ARRAY_GET(e_connman_service_security_get, 1),
455 TEST_DESC_STRING_GET(e_connman_service_passphrase_get, 1),
456 //TEST_DESC_STRING_SET(e_connman_service_passphrase_set, 1),
457 TEST_DESC_BOOL_GET(e_connman_service_passphrase_required_get, 1),
458 TEST_DESC_UCHAR_GET(e_connman_service_strength_get, 1),
459 TEST_DESC_BOOL_GET(e_connman_service_favorite_get, 0),
460 TEST_DESC_BOOL_GET(e_connman_service_immutable_get, 0),
461 TEST_DESC_BOOL_GET(e_connman_service_auto_connect_get, 0),
462 //TEST_DESC_BOOL_SET(e_connman_service_auto_connect_set, 1),
463 TEST_DESC_BOOL_GET(e_connman_service_roaming_get, 1),
464 TEST_DESC_STRING_GET(e_connman_service_ipv4_method_get, 1),
465 TEST_DESC_STRING_GET(e_connman_service_ipv4_address_get, 1),
466 TEST_DESC_STRING_GET(e_connman_service_ipv4_gateway_get, 1),
467 TEST_DESC_STRING_GET(e_connman_service_ipv4_netmask_get, 1),
468 TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_method_get, 1),
469 TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_address_get, 1),
470 TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_gateway_get, 1),
471 TEST_DESC_STRING_GET(e_connman_service_ipv4_configuration_netmask_get, 1),
472 TEST_DESC_STRING_GET(e_connman_service_ethernet_method_get, 1),
473 TEST_DESC_STRING_GET(e_connman_service_ethernet_address_get, 1),
474 TEST_DESC_USHORT_GET(e_connman_service_ethernet_mtu_get, 1),
479 _quit(__UNUSED__ void *data)
481 ecore_main_loop_quit();
482 return ECORE_CALLBACK_CANCEL;
486 _on_exiter(__UNUSED__ void *data)
488 e_connman_system_shutdown();
489 ecore_idle_enterer_add(_quit, NULL);
491 return ECORE_CALLBACK_CANCEL;
495 _exiter_reschedule(void)
498 ecore_timer_del(exiter);
499 exiter = ecore_timer_add(10, _on_exiter, NULL);
502 struct test_element_timer_data
504 E_Connman_Element *element;
509 _test_element_timer(void *data)
511 struct test_element_timer_data *d = data;
512 E_Connman_Element *element = d->element;
514 if (e_connman_element_is_profile(element))
515 _test_element(element, test_desc_profile);
516 else if (e_connman_element_is_manager(element))
517 _test_element(element, test_desc_manager);
518 else if (e_connman_element_is_service(element))
519 _test_element(element, test_desc_service);
521 ERR("!!! don't know how to test %s [%s]",
522 element->path, element->interface);
524 _exiter_reschedule();
527 return ECORE_CALLBACK_CANCEL;
531 _element_listener(void *data, __UNUSED__ const E_Connman_Element *element)
533 struct test_element_timer_data *d = data;
535 ecore_timer_del(d->timer);
536 d->timer = ecore_timer_add(1.0, _test_element_timer, d);
537 _exiter_reschedule();
541 _element_listener_free(void *data)
543 struct test_element_timer_data *d = data;
545 ecore_timer_del(d->timer);
550 _on_element_add(__UNUSED__ void *data, __UNUSED__ int type, void *info)
552 E_Connman_Element *element = info;
553 struct test_element_timer_data *d;
555 d = malloc(sizeof(*d));
557 return ECORE_CALLBACK_PASS_ON;
559 d->element = element;
560 d->timer = ecore_timer_add(1.0, _test_element_timer, d);
561 e_connman_element_listener_add
562 (element, _element_listener, d, _element_listener_free);
564 return ECORE_CALLBACK_PASS_ON;
568 _on_element_del(__UNUSED__ void *data, __UNUSED__ int type, __UNUSED__ void *info)
570 return ECORE_CALLBACK_PASS_ON;
574 _on_element_updated(__UNUSED__ void *data, __UNUSED__ int type, __UNUSED__ void *info)
576 return ECORE_CALLBACK_PASS_ON;
580 main(__UNUSED__ int argc, __UNUSED__ char *argv[])
582 E_DBus_Connection *c;
589 c = e_dbus_bus_get(DBUS_BUS_SYSTEM);
591 printf("ERROR: can't connect to system session\n");
595 e_connman_system_init(c);
596 ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_ADD, _on_element_add, NULL);
597 ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_DEL, _on_element_del, NULL);
598 ecore_event_handler_add(E_CONNMAN_EVENT_ELEMENT_UPDATED,
599 _on_element_updated, NULL);
601 _exiter_reschedule();
603 ecore_main_loop_begin();
605 e_dbus_connection_close(c);
606 eina_stringshare_dump();
611 total = success + failure;
613 fputs("DBG: clean exit, no tests executed.\n", stderr);
615 fprintf(stderr, "DBG: clean exit, success: %d, failure: %d, %d%%\n",
616 success, failure, (success * 100) / total);