eo2: migrated mixin test to eo2.

This commit is contained in:
Tom Hacohen 2013-11-08 10:48:55 +00:00
parent e4f0e4c410
commit f4f62e0f9f
9 changed files with 104 additions and 195 deletions

View File

@ -9,33 +9,29 @@
#define MY_CLASS INHERIT_CLASS
static void
_a_get(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
static int
_a_get(Eo *obj, void *class_data EINA_UNUSED)
{
int *name = va_arg(*list, int *);
eo_do_super(obj, MY_CLASS, simple_a_get(name));
printf("%s\n", __func__);
int ret;
eo2_do_super(obj, MY_CLASS, ret = simple_a_get());
printf("%s %d\n", __func__, ret);
return ret;
}
static void
_class_constructor(Eo_Class *klass)
{
const Eo_Op_Func_Description func_desc[] = {
EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_A_GET), _a_get),
EO_OP_FUNC_SENTINEL
};
eo_class_funcs_set(klass, func_desc);
}
static Eo2_Op_Description op_descs[] = {
EO2_OP_FUNC_OVERRIDE(_a_get, simple_a_get),
EO2_OP_SENTINEL
};
static const Eo_Class_Description class_desc = {
EO_VERSION,
EO2_VERSION,
"Inherit",
EO_CLASS_TYPE_REGULAR,
EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
EO2_CLASS_DESCRIPTION_OPS(op_descs),
NULL,
0,
_class_constructor,
NULL,
NULL
};

View File

@ -18,15 +18,15 @@ main(int argc, char *argv[])
(void) argv;
eo_init();
Eo *obj = eo_add(SIMPLE_CLASS, NULL);
Eo *obj = eo2_add(SIMPLE_CLASS, NULL);
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, sum = 0;
eo_do(obj, simple_a_get(&a), simple_b_get(&b), mixin_ab_sum_get(&sum));
eo2_do(obj, a = simple_a_get(), b = simple_b_get(), sum = mixin_ab_sum_get());
fail_if(sum != a + b + 2); /* 2 for the two mixins... */
eo_do(obj, mixin_ab_sum_get(&sum), mixin_ab_sum_get(&sum));
eo2_do(obj, sum = mixin_ab_sum_get(), sum = mixin_ab_sum_get());
Mixin2_Public_Data *pd2 = eo_data_scope_get(obj, MIXIN2_CLASS);
fail_if(pd2->count != 6);
@ -36,8 +36,9 @@ main(int argc, char *argv[])
eo_unref(obj);
obj = eo_add(INHERIT_CLASS, NULL);
eo_do(obj, simple_a_set(5), simple_a_get(&a));
obj = eo2_add(INHERIT_CLASS, NULL);
eo2_do(obj, simple_a_set(5), a = simple_a_get());
printf("%d\n", a);
fail_if(a != 5);
eo_unref(obj);

View File

@ -6,62 +6,48 @@
#include "mixin_mixin.h"
#include "mixin_simple.h"
EAPI Eo_Op MIXIN_BASE_ID = 0;
#define MY_CLASS MIXIN_CLASS
static void
_ab_sum_get(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
static int
_ab_sum_get(Eo *obj, void *class_data EINA_UNUSED)
{
int a, b;
eo_do(obj, simple_a_get(&a), simple_b_get(&b));
int *sum = va_arg(*list, int *);
if (sum)
*sum = a + b;
eo2_do(obj, a = simple_a_get(), b = simple_b_get());
printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
return a + b;
}
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());
}
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());
}
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_AB_SUM_GET), _ab_sum_get),
EO_OP_FUNC_SENTINEL
};
EAPI EO2_FUNC_BODY(mixin_ab_sum_get, int, 0);
eo_class_funcs_set(klass, func_desc);
}
static const Eo_Op_Description op_desc[] = {
EO_OP_DESCRIPTION(MIXIN_SUB_ID_AB_SUM_GET, "Get the sum of a and b."),
EO_OP_DESCRIPTION_SENTINEL
static Eo2_Op_Description op_descs[] = {
EO2_OP_FUNC_OVERRIDE(_constructor, eo2_constructor),
EO2_OP_FUNC_OVERRIDE(_destructor, eo2_destructor),
EO2_OP_FUNC(_ab_sum_get, mixin_ab_sum_get, "Get the sum of a and b."),
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)

View File

@ -1,22 +1,7 @@
#ifndef MIXIN_H
#define MIXIN_H
extern EAPI Eo_Op MIXIN_BASE_ID;
enum {
MIXIN_SUB_ID_AB_SUM_GET,
MIXIN_SUB_ID_LAST
};
#define MIXIN_ID(sub_id) (MIXIN_BASE_ID + sub_id)
/**
* @def mixin_ab_sum_get(sum)
* @brief Get sum of a,b integer elements
* @param[out] sum integer pointer to sum - value
*/
#define mixin_ab_sum_get(sum) MIXIN_ID(MIXIN_SUB_ID_AB_SUM_GET), EO_TYPECHECK(int *, sum)
EAPI int mixin_ab_sum_get(void);
#define MIXIN_CLASS mixin_class_get()
const Eo_Class *mixin_class_get(void);

View File

@ -11,58 +11,54 @@
#define MY_CLASS MIXIN2_CLASS
static void
_ab_sum_get(Eo *obj, void *class_data, va_list *list)
static int
_ab_sum_get(Eo *obj, void *class_data)
{
/* This cast is a hack just for the tests... */
Mixin2_Public_Data *pd = (Mixin2_Public_Data *) class_data;
int *sum = va_arg(*list, int *);
int sum;
printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
eo_do_super(obj, MY_CLASS, mixin_ab_sum_get(sum));
eo2_do_super(obj, MY_CLASS, sum = mixin_ab_sum_get());
++*sum;
++sum;
pd->count += 2;
{
int _a, _b;
eo_do(obj, simple_a_get(&_a), simple_b_get(&_b));
fail_if(*sum != _a + _b + 1);
eo2_do(obj, _a = simple_a_get(), _b = simple_b_get());
fail_if(sum != _a + _b + 1);
}
return sum;
}
static void
_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
{
eo_do_super(obj, MY_CLASS, eo_constructor());
eo2_do_super(obj, MY_CLASS, eo2_constructor());
}
static void
_destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
{
eo_do_super(obj, MY_CLASS, eo_destructor());
eo2_do_super(obj, MY_CLASS, eo2_destructor());
}
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_AB_SUM_GET), _ab_sum_get),
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_FUNC_OVERRIDE(_destructor, eo2_destructor),
EO2_OP_FUNC_OVERRIDE(_ab_sum_get, mixin_ab_sum_get),
EO2_OP_SENTINEL
};
static const Eo_Class_Description class_desc = {
EO_VERSION,
EO2_VERSION,
"Mixin2",
EO_CLASS_TYPE_MIXIN,
EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
EO2_CLASS_DESCRIPTION_OPS(op_descs),
NULL,
sizeof(Mixin2_Public_Data),
_class_constructor,
NULL,
NULL
};

