From 8be32105cb558a86ba1989e4c8aedc2e915b3220 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 12 Apr 2012 15:27:22 +0000 Subject: [PATCH] Eobj: Added more function override tests. SVN revision: 70151 --- .../examples/function_overrides/inherit.c | 2 -- .../examples/function_overrides/inherit2.c | 25 ++++++++++++++++++- .../examples/function_overrides/inherit2.h | 13 ++++++++++ .../examples/function_overrides/inherit3.c | 2 -- .../eobj/examples/function_overrides/main.c | 8 ++++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/legacy/eobj/examples/function_overrides/inherit.c b/legacy/eobj/examples/function_overrides/inherit.c index a6b86c834e..04da87c320 100644 --- a/legacy/eobj/examples/function_overrides/inherit.c +++ b/legacy/eobj/examples/function_overrides/inherit.c @@ -3,8 +3,6 @@ #include "inherit.h" -EAPI Eobj_Op INHERIT_BASE_ID = 0; - static Eobj_Class *_my_class = NULL; const Eobj_Class * diff --git a/legacy/eobj/examples/function_overrides/inherit2.c b/legacy/eobj/examples/function_overrides/inherit2.c index 412ed47a4c..55f701ea35 100644 --- a/legacy/eobj/examples/function_overrides/inherit2.c +++ b/legacy/eobj/examples/function_overrides/inherit2.c @@ -6,6 +6,8 @@ #include "config.h" +#include "../eunit_tests.h" + EAPI Eobj_Op INHERIT2_BASE_ID = 0; static Eobj_Class *_my_class = NULL; @@ -20,11 +22,26 @@ _a_set(Eobj *obj, void *class_data __UNUSED__, va_list *list) eobj_super_do(obj, SIMPLE_A_SET(a + 1)); } +static void +_print(Eobj *obj, void *class_data __UNUSED__, va_list *list __UNUSED__) +{ + printf("Hey\n"); + fail_if(eobj_super_do(obj, INHERIT2_PRINT())); +} + +static void +_print2(Eobj *obj __UNUSED__, void *class_data __UNUSED__, va_list *list __UNUSED__) +{ + printf("Hey2\n"); +} + 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(INHERIT2_ID(INHERIT2_SUB_ID_PRINT), _print), + EOBJ_OP_FUNC_DESCRIPTION(INHERIT2_ID(INHERIT2_SUB_ID_PRINT2), _print2), EOBJ_OP_FUNC_DESCRIPTION_SENTINEL }; @@ -36,10 +53,16 @@ inherit2_class_get(void) { if (_my_class) return _my_class; + static const Eobj_Op_Description op_desc[] = { + EOBJ_OP_DESCRIPTION(INHERIT2_SUB_ID_PRINT, "", "Print hey"), + EOBJ_OP_DESCRIPTION(INHERIT2_SUB_ID_PRINT2, "", "Print hey2"), + EOBJ_OP_DESCRIPTION_SENTINEL + }; + static const Eobj_Class_Description class_desc = { "Inherit2", EOBJ_CLASS_TYPE_REGULAR, - EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + EOBJ_CLASS_DESCRIPTION_OPS(&INHERIT2_BASE_ID, op_desc, INHERIT2_SUB_ID_LAST), NULL, 0, NULL, diff --git a/legacy/eobj/examples/function_overrides/inherit2.h b/legacy/eobj/examples/function_overrides/inherit2.h index 2fb6ccfe00..6c83778075 100644 --- a/legacy/eobj/examples/function_overrides/inherit2.h +++ b/legacy/eobj/examples/function_overrides/inherit2.h @@ -3,6 +3,19 @@ #include "Eobj.h" +extern EAPI Eobj_Op INHERIT2_BASE_ID; + +enum { + INHERIT2_SUB_ID_PRINT, + INHERIT2_SUB_ID_PRINT2, + INHERIT2_SUB_ID_LAST +}; + +#define INHERIT2_ID(sub_id) (INHERIT2_BASE_ID + sub_id) + +#define INHERIT2_PRINT() INHERIT2_ID(INHERIT2_SUB_ID_PRINT) +#define INHERIT2_PRINT2() INHERIT2_ID(INHERIT2_SUB_ID_PRINT2) + #define INHERIT2_CLASS inherit2_class_get() const Eobj_Class *inherit2_class_get(void) EINA_CONST; diff --git a/legacy/eobj/examples/function_overrides/inherit3.c b/legacy/eobj/examples/function_overrides/inherit3.c index 7b8c8400f5..175cc36951 100644 --- a/legacy/eobj/examples/function_overrides/inherit3.c +++ b/legacy/eobj/examples/function_overrides/inherit3.c @@ -6,8 +6,6 @@ #include "config.h" -EAPI Eobj_Op INHERIT3_BASE_ID = 0; - static Eobj_Class *_my_class = NULL; static void diff --git a/legacy/eobj/examples/function_overrides/main.c b/legacy/eobj/examples/function_overrides/main.c index b026a576ce..221237c493 100644 --- a/legacy/eobj/examples/function_overrides/main.c +++ b/legacy/eobj/examples/function_overrides/main.c @@ -29,6 +29,14 @@ main(int argc, char *argv[]) eobj_unref(obj); + obj = eobj_add(INHERIT2_CLASS, NULL); + eobj_do(obj, INHERIT2_PRINT()); + eobj_unref(obj); + + obj = eobj_add(SIMPLE_CLASS, NULL); + fail_if(eobj_do(obj, INHERIT2_PRINT2())); + eobj_unref(obj); + eobj_shutdown(); return 0; }