summaryrefslogtreecommitdiff
path: root/src/tests/eo/composite_objects/composite_objects_main.c
blob: 9e90eb412aaade901227564797323a3cc8e512da (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
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#define EO_BASE_BETA

#include "Eo.h"
#include "composite_objects_simple.h"
#include "composite_objects_comp.h"

#include "../eunit_tests.h"

static int cb_called = EINA_FALSE;

static Eina_Bool
_a_changed_cb(void *data, const Eo_Event *event)
{
   int new_a = *((int *) event->event_info);
   printf("%s event_info:'%d' data:'%s'\n", __func__, new_a, (const char *) data);

   cb_called = EINA_TRUE;

   return EO_CALLBACK_CONTINUE;
}

int
main(int argc, char *argv[])
{
   Eina_Bool tmp;
   (void) argc;
   (void) argv;
   eo_init();

   Eo *obj = eo_add(COMP_CLASS, NULL);
   eo_event_callback_add(obj, EV_A_CHANGED, _a_changed_cb, NULL);

   fail_if(!eo_isa(obj, COMP_CLASS));
   fail_if(!eo_isa(obj, SIMPLE_CLASS));

   int a = 0;
   cb_called = EINA_FALSE;
   simple_a_set(obj, 1);
   fail_if(!cb_called);

   /* Test functions from all across the chain. */
   cb_called = EINA_FALSE;
   simple_a_set1(obj, 1);
   fail_if(!cb_called);
   cb_called = EINA_FALSE;
   simple_a_set15(obj, 1);
   fail_if(!cb_called);
   cb_called = EINA_FALSE;
   simple_a_set32(obj, 1);
   fail_if(!cb_called);

   a = simple_a_get(obj);
   fail_if(a != 1);

   /* disable the callback forwarder, and fail if it's still called. */
   Eo *simple = NULL;
   simple = eo_key_data_get(obj, "simple-obj");
   eo_ref(simple);
   eo_event_callback_forwarder_del(simple, EV_A_CHANGED, obj);

   cb_called = EINA_FALSE;
   simple_a_set(obj, 2);
   fail_if(cb_called);

   fail_if(!eo_composite_part_is(simple));
   fail_if(!eo_composite_detach(obj, simple));
   fail_if(eo_composite_detach(obj, simple));
   fail_if(eo_composite_part_is(simple));
   fail_if(!eo_composite_attach(obj, simple));
   fail_if(!eo_composite_part_is(simple));
   fail_if(eo_composite_attach(obj, simple));

   fail_if(eo_composite_attach(simple, obj));

   eo_unref(simple);
   eo_unref(obj);

   eo_shutdown();
   return 0;
}