summaryrefslogtreecommitdiff
path: root/src/tests/eo/mixin
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/mixin
parent195d31c73fef88cfaa803b07b2ae3cba983a4093 (diff)
merge: add eo
SVN revision: 77072
Diffstat (limited to 'src/tests/eo/mixin')
-rw-r--r--src/tests/eo/mixin/mixin_inherit.c42
-rw-r--r--src/tests/eo/mixin/mixin_inherit.h7
-rw-r--r--src/tests/eo/mixin/mixin_main.c47
-rw-r--r--src/tests/eo/mixin/mixin_mixin.c67
-rw-r--r--src/tests/eo/mixin/mixin_mixin.h24
-rw-r--r--src/tests/eo/mixin/mixin_mixin2.c70
-rw-r--r--src/tests/eo/mixin/mixin_mixin2.h12
-rw-r--r--src/tests/eo/mixin/mixin_mixin3.c70
-rw-r--r--src/tests/eo/mixin/mixin_mixin3.h12
-rw-r--r--src/tests/eo/mixin/mixin_mixin4.c26
-rw-r--r--src/tests/eo/mixin/mixin_mixin4.h7
-rw-r--r--src/tests/eo/mixin/mixin_simple.c77
-rw-r--r--src/tests/eo/mixin/mixin_simple.h47
13 files changed, 508 insertions, 0 deletions
diff --git a/src/tests/eo/mixin/mixin_inherit.c b/src/tests/eo/mixin/mixin_inherit.c
new file mode 100644
index 0000000000..4dc8fd9e15
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_inherit.c
@@ -0,0 +1,42 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "mixin_simple.h"
7#include "mixin_mixin4.h"
8#include "mixin_inherit.h"
9
10#define MY_CLASS INHERIT_CLASS
11
12static void
13_a_get(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
14{
15 int *name = va_arg(*list, int *);
16 eo_do_super(obj, simple_a_get(name));
17 printf("%s\n", __func__);
18}
19
20static void
21_class_constructor(Eo_Class *klass)
22{
23 const Eo_Op_Func_Description func_desc[] = {
24 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
25 EO_OP_FUNC_SENTINEL
26 };
27
28 eo_class_funcs_set(klass, func_desc);
29}
30
31static const Eo_Class_Description class_desc = {
32 EO_VERSION,
33 "Inherit",
34 EO_CLASS_TYPE_REGULAR,
35 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
36 NULL,
37 0,
38 _class_constructor,
39 NULL
40};
41
42EO_DEFINE_CLASS(inherit_class_get, &class_desc, SIMPLE_CLASS, MIXIN4_CLASS, NULL);
diff --git a/src/tests/eo/mixin/mixin_inherit.h b/src/tests/eo/mixin/mixin_inherit.h
new file mode 100644
index 0000000000..2f33647958
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_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/mixin/mixin_main.c b/src/tests/eo/mixin/mixin_main.c
new file mode 100644
index 0000000000..bb19e9ca18
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_main.c
@@ -0,0 +1,47 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "mixin_simple.h"
7#include "mixin_inherit.h"
8#include "mixin_mixin.h"
9#include "mixin_mixin2.h"
10#include "mixin_mixin3.h"
11
12#include "../eunit_tests.h"
13
14int
15main(int argc, char *argv[])
16{
17 (void) argc;
18 (void) argv;
19 eo_init();
20
21 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
22
23 eo_do(obj, simple_a_set(1), simple_b_set(2));
24
25 int a, b, sum = 0;
26 eo_do(obj, simple_a_get(&a), simple_b_get(&b), mixin_ab_sum_get(&sum));
27 fail_if(sum != a + b + 2); /* 2 for the two mixins... */
28
29 eo_do(obj, mixin_ab_sum_get(&sum), mixin_ab_sum_get(&sum));
30
31 Mixin2_Public_Data *pd2 = eo_data_get(obj, MIXIN2_CLASS);
32 fail_if(pd2->count != 6);
33
34 Mixin3_Public_Data *pd3 = eo_data_get(obj, MIXIN3_CLASS);
35 fail_if(pd3->count != 9);
36
37 eo_unref(obj);
38
39 obj = eo_add(INHERIT_CLASS, NULL);
40 eo_do(obj, simple_a_set(5), simple_a_get(&a));
41 fail_if(a != 5);
42
43 eo_unref(obj);
44 eo_shutdown();
45 return 0;
46}
47
diff --git a/src/tests/eo/mixin/mixin_mixin.c b/src/tests/eo/mixin/mixin_mixin.c
new file mode 100644
index 0000000000..b6fd59e367
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_mixin.c
@@ -0,0 +1,67 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "mixin_mixin.h"
7#include "mixin_simple.h"
8
9EAPI Eo_Op MIXIN_BASE_ID = 0;
10
11#define MY_CLASS MIXIN_CLASS
12
13static void
14_ab_sum_get(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
15{
16 int a, b;
17 eo_do(obj, simple_a_get(&a), simple_b_get(&b));
18 int *sum = va_arg(*list, int *);
19 if (sum)
20 *sum = a + b;
21 printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
22}
23
24static void
25_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
26{
27 eo_do_super(obj, eo_constructor());
28}
29
30static void
31_destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
32{
33 eo_do_super(obj, eo_destructor());
34}
35
36static void
37_class_constructor(Eo_Class *klass)
38{
39 const Eo_Op_Func_Description func_desc[] = {
40 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
41 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
42 EO_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), _ab_sum_get),
43 EO_OP_FUNC_SENTINEL
44 };
45
46 eo_class_funcs_set(klass, func_desc);
47}
48
49
50static const Eo_Op_Description op_desc[] = {
51 EO_OP_DESCRIPTION(MIXIN_SUB_ID_AB_SUM_GET, "Get the sum of a and b."),
52 EO_OP_DESCRIPTION_SENTINEL
53};
54
55static const Eo_Class_Description class_desc = {
56 EO_VERSION,
57 "Mixin",
58 EO_CLASS_TYPE_MIXIN,
59 EO_CLASS_DESCRIPTION_OPS(&MIXIN_BASE_ID, op_desc, MIXIN_SUB_ID_LAST),
60 NULL,
61 0,
62 _class_constructor,
63 NULL
64};
65
66EO_DEFINE_CLASS(mixin_class_get, &class_desc, NULL, NULL)
67
diff --git a/src/tests/eo/mixin/mixin_mixin.h b/src/tests/eo/mixin/mixin_mixin.h
new file mode 100644
index 0000000000..745e5c4683
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_mixin.h
@@ -0,0 +1,24 @@
1#ifndef MIXIN_H
2#define MIXIN_H
3
4extern EAPI Eo_Op MIXIN_BASE_ID;
5
6enum {
7 MIXIN_SUB_ID_AB_SUM_GET,
8 MIXIN_SUB_ID_LAST
9};
10
11#define MIXIN_ID(sub_id) (MIXIN_BASE_ID + sub_id)
12
13
14/**
15 * @def mixin_ab_sum_get(sum)
16 * @brief Get sum of a,b integer elements
17 * @param[out] sum integer pointer to sum - value
18 */
19#define mixin_ab_sum_get(sum) MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), EO_TYPECHECK(int *, sum)
20
21#define MIXIN_CLASS mixin_class_get()
22const Eo_Class *mixin_class_get(void);
23
24#endif
diff --git a/src/tests/eo/mixin/mixin_mixin2.c b/src/tests/eo/mixin/mixin_mixin2.c
new file mode 100644
index 0000000000..dbd7c97d00
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_mixin2.c
@@ -0,0 +1,70 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "mixin_mixin.h"
7#include "mixin_mixin2.h"
8#include "mixin_simple.h"
9
10#include "../eunit_tests.h"
11
12#define MY_CLASS MIXIN2_CLASS
13
14static void
15_ab_sum_get(Eo *obj, void *class_data, va_list *list)
16{
17 /* This cast is a hack just for the tests... */
18 Mixin2_Public_Data *pd = (Mixin2_Public_Data *) class_data;
19 int *sum = va_arg(*list, int *);
20 printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
21 eo_do_super(obj, mixin_ab_sum_get(sum));
22
23 ++*sum;
24 pd->count += 2;
25
26 {
27 int _a, _b;
28 eo_do(obj, simple_a_get(&_a), simple_b_get(&_b));
29 fail_if(*sum != _a + _b + 1);
30 }
31}
32
33static void
34_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
35{
36 eo_do_super(obj, eo_constructor());
37}
38
39static void
40_destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
41{
42 eo_do_super(obj, eo_destructor());
43}
44
45static void
46_class_constructor(Eo_Class *klass)
47{
48 const Eo_Op_Func_Description func_desc[] = {
49 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
50 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
51 EO_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), _ab_sum_get),
52 EO_OP_FUNC_SENTINEL
53 };
54
55 eo_class_funcs_set(klass, func_desc);
56}
57
58static const Eo_Class_Description class_desc = {
59 EO_VERSION,
60 "Mixin2",
61 EO_CLASS_TYPE_MIXIN,
62 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
63 NULL,
64 sizeof(Mixin2_Public_Data),
65 _class_constructor,
66 NULL
67};
68
69EO_DEFINE_CLASS(mixin2_class_get, &class_desc, MIXIN_CLASS, NULL);
70
diff --git a/src/tests/eo/mixin/mixin_mixin2.h b/src/tests/eo/mixin/mixin_mixin2.h
new file mode 100644
index 0000000000..6e4b692d41
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_mixin2.h
@@ -0,0 +1,12 @@
1#ifndef MIXIN2_H
2#define MIXIN2_H
3
4typedef struct
5{
6 int count;
7} Mixin2_Public_Data;
8
9#define MIXIN2_CLASS mixin2_class_get()
10const Eo_Class *mixin2_class_get(void);
11
12#endif
diff --git a/src/tests/eo/mixin/mixin_mixin3.c b/src/tests/eo/mixin/mixin_mixin3.c
new file mode 100644
index 0000000000..08c2b5cc7b
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_mixin3.c
@@ -0,0 +1,70 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "mixin_mixin.h"
7#include "mixin_mixin3.h"
8#include "mixin_simple.h"
9
10#include "../eunit_tests.h"
11
12#define MY_CLASS MIXIN3_CLASS
13
14static void
15_ab_sum_get(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
16{
17 /* This cast is just a hack for the test. */
18 Mixin3_Public_Data *pd = (Mixin3_Public_Data *) class_data;
19 int *sum = va_arg(*list, int *);
20 printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
21 eo_do_super(obj, mixin_ab_sum_get(sum));
22
23 ++*sum;
24 pd->count += 3;
25
26 {
27 int _a, _b;
28 eo_do(obj, simple_a_get(&_a), simple_b_get(&_b));
29 fail_if(*sum != _a + _b + 2);
30 }
31}
32
33static void
34_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
35{
36 eo_do_super(obj, eo_constructor());
37}
38
39static void
40_destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
41{
42 eo_do_super(obj, eo_destructor());
43}
44
45static void
46_class_constructor(Eo_Class *klass)
47{
48 const Eo_Op_Func_Description func_desc[] = {
49 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor),
50 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor),
51 EO_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), _ab_sum_get),
52 EO_OP_FUNC_SENTINEL
53 };
54
55 eo_class_funcs_set(klass, func_desc);
56}
57
58static const Eo_Class_Description class_desc = {
59 EO_VERSION,
60 "Mixin3",
61 EO_CLASS_TYPE_MIXIN,
62 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
63 NULL,
64 sizeof(Mixin3_Public_Data),
65 _class_constructor,
66 NULL
67};
68
69EO_DEFINE_CLASS(mixin3_class_get, &class_desc, MIXIN_CLASS, NULL);
70
diff --git a/src/tests/eo/mixin/mixin_mixin3.h b/src/tests/eo/mixin/mixin_mixin3.h
new file mode 100644
index 0000000000..36b32c0aa8
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_mixin3.h
@@ -0,0 +1,12 @@
1#ifndef MIXIN3_H
2#define MIXIN3_H
3
4typedef struct
5{
6 int count;
7} Mixin3_Public_Data;
8
9#define MIXIN3_CLASS mixin3_class_get()
10const Eo_Class *mixin3_class_get(void);
11
12#endif
diff --git a/src/tests/eo/mixin/mixin_mixin4.c b/src/tests/eo/mixin/mixin_mixin4.c
new file mode 100644
index 0000000000..cf8f16f965
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_mixin4.c
@@ -0,0 +1,26 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "mixin_mixin.h"
7#include "mixin_mixin4.h"
8#include "mixin_simple.h"
9
10#include "../eunit_tests.h"
11
12#define MY_CLASS MIXIN4_CLASS
13
14static const Eo_Class_Description class_desc = {
15 EO_VERSION,
16 "Mixin4",
17 EO_CLASS_TYPE_MIXIN,
18 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
19 NULL,
20 0,
21 NULL,
22 NULL
23};
24
25EO_DEFINE_CLASS(mixin4_class_get, &class_desc, NULL, NULL);
26
diff --git a/src/tests/eo/mixin/mixin_mixin4.h b/src/tests/eo/mixin/mixin_mixin4.h
new file mode 100644
index 0000000000..7b520fad19
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_mixin4.h
@@ -0,0 +1,7 @@
1#ifndef MIXIN4_H
2#define MIXIN4_H
3
4#define MIXIN4_CLASS mixin4_class_get()
5const Eo_Class *mixin4_class_get(void);
6
7#endif
diff --git a/src/tests/eo/mixin/mixin_simple.c b/src/tests/eo/mixin/mixin_simple.c
new file mode 100644
index 0000000000..ff4600d727
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_simple.c
@@ -0,0 +1,77 @@
1#ifdef HAVE_CONFIG_H
2# include <config.h>
3#endif
4
5#include "Eo.h"
6#include "mixin_mixin.h"
7#include "mixin_mixin2.h"
8#include "mixin_mixin3.h"
9#include "mixin_simple.h"
10
11EAPI Eo_Op SIMPLE_BASE_ID = 0;
12
13typedef struct
14{
15 int a;
16 int b;
17} Private_Data;
18
19#define MY_CLASS SIMPLE_CLASS
20
21#define _GET_SET_FUNC(name) \
22static void \
23_##name##_get(Eo *obj EINA_UNUSED, void *class_data, va_list *list) \
24{ \
25 const Private_Data *pd = class_data; \
26 int *name; \
27 name = va_arg(*list, int *); \
28 *name = pd->name; \
29 printf("%s %d\n", __func__, pd->name); \
30} \
31static void \
32_##name##_set(Eo *obj EINA_UNUSED, void *class_data, va_list *list) \
33{ \
34 Private_Data *pd = class_data; \
35 int name; \
36 name = va_arg(*list, int); \
37 pd->name = name; \
38 printf("%s %d\n", __func__, pd->name); \
39}
40
41_GET_SET_FUNC(a)
42_GET_SET_FUNC(b)
43
44static void
45_class_constructor(Eo_Class *klass)
46{
47 const Eo_Op_Func_Description func_desc[] = {
48 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
49 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
50 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_B_SET), _b_set),
51 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_B_GET), _b_get),
52 EO_OP_FUNC_SENTINEL
53 };
54
55 eo_class_funcs_set(klass, func_desc);
56}
57
58static const Eo_Op_Description op_desc[] = {
59 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"),
60 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_GET, "Get property A"),
61 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_B_SET, "Set property B"),
62 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_B_GET, "Get property B"),
63 EO_OP_DESCRIPTION_SENTINEL
64};
65
66static const Eo_Class_Description class_desc = {
67 EO_VERSION,
68 "Simple",
69 EO_CLASS_TYPE_REGULAR,
70 EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
71 NULL,
72 sizeof(Private_Data),
73 _class_constructor,
74 NULL
75};
76
77EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, MIXIN3_CLASS, MIXIN2_CLASS, NULL);
diff --git a/src/tests/eo/mixin/mixin_simple.h b/src/tests/eo/mixin/mixin_simple.h
new file mode 100644
index 0000000000..8df8131278
--- /dev/null
+++ b/src/tests/eo/mixin/mixin_simple.h
@@ -0,0 +1,47 @@
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_B_SET,
10 SIMPLE_SUB_ID_B_GET,
11 SIMPLE_SUB_ID_LAST
12};
13
14#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id)
15
16/**
17 * @def simple_a_set(a)
18 * @brief Set value to a-property
19 * @param[in] a integer value to set
20 */
21#define simple_a_set(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EO_TYPECHECK(int, a)
22
23/**
24 * @def simple_a_get(a)
25 * @brief Get value of a-property
26 * @param[out] integer pointer to a-value
27 */
28#define simple_a_get(a) SIMPLE_ID(SIMPLE_SUB_ID_A_GET), EO_TYPECHECK(int *, a)
29
30/**
31 * @def simple_b_set(b)
32 * @brief Set value to b-property
33 * @param[in] a integer value to set
34 */
35#define simple_b_set(b) SIMPLE_ID(SIMPLE_SUB_ID_B_SET), EO_TYPECHECK(int, b)
36
37/**
38 * @def simple_b_get(b)
39 * @brief Get value of b-property
40 * @param[out] integer pointer to b-value
41 */
42#define simple_b_get(b) SIMPLE_ID(SIMPLE_SUB_ID_B_GET), EO_TYPECHECK(int *, b)
43
44#define SIMPLE_CLASS simple_class_get()
45const Eo_Class *simple_class_get(void);
46
47#endif