jeyzu pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=46a78e8c9d46225f3cd3d6b3c6eca3ab7361f361

commit 46a78e8c9d46225f3cd3d6b3c6eca3ab7361f361
Author: Jérémy Zurcher <jer...@asynk.ch>
Date:   Thu Jul 3 10:41:53 2014 +0200

    eo: constructor tests do not use eo_add_custom(..)
    
    as stated in f92e5d50, instead of using eo_add_custom() thus a custom
    constructor and maybe overriding the default constructor to block it,
    
       - use the default constructor to build the object
       - add calls to eo_add(), to initialize the object
         eo_add(class, parent, val_a_set(1), val_b_set(2), ... );
       - override eo_finalize to validate the object and if needed,
         use eo_error_set(obj) to abort object construction
---
 src/tests/eo/constructors/constructors_main.c   | 17 +++++++++++++++--
 src/tests/eo/constructors/constructors_simple.c | 19 ++++++++-----------
 src/tests/eo/constructors/constructors_simple.h |  1 -
 3 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/src/tests/eo/constructors/constructors_main.c 
b/src/tests/eo/constructors/constructors_main.c
index 7b7da02..cab5e7f 100644
--- a/src/tests/eo/constructors/constructors_main.c
+++ b/src/tests/eo/constructors/constructors_main.c
@@ -66,13 +66,26 @@ main(int argc, char *argv[])
    fail_if(obj);
 
    my_init_count = 0;
-   obj = eo_add_custom(SIMPLE_CLASS, NULL, simple_constructor(7));
+   obj = eo_add(SIMPLE_CLASS, NULL);
    fail_if(!obj);
-
    fail_if(my_init_count != 2);
    eo_do(obj, a = simple_a_get());
+   fail_if(a != 0);
+
+   my_init_count = 0;
+   obj = eo_add(SIMPLE_CLASS, NULL, simple_a_set(7));
+   fail_if(!obj);
+   fail_if(my_init_count != 2);
+   eo_do(obj, a = simple_a_get(););
    fail_if(a != 7);
 
+   my_init_count = 0;
+   obj = eo_add(SIMPLE_CLASS, NULL, simple_b_set(6), simple_a_set(-1),
+                b = simple_b_get());
+   fail_if(obj);
+   fail_if(b != 6);
+   fail_if(my_init_count != 0);
+
    eo_unref(obj);
 
    eo_shutdown();
diff --git a/src/tests/eo/constructors/constructors_simple.c 
b/src/tests/eo/constructors/constructors_simple.c
index fa6b3fd..9a25e2b 100644
--- a/src/tests/eo/constructors/constructors_simple.c
+++ b/src/tests/eo/constructors/constructors_simple.c
@@ -40,24 +40,21 @@ _GET_SET_FUNC(b)
 extern int my_init_count;
 
 static void
-_simple_constructor(Eo *obj, void *class_data, int a)
+_constructor(Eo *obj, void *class_data EINA_UNUSED)
 {
-   Private_Data *pd = class_data;
-
    eo_do_super(obj, MY_CLASS, eo_constructor());
 
-   pd->a = a;
-   printf("%s %d\n", __func__, pd->a);
-
    my_init_count++;
 }
 
-static void
-_constructor(Eo *obj, void *class_data EINA_UNUSED)
+static Eo*
+_finalize(Eo *obj, void *class_data EINA_UNUSED)
 {
-   eo_do_super(obj, MY_CLASS, eo_constructor());
+   Private_Data *pd = class_data;
 
-   my_init_count++;
+   if (pd->a < 0) eo_error_set(obj);
+
+   return eo_do_super(obj, MY_CLASS, eo_finalize());
 }
 
 static void
@@ -85,7 +82,7 @@ EO_VOID_FUNC_BODYV(simple_constructor, EO_FUNC_CALL(a), int 
a);
 static Eo_Op_Description op_descs[] = {
      EO_OP_FUNC_OVERRIDE(eo_constructor, _constructor),
      EO_OP_FUNC_OVERRIDE(eo_destructor, _destructor),
-     EO_OP_FUNC(simple_constructor, _simple_constructor, "Construct and set 
A."),
+     EO_OP_FUNC_OVERRIDE(eo_finalize, _finalize),
      EO_OP_FUNC(simple_a_set, _a_set, "Set property a"),
      EO_OP_FUNC(simple_a_get, _a_get, "Get property a"),
      EO_OP_FUNC(simple_b_set, _b_set, "Set property b"),
diff --git a/src/tests/eo/constructors/constructors_simple.h 
b/src/tests/eo/constructors/constructors_simple.h
index d8ab0e9..c4b3d7b 100644
--- a/src/tests/eo/constructors/constructors_simple.h
+++ b/src/tests/eo/constructors/constructors_simple.h
@@ -1,7 +1,6 @@
 #ifndef SIMPLE_H
 #define SIMPLE_H
 
-EAPI void simple_constructor(int a);
 EAPI void simple_a_set(int a);
 EAPI int simple_a_get(void);
 EAPI void simple_b_set(int b);

-- 


Reply via email to