From cbc9a7bd305669bbf31c5b4d0116149c0427fdec Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 7 Nov 2013 16:06:51 +0000 Subject: [PATCH] eo2: migrated constructors test to eo2. --- src/tests/eo/constructors/constructors_main.c | 22 ++++---- src/tests/eo/constructors/constructors_mixin.c | 46 ++++++---------- src/tests/eo/constructors/constructors_mixin.h | 11 +--- src/tests/eo/constructors/constructors_simple.c | 69 ++++++++++-------------- src/tests/eo/constructors/constructors_simple.h | 23 ++------ src/tests/eo/constructors/constructors_simple2.c | 25 ++++----- src/tests/eo/constructors/constructors_simple3.c | 22 +++----- src/tests/eo/constructors/constructors_simple4.c | 2 +- src/tests/eo/constructors/constructors_simple5.c | 22 +++----- src/tests/eo/constructors/constructors_simple6.c | 26 ++++----- src/tests/eo/constructors/constructors_simple7.c | 23 ++++---- 11 files changed, 107 insertions(+), 184 deletions(-) diff --git a/src/tests/eo/constructors/constructors_main.c b/src/tests/eo/constructors/constructors_main.c index c7db62d..9411320 100644 --- a/src/tests/eo/constructors/constructors_main.c +++ b/src/tests/eo/constructors/constructors_main.c @@ -24,27 +24,27 @@ main(int argc, char *argv[]) (void) argv; eo_init(); - Eo *obj = eo_add(SIMPLE_CLASS, NULL); + Eo *obj = eo2_add(SIMPLE_CLASS, NULL); fail_if(my_init_count != 2); - eo_do(obj, simple_a_set(1), simple_b_set(2)); + eo2_do(obj, simple_a_set(1), simple_b_set(2)); int a, b; - eo_do(obj, simple_a_get(&a), simple_b_get(&b), mixin_add_and_print(5)); + eo2_do(obj, a = simple_a_get(), b = simple_b_get(), mixin_add_and_print(5)); eo_unref(obj); fail_if(my_init_count != 0); - obj = eo_add(SIMPLE2_CLASS, NULL); + obj = eo2_add(SIMPLE2_CLASS, NULL); fail_if(obj); - obj = eo_add(SIMPLE3_CLASS, NULL); + obj = eo2_add(SIMPLE3_CLASS, NULL); fail_if(obj); my_init_count = 0; - obj = eo_add(SIMPLE4_CLASS, NULL); + obj = eo2_add(SIMPLE4_CLASS, NULL); fail_if(my_init_count != 2); @@ -52,23 +52,23 @@ main(int argc, char *argv[]) fail_if(my_init_count != 0); - obj = eo_add(SIMPLE5_CLASS, NULL); + obj = eo2_add(SIMPLE5_CLASS, NULL); fail_if(!obj); eo_unref(obj); - obj = eo_add(SIMPLE6_CLASS, NULL); + obj = eo2_add(SIMPLE6_CLASS, NULL); fail_if(!obj); eo_unref(obj); - obj = eo_add(SIMPLE7_CLASS, NULL); + obj = eo2_add(SIMPLE7_CLASS, NULL); fail_if(obj); my_init_count = 0; - obj = eo_add_custom(SIMPLE_CLASS, NULL, simple_constructor(7)); + obj = eo2_add_custom(SIMPLE_CLASS, NULL, simple_constructor(7)); fail_if(!obj); fail_if(my_init_count != 2); - eo_do(obj, simple_a_get(&a)); + eo2_do(obj, a = simple_a_get()); fail_if(a != 7); eo_unref(obj); diff --git a/src/tests/eo/constructors/constructors_mixin.c b/src/tests/eo/constructors/constructors_mixin.c index 24f7364..a729117 100644 --- a/src/tests/eo/constructors/constructors_mixin.c +++ b/src/tests/eo/constructors/constructors_mixin.c @@ -6,65 +6,53 @@ #include "constructors_mixin.h" #include "constructors_simple.h" -EAPI Eo_Op MIXIN_BASE_ID = 0; - #define MY_CLASS MIXIN_CLASS static void -_add_and_print_set(Eo *obj, void *class_data EINA_UNUSED, va_list *list) +_add_and_print_set(Eo *obj, void *class_data EINA_UNUSED, int x) { - int a, b, x; - eo_do(obj, simple_a_get(&a), simple_b_get(&b)); - x = va_arg(*list, const int); + int a, b; + eo2_do(obj, a = simple_a_get(), b = simple_b_get()); printf("%s %d\n", __func__, a + b + x); } extern int my_init_count; static void -_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) +_constructor(Eo *obj, void *class_data EINA_UNUSED) { - eo_do_super(obj, MY_CLASS, eo_constructor()); + eo2_do_super(obj, MY_CLASS, eo2_constructor()); my_init_count++; } static void -_destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) +_destructor(Eo *obj, void *class_data EINA_UNUSED) { - eo_do_super(obj, MY_CLASS, eo_destructor()); + eo2_do_super(obj, MY_CLASS, eo2_destructor()); my_init_count--; } -static void -_class_constructor(Eo_Class *klass) -{ - const Eo_Op_Func_Description func_desc[] = { - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor), - EO_OP_FUNC(MIXIN_ID(MIXIN_SUB_ID_ADD_AND_SET), _add_and_print_set), - EO_OP_FUNC_SENTINEL - }; - - eo_class_funcs_set(klass, func_desc); -} +EAPI EO2_VOID_FUNC_BODYV(mixin_add_and_print, EO2_FUNC_CALL(x), int x); -static const Eo_Op_Description op_desc[] = { - EO_OP_DESCRIPTION(MIXIN_SUB_ID_ADD_AND_SET, "Add A + B + param and print it"), - EO_OP_DESCRIPTION_SENTINEL +static Eo2_Op_Description op_descs[] = { + EO2_OP_FUNC(_add_and_print_set, mixin_add_and_print, "Add A + B + param and print it"), + EO2_OP_FUNC_OVERRIDE(_constructor, eo2_constructor), + EO2_OP_FUNC_OVERRIDE(_destructor, eo2_destructor), + EO2_OP_SENTINEL }; static const Eo_Class_Description class_desc = { - EO_VERSION, + EO2_VERSION, "Mixin", EO_CLASS_TYPE_MIXIN, - EO_CLASS_DESCRIPTION_OPS(&MIXIN_BASE_ID, op_desc, MIXIN_SUB_ID_LAST), + EO2_CLASS_DESCRIPTION_OPS(op_descs), NULL, 0, - _class_constructor, + NULL, NULL }; -EO_DEFINE_CLASS(mixin_class_get, &class_desc, NULL, NULL); +EO_DEFINE_CLASS(mixin_class_get, &class_desc, NULL, EO2_BASE_CLASS, NULL); diff --git a/src/tests/eo/constructors/constructors_mixin.h b/src/tests/eo/constructors/constructors_mixin.h index 9998b27..ebf923f 100644 --- a/src/tests/eo/constructors/constructors_mixin.h +++ b/src/tests/eo/constructors/constructors_mixin.h @@ -1,16 +1,7 @@ #ifndef MIXIN_H #define MIXIN_H -extern EAPI Eo_Op MIXIN_BASE_ID; - -enum { - MIXIN_SUB_ID_ADD_AND_SET, - MIXIN_SUB_ID_LAST -}; - -#define MIXIN_ID(sub_id) (MIXIN_BASE_ID + sub_id) - -#define mixin_add_and_print(x) MIXIN_ID(MIXIN_SUB_ID_ADD_AND_SET), EO_TYPECHECK(int, x) +EAPI void mixin_add_and_print(int x); #define MIXIN_CLASS mixin_class_get() const Eo_Class *mixin_class_get(void); diff --git a/src/tests/eo/constructors/constructors_simple.c b/src/tests/eo/constructors/constructors_simple.c index 466bd85..768eb47 100644 --- a/src/tests/eo/constructors/constructors_simple.c +++ b/src/tests/eo/constructors/constructors_simple.c @@ -19,24 +19,22 @@ typedef struct static char *class_var = NULL; #define _GET_SET_FUNC(name) \ -static void \ -_##name##_get(Eo *obj EINA_UNUSED, void *class_data, va_list *list) \ +static int \ +_##name##_get(Eo *obj EINA_UNUSED, void *class_data) \ { \ const Private_Data *pd = class_data; \ - int *name; \ - name = va_arg(*list, int *); \ - *name = pd->name; \ printf("%s %d\n", __func__, pd->name); \ + return pd->name; \ } \ static void \ -_##name##_set(Eo *obj EINA_UNUSED, void *class_data, va_list *list) \ +_##name##_set(Eo *obj EINA_UNUSED, void *class_data, int name) \ { \ Private_Data *pd = class_data; \ - int name; \ - name = va_arg(*list, int); \ pd->name = name; \ printf("%s %d\n", __func__, pd->name); \ -} +} \ +EO2_VOID_FUNC_BODYV(simple_##name##_set, EO2_FUNC_CALL(name), int name); \ +EO2_FUNC_BODY(simple_##name##_get, int, 0); _GET_SET_FUNC(a) _GET_SET_FUNC(b) @@ -44,13 +42,11 @@ _GET_SET_FUNC(b) extern int my_init_count; static void -_simple_constructor(Eo *obj, void *class_data, va_list *list) +_simple_constructor(Eo *obj, void *class_data, int a) { Private_Data *pd = class_data; - int a; - a = va_arg(*list, int); - eo_do_super(obj, MY_CLASS, eo_constructor()); + eo2_do_super(obj, MY_CLASS, eo2_constructor()); pd->a = a; printf("%s %d\n", __func__, pd->a); @@ -59,37 +55,24 @@ _simple_constructor(Eo *obj, void *class_data, va_list *list) } static void -_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) +_constructor(Eo *obj, void *class_data EINA_UNUSED) { - eo_do_super(obj, MY_CLASS, eo_constructor()); + eo2_do_super(obj, MY_CLASS, eo2_constructor()); my_init_count++; } static void -_destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) +_destructor(Eo *obj, void *class_data EINA_UNUSED) { - eo_do_super(obj, MY_CLASS, eo_destructor()); + eo2_do_super(obj, MY_CLASS, eo2_destructor()); my_init_count--; } static void -_class_constructor(Eo_Class *klass) +_class_constructor(Eo_Class *klass EINA_UNUSED) { - const Eo_Op_Func_Description func_desc[] = { - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor), - EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_CONSTRUCTOR), _simple_constructor), - EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set), - EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get), - EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_B_SET), _b_set), - EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_B_GET), _b_get), - EO_OP_FUNC_SENTINEL - }; - - eo_class_funcs_set(klass, func_desc); - class_var = malloc(10); } @@ -99,26 +82,30 @@ _class_destructor(Eo_Class *klass EINA_UNUSED) free(class_var); } -static const Eo_Op_Description op_desc[] = { - EO_OP_DESCRIPTION(SIMPLE_SUB_ID_CONSTRUCTOR, "Construct and set A."), - EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"), - EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_GET, "Get property A"), - EO_OP_DESCRIPTION(SIMPLE_SUB_ID_B_SET, "Set property B"), - EO_OP_DESCRIPTION(SIMPLE_SUB_ID_B_GET, "Get property B"), - EO_OP_DESCRIPTION_SENTINEL +EO2_VOID_FUNC_BODYV(simple_constructor, EO2_FUNC_CALL(a), int a); + +static Eo2_Op_Description op_descs[] = { + EO2_OP_FUNC_OVERRIDE(_constructor, eo2_constructor), + EO2_OP_FUNC_OVERRIDE(_destructor, eo2_destructor), + EO2_OP_FUNC(_simple_constructor, simple_constructor, "Construct and set A."), + EO2_OP_FUNC(_a_set, simple_a_set, "Set property a"), + EO2_OP_FUNC(_a_get, simple_a_get, "Get property a"), + EO2_OP_FUNC(_b_set, simple_b_set, "Set property b"), + EO2_OP_FUNC(_b_get, simple_b_get, "Get property b"), + EO2_OP_SENTINEL }; static const Eo_Class_Description class_desc = { - EO_VERSION, + EO2_VERSION, "Simple", EO_CLASS_TYPE_REGULAR, - EO_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST), + EO2_CLASS_DESCRIPTION_OPS(op_descs), NULL, sizeof(Private_Data), _class_constructor, _class_destructor }; -EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, +EO_DEFINE_CLASS(simple_class_get, &class_desc, EO2_BASE_CLASS, MIXIN_CLASS, NULL); diff --git a/src/tests/eo/constructors/constructors_simple.h b/src/tests/eo/constructors/constructors_simple.h index 7342d34..d8ab0e9 100644 --- a/src/tests/eo/constructors/constructors_simple.h +++ b/src/tests/eo/constructors/constructors_simple.h @@ -1,24 +1,11 @@ #ifndef SIMPLE_H #define SIMPLE_H -extern EAPI Eo_Op SIMPLE_BASE_ID; - -enum { - SIMPLE_SUB_ID_CONSTRUCTOR, - SIMPLE_SUB_ID_A_SET, - SIMPLE_SUB_ID_A_GET, - SIMPLE_SUB_ID_B_SET, - SIMPLE_SUB_ID_B_GET, - SIMPLE_SUB_ID_LAST -}; - -#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id) - -#define simple_constructor(a) SIMPLE_ID(SIMPLE_SUB_ID_CONSTRUCTOR), EO_TYPECHECK(int, a) -#define simple_a_set(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EO_TYPECHECK(int, a) -#define simple_a_get(a) SIMPLE_ID(SIMPLE_SUB_ID_A_GET), EO_TYPECHECK(int *, a) -#define simple_b_set(b) SIMPLE_ID(SIMPLE_SUB_ID_B_SET), EO_TYPECHECK(int, b) -#define simple_b_get(b) SIMPLE_ID(SIMPLE_SUB_ID_B_GET), EO_TYPECHECK(int *, b) +EAPI void simple_constructor(int a); +EAPI void simple_a_set(int a); +EAPI int simple_a_get(void); +EAPI void simple_b_set(int b); +EAPI int simple_b_get(void); #define SIMPLE_CLASS simple_class_get() const Eo_Class *simple_class_get(void); diff --git a/src/tests/eo/constructors/constructors_simple2.c b/src/tests/eo/constructors/constructors_simple2.c index b80b22b..3caabd0 100644 --- a/src/tests/eo/constructors/constructors_simple2.c +++ b/src/tests/eo/constructors/constructors_simple2.c @@ -9,34 +9,27 @@ #define MY_CLASS SIMPLE2_CLASS static void -_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) +_constructor(Eo *obj, void *class_data EINA_UNUSED) { - eo_do_super(obj, MY_CLASS, eo_constructor()); + eo2_do_super(obj, MY_CLASS, eo2_constructor()); eo_error_set(obj); } -static void -_class_constructor(Eo_Class *klass) -{ - const Eo_Op_Func_Description func_desc[] = { - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), - EO_OP_FUNC_SENTINEL - }; - - eo_class_funcs_set(klass, func_desc); -} +static Eo2_Op_Description op_descs[] = { + EO2_OP_FUNC_OVERRIDE(_constructor, eo2_constructor), +}; static const Eo_Class_Description class_desc = { - EO_VERSION, + EO2_VERSION, "Simple2", EO_CLASS_TYPE_REGULAR, - EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + EO2_CLASS_DESCRIPTION_OPS(op_descs), NULL, 0, - _class_constructor, + NULL, NULL }; -EO_DEFINE_CLASS(simple2_class_get, &class_desc, EO_BASE_CLASS, NULL); +EO_DEFINE_CLASS(simple2_class_get, &class_desc, EO2_BASE_CLASS, NULL); diff --git a/src/tests/eo/constructors/constructors_simple3.c b/src/tests/eo/constructors/constructors_simple3.c index 13453b7..1a8a32f 100644 --- a/src/tests/eo/constructors/constructors_simple3.c +++ b/src/tests/eo/constructors/constructors_simple3.c @@ -14,27 +14,21 @@ _constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) (void) obj; } -static void -_class_constructor(Eo_Class *klass) -{ - const Eo_Op_Func_Description func_desc[] = { - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), - EO_OP_FUNC_SENTINEL - }; - - eo_class_funcs_set(klass, func_desc); -} +static Eo2_Op_Description op_descs[] = { + EO2_OP_FUNC_OVERRIDE(_constructor, eo2_constructor), + EO2_OP_SENTINEL +}; static const Eo_Class_Description class_desc = { - EO_VERSION, + EO2_VERSION, "Simple3", EO_CLASS_TYPE_REGULAR, - EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + EO2_CLASS_DESCRIPTION_OPS(op_descs), NULL, 0, - _class_constructor, + NULL, NULL }; -EO_DEFINE_CLASS(simple3_class_get, &class_desc, EO_BASE_CLASS, NULL); +EO_DEFINE_CLASS(simple3_class_get, &class_desc, EO2_BASE_CLASS, NULL); diff --git a/src/tests/eo/constructors/constructors_simple4.c b/src/tests/eo/constructors/constructors_simple4.c index abce301..52f17fb 100644 --- a/src/tests/eo/constructors/constructors_simple4.c +++ b/src/tests/eo/constructors/constructors_simple4.c @@ -10,7 +10,7 @@ #define MY_CLASS SIMPLE4_CLASS static const Eo_Class_Description class_desc = { - EO_VERSION, + EO2_VERSION, "Simple4", EO_CLASS_TYPE_REGULAR, EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), diff --git a/src/tests/eo/constructors/constructors_simple5.c b/src/tests/eo/constructors/constructors_simple5.c index bd2f1a5..ea43291 100644 --- a/src/tests/eo/constructors/constructors_simple5.c +++ b/src/tests/eo/constructors/constructors_simple5.c @@ -14,27 +14,21 @@ _destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) (void) obj; } -static void -_class_constructor(Eo_Class *klass) -{ - const Eo_Op_Func_Description func_desc[] = { - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor), - EO_OP_FUNC_SENTINEL - }; - - eo_class_funcs_set(klass, func_desc); -} +static Eo2_Op_Description op_descs[] = { + EO2_OP_FUNC_OVERRIDE(_destructor, eo2_destructor), + EO2_OP_SENTINEL +}; static const Eo_Class_Description class_desc = { - EO_VERSION, + EO2_VERSION, "Simple5", EO_CLASS_TYPE_REGULAR, - EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + EO2_CLASS_DESCRIPTION_OPS(op_descs), NULL, 0, - _class_constructor, + NULL, NULL }; -EO_DEFINE_CLASS(simple5_class_get, &class_desc, EO_BASE_CLASS, NULL); +EO_DEFINE_CLASS(simple5_class_get, &class_desc, EO2_BASE_CLASS, NULL); diff --git a/src/tests/eo/constructors/constructors_simple6.c b/src/tests/eo/constructors/constructors_simple6.c index c998885..d78cad8 100644 --- a/src/tests/eo/constructors/constructors_simple6.c +++ b/src/tests/eo/constructors/constructors_simple6.c @@ -9,34 +9,28 @@ #define MY_CLASS SIMPLE6_CLASS static void -_destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) +_destructor(Eo *obj, void *class_data EINA_UNUSED) { - eo_do_super(obj, MY_CLASS, eo_destructor()); + eo2_do_super(obj, MY_CLASS, eo2_destructor()); eo_error_set(obj); } -static void -_class_constructor(Eo_Class *klass) -{ - const Eo_Op_Func_Description func_desc[] = { - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _destructor), - EO_OP_FUNC_SENTINEL - }; - - eo_class_funcs_set(klass, func_desc); -} +static Eo2_Op_Description op_descs [] = { + EO2_OP_FUNC_OVERRIDE(_destructor, eo2_destructor), + EO2_OP_SENTINEL +}; static const Eo_Class_Description class_desc = { - EO_VERSION, + EO2_VERSION, "Simple6", EO_CLASS_TYPE_REGULAR, - EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + EO2_CLASS_DESCRIPTION_OPS(op_descs), NULL, 0, - _class_constructor, + NULL, NULL }; -EO_DEFINE_CLASS(simple6_class_get, &class_desc, EO_BASE_CLASS, NULL); +EO_DEFINE_CLASS(simple6_class_get, &class_desc, EO2_BASE_CLASS, NULL); diff --git a/src/tests/eo/constructors/constructors_simple7.c b/src/tests/eo/constructors/constructors_simple7.c index 20faba5..90b11c4 100644 --- a/src/tests/eo/constructors/constructors_simple7.c +++ b/src/tests/eo/constructors/constructors_simple7.c @@ -14,28 +14,23 @@ static void _constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED) { - fail_if(eo_do_super(obj, MY_CLASS, eo_constructor())); + /* FIXME: Actually test it. */ + eo2_do_super(obj, MY_CLASS, eo2_constructor()); } -static void -_class_constructor(Eo_Class *klass) -{ - const Eo_Op_Func_Description func_desc[] = { - EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _constructor), - EO_OP_FUNC_SENTINEL - }; - - eo_class_funcs_set(klass, func_desc); -} +static Eo2_Op_Description op_descs [] = { + EO2_OP_FUNC_OVERRIDE(_constructor, eo2_constructor), + EO2_OP_SENTINEL +}; static const Eo_Class_Description class_desc = { - EO_VERSION, + EO2_VERSION, "Simple7", EO_CLASS_TYPE_REGULAR, - EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + EO2_CLASS_DESCRIPTION_OPS(op_descs), NULL, 0, - _class_constructor, + NULL, NULL }; -- 2.7.4