summaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
authorVincent Torri <vincent dot torri at gmail dot com>2016-02-04 14:35:53 +0100
committerTom Hacohen <tom@stosb.com>2016-02-16 12:41:06 +0000
commit92ff735c110abac6fcb5cc9089d5c960d843888f (patch)
tree7eaeae0b6c5c0df98b442f0a52f6add6a5e1c29a /src/tests
parent0b84e7593fd6d9fcbdba12f33133c33b96dafa7d (diff)
Test rework #7: Eeze
eeze_suite.c has also been splitted
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/eeze/eeze_suite.c683
-rw-r--r--src/tests/eeze/eeze_suite.h11
-rw-r--r--src/tests/eeze/eeze_test_init.c24
-rw-r--r--src/tests/eeze/eeze_test_net.c116
-rw-r--r--src/tests/eeze/eeze_test_sensor.c280
-rw-r--r--src/tests/eeze/eeze_test_udev.c254
6 files changed, 699 insertions, 669 deletions
diff --git a/src/tests/eeze/eeze_suite.c b/src/tests/eeze/eeze_suite.c
index c1b496cf85..48884dc59e 100644
--- a/src/tests/eeze/eeze_suite.c
+++ b/src/tests/eeze/eeze_suite.c
@@ -2,684 +2,29 @@
2# include <config.h> 2# include <config.h>
3#endif /* ifdef HAVE_CONFIG_H */ 3#endif /* ifdef HAVE_CONFIG_H */
4 4
5#include <stdlib.h> 5#include "ecore_suite.h"
6#include <stdio.h> 6#include "../efl_check.h"
7 7
8#include <Eina.h> 8static const Efl_Test_Case etc[] = {
9 9 { "Init", eeze_test_init },
10#include <check.h> 10 { "UDev", eeze_test_udev },
11 11 { "Net", eeze_test_net },
12#include <Eeze.h> 12 { "Sensor", eeze_test_sensor },
13#include <Eeze_Sensor.h> 13 { NULL, NULL }
14#include <Eeze_Net.h> 14};
15
16#include "eeze_udev_private.h"
17#include "eeze_sensor_private.h"
18
19START_TEST(eeze_test_init)
20{
21 int ret;
22
23 ret = eeze_init();
24 fail_if(ret != 1);
25
26 ret = eeze_shutdown();
27 fail_if(ret != 0);
28}
29END_TEST
30
31static void
32catch_events(const char *device EINA_UNUSED, Eeze_Udev_Event event EINA_UNUSED,
33 void *data EINA_UNUSED, Eeze_Udev_Watch *watch EINA_UNUSED)
34{
35}
36
37#if 0
38// FIXME split udev tests into pieces here
39START_TEST(eeze_test_udev_types)
40{
41 Eina_List *type;
42
43 eeze_init();
44
45 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NONE, NULL);
46 type = eeze_udev_find_unlisted_similar(type);
47 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL);
48 type = eeze_udev_find_unlisted_similar(type);
49 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL);
50 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_TOUCHPAD, NULL);
51 type = eeze_udev_find_unlisted_similar(type);
52 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL);
53 type = eeze_udev_find_unlisted_similar(type);
54 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
55 type = eeze_udev_find_unlisted_similar(type);
56 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
57 type = eeze_udev_find_unlisted_similar(type);
58 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_CDROM, NULL);
59 type = eeze_udev_find_unlisted_similar(type);
60 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_AC, NULL);
61 type = eeze_udev_find_unlisted_similar(type);
62 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_BAT, NULL);
63 type = eeze_udev_find_unlisted_similar(type);
64 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR, NULL);
65 type = eeze_udev_find_unlisted_similar(type);
66 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL);
67 type = eeze_udev_find_unlisted_similar(type);
68 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
69 type = eeze_udev_find_unlisted_similar(type);
70 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_BLUETOOTH, NULL);
71 type = eeze_udev_find_unlisted_similar(type);
72 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, NULL);
73 type = eeze_udev_find_unlisted_similar(type);
74 type = eeze_udev_find_by_type(0, NULL);
75 type = eeze_udev_find_unlisted_similar(type);
76
77 eeze_shutdown();
78}
79END_TEST
80#endif
81
82START_TEST(eeze_test_udev_watch)
83{
84 Eeze_Udev_Watch *watch;
85
86 ecore_init();
87 eeze_init();
88
89 /* watch never gets triggered as this is run without user interaction */
90 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_KEYBOARD, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
91 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_DRIVE_INTERNAL, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
92 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_POWER_AC, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
93 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_NET, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
94 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
95 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
96 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_BLUETOOTH, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
97 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_NONE, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
98 eeze_udev_watch_del(watch);
99
100 eeze_shutdown();
101 ecore_shutdown();
102}
103END_TEST
104
105START_TEST(eeze_test_udev_syspath)
106{
107 Eina_List *type, *l;
108 const char *name;
109 Eina_Bool r;
110
111 eeze_init();
112
113 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL);
114 type = eeze_udev_find_unlisted_similar(type);
115 EINA_LIST_FOREACH(type, l, name)
116 {
117 eeze_udev_syspath_get_devpath(name);
118 eeze_udev_find_similar_from_syspath(name);
119 eeze_udev_find_similar_from_syspath(NULL);
120 eeze_udev_syspath_get_parent(name);
121 eeze_udev_syspath_get_parent(NULL);
122 eeze_udev_syspath_get_parents(name);
123 eeze_udev_syspath_get_parents(NULL);
124 eeze_udev_syspath_get_devname(name);
125 eeze_udev_syspath_get_devname(NULL);
126 eeze_udev_syspath_get_subsystem(name);
127 eeze_udev_syspath_get_sysattr(name, "manufacturer");
128 eeze_udev_syspath_is_mouse(name);
129 eeze_udev_syspath_is_kbd(name);
130 eeze_udev_syspath_is_touchpad(name);
131 eeze_udev_syspath_is_joystick(name);
132 eeze_udev_walk_get_sysattr(name, "manufacturer");
133 eeze_udev_find_by_sysattr("manufacturer", NULL);
134 eeze_udev_find_by_sysattr(NULL, NULL);
135 eeze_udev_walk_check_sysattr(name, "manufacturer", NULL);
136 eeze_udev_walk_check_sysattr(name, "manufacturer", "foo");
137 eeze_udev_walk_get_sysattr(NULL, "manufacturer");
138 eeze_udev_walk_get_sysattr(name, NULL);
139 }
140
141 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL);
142 type = eeze_udev_find_unlisted_similar(type);
143 EINA_LIST_FOREACH(type, l, name)
144 {
145 r = eeze_udev_syspath_is_mouse(name);
146 fail_unless(r);
147
148 eeze_udev_syspath_is_touchpad(name);
149 eeze_udev_syspath_is_joystick(name);
150 }
151
152 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_TOUCHPAD, NULL);
153 type = eeze_udev_find_unlisted_similar(type);
154 EINA_LIST_FOREACH(type, l, name)
155 {
156 r = eeze_udev_syspath_is_touchpad(name);
157 fail_unless(r);
158 }
159
160 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, NULL);
161 type = eeze_udev_find_unlisted_similar(type);
162 EINA_LIST_FOREACH(type, l, name)
163 {
164 r = eeze_udev_syspath_is_joystick(name);
165 fail_unless(r);
166 }
167
168 eeze_udev_devpath_get_syspath("/dev/null");
169
170 eeze_shutdown();
171}
172END_TEST
173
174START_TEST(eeze_test_udev_attr)
175{
176 Eina_List *type;
177 const char *name, *check, *check2;
178
179 eeze_init();
180
181 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
182 type = eeze_udev_find_unlisted_similar(type);
183 eeze_udev_find_by_filter("backlight", NULL, NULL);
184
185 eeze_udev_find_by_filter(NULL, NULL, NULL);
186
187 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL);
188 type = eeze_udev_find_unlisted_similar(type);
189 EINA_LIST_FREE(type, name)
190 {
191 check = eeze_udev_syspath_get_property(name, "INTERFACE");
192 }
193
194 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
195 type = eeze_udev_find_unlisted_similar(type);
196 EINA_LIST_FREE(type, name)
197 {
198 check = eeze_udev_syspath_get_property(name, "ID_SERIAL");
199 }
200
201 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
202 type = eeze_udev_find_unlisted_similar(type);
203 EINA_LIST_FREE(type, name)
204 {
205 if ((check = eeze_udev_syspath_get_sysattr(name, "model")))
206 {
207 check2 = eeze_udev_syspath_get_subsystem(name);
208 }
209 }
210
211 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
212 type = eeze_udev_find_unlisted_similar(type);
213 EINA_LIST_FREE(type, name)
214 {
215 if ((check = eeze_udev_syspath_get_property(name, "DEVNAME")))
216 {
217 if ((check2 = eeze_udev_syspath_get_sysattr(name, "name")))
218 {
219 eina_stringshare_del(check2);
220 }
221 eina_stringshare_del(check);
222 }
223 eina_stringshare_del(name);
224 }
225
226 eeze_shutdown();
227}
228END_TEST
229
230/*
231START_TEST(eeze_test_udev_device)
232{
233 Eina_List *type, *l;
234 _udev_device *device, *device2;
235 const char *name;
236
237 eeze_init();
238
239 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
240 fail_if(type == NULL);
241 type = eeze_udev_find_unlisted_similar(type);
242 fail_if(type == NULL);
243 EINA_LIST_FOREACH(type, l, name)
244 {
245 device = _new_device(name);
246 fail_if(device == NULL);
247 _walk_parents_get_attr(device, "FOO", EINA_FALSE);
248 _walk_parents_get_attr(device, "FOO", EINA_TRUE);
249 _walk_children_get_attr(name, "FOO", "BAR", EINA_FALSE);
250 _walk_children_get_attr(name, "FOO", "BAR", EINA_TRUE);
251 }
252
253 device = _new_device("Wrong path");
254 fail_if(device != NULL);
255
256 device2 = _copy_device(device);
257 fail_if(device2 != NULL);
258
259 eeze_shutdown();
260}
261END_TEST
262*/
263
264START_TEST(eeze_test_net_list)
265{
266 int ret;
267 Eina_List *list = NULL;
268
269 ret = eeze_init();
270 fail_if(ret != 1);
271
272 list = eeze_net_list();
273 fail_if(list == NULL);
274
275 ret = eeze_shutdown();
276 fail_if(ret != 0);
277}
278END_TEST
279
280START_TEST(eeze_test_net_attr)
281{
282 int ret;
283 int idx = 0;
284 Eeze_Net *net = NULL;
285 const char *tmp = NULL;
286
287 ret = eeze_init();
288 fail_if(ret != 1);
289
290 net = eeze_net_new("lo");
291 fail_if(net == NULL);
292
293 tmp = eeze_net_mac_get(net);
294 fail_if(tmp == NULL);
295 tmp = NULL;
296
297 idx = eeze_net_idx_get(net);
298 fail_if(!idx);
299
300 eeze_net_scan(net);
301
302 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_IP);
303 fail_if(tmp == NULL);
304 tmp = NULL;
305
306 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_BROADCAST);
307 fail_if(tmp == NULL);
308 tmp = NULL;
309
310 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_NETMASK);
311 fail_if(tmp == NULL);
312 tmp = NULL;
313
314 tmp = eeze_net_attribute_get(net, "carrier");
315 fail_if(tmp == NULL);
316 tmp = NULL;
317
318 tmp = eeze_net_syspath_get(net);
319 fail_if(tmp == NULL);
320
321 eeze_net_free(net);
322
323 ret = eeze_shutdown();
324 fail_if(ret != 0);
325}
326END_TEST
327
328/*
329#ifdef HAVE_IPV6
330START_TEST(eeze_test_net_attr_ipv6)
331{
332 int ret;
333 Eeze_Net *net = NULL;
334 const char *tmp = NULL;
335
336 ret = eeze_init();
337 fail_if(ret != 1);
338
339 net = eeze_net_new("lo");
340 fail_if(net == NULL);
341
342 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_IP6);
343 fail_if(tmp == NULL);
344 tmp = NULL;
345
346 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_BROADCAST6);
347 fail_if(tmp == NULL);
348 tmp = NULL;
349
350 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_NETMASK6);
351 fail_if(tmp == NULL);
352
353 eeze_net_free(net);
354
355 ret = eeze_shutdown();
356 fail_if(ret != 0);
357}
358END_TEST
359#endif
360*/
361
362START_TEST(eeze_test_sensor_read)
363{
364 Eeze_Sensor_Obj *sens = NULL;
365 int ret = 0;
366 float x, y, z;
367 int acc;
368 double timestamp;
369 Eina_Bool rc = EINA_FALSE;
370
371 ecore_init();
372 ret = eeze_init();
373 fail_if(ret != 1);
374
375 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
376 fail_if(sens == NULL);
377 rc = eeze_sensor_read(sens);
378 fail_if(rc == EINA_FALSE);
379 rc = eeze_sensor_accuracy_get(sens, &acc);
380 fail_if(rc == EINA_FALSE);
381 rc = eeze_sensor_timestamp_get(sens, &timestamp);
382 fail_if(rc == EINA_FALSE);
383 rc = eeze_sensor_xyz_get(sens, &x, &y, &z);
384 fail_if(rc == EINA_FALSE);
385
386 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC);
387 fail_if(sens == NULL);
388 rc = eeze_sensor_read(sens);
389 fail_if(rc == EINA_FALSE);
390 rc = eeze_sensor_accuracy_get(sens, &acc);
391 fail_if(rc == EINA_FALSE);
392 rc = eeze_sensor_timestamp_get(sens, &timestamp);
393 fail_if(rc == EINA_FALSE);
394 rc = eeze_sensor_xyz_get(sens, &x, &y, &z);
395 fail_if(rc == EINA_FALSE);
396
397 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION);
398 fail_if(sens == NULL);
399 rc = eeze_sensor_read(sens);
400 fail_if(rc == EINA_FALSE);
401 rc = eeze_sensor_accuracy_get(sens, &acc);
402 fail_if(rc == EINA_FALSE);
403 rc = eeze_sensor_timestamp_get(sens, &timestamp);
404 fail_if(rc == EINA_FALSE);
405 rc = eeze_sensor_xyz_get(sens, &x, &y, &z);
406 fail_if(rc == EINA_FALSE);
407
408 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
409 fail_if(sens == NULL);
410 rc = eeze_sensor_read(sens);
411 fail_if(rc == EINA_FALSE);
412 rc = eeze_sensor_accuracy_get(sens, &acc);
413 fail_if(rc == EINA_FALSE);
414 rc = eeze_sensor_timestamp_get(sens, &timestamp);
415 fail_if(rc == EINA_FALSE);
416 rc = eeze_sensor_xyz_get(sens, &x, &y, &z);
417 fail_if(rc == EINA_FALSE);
418
419 /* Use gyro with xy here even if it offers xzy */
420 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
421 fail_if(sens == NULL);
422 rc = eeze_sensor_read(sens);
423 fail_if(rc == EINA_FALSE);
424 rc = eeze_sensor_accuracy_get(sens, &acc);
425 fail_if(rc == EINA_FALSE);
426 rc = eeze_sensor_timestamp_get(sens, &timestamp);
427 fail_if(rc == EINA_FALSE);
428 rc = eeze_sensor_xy_get(sens, &x, &y);
429 fail_if(rc == EINA_FALSE);
430
431 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY);
432 fail_if(sens == NULL);
433 rc = eeze_sensor_read(sens);
434 fail_if(rc == EINA_FALSE);
435 rc = eeze_sensor_accuracy_get(sens, &acc);
436 fail_if(rc == EINA_FALSE);
437 rc = eeze_sensor_timestamp_get(sens, &timestamp);
438 fail_if(rc == EINA_FALSE);
439 rc = eeze_sensor_x_get(sens, &x);
440 fail_if(rc == EINA_FALSE);
441
442 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
443 fail_if(sens == NULL);
444 rc = eeze_sensor_read(sens);
445 fail_if(rc == EINA_FALSE);
446 rc = eeze_sensor_accuracy_get(sens, &acc);
447 fail_if(rc == EINA_FALSE);
448 rc = eeze_sensor_timestamp_get(sens, &timestamp);
449 fail_if(rc == EINA_FALSE);
450 rc = eeze_sensor_x_get(sens, &x);
451 fail_if(rc == EINA_FALSE);
452
453 /* Call non existing type */
454 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LAST + 1);
455 fail_if(sens != NULL);
456
457 /* Give NULL as sensor object */
458 rc = eeze_sensor_read(NULL);
459 fail_if(rc != EINA_FALSE);
460
461 /* Change sensor type after creation but before read */
462 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
463 fail_if(sens == NULL);
464 sens->type = EEZE_SENSOR_TYPE_LAST + 1;
465 rc = eeze_sensor_read(sens);
466 fail_if(rc != EINA_FALSE);
467
468 /* Try to read from a type you can't read from */
469 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
470 fail_if(sens == NULL);
471 sens->type = EEZE_SENSOR_TYPE_LAST;
472 rc = eeze_sensor_read(sens);
473 fail_if(rc != EINA_FALSE);
474
475 /* Try all getter functions with a NULL sensor object */
476 rc = eeze_sensor_xyz_get(NULL, &x, &y, &z);
477 fail_if(rc != EINA_FALSE);
478 rc = eeze_sensor_xy_get(NULL, &x, &y);
479 fail_if(rc != EINA_FALSE);
480 rc = eeze_sensor_x_get(NULL, &x);
481 fail_if(rc != EINA_FALSE);
482 rc = eeze_sensor_accuracy_get(NULL, &acc);
483 fail_if(rc != EINA_FALSE);
484 rc = eeze_sensor_timestamp_get(NULL, &timestamp);
485 fail_if(rc != EINA_FALSE);
486
487 eeze_sensor_free(sens);
488
489 /* Try free on NULL */
490 eeze_sensor_free(NULL);
491
492 ret = eeze_shutdown();
493 fail_if(ret != 0);
494}
495END_TEST
496
497static int cb_count = 0;
498
499static Eina_Bool
500event_cb(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
501{
502 Eeze_Sensor_Obj *sens = NULL;
503 int acc;
504 double timestamp;
505 Eina_Bool rc = EINA_FALSE;
506
507 sens = event;
508 fail_if(sens == NULL);
509 rc = eeze_sensor_accuracy_get(sens, &acc);
510 fail_if(rc == EINA_FALSE);
511 rc = eeze_sensor_timestamp_get(sens, &timestamp);
512 fail_if(rc == EINA_FALSE);
513
514 /* We expect 5 callbacks from async reads right now */
515 if (++cb_count == 5)
516 ecore_main_loop_quit();
517
518 return ECORE_CALLBACK_DONE;
519}
520
521START_TEST(eeze_test_sensor_async_read)
522{
523 Ecore_Event_Handler *handler;
524
525 Eeze_Sensor_Obj *sens = NULL;
526 int ret = 0;
527 Eina_Bool rc = EINA_FALSE;
528
529 ecore_init();
530 ret = eeze_init();
531 fail_if(ret != 1);
532
533 handler = ecore_event_handler_add(EEZE_SENSOR_EVENT_ACCELEROMETER, event_cb, NULL);
534 fail_if(handler == NULL);
535 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
536 fail_if(sens == NULL);
537 rc = eeze_sensor_async_read(sens, NULL);
538 fail_if(rc == EINA_FALSE);
539
540 ecore_event_handler_add(EEZE_SENSOR_EVENT_MAGNETIC, event_cb, NULL);
541 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC);
542 fail_if(sens == NULL);
543 rc = eeze_sensor_async_read(sens, NULL);
544 fail_if(rc == EINA_FALSE);
545
546 ecore_event_handler_add(EEZE_SENSOR_EVENT_ORIENTATION, event_cb, NULL);
547 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION);
548 fail_if(sens == NULL);
549 rc = eeze_sensor_async_read(sens, NULL);
550 fail_if(rc == EINA_FALSE);
551
552 ecore_event_handler_add(EEZE_SENSOR_EVENT_GYROSCOPE, event_cb, NULL);
553 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
554 fail_if(sens == NULL);
555 rc = eeze_sensor_async_read(sens, NULL);
556 fail_if(rc == EINA_FALSE);
557
558 ecore_event_handler_add(EEZE_SENSOR_EVENT_PROXIMITY, event_cb, NULL);
559 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY);
560 fail_if(sens == NULL);
561 rc = eeze_sensor_async_read(sens, NULL);
562 fail_if(rc == EINA_FALSE);
563
564 ecore_event_handler_add(EEZE_SENSOR_EVENT_LIGHT, event_cb, NULL);
565 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
566 fail_if(sens == NULL);
567 rc = eeze_sensor_async_read(sens, NULL);
568 fail_if(rc == EINA_FALSE);
569
570 /* Error case */
571 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LAST + 1);
572 fail_if(sens != NULL);
573 rc = eeze_sensor_async_read(NULL, NULL);
574 fail_if(rc != EINA_FALSE);
575
576 /* Change sensor type after creation but before read */
577 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
578 fail_if(sens == NULL);
579 sens->type = EEZE_SENSOR_TYPE_LAST + 1;
580 rc = eeze_sensor_async_read(sens, NULL);
581 fail_if(rc != EINA_FALSE);
582
583 /* Try to read from a type you can't read from */
584 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
585 fail_if(sens == NULL);
586 sens->type = EEZE_SENSOR_TYPE_LAST;
587 rc = eeze_sensor_async_read(sens, NULL);
588 fail_if(rc != EINA_FALSE);
589
590 ecore_main_loop_begin();
591
592 ret = eeze_shutdown();
593 fail_if(ret != 0);
594}
595END_TEST
596
597START_TEST(eeze_test_sensor_obj_get)
598{
599 Eeze_Sensor_Obj *obj = NULL, *obj_tmp = NULL;
600 int ret = 0;
601
602 ecore_init();
603 ret = eeze_init();
604 fail_if(ret != 1);
605
606 obj = calloc(1, sizeof(Eeze_Sensor_Obj));
607 fail_if(obj == NULL);
608
609 obj_tmp = obj;
610
611 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER);
612 fail_if(obj == obj_tmp);
613
614 free(obj);
615
616 /* Try to get non existing obj */
617 obj_tmp = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LAST + 1);
618 fail_if(obj_tmp != NULL);
619
620 ret = eeze_shutdown();
621 fail_if(ret != 0);
622}
623END_TEST
624
625Suite *
626eeze_suite(void)
627{
628 Suite *s;
629 TCase *tc;
630
631 s = suite_create("Eeze");
632
633 tc = tcase_create("Eeze_Init");
634 tcase_add_test(tc, eeze_test_init);
635 suite_add_tcase(s, tc);
636
637 tc = tcase_create("Eeze_Udev");
638 //FIXME This also fails all the time. Enable this once we verify it's not completely useless
639 //tcase_add_test(tc, eeze_test_udev_types);
640 tcase_add_test(tc, eeze_test_udev_watch);
641 tcase_add_test(tc, eeze_test_udev_syspath);
642 tcase_add_test(tc, eeze_test_udev_attr);
643 //FIXME Tested functions here are hidden (not EAPI) and thus can not be tested like this with
644 //-fvisibility=hidden turned on.
645 //tcase_add_test(tc, eeze_test_udev_device);
646 suite_add_tcase(s, tc);
647
648 tc = tcase_create("Eeze_Net");
649 tcase_add_test(tc, eeze_test_net_list);
650 tcase_add_test(tc, eeze_test_net_attr);
651#ifdef HAVE_IPV6
652 //FIXME Figure out why we fail for the ipv6 tests here (code or test)
653 //tcase_add_test(tc, eeze_test_net_attr_ipv6);
654#endif
655 suite_add_tcase(s, tc);
656
657 tc = tcase_create("Eeze Sensor");
658 tcase_add_test(tc, eeze_test_sensor_read);
659 tcase_add_test(tc, eeze_test_sensor_async_read);
660 tcase_add_test(tc, eeze_test_sensor_obj_get);
661 suite_add_tcase(s, tc);
662
663 tcase_set_timeout(tc, 0);
664
665 return s;
666}
667 15
668int 16int
669main(void) 17main(void)
670{ 18{
671 Suite *s;
672 SRunner *sr;
673 int failed_count; 19 int failed_count;
674 20
21 if (!_efl_test_option_disp(argc, argv, etc))
22 return 0;
23
675 putenv("EFL_RUN_IN_TREE=1"); 24 putenv("EFL_RUN_IN_TREE=1");
676 25
677 s = eeze_suite(); 26 failed_count = _efl_suite_build_and_run(argc - 1, (const char **)argv + 1,
678 sr = srunner_create(s); 27 "Eeze", etc);
679 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
680 srunner_run_all(sr, CK_ENV);
681 failed_count = srunner_ntests_failed(sr);
682 srunner_free(sr);
683 28
684 return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE; 29 return (failed_count == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
685} 30}
diff --git a/src/tests/eeze/eeze_suite.h b/src/tests/eeze/eeze_suite.h
new file mode 100644
index 0000000000..d8fcfb3d57
--- /dev/null
+++ b/src/tests/eeze/eeze_suite.h
@@ -0,0 +1,11 @@
1#ifndef _EEZE_SUITE_H
2#define _EEZE_SUITE_H
3
4#include <check.h>
5
6void eeze_test_init(TCase *tc);
7void eeze_test_udev(TCase *tc);
8void eeze_test_net(TCase *tc);
9void eeze_test_sensor(TCase *tc);
10
11#endif /* _EEZE_SUITE_H */
diff --git a/src/tests/eeze/eeze_test_init.c b/src/tests/eeze/eeze_test_init.c
new file mode 100644
index 0000000000..6c72acbd19
--- /dev/null
+++ b/src/tests/eeze/eeze_test_init.c
@@ -0,0 +1,24 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Eeze.h>
6
7#include "eeze_suite.h"
8
9START_TEST(eeze_test_eeze_init)
10{
11 int ret;
12
13 ret = eeze_init();
14 fail_if(ret != 1);
15
16 ret = eeze_shutdown();
17 fail_if(ret != 0);
18}
19END_TEST
20
21void eeze_test_init(TCase *tc)
22{
23 tcase_add_test(tc, eeze_test_eeze_init);
24}
diff --git a/src/tests/eeze/eeze_test_net.c b/src/tests/eeze/eeze_test_net.c
new file mode 100644
index 0000000000..6d9f8589d6
--- /dev/null
+++ b/src/tests/eeze/eeze_test_net.c
@@ -0,0 +1,116 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Eeze.h>
6#include <Eeze_Net.h>
7
8#include "eeze_suite.h"
9
10START_TEST(eeze_test_net_list)
11{
12 int ret;
13 Eina_List *list = NULL;
14
15 ret = eeze_init();
16 fail_if(ret != 1);
17
18 list = eeze_net_list();
19 fail_if(list == NULL);
20
21 ret = eeze_shutdown();
22 fail_if(ret != 0);
23}
24END_TEST
25
26START_TEST(eeze_test_net_attr)
27{
28 int ret;
29 int idx = 0;
30 Eeze_Net *net = NULL;
31 const char *tmp = NULL;
32
33 ret = eeze_init();
34 fail_if(ret != 1);
35
36 net = eeze_net_new("lo");
37 fail_if(net == NULL);
38
39 tmp = eeze_net_mac_get(net);
40 fail_if(tmp == NULL);
41 tmp = NULL;
42
43 idx = eeze_net_idx_get(net);
44 fail_if(!idx);
45
46 eeze_net_scan(net);
47
48 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_IP);
49 fail_if(tmp == NULL);
50 tmp = NULL;
51
52 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_BROADCAST);
53 fail_if(tmp == NULL);
54 tmp = NULL;
55
56 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_NETMASK);
57 fail_if(tmp == NULL);
58 tmp = NULL;
59
60 tmp = eeze_net_attribute_get(net, "carrier");
61 fail_if(tmp == NULL);
62 tmp = NULL;
63
64 tmp = eeze_net_syspath_get(net);
65 fail_if(tmp == NULL);
66
67 eeze_net_free(net);
68
69 ret = eeze_shutdown();
70 fail_if(ret != 0);
71}
72END_TEST
73
74/*
75#ifdef HAVE_IPV6
76START_TEST(eeze_test_net_attr_ipv6)
77{
78 int ret;
79 Eeze_Net *net = NULL;
80 const char *tmp = NULL;
81
82 ret = eeze_init();
83 fail_if(ret != 1);
84
85 net = eeze_net_new("lo");
86 fail_if(net == NULL);
87
88 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_IP6);
89 fail_if(tmp == NULL);
90 tmp = NULL;
91
92 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_BROADCAST6);
93 fail_if(tmp == NULL);
94 tmp = NULL;
95
96 tmp = eeze_net_addr_get(net, EEZE_NET_ADDR_TYPE_NETMASK6);
97 fail_if(tmp == NULL);
98
99 eeze_net_free(net);
100
101 ret = eeze_shutdown();
102 fail_if(ret != 0);
103}
104END_TEST
105#endif
106*/
107
108void eeze_test_net(TCase *tc)
109{
110 tcase_add_test(tc, eeze_test_net_list);
111 tcase_add_test(tc, eeze_test_net_attr);
112#ifdef HAVE_IPV6
113 //FIXME Figure out why we fail for the ipv6 tests here (code or test)
114 //tcase_add_test(tc, eeze_test_net_attr_ipv6);
115#endif
116}
diff --git a/src/tests/eeze/eeze_test_sensor.c b/src/tests/eeze/eeze_test_sensor.c
new file mode 100644
index 0000000000..7cd415e65d
--- /dev/null
+++ b/src/tests/eeze/eeze_test_sensor.c
@@ -0,0 +1,280 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Ecore.h>
6#include <Eeze.h>
7#include <Eeze_Sensor.h>
8
9#include "eeze_suite.h"
10#include "eeze_sensor_private.h"
11
12static int cb_count = 0;
13
14static Eina_Bool
15event_cb(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *event)
16{
17 Eeze_Sensor_Obj *sens = NULL;
18 int acc;
19 double timestamp;
20 Eina_Bool rc = EINA_FALSE;
21
22 sens = event;
23 fail_if(sens == NULL);
24 rc = eeze_sensor_accuracy_get(sens, &acc);
25 fail_if(rc == EINA_FALSE);
26 rc = eeze_sensor_timestamp_get(sens, &timestamp);
27 fail_if(rc == EINA_FALSE);
28
29 /* We expect 5 callbacks from async reads right now */
30 if (++cb_count == 5)
31 ecore_main_loop_quit();
32
33 return ECORE_CALLBACK_DONE;
34}
35
36START_TEST(eeze_test_sensor_read)
37{
38 Eeze_Sensor_Obj *sens = NULL;
39 int ret = 0;
40 float x, y, z;
41 int acc;
42 double timestamp;
43 Eina_Bool rc = EINA_FALSE;
44
45 ecore_init();
46 ret = eeze_init();
47 fail_if(ret != 1);
48
49 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
50 fail_if(sens == NULL);
51 rc = eeze_sensor_read(sens);
52 fail_if(rc == EINA_FALSE);
53 rc = eeze_sensor_accuracy_get(sens, &acc);
54 fail_if(rc == EINA_FALSE);
55 rc = eeze_sensor_timestamp_get(sens, &timestamp);
56 fail_if(rc == EINA_FALSE);
57 rc = eeze_sensor_xyz_get(sens, &x, &y, &z);
58 fail_if(rc == EINA_FALSE);
59
60 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC);
61 fail_if(sens == NULL);
62 rc = eeze_sensor_read(sens);
63 fail_if(rc == EINA_FALSE);
64 rc = eeze_sensor_accuracy_get(sens, &acc);
65 fail_if(rc == EINA_FALSE);
66 rc = eeze_sensor_timestamp_get(sens, &timestamp);
67 fail_if(rc == EINA_FALSE);
68 rc = eeze_sensor_xyz_get(sens, &x, &y, &z);
69 fail_if(rc == EINA_FALSE);
70
71 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION);
72 fail_if(sens == NULL);
73 rc = eeze_sensor_read(sens);
74 fail_if(rc == EINA_FALSE);
75 rc = eeze_sensor_accuracy_get(sens, &acc);
76 fail_if(rc == EINA_FALSE);
77 rc = eeze_sensor_timestamp_get(sens, &timestamp);
78 fail_if(rc == EINA_FALSE);
79 rc = eeze_sensor_xyz_get(sens, &x, &y, &z);
80 fail_if(rc == EINA_FALSE);
81
82 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
83 fail_if(sens == NULL);
84 rc = eeze_sensor_read(sens);
85 fail_if(rc == EINA_FALSE);
86 rc = eeze_sensor_accuracy_get(sens, &acc);
87 fail_if(rc == EINA_FALSE);
88 rc = eeze_sensor_timestamp_get(sens, &timestamp);
89 fail_if(rc == EINA_FALSE);
90 rc = eeze_sensor_xyz_get(sens, &x, &y, &z);
91 fail_if(rc == EINA_FALSE);
92
93 /* Use gyro with xy here even if it offers xzy */
94 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
95 fail_if(sens == NULL);
96 rc = eeze_sensor_read(sens);
97 fail_if(rc == EINA_FALSE);
98 rc = eeze_sensor_accuracy_get(sens, &acc);
99 fail_if(rc == EINA_FALSE);
100 rc = eeze_sensor_timestamp_get(sens, &timestamp);
101 fail_if(rc == EINA_FALSE);
102 rc = eeze_sensor_xy_get(sens, &x, &y);
103 fail_if(rc == EINA_FALSE);
104
105 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY);
106 fail_if(sens == NULL);
107 rc = eeze_sensor_read(sens);
108 fail_if(rc == EINA_FALSE);
109 rc = eeze_sensor_accuracy_get(sens, &acc);
110 fail_if(rc == EINA_FALSE);
111 rc = eeze_sensor_timestamp_get(sens, &timestamp);
112 fail_if(rc == EINA_FALSE);
113 rc = eeze_sensor_x_get(sens, &x);
114 fail_if(rc == EINA_FALSE);
115
116 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
117 fail_if(sens == NULL);
118 rc = eeze_sensor_read(sens);
119 fail_if(rc == EINA_FALSE);
120 rc = eeze_sensor_accuracy_get(sens, &acc);
121 fail_if(rc == EINA_FALSE);
122 rc = eeze_sensor_timestamp_get(sens, &timestamp);
123 fail_if(rc == EINA_FALSE);
124 rc = eeze_sensor_x_get(sens, &x);
125 fail_if(rc == EINA_FALSE);
126
127 /* Call non existing type */
128 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LAST + 1);
129 fail_if(sens != NULL);
130
131 /* Give NULL as sensor object */
132 rc = eeze_sensor_read(NULL);
133 fail_if(rc != EINA_FALSE);
134
135 /* Change sensor type after creation but before read */
136 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
137 fail_if(sens == NULL);
138 sens->type = EEZE_SENSOR_TYPE_LAST + 1;
139 rc = eeze_sensor_read(sens);
140 fail_if(rc != EINA_FALSE);
141
142 /* Try to read from a type you can't read from */
143 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
144 fail_if(sens == NULL);
145 sens->type = EEZE_SENSOR_TYPE_LAST;
146 rc = eeze_sensor_read(sens);
147 fail_if(rc != EINA_FALSE);
148
149 /* Try all getter functions with a NULL sensor object */
150 rc = eeze_sensor_xyz_get(NULL, &x, &y, &z);
151 fail_if(rc != EINA_FALSE);
152 rc = eeze_sensor_xy_get(NULL, &x, &y);
153 fail_if(rc != EINA_FALSE);
154 rc = eeze_sensor_x_get(NULL, &x);
155 fail_if(rc != EINA_FALSE);
156 rc = eeze_sensor_accuracy_get(NULL, &acc);
157 fail_if(rc != EINA_FALSE);
158 rc = eeze_sensor_timestamp_get(NULL, &timestamp);
159 fail_if(rc != EINA_FALSE);
160
161 eeze_sensor_free(sens);
162
163 /* Try free on NULL */
164 eeze_sensor_free(NULL);
165
166 ret = eeze_shutdown();
167 fail_if(ret != 0);
168}
169END_TEST
170
171START_TEST(eeze_test_sensor_async_read)
172{
173 Ecore_Event_Handler *handler;
174
175 Eeze_Sensor_Obj *sens = NULL;
176 int ret = 0;
177 Eina_Bool rc = EINA_FALSE;
178
179 ecore_init();
180 ret = eeze_init();
181 fail_if(ret != 1);
182
183 handler = ecore_event_handler_add(EEZE_SENSOR_EVENT_ACCELEROMETER, event_cb, NULL);
184 fail_if(handler == NULL);
185 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ACCELEROMETER);
186 fail_if(sens == NULL);
187 rc = eeze_sensor_async_read(sens, NULL);
188 fail_if(rc == EINA_FALSE);
189
190 ecore_event_handler_add(EEZE_SENSOR_EVENT_MAGNETIC, event_cb, NULL);
191 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_MAGNETIC);
192 fail_if(sens == NULL);
193 rc = eeze_sensor_async_read(sens, NULL);
194 fail_if(rc == EINA_FALSE);
195
196 ecore_event_handler_add(EEZE_SENSOR_EVENT_ORIENTATION, event_cb, NULL);
197 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_ORIENTATION);
198 fail_if(sens == NULL);
199 rc = eeze_sensor_async_read(sens, NULL);
200 fail_if(rc == EINA_FALSE);
201
202 ecore_event_handler_add(EEZE_SENSOR_EVENT_GYROSCOPE, event_cb, NULL);
203 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_GYROSCOPE);
204 fail_if(sens == NULL);
205 rc = eeze_sensor_async_read(sens, NULL);
206 fail_if(rc == EINA_FALSE);
207
208 ecore_event_handler_add(EEZE_SENSOR_EVENT_PROXIMITY, event_cb, NULL);
209 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_PROXIMITY);
210 fail_if(sens == NULL);
211 rc = eeze_sensor_async_read(sens, NULL);
212 fail_if(rc == EINA_FALSE);
213
214 ecore_event_handler_add(EEZE_SENSOR_EVENT_LIGHT, event_cb, NULL);
215 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
216 fail_if(sens == NULL);
217 rc = eeze_sensor_async_read(sens, NULL);
218 fail_if(rc == EINA_FALSE);
219
220 /* Error case */
221 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LAST + 1);
222 fail_if(sens != NULL);
223 rc = eeze_sensor_async_read(NULL, NULL);
224 fail_if(rc != EINA_FALSE);
225
226 /* Change sensor type after creation but before read */
227 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
228 fail_if(sens == NULL);
229 sens->type = EEZE_SENSOR_TYPE_LAST + 1;
230 rc = eeze_sensor_async_read(sens, NULL);
231 fail_if(rc != EINA_FALSE);
232
233 /* Try to read from a type you can't read from */
234 sens = eeze_sensor_new(EEZE_SENSOR_TYPE_LIGHT);
235 fail_if(sens == NULL);
236 sens->type = EEZE_SENSOR_TYPE_LAST;
237 rc = eeze_sensor_async_read(sens, NULL);
238 fail_if(rc != EINA_FALSE);
239
240 ecore_main_loop_begin();
241
242 ret = eeze_shutdown();
243 fail_if(ret != 0);
244}
245END_TEST
246
247START_TEST(eeze_test_sensor_obj_get)
248{
249 Eeze_Sensor_Obj *obj = NULL, *obj_tmp = NULL;
250 int ret = 0;
251
252 ecore_init();
253 ret = eeze_init();
254 fail_if(ret != 1);
255
256 obj = calloc(1, sizeof(Eeze_Sensor_Obj));
257 fail_if(obj == NULL);
258
259 obj_tmp = obj;
260
261 obj = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_ACCELEROMETER);
262 fail_if(obj == obj_tmp);
263
264 free(obj);
265
266 /* Try to get non existing obj */
267 obj_tmp = eeze_sensor_obj_get(EEZE_SENSOR_TYPE_LAST + 1);
268 fail_if(obj_tmp != NULL);
269
270 ret = eeze_shutdown();
271 fail_if(ret != 0);
272}
273END_TEST
274
275void eeze_test_sensor(TCase *tc)
276{
277 tcase_add_test(tc, eeze_test_sensor_read);
278 tcase_add_test(tc, eeze_test_sensor_async_read);
279 tcase_add_test(tc, eeze_test_sensor_obj_get);
280}
diff --git a/src/tests/eeze/eeze_test_udev.c b/src/tests/eeze/eeze_test_udev.c
new file mode 100644
index 0000000000..1e8b3c821a
--- /dev/null
+++ b/src/tests/eeze/eeze_test_udev.c
@@ -0,0 +1,254 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include <Ecore.h>
6#include <Eeze.h>
7
8#include "eeze_suite.h"
9/* #include "eeze_udev_private.h" */
10
11static void
12catch_events(const char *device EINA_UNUSED, Eeze_Udev_Event event EINA_UNUSED,
13 void *data EINA_UNUSED, Eeze_Udev_Watch *watch EINA_UNUSED)
14{
15}
16
17#if 0
18// FIXME split udev tests into pieces here
19START_TEST(eeze_test_udev_types)
20{
21 Eina_List *type;
22
23 eeze_init();
24
25 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NONE, NULL);
26 type = eeze_udev_find_unlisted_similar(type);
27 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL);
28 type = eeze_udev_find_unlisted_similar(type);
29 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL);
30 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_TOUCHPAD, NULL);
31 type = eeze_udev_find_unlisted_similar(type);
32 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_MOUNTABLE, NULL);
33 type = eeze_udev_find_unlisted_similar(type);
34 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
35 type = eeze_udev_find_unlisted_similar(type);
36 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
37 type = eeze_udev_find_unlisted_similar(type);
38 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_CDROM, NULL);
39 type = eeze_udev_find_unlisted_similar(type);
40 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_AC, NULL);
41 type = eeze_udev_find_unlisted_similar(type);
42 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_POWER_BAT, NULL);
43 type = eeze_udev_find_unlisted_similar(type);
44 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR, NULL);
45 type = eeze_udev_find_unlisted_similar(type);
46 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL);
47 type = eeze_udev_find_unlisted_similar(type);
48 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
49 type = eeze_udev_find_unlisted_similar(type);
50 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_BLUETOOTH, NULL);
51 type = eeze_udev_find_unlisted_similar(type);
52 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, NULL);
53 type = eeze_udev_find_unlisted_similar(type);
54 type = eeze_udev_find_by_type(0, NULL);
55 type = eeze_udev_find_unlisted_similar(type);
56
57 eeze_shutdown();
58}
59END_TEST
60#endif
61
62START_TEST(eeze_test_udev_watch)
63{
64 Eeze_Udev_Watch *watch;
65
66 ecore_init();
67 eeze_init();
68
69 /* watch never gets triggered as this is run without user interaction */
70 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_KEYBOARD, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
71 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_DRIVE_INTERNAL, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
72 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_POWER_AC, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
73 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_NET, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
74 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_IS_IT_HOT_OR_IS_IT_COLD_SENSOR, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
75 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_V4L, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
76 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_BLUETOOTH, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
77 watch = eeze_udev_watch_add(EEZE_UDEV_TYPE_NONE, (EEZE_UDEV_EVENT_ADD | EEZE_UDEV_EVENT_REMOVE), catch_events, NULL);
78 eeze_udev_watch_del(watch);
79
80 eeze_shutdown();
81 ecore_shutdown();
82}
83END_TEST
84
85START_TEST(eeze_test_udev_syspath)
86{
87 Eina_List *type, *l;
88 const char *name;
89 Eina_Bool r;
90
91 eeze_init();
92
93 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_KEYBOARD, NULL);
94 type = eeze_udev_find_unlisted_similar(type);
95 EINA_LIST_FOREACH(type, l, name)
96 {
97 eeze_udev_syspath_get_devpath(name);
98 eeze_udev_find_similar_from_syspath(name);
99 eeze_udev_find_similar_from_syspath(NULL);
100 eeze_udev_syspath_get_parent(name);
101 eeze_udev_syspath_get_parent(NULL);
102 eeze_udev_syspath_get_parents(name);
103 eeze_udev_syspath_get_parents(NULL);
104 eeze_udev_syspath_get_devname(name);
105 eeze_udev_syspath_get_devname(NULL);
106 eeze_udev_syspath_get_subsystem(name);
107 eeze_udev_syspath_get_sysattr(name, "manufacturer");
108 eeze_udev_syspath_is_mouse(name);
109 eeze_udev_syspath_is_kbd(name);
110 eeze_udev_syspath_is_touchpad(name);
111 eeze_udev_syspath_is_joystick(name);
112 eeze_udev_walk_get_sysattr(name, "manufacturer");
113 eeze_udev_find_by_sysattr("manufacturer", NULL);
114 eeze_udev_find_by_sysattr(NULL, NULL);
115 eeze_udev_walk_check_sysattr(name, "manufacturer", NULL);
116 eeze_udev_walk_check_sysattr(name, "manufacturer", "foo");
117 eeze_udev_walk_get_sysattr(NULL, "manufacturer");
118 eeze_udev_walk_get_sysattr(name, NULL);
119 }
120
121 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_MOUSE, NULL);
122 type = eeze_udev_find_unlisted_similar(type);
123 EINA_LIST_FOREACH(type, l, name)
124 {
125 r = eeze_udev_syspath_is_mouse(name);
126 fail_unless(r);
127
128 eeze_udev_syspath_is_touchpad(name);
129 eeze_udev_syspath_is_joystick(name);
130 }
131
132 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_TOUCHPAD, NULL);
133 type = eeze_udev_find_unlisted_similar(type);
134 EINA_LIST_FOREACH(type, l, name)
135 {
136 r = eeze_udev_syspath_is_touchpad(name);
137 fail_unless(r);
138 }
139
140 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_JOYSTICK, NULL);
141 type = eeze_udev_find_unlisted_similar(type);
142 EINA_LIST_FOREACH(type, l, name)
143 {
144 r = eeze_udev_syspath_is_joystick(name);
145 fail_unless(r);
146 }
147
148 eeze_udev_devpath_get_syspath("/dev/null");
149
150 eeze_shutdown();
151}
152END_TEST
153
154START_TEST(eeze_test_udev_attr)
155{
156 Eina_List *type;
157 const char *name, *check, *check2;
158
159 eeze_init();
160
161 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
162 type = eeze_udev_find_unlisted_similar(type);
163 eeze_udev_find_by_filter("backlight", NULL, NULL);
164
165 eeze_udev_find_by_filter(NULL, NULL, NULL);
166
167 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_NET, NULL);
168 type = eeze_udev_find_unlisted_similar(type);
169 EINA_LIST_FREE(type, name)
170 {
171 check = eeze_udev_syspath_get_property(name, "INTERFACE");
172 }
173
174 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
175 type = eeze_udev_find_unlisted_similar(type);
176 EINA_LIST_FREE(type, name)
177 {
178 check = eeze_udev_syspath_get_property(name, "ID_SERIAL");
179 }
180
181 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_REMOVABLE, NULL);
182 type = eeze_udev_find_unlisted_similar(type);
183 EINA_LIST_FREE(type, name)
184 {
185 if ((check = eeze_udev_syspath_get_sysattr(name, "model")))
186 {
187 check2 = eeze_udev_syspath_get_subsystem(name);
188 }
189 }
190
191 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_V4L, NULL);
192 type = eeze_udev_find_unlisted_similar(type);
193 EINA_LIST_FREE(type, name)
194 {
195 if ((check = eeze_udev_syspath_get_property(name, "DEVNAME")))
196 {
197 if ((check2 = eeze_udev_syspath_get_sysattr(name, "name")))
198 {
199 eina_stringshare_del(check2);
200 }
201 eina_stringshare_del(check);
202 }
203 eina_stringshare_del(name);
204 }
205
206 eeze_shutdown();
207}
208END_TEST
209
210/*
211START_TEST(eeze_test_udev_device)
212{
213 Eina_List *type, *l;
214 _udev_device *device, *device2;
215 const char *name;
216
217 eeze_init();
218
219 type = eeze_udev_find_by_type(EEZE_UDEV_TYPE_DRIVE_INTERNAL, NULL);
220 fail_if(type == NULL);
221 type = eeze_udev_find_unlisted_similar(type);
222 fail_if(type == NULL);
223 EINA_LIST_FOREACH(type, l, name)
224 {
225 device = _new_device(name);
226 fail_if(device == NULL);
227 _walk_parents_get_attr(device, "FOO", EINA_FALSE);
228 _walk_parents_get_attr(device, "FOO", EINA_TRUE);
229 _walk_children_get_attr(name, "FOO", "BAR", EINA_FALSE);
230 _walk_children_get_attr(name, "FOO", "BAR", EINA_TRUE);
231 }
232
233 device = _new_device("Wrong path");
234 fail_if(device != NULL);
235
236 device2 = _copy_device(device);
237 fail_if(device2 != NULL);
238
239 eeze_shutdown();
240}
241END_TEST
242*/
243
244void eeze_test_udev(TCase *tc)
245{
246 //FIXME This also fails all the time. Enable this once we verify it's not completely useless
247 //tcase_add_test(tc, eeze_test_udev_types);
248 tcase_add_test(tc, eeze_test_udev_watch);
249 tcase_add_test(tc, eeze_test_udev_syspath);
250 tcase_add_test(tc, eeze_test_udev_attr);
251 //FIXME Tested functions here are hidden (not EAPI) and thus can not be tested like this with
252 //-fvisibility=hidden turned on.
253 //tcase_add_test(tc, eeze_test_udev_device);
254}