diff options
author | tasn <tasn> | 2012-06-14 10:29:39 +0000 |
---|---|---|
committer | tasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33> | 2012-06-14 10:29:39 +0000 |
commit | 83150d1f3148a92f03082a9f5cf30eefd5a75001 (patch) | |
tree | 8c594ee861e0742711f3c803d519a50e1b846c33 /src | |
parent | 8dc2c2ee98146a71e46ea4d29933fcdcca5d7374 (diff) | |
download | eobj-83150d1f3148a92f03082a9f5cf30eefd5a75001.tar.gz eobj-83150d1f3148a92f03082a9f5cf30eefd5a75001.tar.bz2 eobj-83150d1f3148a92f03082a9f5cf30eefd5a75001.zip |
Eo: Fixed eo_isa to work with comp objects and fixed eo_data_get's checks.
eo_data_get() now has correct checks again.
eo_isa now correctly handles composite objects, interfaces and etc.
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/PROTO/eobj@72123 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/eo.c | 21 | ||||
-rw-r--r-- | src/tests/eo_suite/eo_test_general.c | 81 |
2 files changed, 98 insertions, 4 deletions
diff --git a/src/lib/eo.c b/src/lib/eo.c index 4c5b9c6..c8f9d3b 100644 --- a/src/lib/eo.c +++ b/src/lib/eo.c @@ -592,6 +592,22 @@ _eo_class_base_op_init(Eo_Class *klass) *(desc->ops.base_op_id) = EO_CLASS_ID_TO_BASE_ID(klass->class_id); } +#ifndef NDEBUG +static Eina_Bool +_eo_class_mro_has(const Eo_Class *klass, const Eo_Class *find) +{ + const Eo_Class **itr; + for (itr = klass->mro ; *itr ; itr++) + { + if (*itr == find) + { + return EINA_TRUE; + } + } + return EINA_FALSE; +} +#endif + static Eina_List * _eo_class_mro_add(Eina_List *mro, const Eo_Class *klass) { @@ -889,9 +905,6 @@ eo_class_new(const Eo_Class_Description *desc, Eo_Class_Id id, const Eo_Class *p { case EO_CLASS_TYPE_REGULAR: case EO_CLASS_TYPE_REGULAR_NO_INSTANT: - /* Ignore regular classes ATM. */ - break; - case EO_CLASS_TYPE_INTERFACE: case EO_CLASS_TYPE_MIXIN: extn_list = eina_list_append(extn_list, extn); @@ -1453,7 +1466,7 @@ eo_data_get(const Eo *obj, const Eo_Class *klass) EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL); #ifndef NDEBUG - if ((klass->desc->type == EO_CLASS_TYPE_INTERFACE) || !eo_isa(obj, klass)) + if (!_eo_class_mro_has(obj->klass, klass)) { ERR("Tried getting data of class '%s' from object of class '%s', but the former is not a direct inheritance of the latter.", klass->desc->name, obj->klass->desc->name); return NULL; diff --git a/src/tests/eo_suite/eo_test_general.c b/src/tests/eo_suite/eo_test_general.c index 9676263..ef62cac 100644 --- a/src/tests/eo_suite/eo_test_general.c +++ b/src/tests/eo_suite/eo_test_general.c @@ -63,6 +63,83 @@ START_TEST(eo_data_fetch) } END_TEST +START_TEST(eo_isa_tests) +{ + eo_init(); + + const Eo_Class *klass, *iface, *mixin; + + { + /* Usually should be const, not const only for the test... */ + static Eo_Class_Description class_desc = { + "Iface", + EO_CLASS_TYPE_INTERFACE, + EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + NULL, + 0, + NULL, + NULL + }; + + iface = eo_class_new(&class_desc, 0, NULL, NULL); + fail_if(!iface); + } + + { + /* Usually should be const, not const only for the test... */ + static Eo_Class_Description class_desc = { + "Mixin", + EO_CLASS_TYPE_MIXIN, + EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + NULL, + 0, + NULL, + NULL + }; + + mixin = eo_class_new(&class_desc, 0, NULL, NULL); + fail_if(!mixin); + } + + { + /* Usually should be const, not const only for the test... */ + static Eo_Class_Description class_desc = { + "Simple2", + EO_CLASS_TYPE_REGULAR, + EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0), + NULL, + 10, + NULL, + NULL + }; + + klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, iface, mixin, NULL); + fail_if(!klass); + } + + Eo *obj = eo_add(klass, NULL); + fail_if(!obj); + fail_if(eo_isa(obj, SIMPLE_CLASS)); + fail_if(!eo_isa(obj, iface)); + fail_if(!eo_isa(obj, mixin)); + fail_if(!eo_isa(obj, klass)); + fail_if(!eo_isa(obj, EO_BASE_CLASS)); + eo_unref(obj); + + obj = eo_add(SIMPLE_CLASS, NULL); + fail_if(!obj); + fail_if(eo_isa(obj, klass)); + fail_if(eo_isa(obj, iface)); + fail_if(eo_isa(obj, mixin)); + fail_if(!eo_isa(obj, SIMPLE_CLASS)); + fail_if(!eo_isa(obj, EO_BASE_CLASS)); + eo_unref(obj); + + eo_shutdown(); +} +END_TEST + + START_TEST(eo_composite_tests) { eo_init(); @@ -531,6 +608,9 @@ START_TEST(eo_magic_checks) eo_unref((Eo *) buf); eo_del((Eo *) buf); + eo_isa((Eo *) buf, SIMPLE_CLASS); + eo_isa(obj, (Eo_Class *) buf); + fail_if(0 != eo_ref_get((Eo *) buf)); Eo *wref = NULL; @@ -579,4 +659,5 @@ void eo_test_general(TCase *tc) tcase_add_test(tc, eo_man_free); tcase_add_test(tc, eo_static_classes); tcase_add_test(tc, eo_composite_tests); + tcase_add_test(tc, eo_isa_tests); } |