summaryrefslogtreecommitdiff
path: root/src/tests/eo/children/children_main.c
blob: 0e0832f8ce641fdd1c0e9e3118091e5c1bf0a819 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include "Eo.h"

#include "../eunit_tests.h"
#include "children_simple.h"


#define CHECK_ITER_DATA(iter, data, expected_data) \
   fail_if(!eina_iterator_next(iter, &(data))); \
   fail_if(expected_data != data);

int
main(int argc, char *argv[])
{
   (void) argc;
   (void) argv;
   Eina_Iterator *iter = NULL;
   void *chld;

   eo_init();

   Eo *parent = eo_add(SIMPLE_CLASS, NULL);

   Eo *child1 = eo_add(SIMPLE_CLASS, parent);
   Eo *child2 = eo_add(SIMPLE_CLASS, parent);
   Eo *child3 = eo_add(SIMPLE_CLASS, parent);

   eo_do(parent, iter = eo_children_iterator_new());
   fail_if(!iter);

   CHECK_ITER_DATA(iter, chld, child1);
   CHECK_ITER_DATA(iter, chld, child2);
   CHECK_ITER_DATA(iter, chld, child3);
   fail_if(eina_iterator_next(iter, &chld));

   eina_iterator_free(iter);

   eo_del(child2);

   eo_do(parent, iter = eo_children_iterator_new());
   fail_if(!iter);

   CHECK_ITER_DATA(iter, chld, child1);
   CHECK_ITER_DATA(iter, chld, child3);
   fail_if(eina_iterator_next(iter, &chld));

   eina_iterator_free(iter);


   eo_del(child1);

   eo_do(parent, iter = eo_children_iterator_new());
   fail_if(!iter);

   CHECK_ITER_DATA(iter, chld, child3);
   fail_if(eina_iterator_next(iter,  &chld));
   eina_iterator_free(iter);


   eo_del(child3);

   eo_do(parent, iter = eo_children_iterator_new());
   fail_if(iter);

   eo_unref(parent);

   eo_shutdown();
   return 0;
}