From 5701afe0a0c59357301cfd56e78352245ac71665 Mon Sep 17 00:00:00 2001 From: tasn Date: Thu, 12 Apr 2012 15:27:22 +0000 Subject: [PATCH] Eobj: Added more function override tests. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/PROTO/eobj@70151 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- examples/function_overrides/inherit.c | 2 -- examples/function_overrides/inherit2.c | 25 ++++++++++++++++++++++++- examples/function_overrides/inherit2.h | 13 +++++++++++++ examples/function_overrides/inherit3.c | 2 -- examples/function_overrides/main.c | 8 ++++++++ 5 files changed, 45 insertions(+), 5 deletions(-) diff --git a/examples/function_overrides/inherit.c b/examples/function_overrides/inherit.c index a6b86c8..04da87c 100644 --- a/examples/function_overrides/inherit.c +++ b/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/examples/function_overrides/inherit2.c b/examples/function_overrides/inherit2.c index 412ed47..55f701e 100644 --- a/examples/function_overrides/inherit2.c +++ b/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; @@ -21,10 +23,25 @@ _a_set(Eobj *obj, void *class_data __UNUSED__, va_list *list) } 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/examples/function_overrides/inherit2.h b/examples/function_overrides/inherit2.h index 2fb6ccf..6c83778 100644 --- a/examples/function_overrides/inherit2.h +++ b/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/examples/function_overrides/inherit3.c b/examples/function_overrides/inherit3.c index 7b8c840..175cc36 100644 --- a/examples/function_overrides/inherit3.c +++ b/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/examples/function_overrides/main.c b/examples/function_overrides/main.c index b026a57..221237c 100644 --- a/examples/function_overrides/main.c +++ b/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; } -- 2.7.4