summaryrefslogtreecommitdiff
path: root/src/tests/eo/composite_objects
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-09-26 06:56:52 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-09-26 06:56:52 +0000
commit3b5a3448b7dfc53c2f129bdb04bea9f7a02741a6 (patch)
tree18ad8a6b1841e9832c85a46f887b2cd6d6dacc4b /src/tests/eo/composite_objects
parent195d31c73fef88cfaa803b07b2ae3cba983a4093 (diff)
merge: add eo
SVN revision: 77072
Diffstat (limited to 'src/tests/eo/composite_objects')
-rw-r--r--src/tests/eo/composite_objects/composite_objects_comp.c65
-rw-r--r--src/tests/eo/composite_objects/composite_objects_comp.h7
-rw-r--r--src/tests/eo/composite_objects/composite_objects_main.c65
-rw-r--r--src/tests/eo/composite_objects/composite_objects_simple.c71
-rw-r--r--src/tests/eo/composite_objects/composite_objects_simple.h28
5 files changed, 236 insertions, 0 deletions
diff --git a/src/tests/eo/composite_objects/composite_objects_comp.c b/src/tests/eo/composite_objects/composite_objects_comp.c
new file mode 100644
index 0000000000..b15770c9da
--- /dev/null
+++ b/src/tests/eo/composite_objects/composite_objects_comp.c
@@ -0,0 +1,65 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "composite_objects_simple.h"
7#include "composite_objects_comp.h"
8
9#include "../eunit_tests.h"
10
11EAPI Eo_Op COMP_BASE_ID = 0;
12
13#define MY_CLASS COMP_CLASS
14
15static void
16_a_get(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
17{
18 int *a;
19 a = va_arg(*list, int *);
20 eo_do_super(obj, simple_a_get(a));
21}
22
23static void
24_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
25{
26 eo_do_super(obj, eo_constructor());
27
28 Eo *simple = eo_add(SIMPLE_CLASS, obj);
29 eo_composite_attach(simple, obj);
30 eo_do(simple, eo_event_callback_forwarder_add(EV_A_CHANGED, obj));
31
32 fail_if(eo_composite_is(obj));
33 fail_if(!eo_composite_is(simple));
34
35 eo_do(obj, eo_base_data_set("simple-obj", simple, NULL));
36
37 eo_unref(simple);
38}
39
40static void
41_class_constructor(Eo_Class *klass)
42{
43 const Eo_Op_Func_Description func_desc[] = {
44 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
45 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
46 EO_OP_FUNC_SENTINEL
47 };
48
49 eo_class_funcs_set(klass, func_desc);
50}
51
52static const Eo_Class_Description class_desc = {
53 EO_VERSION,
54 "Comp",
55 EO_CLASS_TYPE_REGULAR,
56 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
57 NULL,
58 0,
59 _class_constructor,
60 NULL
61};
62
63EO_DEFINE_CLASS(comp_class_get, &class_desc, EO_BASE_CLASS,
64 SIMPLE_CLASS, NULL);
65
diff --git a/src/tests/eo/composite_objects/composite_objects_comp.h b/src/tests/eo/composite_objects/composite_objects_comp.h
new file mode 100644
index 0000000000..95001b7020
--- /dev/null
+++ b/src/tests/eo/composite_objects/composite_objects_comp.h
@@ -0,0 +1,7 @@
1#ifndef COMP_H
2#define COMP_H
3
4#define COMP_CLASS comp_class_get()
5const Eo_Class *comp_class_get(void);
6
7#endif
diff --git a/src/tests/eo/composite_objects/composite_objects_main.c b/src/tests/eo/composite_objects/composite_objects_main.c
new file mode 100644
index 0000000000..2e5d9ab005
--- /dev/null
+++ b/src/tests/eo/composite_objects/composite_objects_main.c
@@ -0,0 +1,65 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "composite_objects_simple.h"
7#include "composite_objects_comp.h"
8
9#include "../eunit_tests.h"
10
11static int cb_called = EINA_FALSE;
12
13static Eina_Bool
14_a_changed_cb(void *data, Eo *obj, const Eo_Event_Description *desc, void *event_info)
15{
16 (void) desc;
17 (void) obj;
18 int new_a = *((int *) event_info);
19 printf("%s event_info:'%d' data:'%s'\n", __func__, new_a, (const char *) data);
20
21 cb_called = EINA_TRUE;
22
23 return EO_CALLBACK_CONTINUE;
24}
25
26int
27main(int argc, char *argv[])
28{
29 (void) argc;
30 (void) argv;
31 eo_init();
32
33 Eo *obj = eo_add(COMP_CLASS, NULL);
34 eo_do(obj, eo_event_callback_add(EV_A_CHANGED, _a_changed_cb, NULL));
35
36 int a;
37 eo_do(obj, simple_a_set(1));
38 fail_if(!cb_called);
39
40 eo_do(obj, simple_a_get(&a));
41 fail_if(a != 1);
42
43 /* disable the callback forwarder, and fail if it's still called. */
44 Eo *simple;
45 eo_do(obj, eo_base_data_get("simple-obj", (void **) &simple));
46 eo_ref(simple);
47 eo_do(simple, eo_event_callback_forwarder_del(EV_A_CHANGED, obj));
48
49 cb_called = EINA_FALSE;
50 eo_do(obj, simple_a_set(2));
51 fail_if(cb_called);
52
53 fail_if(!eo_composite_is(simple));
54 eo_composite_detach(simple, obj);
55 fail_if(eo_composite_is(simple));
56 eo_composite_attach(simple, obj);
57 fail_if(!eo_composite_is(simple));
58
59 eo_unref(simple);
60 eo_unref(obj);
61
62 eo_shutdown();
63 return 0;
64}
65
diff --git a/src/tests/eo/composite_objects/composite_objects_simple.c b/src/tests/eo/composite_objects/composite_objects_simple.c
new file mode 100644
index 0000000000..5420ef895d
--- /dev/null
+++ b/src/tests/eo/composite_objects/composite_objects_simple.c
@@ -0,0 +1,71 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "composite_objects_simple.h"
7
8EAPI Eo_Op SIMPLE_BASE_ID = 0;
9
10EAPI const Eo_Event_Description _EV_A_CHANGED =
11 EO_EVENT_DESCRIPTION("a,changed", "Called when a has changed.");
12
13#define MY_CLASS SIMPLE_CLASS
14
15static void
16_a_set(Eo *obj, void *class_data, va_list *list)
17{
18 Simple_Public_Data *pd = class_data;
19 int a;
20 a = va_arg(*list, int);
21 printf("%s %d\n", eo_class_name_get(MY_CLASS), a);
22 pd->a = a;
23
24 eo_do(obj, eo_event_callback_call(EV_A_CHANGED, &pd->a, NULL));
25}
26
27static void
28_a_get(Eo *obj EINA_UNUSED, void *class_data, va_list *list)
29{
30 const Simple_Public_Data *pd = class_data;
31 int *a;
32 a = va_arg(*list, int *);
33 *a = pd->a;
34}
35
36static void
37_class_constructor(Eo_Class *klass)
38{
39 const Eo_Op_Func_Description func_desc[] = {
40 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
41 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
42 EO_OP_FUNC_SENTINEL
43 };
44
45 eo_class_funcs_set(klass, func_desc);
46}
47
48static const Eo_Op_Description op_desc[] = {
49 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"),
50 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_GET, "Get property A"),
51 EO_OP_DESCRIPTION_SENTINEL
52};
53
54static const Eo_Event_Description *event_desc[] = {
55 EV_A_CHANGED,
56 NULL
57};
58
59static const Eo_Class_Description class_desc = {
60 EO_VERSION,
61 "Simple",
62 EO_CLASS_TYPE_REGULAR,
63 EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
64 event_desc,
65 sizeof(Simple_Public_Data),
66 _class_constructor,
67 NULL
68};
69
70EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, NULL);
71
diff --git a/src/tests/eo/composite_objects/composite_objects_simple.h b/src/tests/eo/composite_objects/composite_objects_simple.h
new file mode 100644
index 0000000000..32a62465b8
--- /dev/null
+++ b/src/tests/eo/composite_objects/composite_objects_simple.h
@@ -0,0 +1,28 @@
1#ifndef SIMPLE_H
2#define SIMPLE_H
3
4extern EAPI Eo_Op SIMPLE_BASE_ID;
5
6enum {
7 SIMPLE_SUB_ID_A_SET,
8 SIMPLE_SUB_ID_A_GET,
9 SIMPLE_SUB_ID_LAST
10};
11
12typedef struct
13{
14 int a;
15} Simple_Public_Data;
16
17#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id)
18
19#define simple_a_set(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EO_TYPECHECK(int, a)
20#define simple_a_get(a) SIMPLE_ID(SIMPLE_SUB_ID_A_GET), EO_TYPECHECK(int *, a)
21
22extern const Eo_Event_Description _EV_A_CHANGED;
23#define EV_A_CHANGED (&(_EV_A_CHANGED))
24
25#define SIMPLE_CLASS simple_class_get()
26const Eo_Class *simple_class_get(void);
27
28#endif