10 #include "class_simple.h"
15 Eo *obj = eo_add(EO_BASE_CLASS, NULL);
18 obj = eo_add(SIMPLE_CLASS, NULL);
20 eo_do(obj, eo_constructor());
21 eo_do(obj, eo_destructor());
28 START_TEST(eo_data_fetch)
32 /* Usually should be const, not const only for the test... */
33 static Eo_Class_Description class_desc = {
36 EO_CLASS_TYPE_REGULAR,
37 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
44 const Eo_Class *klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
47 Eo *obj = eo_add(klass, NULL);
50 fail_if(eo_data_get(obj, SIMPLE_CLASS));
54 class_desc.data_size = 0;
55 klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
58 obj = eo_add(klass, NULL);
60 fail_if(eo_data_get(obj, klass));
67 START_TEST(eo_isa_tests)
71 const Eo_Class *klass, *iface, *mixin;
74 /* Usually should be const, not const only for the test... */
75 static Eo_Class_Description class_desc = {
78 EO_CLASS_TYPE_INTERFACE,
79 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
86 iface = eo_class_new(&class_desc, NULL, NULL);
91 /* Usually should be const, not const only for the test... */
92 static Eo_Class_Description class_desc = {
96 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
103 mixin = eo_class_new(&class_desc, NULL, NULL);
108 /* Usually should be const, not const only for the test... */
109 static Eo_Class_Description class_desc = {
112 EO_CLASS_TYPE_REGULAR,
113 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
120 klass = eo_class_new(&class_desc, EO_BASE_CLASS, iface, mixin, NULL);
124 Eo *obj = eo_add(klass, NULL);
126 fail_if(eo_isa(obj, SIMPLE_CLASS));
127 fail_if(!eo_isa(obj, iface));
128 fail_if(!eo_isa(obj, mixin));
129 fail_if(!eo_isa(obj, klass));
130 fail_if(!eo_isa(obj, EO_BASE_CLASS));
133 obj = eo_add(SIMPLE_CLASS, NULL);
135 fail_if(eo_isa(obj, klass));
136 fail_if(eo_isa(obj, iface));
137 fail_if(eo_isa(obj, mixin));
138 fail_if(!eo_isa(obj, SIMPLE_CLASS));
139 fail_if(!eo_isa(obj, EO_BASE_CLASS));
147 START_TEST(eo_composite_tests)
151 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
153 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
156 eo_composite_attach(obj2, obj);
157 eo_parent_set(obj2, NULL);
158 fail_if(eo_composite_is(obj2));
167 static Eina_Bool _man_should_con = EINA_TRUE;
168 static Eina_Bool _man_should_des = EINA_TRUE;
171 _man_con(Eo *obj, void *data EINA_UNUSED, va_list *list EINA_UNUSED)
174 eo_manual_free_set(obj, EINA_TRUE);
175 eo_do_super(obj, eo_constructor());
179 _man_des(Eo *obj, void *data EINA_UNUSED, va_list *list EINA_UNUSED)
181 eo_do_super(obj, eo_destructor());
183 eo_manual_free_set(obj, EINA_FALSE);
188 _man_class_constructor(Eo_Class *klass)
190 const Eo_Op_Func_Description func_desc[] = {
191 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _man_con),
192 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _man_des),
193 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _man_des),
197 eo_class_funcs_set(klass, func_desc);
200 START_TEST(eo_man_free)
204 /* Usually should be const, not const only for the test... */
205 static Eo_Class_Description class_desc = {
208 EO_CLASS_TYPE_REGULAR,
209 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
212 _man_class_constructor,
216 const Eo_Class *klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
219 Eo *obj = eo_add(klass, NULL);
223 obj = eo_add(klass, NULL);
228 _man_should_des = EINA_FALSE;
229 klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
232 obj = eo_add(klass, NULL);
238 obj = eo_add(klass, NULL);
243 _man_should_con = EINA_FALSE;
244 klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
247 obj = eo_add(klass, NULL);
252 obj = eo_add(klass, NULL);
254 eo_manual_free_set(obj, EINA_TRUE);
261 obj = eo_add(klass, NULL);
263 eo_manual_free_set(obj, EINA_TRUE);
279 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
280 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
281 Eo *obj3 = eo_add(SIMPLE_CLASS, NULL);
284 fail_if(eo_ref_get(obj) != 2);
286 fail_if(eo_ref_get(obj) != 3);
288 eo_xunref(obj, obj2);
289 fail_if(eo_ref_get(obj) != 2);
290 eo_xunref(obj, obj3);
291 fail_if(eo_ref_get(obj) != 1);
294 eo_xunref(obj, obj3);
295 fail_if(eo_ref_get(obj) != 1);
298 fail_if(eo_ref_get(obj) != 2);
300 eo_xunref(obj, obj3);
301 fail_if(eo_ref_get(obj) != 2);
303 eo_xunref(obj, obj2);
304 fail_if(eo_ref_get(obj) != 1);
307 /* Check we don't seg if there's an extra xref. */
315 /* Check hierarchy */
316 obj = eo_add(SIMPLE_CLASS, NULL);
317 obj2 = eo_add(SIMPLE_CLASS, obj);
320 eo_do(obj2, eo_wref_add(&wref));
325 fail_if(!wref); /* Parent is still holding a reference. */
331 /* Just check it doesn't seg atm. */
332 obj = eo_add(SIMPLE_CLASS, NULL);
337 obj = eo_add(SIMPLE_CLASS, NULL);
338 obj2 = eo_add(SIMPLE_CLASS, obj);
348 START_TEST(eo_weak_reference)
352 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
353 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
354 Eo *wref, *wref2, *wref3;
355 eo_do(obj, eo_wref_add(&wref));
361 obj = eo_add(SIMPLE_CLASS, NULL);
362 eo_do(obj, eo_wref_add(&wref));
373 obj = eo_add(SIMPLE_CLASS, NULL);
375 eo_do(obj, eo_wref_add(&wref));
376 eo_do(obj, eo_wref_del(&wref));
379 eo_do(obj, eo_wref_add(&wref));
380 eo_do(obj2, eo_wref_del(&wref));
382 eo_wref_del_safe(&wref);
386 eo_do(obj, eo_wref_del(&wref));
389 wref = wref2 = wref3 = NULL;
390 eo_do(obj, eo_wref_add(&wref), eo_wref_add(&wref2), eo_wref_add(&wref3));
394 eo_do(obj, eo_wref_del(&wref), eo_wref_del(&wref2), eo_wref_del(&wref3));
399 eo_do(obj, eo_wref_add(&wref2), eo_wref_add(&wref3));
401 eo_do(obj, eo_wref_del(&wref));
403 eo_do(obj, eo_wref_del(&wref2), eo_wref_del(&wref3));
414 _a_set(Eo *obj EINA_UNUSED, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
420 _op_errors_class_constructor(Eo_Class *klass)
422 const Eo_Op_Func_Description func_desc[] = {
423 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_LAST), _a_set),
424 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_LAST + 1), _a_set),
425 EO_OP_FUNC(0x0F010111, _a_set),
429 eo_class_funcs_set(klass, func_desc);
432 START_TEST(eo_op_errors)
436 static const Eo_Class_Description class_desc = {
439 EO_CLASS_TYPE_REGULAR,
440 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
443 _op_errors_class_constructor,
447 const Eo_Class *klass = eo_class_new(&class_desc, SIMPLE_CLASS, NULL);
450 Eo *obj = eo_add(klass, NULL);
452 /* Out of bounds op for a legal class. */
453 fail_if(eo_do(obj, EO_BASE_ID(0x0111)));
456 fail_if(eo_do(obj, 0x0F010111));
458 fail_if(eo_ref_get(obj) != 1);
461 fail_if(eo_ref_get(obj) != 2);
464 fail_if(eo_ref_get(obj) != 3);
467 fail_if(eo_ref_get(obj) != 2);
470 fail_if(eo_ref_get(obj) != 1);
474 obj = eo_add(SIMPLE_CLASS, NULL);
475 fail_if(!eo_do(obj, simple_a_print()));
476 fail_if(!eo_do(obj, simple_a_print()));
477 fail_if(!eo_do(obj, simple_a_set(1)));
485 _fake_free_func(void *data)
494 START_TEST(eo_generic_data)
497 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
500 eo_do(obj, eo_base_data_set("test1", (void *) 1, NULL));
501 eo_do(obj, eo_base_data_get("test1", &data));
502 fail_if(1 != (int) data);
503 eo_do(obj, eo_base_data_del("test1"));
504 eo_do(obj, eo_base_data_get("test1", &data));
507 eo_do(obj, eo_base_data_set("test1", (void *) 1, NULL));
508 eo_do(obj, eo_base_data_set("test2", (void *) 2, NULL));
509 eo_do(obj, eo_base_data_get("test1", &data));
510 fail_if(1 != (int) data);
511 eo_do(obj, eo_base_data_get("test2", &data));
512 fail_if(2 != (int) data);
514 eo_do(obj, eo_base_data_get("test2", &data));
515 fail_if(2 != (int) data);
516 eo_do(obj, eo_base_data_del("test2"));
517 eo_do(obj, eo_base_data_get("test2", &data));
520 eo_do(obj, eo_base_data_get("test1", &data));
521 fail_if(1 != (int) data);
522 eo_do(obj, eo_base_data_del("test1"));
523 eo_do(obj, eo_base_data_get("test1", &data));
527 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
528 eo_do(obj, eo_base_data_get("test3", &data));
530 eo_do(obj, eo_base_data_get("test3", NULL));
531 eo_do(obj, eo_base_data_del("test3"));
535 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
536 eo_do(obj, eo_base_data_set("test3", NULL, _fake_free_func));
540 eo_do(obj, eo_base_data_set(NULL, &a, _fake_free_func));
541 eo_do(obj, eo_base_data_get(NULL, &data));
543 eo_do(obj, eo_base_data_del(NULL));
546 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
547 eo_do(obj, eo_base_data_set("test3", NULL, NULL));
549 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
558 START_TEST(eo_magic_checks)
560 char _buf[sizeof(long)]; /* Just enough to hold eina magic + a bit more. */
564 memset(_buf, 1, sizeof(_buf));
566 Eo *obj = eo_add(SIMPLE_CLASS, (Eo *) buf);
571 obj = eo_add((Eo_Class *) buf, NULL);
574 obj = eo_add(SIMPLE_CLASS, NULL);
577 fail_if(eo_do((Eo *) buf, EO_NOOP));
578 fail_if(eo_do_super((Eo *) buf, EO_NOOP));
579 fail_if(eo_class_get((Eo *) buf));
580 fail_if(eo_class_name_get((Eo_Class*) buf));
581 eo_class_funcs_set((Eo_Class *) buf, NULL);
582 eo_class_do((Eo_Class *) buf, NULL);
583 eo_class_do_super((Eo_Class *) buf, EO_NOOP);
585 fail_if(eo_class_new(NULL, (Eo_Class *) buf), NULL);
587 eo_xref(obj, (Eo *) buf);
588 eo_xunref(obj, (Eo *) buf);
589 eo_xref((Eo *) buf, obj);
590 eo_xunref((Eo *) buf, obj);
593 eo_unref((Eo *) buf);
596 eo_isa((Eo *) buf, SIMPLE_CLASS);
597 eo_isa(obj, (Eo_Class *) buf);
599 fail_if(0 != eo_ref_get((Eo *) buf));
602 eo_do((Eo *) buf, eo_wref_add(&wref));
605 fail_if(eo_parent_get((Eo *) buf));
607 eo_error_set((Eo *) buf);
609 fail_if(eo_data_get((Eo *) buf, SIMPLE_CLASS));
611 eo_composite_attach((Eo *) buf, obj);
612 eo_composite_attach(obj, (Eo *) buf);
613 eo_composite_detach((Eo *) buf, obj);
614 eo_composite_detach(obj, (Eo *) buf);
615 eo_composite_is((Eo *) buf);
617 eo_do(obj, eo_event_callback_forwarder_add(NULL, (Eo *) buf));
618 eo_do(obj, eo_event_callback_forwarder_del(NULL, (Eo *) buf));
620 eo_manual_free_set((Eo *) buf, EINA_TRUE);
621 eo_manual_free((Eo *) buf);
636 static Eo_Op MULTI_BASE_ID;
637 #define MULTI_ID(sub_id) (MULTI_BASE_ID + sub_id)
638 #define multi_a_print() MULTI_ID(MULTI_SUB_ID_A_PRINT)
639 #define multi_class_hi_print() MULTI_ID(MULTI_SUB_ID_CLASS_HI_PRINT)
642 _a_print(Eo *obj EINA_UNUSED, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
648 _class_hi_print(const Eo_Class *klass EINA_UNUSED, va_list *list EINA_UNUSED)
654 MULTI_SUB_ID_A_PRINT,
655 MULTI_SUB_ID_CLASS_HI_PRINT,
660 _eo_multiple_do_class_constructor(Eo_Class *klass)
662 const Eo_Op_Func_Description func_desc[] = {
663 EO_OP_FUNC(MULTI_ID(MULTI_SUB_ID_A_PRINT), _a_print),
664 EO_OP_FUNC_CLASS(MULTI_ID(MULTI_SUB_ID_CLASS_HI_PRINT), _class_hi_print),
668 eo_class_funcs_set(klass, func_desc);
671 static const Eo_Op_Description _eo_multiple_do_op_desc[] = {
672 EO_OP_DESCRIPTION(MULTI_SUB_ID_A_PRINT, "Print property A"),
673 EO_OP_DESCRIPTION_CLASS(MULTI_SUB_ID_CLASS_HI_PRINT, "Print Hi"),
674 EO_OP_DESCRIPTION_SENTINEL
678 START_TEST(eo_multiple_do)
682 /* Usually should be const, not const only for the test... */
683 static Eo_Class_Description class_desc = {
686 EO_CLASS_TYPE_REGULAR,
687 EO_CLASS_DESCRIPTION_OPS(&MULTI_BASE_ID, _eo_multiple_do_op_desc, MULTI_SUB_ID_LAST),
690 _eo_multiple_do_class_constructor,
694 const Eo_Class *klass = eo_class_new(&class_desc, SIMPLE_CLASS, NULL);
697 Eo *obj = eo_add(klass, NULL);
700 fail_if(!eo_do(obj, simple_a_print(), multi_a_print(), multi_a_print()));
701 fail_if(!eo_class_do(klass, simple_class_hi_print(), multi_class_hi_print(), multi_class_hi_print()));
709 START_TEST(eo_add_do_and_custom)
711 Simple_Public_Data *pd = NULL;
715 obj = eo_add_custom(SIMPLE_CLASS, NULL, eo_constructor());
719 obj = eo_add(SIMPLE_CLASS, NULL, simple_a_set(7));
721 pd = eo_data_get(obj, SIMPLE_CLASS);
725 obj = eo_add_custom(SIMPLE_CLASS, NULL, eo_constructor(), simple_a_set(7));
727 pd = eo_data_get(obj, SIMPLE_CLASS);
735 void eo_test_general(TCase *tc)
737 tcase_add_test(tc, eo_generic_data);
738 tcase_add_test(tc, eo_op_errors);
739 tcase_add_test(tc, eo_simple);
740 tcase_add_test(tc, eo_weak_reference);
741 tcase_add_test(tc, eo_refs);
742 tcase_add_test(tc, eo_magic_checks);
743 tcase_add_test(tc, eo_data_fetch);
744 tcase_add_test(tc, eo_man_free);
745 tcase_add_test(tc, eo_composite_tests);
746 tcase_add_test(tc, eo_isa_tests);
747 tcase_add_test(tc, eo_multiple_do);
748 tcase_add_test(tc, eo_add_do_and_custom);