forked from enlightenment/efl
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. SVN revision: 72123
This commit is contained in:
parent
d636db3c66
commit
54b9313197
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue