From 6996e85cd2cbe7ccf4ac453af8ab3779f3a67809 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 12 Apr 2012 08:27:38 +0000 Subject: [PATCH] Eobj: Added a couple of function_overrides tests. SVN revision: 70128 --- legacy/eobj/CMakeLists.txt | 1 + .../function_overrides/CMakeLists.txt | 25 ++++++++ .../examples/function_overrides/inherit.c | 28 +++++++++ .../examples/function_overrides/inherit.h | 9 +++ .../examples/function_overrides/inherit2.c | 51 +++++++++++++++ .../examples/function_overrides/inherit2.h | 9 +++ .../examples/function_overrides/inherit3.c | 50 +++++++++++++++ .../examples/function_overrides/inherit3.h | 9 +++ .../eobj/examples/function_overrides/main.c | 38 +++++++++++ .../eobj/examples/function_overrides/simple.c | 63 +++++++++++++++++++ .../eobj/examples/function_overrides/simple.h | 30 +++++++++ 11 files changed, 313 insertions(+) create mode 100644 legacy/eobj/examples/function_overrides/CMakeLists.txt create mode 100644 legacy/eobj/examples/function_overrides/inherit.c create mode 100644 legacy/eobj/examples/function_overrides/inherit.h create mode 100644 legacy/eobj/examples/function_overrides/inherit2.c create mode 100644 legacy/eobj/examples/function_overrides/inherit2.h create mode 100644 legacy/eobj/examples/function_overrides/inherit3.c create mode 100644 legacy/eobj/examples/function_overrides/inherit3.h create mode 100644 legacy/eobj/examples/function_overrides/main.c create mode 100644 legacy/eobj/examples/function_overrides/simple.c create mode 100644 legacy/eobj/examples/function_overrides/simple.h diff --git a/legacy/eobj/CMakeLists.txt b/legacy/eobj/CMakeLists.txt index 9095d24af7..6d08d0c75c 100644 --- a/legacy/eobj/CMakeLists.txt +++ b/legacy/eobj/CMakeLists.txt @@ -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) diff --git a/legacy/eobj/examples/function_overrides/CMakeLists.txt b/legacy/eobj/examples/function_overrides/CMakeLists.txt new file mode 100644 index 0000000000..b17f19a5b5 --- /dev/null +++ b/legacy/eobj/examples/function_overrides/CMakeLists.txt @@ -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) diff --git a/legacy/eobj/examples/function_overrides/inherit.c b/legacy/eobj/examples/function_overrides/inherit.c new file mode 100644 index 0000000000..a6b86c834e --- /dev/null +++ b/legacy/eobj/examples/function_overrides/inherit.c @@ -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); +} diff --git a/legacy/eobj/examples/function_overrides/inherit.h b/legacy/eobj/examples/function_overrides/inherit.h new file mode 100644 index 0000000000..44007d72b2 --- /dev/null +++ b/legacy/eobj/examples/function_overrides/inherit.h @@ -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 diff --git a/legacy/eobj/examples/function_overrides/inherit2.c b/legacy/eobj/examples/function_overrides/inherit2.c new file mode 100644 index 0000000000..be628d44f6 --- /dev/null +++ b/legacy/eobj/examples/function_overrides/inherit2.c @@ -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); +} diff --git a/legacy/eobj/examples/function_overrides/inherit2.h b/legacy/eobj/examples/function_overrides/inherit2.h new file mode 100644 index 0000000000..2fb6ccfe00 --- /dev/null +++ b/legacy/eobj/examples/function_overrides/inherit2.h @@ -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 diff --git a/legacy/eobj/examples/function_overrides/inherit3.c b/legacy/eobj/examples/function_overrides/inherit3.c new file mode 100644 index 0000000000..b7c754b4e5 --- /dev/null +++ b/legacy/eobj/examples/function_overrides/inherit3.c @@ -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); +} diff --git a/legacy/eobj/examples/function_overrides/inherit3.h b/legacy/eobj/examples/function_overrides/inherit3.h new file mode 100644 index 0000000000..19feca9d7d --- /dev/null +++ b/legacy/eobj/examples/function_overrides/inherit3.h @@ -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 diff --git a/legacy/eobj/examples/function_overrides/main.c b/legacy/eobj/examples/function_overrides/main.c new file mode 100644 index 0000000000..9715a9b2a1 --- /dev/null +++ b/legacy/eobj/examples/function_overrides/main.c @@ -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; +} + diff --git a/legacy/eobj/examples/function_overrides/simple.c b/legacy/eobj/examples/function_overrides/simple.c new file mode 100644 index 0000000000..4c5fc87154 --- /dev/null +++ b/legacy/eobj/examples/function_overrides/simple.c @@ -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); +} diff --git a/legacy/eobj/examples/function_overrides/simple.h b/legacy/eobj/examples/function_overrides/simple.h new file mode 100644 index 0000000000..c6b461172c --- /dev/null +++ b/legacy/eobj/examples/function_overrides/simple.h @@ -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