summaryrefslogtreecommitdiff
path: root/legacy/eobj
diff options
context:
space:
mode:
authorTom Hacohen <tom@stosb.com>2012-06-14 10:29:39 +0000
committerTom Hacohen <tom@stosb.com>2012-06-14 10:29:39 +0000
commit54b9313197a4286312bba6f6891eb9cdad26cee2 (patch)
tree33778dd8154e1b910f6517524bbb2aa09335f88c /legacy/eobj
parentd636db3c668a73aa0ce2d1246da872610da7f594 (diff)
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
Diffstat (limited to 'legacy/eobj')
-rw-r--r--legacy/eobj/src/lib/eo.c21
-rw-r--r--legacy/eobj/src/tests/eo_suite/eo_test_general.c81
2 files changed, 98 insertions, 4 deletions
diff --git a/legacy/eobj/src/lib/eo.c b/legacy/eobj/src/lib/eo.c
index 4c5b9c6035..c8f9d3b8f6 100644
--- a/legacy/eobj/src/lib/eo.c
+++ b/legacy/eobj/src/lib/eo.c
@@ -592,6 +592,22 @@ _eo_class_base_op_init(Eo_Class *klass)
592 *(desc->ops.base_op_id) = EO_CLASS_ID_TO_BASE_ID(klass->class_id); 592 *(desc->ops.base_op_id) = EO_CLASS_ID_TO_BASE_ID(klass->class_id);
593} 593}
594 594
595#ifndef NDEBUG
596static Eina_Bool
597_eo_class_mro_has(const Eo_Class *klass, const Eo_Class *find)
598{
599 const Eo_Class **itr;
600 for (itr = klass->mro ; *itr ; itr++)
601 {
602 if (*itr == find)
603 {
604 return EINA_TRUE;
605 }
606 }
607 return EINA_FALSE;
608}
609#endif
610
595static Eina_List * 611static Eina_List *
596_eo_class_mro_add(Eina_List *mro, const Eo_Class *klass) 612_eo_class_mro_add(Eina_List *mro, const Eo_Class *klass)
597{ 613{
@@ -889,9 +905,6 @@ eo_class_new(const Eo_Class_Description *desc, Eo_Class_Id id, const Eo_Class *p
889 { 905 {
890 case EO_CLASS_TYPE_REGULAR: 906 case EO_CLASS_TYPE_REGULAR:
891 case EO_CLASS_TYPE_REGULAR_NO_INSTANT: 907 case EO_CLASS_TYPE_REGULAR_NO_INSTANT:
892 /* Ignore regular classes ATM. */
893 break;
894
895 case EO_CLASS_TYPE_INTERFACE: 908 case EO_CLASS_TYPE_INTERFACE:
896 case EO_CLASS_TYPE_MIXIN: 909 case EO_CLASS_TYPE_MIXIN:
897 extn_list = eina_list_append(extn_list, extn); 910 extn_list = eina_list_append(extn_list, extn);
@@ -1453,7 +1466,7 @@ eo_data_get(const Eo *obj, const Eo_Class *klass)
1453 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL); 1466 EO_MAGIC_RETURN_VAL(klass, EO_CLASS_EINA_MAGIC, NULL);
1454 1467
1455#ifndef NDEBUG 1468#ifndef NDEBUG
1456 if ((klass->desc->type == EO_CLASS_TYPE_INTERFACE) || !eo_isa(obj, klass)) 1469 if (!_eo_class_mro_has(obj->klass, klass))
1457 { 1470 {
1458 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); 1471 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);
1459 return NULL; 1472 return NULL;
diff --git a/legacy/eobj/src/tests/eo_suite/eo_test_general.c b/legacy/eobj/src/tests/eo_suite/eo_test_general.c
index 9676263848..ef62cac06c 100644
--- a/legacy/eobj/src/tests/eo_suite/eo_test_general.c
+++ b/legacy/eobj/src/tests/eo_suite/eo_test_general.c
@@ -63,6 +63,83 @@ START_TEST(eo_data_fetch)
63} 63}
64END_TEST 64END_TEST
65 65
66START_TEST(eo_isa_tests)
67{
68 eo_init();
69
70 const Eo_Class *klass, *iface, *mixin;
71
72 {
73 /* Usually should be const, not const only for the test... */
74 static Eo_Class_Description class_desc = {
75 "Iface",
76 EO_CLASS_TYPE_INTERFACE,
77 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
78 NULL,
79 0,
80 NULL,
81 NULL
82 };
83
84 iface = eo_class_new(&class_desc, 0, NULL, NULL);
85 fail_if(!iface);
86 }
87
88 {
89 /* Usually should be const, not const only for the test... */
90 static Eo_Class_Description class_desc = {
91 "Mixin",
92 EO_CLASS_TYPE_MIXIN,
93 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
94 NULL,
95 0,
96 NULL,
97 NULL
98 };
99
100 mixin = eo_class_new(&class_desc, 0, NULL, NULL);
101 fail_if(!mixin);
102 }
103
104 {
105 /* Usually should be const, not const only for the test... */
106 static Eo_Class_Description class_desc = {
107 "Simple2",
108 EO_CLASS_TYPE_REGULAR,
109 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
110 NULL,
111 10,
112 NULL,
113 NULL
114 };
115
116 klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, iface, mixin, NULL);
117 fail_if(!klass);
118 }
119
120 Eo *obj = eo_add(klass, NULL);
121 fail_if(!obj);
122 fail_if(eo_isa(obj, SIMPLE_CLASS));
123 fail_if(!eo_isa(obj, iface));
124 fail_if(!eo_isa(obj, mixin));
125 fail_if(!eo_isa(obj, klass));
126 fail_if(!eo_isa(obj, EO_BASE_CLASS));
127 eo_unref(obj);
128
129 obj = eo_add(SIMPLE_CLASS, NULL);
130 fail_if(!obj);
131 fail_if(eo_isa(obj, klass));
132 fail_if(eo_isa(obj, iface));
133 fail_if(eo_isa(obj, mixin));
134 fail_if(!eo_isa(obj, SIMPLE_CLASS));
135 fail_if(!eo_isa(obj, EO_BASE_CLASS));
136 eo_unref(obj);
137
138 eo_shutdown();
139}
140END_TEST
141
142
66START_TEST(eo_composite_tests) 143START_TEST(eo_composite_tests)
67{ 144{
68 eo_init(); 145 eo_init();
@@ -531,6 +608,9 @@ START_TEST(eo_magic_checks)
531 eo_unref((Eo *) buf); 608 eo_unref((Eo *) buf);
532 eo_del((Eo *) buf); 609 eo_del((Eo *) buf);
533 610
611 eo_isa((Eo *) buf, SIMPLE_CLASS);
612 eo_isa(obj, (Eo_Class *) buf);
613
534 fail_if(0 != eo_ref_get((Eo *) buf)); 614 fail_if(0 != eo_ref_get((Eo *) buf));
535 615
536 Eo *wref = NULL; 616 Eo *wref = NULL;
@@ -579,4 +659,5 @@ void eo_test_general(TCase *tc)
579 tcase_add_test(tc, eo_man_free); 659 tcase_add_test(tc, eo_man_free);
580 tcase_add_test(tc, eo_static_classes); 660 tcase_add_test(tc, eo_static_classes);
581 tcase_add_test(tc, eo_composite_tests); 661 tcase_add_test(tc, eo_composite_tests);
662 tcase_add_test(tc, eo_isa_tests);
582} 663}