Eobj: Improved constructors test.
authortasn <tasn>
Thu, 12 Apr 2012 14:59:01 +0000 (14:59 +0000)
committertasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Thu, 12 Apr 2012 14:59:01 +0000 (14:59 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/PROTO/eobj@70149 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

examples/constructors/CMakeLists.txt
examples/constructors/main.c
examples/constructors/simple.c
examples/constructors/simple5.c [new file with mode: 0644]
examples/constructors/simple5.h [new file with mode: 0644]
examples/constructors/simple6.c [new file with mode: 0644]
examples/constructors/simple6.h [new file with mode: 0644]

index 5ba872c..aa930bd 100644 (file)
@@ -4,6 +4,8 @@ LIST(APPEND CONSTRUCTORS_CC_SOURCES
    simple2.c
    simple3.c
    simple4.c
+   simple5.c
+   simple6.c
    mixin.c
    )
 
index 70a9ecb..b67e873 100644 (file)
@@ -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;
 }
index 3a2090b..8c0578c 100644 (file)
@@ -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 (file)
index 0000000..cd0ed9b
--- /dev/null
@@ -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 (file)
index 0000000..9713508
--- /dev/null
@@ -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 (file)
index 0000000..8cbd41e
--- /dev/null
@@ -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 (file)
index 0000000..52797b5
--- /dev/null
@@ -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