View File

@ -11,58 +11,54 @@
#define MY_CLASS MIXIN3_CLASS
static void
_ab_sum_get(Eo *obj, void *class_data EINA_UNUSED, va_list *list)
static int
_ab_sum_get(Eo *obj, void *class_data EINA_UNUSED)
{
/* This cast is just a hack for the test. */
Mixin3_Public_Data *pd = (Mixin3_Public_Data *) class_data;
int *sum = va_arg(*list, int *);
int sum;
printf("%s %s\n", eo_class_name_get(MY_CLASS), __func__);
eo_do_super(obj, MY_CLASS, mixin_ab_sum_get(sum));
eo2_do_super(obj, MY_CLASS, sum = mixin_ab_sum_get());
++*sum;
++sum;
pd->count += 3;
{
int _a, _b;
eo_do(obj, simple_a_get(&_a), simple_b_get(&_b));
fail_if(*sum != _a + _b + 2);
eo2_do(obj, _a = simple_a_get(), _b = simple_b_get());
fail_if(sum != _a + _b + 2);
}
return sum;
}
static void
_constructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
{
eo_do_super(obj, MY_CLASS, eo_constructor());
eo2_do_super(obj, MY_CLASS, eo2_constructor());
}
static void
_destructor(Eo *obj, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
{
eo_do_super(obj, MY_CLASS, eo_destructor());
eo2_do_super(obj, MY_CLASS, eo2_destructor());
}
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_AB_SUM_GET), _ab_sum_get),
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_FUNC_OVERRIDE(_destructor, eo2_destructor),
EO2_OP_FUNC_OVERRIDE(_ab_sum_get, mixin_ab_sum_get),
EO2_OP_SENTINEL
};
static const Eo_Class_Description class_desc = {
EO_VERSION,
EO2_VERSION,
"Mixin3",
EO_CLASS_TYPE_MIXIN,
EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
EO2_CLASS_DESCRIPTION_OPS(op_descs),
NULL,
sizeof(Mixin3_Public_Data),
_class_constructor,
NULL,
NULL
};

View File

@ -12,7 +12,7 @@
#define MY_CLASS MIXIN4_CLASS
static const Eo_Class_Description class_desc = {
EO_VERSION,
EO2_VERSION,
"Mixin4",
EO_CLASS_TYPE_MIXIN,
EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),

View File

@ -8,8 +8,6 @@
#include "mixin_mixin3.h"
#include "mixin_simple.h"
EAPI Eo_Op SIMPLE_BASE_ID = 0;
typedef struct
{
int a;
@ -19,59 +17,45 @@ typedef struct
#define MY_CLASS SIMPLE_CLASS
#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)
static void
_class_constructor(Eo_Class *klass)
{
const Eo_Op_Func_Description func_desc[] = {
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);
}
static const Eo_Op_Description op_desc[] = {
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
static Eo2_Op_Description op_descs[] = {
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,
NULL,
NULL
};
EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, MIXIN3_CLASS, MIXIN2_CLASS, NULL);
EO_DEFINE_CLASS(simple_class_get, &class_desc, EO2_BASE_CLASS,
MIXIN3_CLASS, MIXIN2_CLASS, NULL);

View File

@ -1,45 +1,10 @@
#ifndef SIMPLE_H
#define SIMPLE_H
extern EAPI Eo_Op SIMPLE_BASE_ID;
enum {
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)
/**
* @def simple_a_set(a)
* @brief Set value to a-property
* @param[in] a integer value to set
*/
#define simple_a_set(a) SIMPLE_ID(SIMPLE_SUB_ID_A_SET), EO_TYPECHECK(int, a)
/**
* @def simple_a_get(a)
* @brief Get value of a-property
* @param[out] integer pointer to a-value
*/
#define simple_a_get(a) SIMPLE_ID(SIMPLE_SUB_ID_A_GET), EO_TYPECHECK(int *, a)
/**
* @def simple_b_set(b)
* @brief Set value to b-property
* @param[in] a integer value to set
*/
#define simple_b_set(b) SIMPLE_ID(SIMPLE_SUB_ID_B_SET), EO_TYPECHECK(int, b)
/**
* @def simple_b_get(b)
* @brief Get value of b-property
* @param[out] integer pointer to b-value
*/
#define simple_b_get(b) SIMPLE_ID(SIMPLE_SUB_ID_B_GET), EO_TYPECHECK(int *, b)
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);