summaryrefslogtreecommitdiff
path: root/src/tests/eo/function_overrides
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/function_overrides
parent195d31c73fef88cfaa803b07b2ae3cba983a4093 (diff)
merge: add eo
SVN revision: 77072
Diffstat (limited to 'src/tests/eo/function_overrides')
-rw-r--r--src/tests/eo/function_overrides/function_overrides_inherit.c22
-rw-r--r--src/tests/eo/function_overrides/function_overrides_inherit.h7
-rw-r--r--src/tests/eo/function_overrides/function_overrides_inherit2.c82
-rw-r--r--src/tests/eo/function_overrides/function_overrides_inherit2.h20
-rw-r--r--src/tests/eo/function_overrides/function_overrides_inherit3.c44
-rw-r--r--src/tests/eo/function_overrides/function_overrides_inherit3.h7
-rw-r--r--src/tests/eo/function_overrides/function_overrides_main.c63
-rw-r--r--src/tests/eo/function_overrides/function_overrides_simple.c82
-rw-r--r--src/tests/eo/function_overrides/function_overrides_simple.h32
9 files changed, 359 insertions, 0 deletions
diff --git a/src/tests/eo/function_overrides/function_overrides_inherit.c b/src/tests/eo/function_overrides/function_overrides_inherit.c
new file mode 100644
index 0000000000..e2dadbec1b
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_inherit.c
@@ -0,0 +1,22 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "function_overrides_simple.h"
7#include "function_overrides_inherit.h"
8
9#define MY_CLASS INHERIT_CLASS
10
11static const Eo_Class_Description class_desc = {
12 EO_VERSION,
13 "Inherit",
14 EO_CLASS_TYPE_REGULAR,
15 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
16 NULL,
17 0,
18 NULL,
19 NULL
20};
21
22EO_DEFINE_CLASS(inherit_class_get, &class_desc, SIMPLE_CLASS, NULL);
diff --git a/src/tests/eo/function_overrides/function_overrides_inherit.h b/src/tests/eo/function_overrides/function_overrides_inherit.h
new file mode 100644
index 0000000000..2f33647958
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_inherit.h
@@ -0,0 +1,7 @@
1#ifndef INHERIT_H
2#define INHERIT_H
3
4#define INHERIT_CLASS inherit_class_get()
5const Eo_Class *inherit_class_get(void);
6
7#endif
diff --git a/src/tests/eo/function_overrides/function_overrides_inherit2.c b/src/tests/eo/function_overrides/function_overrides_inherit2.c
new file mode 100644
index 0000000000..1386759bc6
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_inherit2.c
@@ -0,0 +1,82 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "function_overrides_simple.h"
7#include "function_overrides_inherit.h"
8#include "function_overrides_inherit2.h"
9
10#include "../eunit_tests.h"
11
12EAPI Eo_Op INHERIT2_BASE_ID = 0;
13
14#define MY_CLASS INHERIT2_CLASS
15
16static void
17_a_set(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
18{
19 int a;
20 a = va_arg(*list, int);
21 printf("%s %d\n", eo_class_name_get(MY_CLASS), a);
22 eo_do(obj, simple_a_print());
23 eo_do_super(obj, simple_a_set(a + 1));
24
25 fail_if(!eo_do_super(obj, simple_a_print()));
26}
27
28static void
29_print(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
30{
31 printf("Hey\n");
32 fail_if(eo_do_super(obj, inherit2_print()));
33}
34
35static void
36_print2(Eo *obj EINA_UNUSED, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
37{
38 printf("Hey2\n");
39}
40
41static void
42_class_print(const Eo_Class *klass, va_list *list)
43{
44 (void) list;
45 printf("Print %s-%s\n", eo_class_name_get(klass), eo_class_name_get(MY_CLASS));
46 fail_if(!eo_class_do_super(klass, simple_class_print()));
47 fail_if(!eo_class_do_super(klass, simple_class_print2()));
48}
49
50static void
51_class_constructor(Eo_Class *klass)
52{
53 const Eo_Op_Func_Description func_desc[] = {
54 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
55 EO_OP_FUNC(INHERIT2_ID(INHERIT2_SUB_ID_PRINT), _print),
56 EO_OP_FUNC(INHERIT2_ID(INHERIT2_SUB_ID_PRINT2), _print2),
57 EO_OP_FUNC_CLASS(SIMPLE_ID(SIMPLE_SUB_ID_CLASS_PRINT), _class_print),
58 EO_OP_FUNC_SENTINEL
59 };
60
61 eo_class_funcs_set(klass, func_desc);
62}
63
64static const Eo_Op_Description op_desc[] = {
65 EO_OP_DESCRIPTION(INHERIT2_SUB_ID_PRINT, "Print hey"),
66 EO_OP_DESCRIPTION(INHERIT2_SUB_ID_PRINT2, "Print hey2"),
67 EO_OP_DESCRIPTION_SENTINEL
68};
69
70static const Eo_Class_Description class_desc = {
71 EO_VERSION,
72 "Inherit2",
73 EO_CLASS_TYPE_REGULAR,
74 EO_CLASS_DESCRIPTION_OPS(&INHERIT2_BASE_ID, op_desc, INHERIT2_SUB_ID_LAST),
75 NULL,
76 0,
77 _class_constructor,
78 NULL
79};
80
81EO_DEFINE_CLASS(inherit2_class_get, &class_desc, INHERIT_CLASS, NULL);
82
diff --git a/src/tests/eo/function_overrides/function_overrides_inherit2.h b/src/tests/eo/function_overrides/function_overrides_inherit2.h
new file mode 100644
index 0000000000..2bc0b0d36a
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_inherit2.h
@@ -0,0 +1,20 @@
1#ifndef INHERIT2_H
2#define INHERIT2_H
3
4extern EAPI Eo_Op INHERIT2_BASE_ID;
5
6enum {
7 INHERIT2_SUB_ID_PRINT,
8 INHERIT2_SUB_ID_PRINT2,
9 INHERIT2_SUB_ID_LAST
10};
11
12#define INHERIT2_ID(sub_id) (INHERIT2_BASE_ID + sub_id)
13
14#define inherit2_print() INHERIT2_ID(INHERIT2_SUB_ID_PRINT)
15#define inherit2_print2() INHERIT2_ID(INHERIT2_SUB_ID_PRINT2)
16
17#define INHERIT2_CLASS inherit2_class_get()
18const Eo_Class *inherit2_class_get(void);
19
20#endif
diff --git a/src/tests/eo/function_overrides/function_overrides_inherit3.c b/src/tests/eo/function_overrides/function_overrides_inherit3.c
new file mode 100644
index 0000000000..186291328a
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_inherit3.c
@@ -0,0 +1,44 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "function_overrides_simple.h"
7#include "function_overrides_inherit2.h"
8#include "function_overrides_inherit3.h"
9
10#define MY_CLASS INHERIT3_CLASS
11
12static void
13_a_set(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
14{
15 int a;
16 a = va_arg(*list, int);
17 printf("%s %d\n", eo_class_name_get(MY_CLASS), a);
18 eo_do_super(obj, simple_a_set(a + 1));
19}
20
21static void
22_class_constructor(Eo_Class *klass)
23{
24 const Eo_Op_Func_Description func_desc[] = {
25 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
26 EO_OP_FUNC_SENTINEL
27 };
28
29 eo_class_funcs_set(klass, func_desc);
30}
31
32static const Eo_Class_Description class_desc = {
33 EO_VERSION,
34 "Inherit3",
35 EO_CLASS_TYPE_REGULAR,
36 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
37 NULL,
38 0,
39 _class_constructor,
40 NULL
41};
42
43EO_DEFINE_CLASS(inherit3_class_get, &class_desc, INHERIT2_CLASS, NULL);
44
diff --git a/src/tests/eo/function_overrides/function_overrides_inherit3.h b/src/tests/eo/function_overrides/function_overrides_inherit3.h
new file mode 100644
index 0000000000..73436ba239
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_inherit3.h
@@ -0,0 +1,7 @@
1#ifndef INHERIT3_H
2#define INHERIT3_H
3
4#define INHERIT3_CLASS inherit3_class_get()
5const Eo_Class *inherit3_class_get(void);
6
7#endif
diff --git a/src/tests/eo/function_overrides/function_overrides_main.c b/src/tests/eo/function_overrides/function_overrides_main.c
new file mode 100644
index 0000000000..4ab695f982
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_main.c
@@ -0,0 +1,63 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "function_overrides_simple.h"
7#include "function_overrides_inherit.h"
8#include "function_overrides_inherit2.h"
9#include "function_overrides_inherit3.h"
10
11#include "../eunit_tests.h"
12
13int
14main(int argc, char *argv[])
15{
16 (void) argc;
17 (void) argv;
18 eo_init();
19
20 Eo *obj = eo_add(INHERIT2_CLASS, NULL);
21
22 eo_do(obj, simple_a_set(1));
23 Simple_Public_Data *pd = eo_data_get(obj, SIMPLE_CLASS);
24 fail_if(pd->a != 2);
25
26 eo_unref(obj);
27
28 obj = eo_add(INHERIT3_CLASS, NULL);
29
30 eo_do(obj, simple_a_set(1));
31 pd = eo_data_get(obj, SIMPLE_CLASS);
32 fail_if(pd->a != 3);
33
34 eo_unref(obj);
35
36 obj = eo_add(INHERIT2_CLASS, NULL);
37 fail_if(!eo_do(obj, inherit2_print()));
38 fail_if(!eo_do(obj, inherit2_print(), inherit2_print()));
39 eo_unref(obj);
40
41 obj = eo_add(SIMPLE_CLASS, NULL);
42 fail_if(eo_do(obj, inherit2_print2()));
43
44 fail_if(eo_do_super(obj, simple_a_print()));
45
46 fail_if(eo_do(obj, simple_class_print()));
47
48 fail_if(!eo_class_do(SIMPLE_CLASS, simple_class_print()));
49 fail_if(!eo_class_do(INHERIT_CLASS, simple_class_print()));
50 fail_if(!eo_class_do(INHERIT2_CLASS, simple_class_print()));
51 fail_if(!eo_class_do(INHERIT3_CLASS, simple_class_print()));
52
53 fail_if(eo_class_do(SIMPLE_CLASS, simple_a_print()));
54
55 eo_do_super(obj, eo_constructor());
56 eo_do_super(obj, eo_destructor());
57
58 eo_unref(obj);
59
60 eo_shutdown();
61 return 0;
62}
63
diff --git a/src/tests/eo/function_overrides/function_overrides_simple.c b/src/tests/eo/function_overrides/function_overrides_simple.c
new file mode 100644
index 0000000000..1672943939
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_simple.c
@@ -0,0 +1,82 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "function_overrides_simple.h"
7
8#include "../eunit_tests.h"
9
10EAPI Eo_Op SIMPLE_BASE_ID = 0;
11
12#define MY_CLASS SIMPLE_CLASS
13
14static void
15_a_set(Eo *obj EINA_UNUSED, void *class_data, va_list *list)
16{
17 Simple_Public_Data *pd = class_data;
18 int a;
19 a = va_arg(*list, int);
20 printf("%s %d\n", eo_class_name_get(MY_CLASS), a);
21 pd->a = a;
22}
23
24static void
25_a_print(Eo *obj EINA_UNUSED, void *class_data, va_list *list)
26{
27 const Simple_Public_Data *pd = class_data;
28 (void) list;
29 printf("Print %s %d\n", eo_class_name_get(MY_CLASS), pd->a);
30}
31
32static void
33_class_print(const Eo_Class *klass, va_list *list)
34{
35 (void) list;
36 printf("Print %s-%s\n", eo_class_name_get(klass), eo_class_name_get(MY_CLASS));
37 fail_if(eo_class_do_super(klass, simple_class_print()));
38 fail_if(eo_class_do_super(klass, simple_class_print2()));
39}
40
41static void
42_class_print2(const Eo_Class *klass, va_list *list)
43{
44 (void) list;
45 printf("Print %s-%s\n", eo_class_name_get(klass), eo_class_name_get(MY_CLASS));
46}
47
48static void
49_class_constructor(Eo_Class *klass)
50{
51 const Eo_Op_Func_Description func_desc[] = {
52 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
53 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_PRINT), _a_print),
54 EO_OP_FUNC_CLASS(SIMPLE_ID(SIMPLE_SUB_ID_CLASS_PRINT), _class_print),
55 EO_OP_FUNC_CLASS(SIMPLE_ID(SIMPLE_SUB_ID_CLASS_PRINT2), _class_print2),
56 EO_OP_FUNC_SENTINEL
57 };
58
59 eo_class_funcs_set(klass, func_desc);
60}
61
62static const Eo_Op_Description op_desc[] = {
63 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"),
64 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_PRINT, "Print property A"),
65 EO_OP_DESCRIPTION_CLASS(SIMPLE_SUB_ID_CLASS_PRINT, "Print class name."),
66 EO_OP_DESCRIPTION_CLASS(SIMPLE_SUB_ID_CLASS_PRINT2, "Print2 class name."),
67 EO_OP_DESCRIPTION_SENTINEL
68};
69
70static const Eo_Class_Description class_desc = {
71 EO_VERSION,
72 "Simple",
73 EO_CLASS_TYPE_REGULAR,
74 EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
75 NULL,
76 sizeof(Simple_Public_Data),
77 _class_constructor,
78 NULL
79};
80
81EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, NULL);
82
diff --git a/src/tests/eo/function_overrides/function_overrides_simple.h b/src/tests/eo/function_overrides/function_overrides_simple.h
new file mode 100644
index 0000000000..3a620fa611
--- /dev/null
+++ b/src/tests/eo/function_overrides/function_overrides_simple.h
@@ -0,0 +1,32 @@
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_PRINT,
9 SIMPLE_SUB_ID_CLASS_PRINT,
10 SIMPLE_SUB_ID_CLASS_PRINT2,
11 SIMPLE_SUB_ID_LAST
12};
13
14typedef struct
15{
16 int a;
17} Simple_Public_Data;
18
19#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id)
20
21#define simple_a_set(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EO_TYPECHECK(int, a)
22#define simple_a_print() SIMPLE_ID(SIMPLE_SUB_ID_A_PRINT)
23#define simple_class_print() SIMPLE_ID(SIMPLE_SUB_ID_CLASS_PRINT)
24#define simple_class_print2() SIMPLE_ID(SIMPLE_SUB_ID_CLASS_PRINT2)
25
26extern const Eo_Event_Description _SIG_A_CHANGED;
27#define SIG_A_CHANGED (&(_SIG_A_CHANGED))
28
29#define SIMPLE_CLASS simple_class_get()
30const Eo_Class *simple_class_get(void);
31
32#endif