forked from enlightenment/efl
Eobj: Added a couple of function_overrides tests.
SVN revision: 70128
This commit is contained in:
parent
f4cc28cde9
commit
6996e85cd2
|
@ -44,6 +44,7 @@ add_subdirectory(examples/mixin)
|
|||
add_subdirectory(examples/signals)
|
||||
add_subdirectory(examples/access)
|
||||
add_subdirectory(examples/constructors)
|
||||
add_subdirectory(examples/function_overrides)
|
||||
|
||||
add_subdirectory(tests EXCLUDE_FROM_ALL)
|
||||
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
LIST(APPEND FUNCTION_OVERRIDES_CC_SOURCES
|
||||
main.c
|
||||
simple.c
|
||||
inherit.c
|
||||
inherit2.c
|
||||
inherit3.c
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${EINA_INCLUDE_DIRS}
|
||||
${EVAS_INCLUDE_DIRS}
|
||||
${CMAKE_SOURCE_DIR}/lib
|
||||
)
|
||||
|
||||
add_executable(function_overrides ${FUNCTION_OVERRIDES_CC_SOURCES})
|
||||
|
||||
get_target_property(eobj_LIB_FILE eobj LOCATION)
|
||||
target_link_libraries(function_overrides
|
||||
${EINA_LIBRARIES}
|
||||
${eobj_LIB_FILE}
|
||||
)
|
||||
|
||||
add_dependencies(function_overrides eobj)
|
||||
|
||||
add_test(Example_function_overrides function_overrides)
|
|
@ -0,0 +1,28 @@
|
|||
#include "Eobj.h"
|
||||
#include "simple.h"
|
||||
|
||||
#include "inherit.h"
|
||||
|
||||
EAPI Eobj_Op INHERIT_BASE_ID = 0;
|
||||
|
||||
static Eobj_Class *_my_class = NULL;
|
||||
|
||||
const Eobj_Class *
|
||||
inherit_class_get(void)
|
||||
{
|
||||
if (_my_class) return _my_class;
|
||||
|
||||
static const Eobj_Class_Description class_desc = {
|
||||
"Inherit",
|
||||
EOBJ_CLASS_TYPE_REGULAR,
|
||||
EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
return _my_class = eobj_class_new(&class_desc, SIMPLE_CLASS, NULL);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef INHERIT_H
|
||||
#define INHERIT_H
|
||||
|
||||
#include "Eobj.h"
|
||||
|
||||
#define INHERIT_CLASS inherit_class_get()
|
||||
const Eobj_Class *inherit_class_get(void) EINA_CONST;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,51 @@
|
|||
#include "Eobj.h"
|
||||
#include "simple.h"
|
||||
|
||||
#include "inherit.h"
|
||||
#include "inherit2.h"
|
||||
|
||||
EAPI Eobj_Op INHERIT2_BASE_ID = 0;
|
||||
|
||||
static Eobj_Class *_my_class = NULL;
|
||||
|
||||
static void
|
||||
_a_set(Eobj *obj, Eobj_Op op, va_list *list)
|
||||
{
|
||||
(void) op;
|
||||
int a;
|
||||
a = va_arg(*list, int);
|
||||
printf("%s %d\n", eobj_class_name_get(_my_class), a);
|
||||
eobj_do(obj, SIMPLE_A_PRINT());
|
||||
eobj_super_do(obj, SIMPLE_A_SET(a + 1));
|
||||
}
|
||||
|
||||
static void
|
||||
_class_constructor(Eobj_Class *klass)
|
||||
{
|
||||
const Eobj_Op_Func_Description func_desc[] = {
|
||||
EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
|
||||
EOBJ_OP_FUNC_DESCRIPTION_SENTINEL
|
||||
};
|
||||
|
||||
eobj_class_funcs_set(klass, func_desc);
|
||||
}
|
||||
|
||||
const Eobj_Class *
|
||||
inherit2_class_get(void)
|
||||
{
|
||||
if (_my_class) return _my_class;
|
||||
|
||||
static const Eobj_Class_Description class_desc = {
|
||||
"Inherit2",
|
||||
EOBJ_CLASS_TYPE_REGULAR,
|
||||
EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
_class_constructor,
|
||||
NULL
|
||||
};
|
||||
|
||||
return _my_class = eobj_class_new(&class_desc, INHERIT_CLASS, NULL);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef INHERIT2_H
|
||||
#define INHERIT2_H
|
||||
|
||||
#include "Eobj.h"
|
||||
|
||||
#define INHERIT2_CLASS inherit2_class_get()
|
||||
const Eobj_Class *inherit2_class_get(void) EINA_CONST;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,50 @@
|
|||
#include "Eobj.h"
|
||||
#include "simple.h"
|
||||
|
||||
#include "inherit2.h"
|
||||
#include "inherit3.h"
|
||||
|
||||
EAPI Eobj_Op INHERIT3_BASE_ID = 0;
|
||||
|
||||
static Eobj_Class *_my_class = NULL;
|
||||
|
||||
static void
|
||||
_a_set(Eobj *obj, Eobj_Op op, va_list *list)
|
||||
{
|
||||
(void) op;
|
||||
int a;
|
||||
a = va_arg(*list, int);
|
||||
printf("%s %d\n", eobj_class_name_get(_my_class), a);
|
||||
eobj_super_do(obj, SIMPLE_A_SET(a + 1));
|
||||
}
|
||||
|
||||
static void
|
||||
_class_constructor(Eobj_Class *klass)
|
||||
{
|
||||
const Eobj_Op_Func_Description func_desc[] = {
|
||||
EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
|
||||
EOBJ_OP_FUNC_DESCRIPTION_SENTINEL
|
||||
};
|
||||
|
||||
eobj_class_funcs_set(klass, func_desc);
|
||||
}
|
||||
|
||||
const Eobj_Class *
|
||||
inherit3_class_get(void)
|
||||
{
|
||||
if (_my_class) return _my_class;
|
||||
|
||||
static const Eobj_Class_Description class_desc = {
|
||||
"Inherit3",
|
||||
EOBJ_CLASS_TYPE_REGULAR,
|
||||
EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
|
||||
NULL,
|
||||
0,
|
||||
NULL,
|
||||
NULL,
|
||||
_class_constructor,
|
||||
NULL
|
||||
};
|
||||
|
||||
return _my_class = eobj_class_new(&class_desc, INHERIT2_CLASS, NULL);
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef INHERIT3_H
|
||||
#define INHERIT3_H
|
||||
|
||||
#include "Eobj.h"
|
||||
|
||||
#define INHERIT3_CLASS inherit3_class_get()
|
||||
const Eobj_Class *inherit3_class_get(void) EINA_CONST;
|
||||
|
||||
#endif
|
|
@ -0,0 +1,38 @@
|
|||
#include "Eobj.h"
|
||||
#include "simple.h"
|
||||
#include "inherit.h"
|
||||
#include "inherit2.h"
|
||||
#include "inherit3.h"
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
eobj_init();
|
||||
|
||||
Eobj *obj = eobj_add(INHERIT2_CLASS, NULL);
|
||||
|
||||
eobj_do(obj, SIMPLE_A_SET(1));
|
||||
Simple_Public_Data *pd = eobj_data_get(obj, SIMPLE_CLASS);
|
||||
if (pd->a != 2)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
eobj_unref(obj);
|
||||
|
||||
obj = eobj_add(INHERIT3_CLASS, NULL);
|
||||
|
||||
eobj_do(obj, SIMPLE_A_SET(1));
|
||||
pd = eobj_data_get(obj, SIMPLE_CLASS);
|
||||
if (pd->a != 3)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
eobj_unref(obj);
|
||||
|
||||
eobj_shutdown();
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
#include "Eobj.h"
|
||||
#include "simple.h"
|
||||
|
||||
EAPI Eobj_Op SIMPLE_BASE_ID = 0;
|
||||
|
||||
static Eobj_Class *_my_class = NULL;
|
||||
|
||||
static void
|
||||
_a_set(Eobj *obj, Eobj_Op op, va_list *list)
|
||||
{
|
||||
Simple_Public_Data *pd = eobj_data_get(obj, _my_class);
|
||||
(void) op;
|
||||
int a;
|
||||
a = va_arg(*list, int);
|
||||
printf("%s %d\n", eobj_class_name_get(_my_class), a);
|
||||
pd->a = a;
|
||||
}
|
||||
|
||||
static void
|
||||
_a_print(Eobj *obj, Eobj_Op op, va_list *list)
|
||||
{
|
||||
Simple_Public_Data *pd = eobj_data_get(obj, _my_class);
|
||||
(void) op;
|
||||
(void) list;
|
||||
printf("Print %s %d\n", eobj_class_name_get(_my_class), pd->a);
|
||||
}
|
||||
|
||||
static void
|
||||
_class_constructor(Eobj_Class *klass)
|
||||
{
|
||||
const Eobj_Op_Func_Description func_desc[] = {
|
||||
EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_SET), _a_set),
|
||||
EOBJ_OP_FUNC_DESCRIPTION(SIMPLE_ID(SIMPLE_SUB_ID_A_PRINT), _a_print),
|
||||
EOBJ_OP_FUNC_DESCRIPTION_SENTINEL
|
||||
};
|
||||
|
||||
eobj_class_funcs_set(klass, func_desc);
|
||||
}
|
||||
|
||||
const Eobj_Class *
|
||||
simple_class_get(void)
|
||||
{
|
||||
if (_my_class) return _my_class;
|
||||
|
||||
static const Eobj_Op_Description op_desc[] = {
|
||||
EOBJ_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "i", "Set property A"),
|
||||
EOBJ_OP_DESCRIPTION_SENTINEL
|
||||
};
|
||||
|
||||
static const Eobj_Class_Description class_desc = {
|
||||
"Simple",
|
||||
EOBJ_CLASS_TYPE_REGULAR,
|
||||
EOBJ_CLASS_DESCRIPTION_OPS(&SIMPLE_BASE_ID, op_desc, SIMPLE_SUB_ID_LAST),
|
||||
NULL,
|
||||
sizeof(Simple_Public_Data),
|
||||
NULL,
|
||||
NULL,
|
||||
_class_constructor,
|
||||
NULL
|
||||
};
|
||||
|
||||
return _my_class = eobj_class_new(&class_desc, EOBJ_CLASS_BASE, NULL);
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
#ifndef SIMPLE_H
|
||||
#define SIMPLE_H
|
||||
|
||||
#include "Eobj.h"
|
||||
|
||||
extern EAPI Eobj_Op SIMPLE_BASE_ID;
|
||||
|
||||
enum {
|
||||
SIMPLE_SUB_ID_A_SET,
|
||||
SIMPLE_SUB_ID_A_PRINT,
|
||||
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), EOBJ_TYPECHECK(int, a)
|
||||
#define SIMPLE_A_PRINT() SIMPLE_ID(SIMPLE_SUB_ID_A_PRINT)
|
||||
|
||||
extern const Eobj_Event_Description _SIG_A_CHANGED;
|
||||
#define SIG_A_CHANGED (&(_SIG_A_CHANGED))
|
||||
|
||||
#define SIMPLE_CLASS simple_class_get()
|
||||
const Eobj_Class *simple_class_get(void) EINA_CONST;
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue