From d6affb56f75055fc05bdd12d89869dfd508e24a9 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 12 Apr 2012 14:59:01 +0000 Subject: [PATCH] Eobj: Improved constructors test. SVN revision: 70149 --- .../eobj/examples/constructors/CMakeLists.txt | 2 ++ legacy/eobj/examples/constructors/main.c | 8 +++++ legacy/eobj/examples/constructors/simple.c | 12 ++++++- legacy/eobj/examples/constructors/simple5.c | 34 ++++++++++++++++++ legacy/eobj/examples/constructors/simple5.h | 9 +++++ legacy/eobj/examples/constructors/simple6.c | 36 +++++++++++++++++++ legacy/eobj/examples/constructors/simple6.h | 9 +++++ 7 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 legacy/eobj/examples/constructors/simple5.c create mode 100644 legacy/eobj/examples/constructors/simple5.h create mode 100644 legacy/eobj/examples/constructors/simple6.c create mode 100644 legacy/eobj/examples/constructors/simple6.h diff --git a/legacy/eobj/examples/constructors/CMakeLists.txt b/legacy/eobj/examples/constructors/CMakeLists.txt index 5ba872c9d4..aa930bd41e 100644 --- a/legacy/eobj/examples/constructors/CMakeLists.txt +++ b/legacy/eobj/examples/constructors/CMakeLists.txt @@ -4,6 +4,8 @@ LIST(APPEND CONSTRUCTORS_CC_SOURCES simple2.c simple3.c simple4.c + simple5.c + simple6.c mixin.c ) diff --git a/legacy/eobj/examples/constructors/main.c b/legacy/eobj/examples/constructors/main.c index 70a9ecb6ff..b67e873728 100644 --- a/legacy/eobj/examples/constructors/main.c +++ b/legacy/eobj/examples/constructors/main.c @@ -3,6 +3,8 @@ #include "simple2.h" #include "simple3.h" #include "simple4.h" +#include "simple5.h" +#include "simple6.h" #include "mixin.h" #include "../eunit_tests.h" @@ -45,6 +47,12 @@ main(int argc, char *argv[]) fail_if(my_init_count != 0); + obj = eobj_add(SIMPLE5_CLASS, NULL); + eobj_unref(obj); + + obj = eobj_add(SIMPLE6_CLASS, NULL); + eobj_unref(obj); + eobj_shutdown(); return ret; } diff --git a/legacy/eobj/examples/constructors/simple.c b/legacy/eobj/examples/constructors/simple.c index 3a2090b67d..8c0578c19d 100644 --- a/legacy/eobj/examples/constructors/simple.c +++ b/legacy/eobj/examples/constructors/simple.c @@ -14,6 +14,8 @@ typedef struct static Eobj_Class *_my_class = NULL; +static char *class_var = NULL; + #define _GET_SET_FUNC(name) \ static void \ _##name##_get(Eobj *obj __UNUSED__, void *class_data, va_list *list) \ @@ -67,6 +69,14 @@ _class_constructor(Eobj_Class *klass) }; eobj_class_funcs_set(klass, func_desc); + + class_var = malloc(10); +} + +static void +_class_destructor(Eobj_Class *klass __UNUSED__) +{ + free(class_var); } const Eobj_Class * @@ -91,7 +101,7 @@ simple_class_get(void) _constructor, _destructor, _class_constructor, - NULL + _class_destructor }; return _my_class = eobj_class_new(&class_desc, EOBJ_CLASS_BASE, MIXIN_CLASS, NULL); diff --git a/legacy/eobj/examples/constructors/simple5.c b/legacy/eobj/examples/constructors/simple5.c new file mode 100644 index 0000000000..cd0ed9b929 --- /dev/null +++ b/legacy/eobj/examples/constructors/simple5.c @@ -0,0 +1,34 @@ +#include "Eobj.h" +#include "mixin.h" +#include "simple5.h" + +#include "config.h" + +static Eobj_Class *_my_class = NULL; + +static void +_destructor(Eobj *obj, void *class_data __UNUSED__) +{ + (void) obj; +} + +const Eobj_Class * +simple5_class_get(void) +{ + if (_my_class) return _my_class; + + static const Eobj_Class_Description class_desc = { + "Simple5", + EOBJ_CLASS_TYPE_REGULAR, + EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + NULL, + 0, + NULL, + _destructor, + NULL, + NULL + }; + + _my_class = eobj_class_new(&class_desc, EOBJ_CLASS_BASE, NULL); + return _my_class; +} diff --git a/legacy/eobj/examples/constructors/simple5.h b/legacy/eobj/examples/constructors/simple5.h new file mode 100644 index 0000000000..97135086f5 --- /dev/null +++ b/legacy/eobj/examples/constructors/simple5.h @@ -0,0 +1,9 @@ +#ifndef SIMPLE5_H +#define SIMPLE5_H + +#include "Eobj.h" + +#define SIMPLE5_CLASS simple5_class_get() +const Eobj_Class *simple5_class_get(void) EINA_CONST; + +#endif diff --git a/legacy/eobj/examples/constructors/simple6.c b/legacy/eobj/examples/constructors/simple6.c new file mode 100644 index 0000000000..8cbd41effb --- /dev/null +++ b/legacy/eobj/examples/constructors/simple6.c @@ -0,0 +1,36 @@ +#include "Eobj.h" +#include "mixin.h" +#include "simple6.h" + +#include "config.h" + +static Eobj_Class *_my_class = NULL; + +static void +_destructor(Eobj *obj, void *class_data __UNUSED__) +{ + eobj_constructor_super(obj); + + eobj_constructor_error_set(obj); +} + +const Eobj_Class * +simple6_class_get(void) +{ + if (_my_class) return _my_class; + + static const Eobj_Class_Description class_desc = { + "Simple6", + EOBJ_CLASS_TYPE_REGULAR, + EOBJ_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + NULL, + 0, + NULL, + _destructor, + NULL, + NULL + }; + + _my_class = eobj_class_new(&class_desc, EOBJ_CLASS_BASE, NULL); + return _my_class; +} diff --git a/legacy/eobj/examples/constructors/simple6.h b/legacy/eobj/examples/constructors/simple6.h new file mode 100644 index 0000000000..52797b536c --- /dev/null +++ b/legacy/eobj/examples/constructors/simple6.h @@ -0,0 +1,9 @@ +#ifndef SIMPLE6_H +#define SIMPLE6_H + +#include "Eobj.h" + +#define SIMPLE6_CLASS simple6_class_get() +const Eobj_Class *simple6_class_get(void) EINA_CONST; + +#endif