From 6af49ff01cc985c749b44f6c217a44ce8bc220b6 Mon Sep 17 00:00:00 2001 From: tasn Date: Thu, 12 Apr 2012 14:59:01 +0000 Subject: [PATCH] Eobj: Improved constructors test. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/PROTO/eobj@70149 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- examples/constructors/CMakeLists.txt | 2 ++ examples/constructors/main.c | 8 ++++++++ examples/constructors/simple.c | 12 +++++++++++- examples/constructors/simple5.c | 34 ++++++++++++++++++++++++++++++++++ examples/constructors/simple5.h | 9 +++++++++ examples/constructors/simple6.c | 36 ++++++++++++++++++++++++++++++++++++ examples/constructors/simple6.h | 9 +++++++++ 7 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 examples/constructors/simple5.c create mode 100644 examples/constructors/simple5.h create mode 100644 examples/constructors/simple6.c create mode 100644 examples/constructors/simple6.h diff --git a/examples/constructors/CMakeLists.txt b/examples/constructors/CMakeLists.txt index 5ba872c..aa930bd 100644 --- a/examples/constructors/CMakeLists.txt +++ b/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/examples/constructors/main.c b/examples/constructors/main.c index 70a9ecb..b67e873 100644 --- a/examples/constructors/main.c +++ b/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/examples/constructors/simple.c b/examples/constructors/simple.c index 3a2090b..8c0578c 100644 --- a/examples/constructors/simple.c +++ b/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/examples/constructors/simple5.c b/examples/constructors/simple5.c new file mode 100644 index 0000000..cd0ed9b --- /dev/null +++ b/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/examples/constructors/simple5.h b/examples/constructors/simple5.h new file mode 100644 index 0000000..9713508 --- /dev/null +++ b/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/examples/constructors/simple6.c b/examples/constructors/simple6.c new file mode 100644 index 0000000..8cbd41e --- /dev/null +++ b/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/examples/constructors/simple6.h b/examples/constructors/simple6.h new file mode 100644 index 0000000..52797b5 --- /dev/null +++ b/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 -- 2.7.4