forked from enlightenment/efl
eo2: migrated the composite test to eo2.
This commit is contained in:
parent
5e92ffb121
commit
e5c7d666e0
|
@ -8,58 +8,51 @@
|
|||
|
||||
#include "../eunit_tests.h"
|
||||
|
||||
EAPI Eo_Op COMP_BASE_ID = 0;
|
||||
|
||||
#define MY_CLASS COMP_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 *a;
|
||||
a = va_arg(*list, int *);
|
||||
eo_do_super(obj, MY_CLASS, simple_a_get(a));
|
||||
int a;
|
||||
eo2_do_super(obj, MY_CLASS, a = simple_a_get());
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
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 *simple = eo_add(SIMPLE_CLASS, obj);
|
||||
Eo *simple = eo2_add(SIMPLE_CLASS, obj);
|
||||
eo_composite_attach(simple, obj);
|
||||
eo_do(simple, eo_event_callback_forwarder_add(EV_A_CHANGED, obj));
|
||||
eo2_do(simple, eo2_event_callback_forwarder_add(EV_A_CHANGED, obj));
|
||||
|
||||
fail_if(eo_composite_is(obj));
|
||||
fail_if(!eo_composite_is(simple));
|
||||
|
||||
eo_do(obj, eo_base_data_set("simple-obj", simple, NULL));
|
||||
eo2_do(obj, eo2_base_data_set("simple-obj", simple, NULL));
|
||||
|
||||
eo_unref(simple);
|
||||
}
|
||||
|
||||
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(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(_constructor, eo2_constructor),
|
||||
EO2_OP_FUNC_OVERRIDE(_a_get, simple_a_get),
|
||||
EO2_OP_SENTINEL
|
||||
};
|
||||
|
||||
static const Eo_Class_Description class_desc = {
|
||||
EO_VERSION,
|
||||
EO2_VERSION,
|
||||
"Comp",
|
||||
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(comp_class_get, &class_desc, EO_BASE_CLASS,
|
||||
EO_DEFINE_CLASS(comp_class_get, &class_desc, EO2_BASE_CLASS,
|
||||
SIMPLE_CLASS, NULL);
|
||||
|
||||
|
|
|
@ -31,26 +31,26 @@ main(int argc, char *argv[])
|
|||
eo_init();
|
||||
|
||||
Eo *obj = eo_add(COMP_CLASS, NULL);
|
||||
eo_do(obj, eo_event_callback_add(EV_A_CHANGED, _a_changed_cb, NULL));
|
||||
eo2_do(obj, eo2_event_callback_add(EV_A_CHANGED, _a_changed_cb, NULL));
|
||||
|
||||
fail_if(!eo_isa(obj, COMP_CLASS));
|
||||
fail_if(!eo_isa(obj, SIMPLE_CLASS));
|
||||
|
||||
int a;
|
||||
eo_do(obj, simple_a_set(1));
|
||||
eo2_do(obj, simple_a_set(1));
|
||||
fail_if(!cb_called);
|
||||
|
||||
eo_do(obj, simple_a_get(&a));
|
||||
eo2_do(obj, a = simple_a_get());
|
||||
fail_if(a != 1);
|
||||
|
||||
/* disable the callback forwarder, and fail if it's still called. */
|
||||
Eo *simple;
|
||||
eo_do(obj, eo_base_data_get("simple-obj", (void **) &simple));
|
||||
eo2_do(obj, simple = eo2_base_data_get("simple-obj"));
|
||||
eo_ref(simple);
|
||||
eo_do(simple, eo_event_callback_forwarder_del(EV_A_CHANGED, obj));
|
||||
eo2_do(simple, eo2_event_callback_forwarder_del(EV_A_CHANGED, obj));
|
||||
|
||||
cb_called = EINA_FALSE;
|
||||
eo_do(obj, simple_a_set(2));
|
||||
eo2_do(obj, simple_a_set(2));
|
||||
fail_if(cb_called);
|
||||
|
||||
fail_if(!eo_composite_is(simple));
|
||||
|
|
|
@ -5,50 +5,35 @@
|
|||
#include "Eo.h"
|
||||
#include "composite_objects_simple.h"
|
||||
|
||||
EAPI Eo_Op SIMPLE_BASE_ID = 0;
|
||||
|
||||
EAPI const Eo_Event_Description _EV_A_CHANGED =
|
||||
EO_EVENT_DESCRIPTION("a,changed", "Called when a has changed.");
|
||||
|
||||
#define MY_CLASS SIMPLE_CLASS
|
||||
|
||||
static void
|
||||
_a_set(Eo *obj, void *class_data, va_list *list)
|
||||
_a_set(Eo *obj, void *class_data, int a)
|
||||
{
|
||||
Simple_Public_Data *pd = class_data;
|
||||
int a;
|
||||
a = va_arg(*list, int);
|
||||
printf("%s %d\n", eo_class_name_get(MY_CLASS), a);
|
||||
pd->a = a;
|
||||
|
||||
eo_do(obj, eo_event_callback_call(EV_A_CHANGED, &pd->a, NULL));
|
||||
eo2_do(obj, eo2_event_callback_call(EV_A_CHANGED, &pd->a));
|
||||
}
|
||||
|
||||
static void
|
||||
_a_get(Eo *obj EINA_UNUSED, void *class_data, va_list *list)
|
||||
static int
|
||||
_a_get(Eo *obj EINA_UNUSED, void *class_data)
|
||||
{
|
||||
const Simple_Public_Data *pd = class_data;
|
||||
int *a;
|
||||
a = va_arg(*list, int *);
|
||||
*a = pd->a;
|
||||
return pd->a;
|
||||
}
|
||||
|
||||
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_SENTINEL
|
||||
};
|
||||
EAPI EO2_VOID_FUNC_BODYV(simple_a_set, EO2_FUNC_CALL(a), int a);
|
||||
EAPI EO2_FUNC_BODY(simple_a_get, int, 0);
|
||||
|
||||
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_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_SENTINEL
|
||||
};
|
||||
|
||||
static const Eo_Event_Description *event_desc[] = {
|
||||
|
@ -57,15 +42,15 @@ static const Eo_Event_Description *event_desc[] = {
|
|||
};
|
||||
|
||||
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),
|
||||
event_desc,
|
||||
sizeof(Simple_Public_Data),
|
||||
_class_constructor,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
EO_DEFINE_CLASS(simple_class_get, &class_desc, EO_BASE_CLASS, NULL);
|
||||
EO_DEFINE_CLASS(simple_class_get, &class_desc, EO2_BASE_CLASS, NULL);
|
||||
|
||||
|
|
|
@ -1,23 +1,13 @@
|
|||
#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_LAST
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int a;
|
||||
} Simple_Public_Data;
|
||||
|
||||
#define SIMPLE_ID(sub_id) (SIMPLE_BASE_ID + sub_id)
|
||||
|
||||
#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)
|
||||
EAPI void simple_a_set(int a);
|
||||
EAPI int simple_a_get(void);
|
||||
|
||||
extern const Eo_Event_Description _EV_A_CHANGED;
|
||||
#define EV_A_CHANGED (&(_EV_A_CHANGED))
|
||||
|
|
Loading…
Reference in New Issue