9 #include "class_simple.h"
14 Eo *obj = eo_add(EO_BASE_CLASS, NULL);
17 obj = eo_add(SIMPLE_CLASS, NULL);
19 eo_do(obj, eo_constructor());
20 eo_do(obj, eo_destructor());
27 START_TEST(eo_data_fetch)
31 /* Usually should be const, not const only for the test... */
32 static Eo_Class_Description class_desc = {
35 EO_CLASS_TYPE_REGULAR,
36 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
43 const Eo_Class *klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
46 Eo *obj = eo_add(klass, NULL);
49 fail_if(eo_data_get(obj, SIMPLE_CLASS));
53 class_desc.data_size = 0;
54 klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
57 obj = eo_add(klass, NULL);
59 fail_if(eo_data_get(obj, klass));
66 START_TEST(eo_isa_tests)
70 const Eo_Class *klass, *iface, *mixin;
73 /* Usually should be const, not const only for the test... */
74 static Eo_Class_Description class_desc = {
77 EO_CLASS_TYPE_INTERFACE,
78 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
85 iface = eo_class_new(&class_desc, NULL, NULL);
90 /* Usually should be const, not const only for the test... */
91 static Eo_Class_Description class_desc = {
95 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
102 mixin = eo_class_new(&class_desc, NULL, NULL);
107 /* Usually should be const, not const only for the test... */
108 static Eo_Class_Description class_desc = {
111 EO_CLASS_TYPE_REGULAR,
112 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
119 klass = eo_class_new(&class_desc, EO_BASE_CLASS, iface, mixin, NULL);
123 Eo *obj = eo_add(klass, NULL);
125 fail_if(eo_isa(obj, SIMPLE_CLASS));
126 fail_if(!eo_isa(obj, iface));
127 fail_if(!eo_isa(obj, mixin));
128 fail_if(!eo_isa(obj, klass));
129 fail_if(!eo_isa(obj, EO_BASE_CLASS));
132 obj = eo_add(SIMPLE_CLASS, NULL);
134 fail_if(eo_isa(obj, klass));
135 fail_if(eo_isa(obj, iface));
136 fail_if(eo_isa(obj, mixin));
137 fail_if(!eo_isa(obj, SIMPLE_CLASS));
138 fail_if(!eo_isa(obj, EO_BASE_CLASS));
146 START_TEST(eo_composite_tests)
150 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
152 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
155 eo_composite_attach(obj2, obj);
156 eo_parent_set(obj2, NULL);
157 fail_if(eo_composite_is(obj2));
166 static Eina_Bool _man_should_con = EINA_TRUE;
167 static Eina_Bool _man_should_des = EINA_TRUE;
170 _man_con(Eo *obj, void *data EINA_UNUSED, va_list *list EINA_UNUSED)
173 eo_manual_free_set(obj, EINA_TRUE);
174 eo_do_super(obj, eo_constructor());
178 _man_des(Eo *obj, void *data EINA_UNUSED, va_list *list EINA_UNUSED)
180 eo_do_super(obj, eo_destructor());
182 eo_manual_free_set(obj, EINA_FALSE);
187 _man_class_constructor(Eo_Class *klass)
189 const Eo_Op_Func_Description func_desc[] = {
190 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _man_con),
191 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _man_des),
192 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _man_des),
196 eo_class_funcs_set(klass, func_desc);
199 START_TEST(eo_man_free)
203 /* Usually should be const, not const only for the test... */
204 static Eo_Class_Description class_desc = {
207 EO_CLASS_TYPE_REGULAR,
208 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
211 _man_class_constructor,
215 const Eo_Class *klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
218 Eo *obj = eo_add(klass, NULL);
222 obj = eo_add(klass, NULL);
227 _man_should_des = EINA_FALSE;
228 klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
231 obj = eo_add(klass, NULL);
237 obj = eo_add(klass, NULL);
242 _man_should_con = EINA_FALSE;
243 klass = eo_class_new(&class_desc, EO_BASE_CLASS, NULL);
246 obj = eo_add(klass, NULL);
251 obj = eo_add(klass, NULL);
253 eo_manual_free_set(obj, EINA_TRUE);
260 obj = eo_add(klass, NULL);
262 eo_manual_free_set(obj, EINA_TRUE);
278 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
279 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
280 Eo *obj3 = eo_add(SIMPLE_CLASS, NULL);
283 fail_if(eo_ref_get(obj) != 2);
285 fail_if(eo_ref_get(obj) != 3);
287 eo_xunref(obj, obj2);
288 fail_if(eo_ref_get(obj) != 2);
289 eo_xunref(obj, obj3);
290 fail_if(eo_ref_get(obj) != 1);
293 eo_xunref(obj, obj3);
294 fail_if(eo_ref_get(obj) != 1);
297 fail_if(eo_ref_get(obj) != 2);
299 eo_xunref(obj, obj3);
300 fail_if(eo_ref_get(obj) != 2);
302 eo_xunref(obj, obj2);
303 fail_if(eo_ref_get(obj) != 1);
306 /* Check we don't seg if there's an extra xref. */
314 /* Check hierarchy */
315 obj = eo_add(SIMPLE_CLASS, NULL);
316 obj2 = eo_add(SIMPLE_CLASS, obj);
319 eo_do(obj2, eo_wref_add(&wref));
324 fail_if(!wref); /* Parent is still holding a reference. */
330 /* Just check it doesn't seg atm. */
331 obj = eo_add(SIMPLE_CLASS, NULL);
336 obj = eo_add(SIMPLE_CLASS, NULL);
337 obj2 = eo_add(SIMPLE_CLASS, obj);
347 START_TEST(eo_weak_reference)
351 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
352 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
353 Eo *wref, *wref2, *wref3;
354 eo_do(obj, eo_wref_add(&wref));
360 obj = eo_add(SIMPLE_CLASS, NULL);
361 eo_do(obj, eo_wref_add(&wref));
372 obj = eo_add(SIMPLE_CLASS, NULL);
374 eo_do(obj, eo_wref_add(&wref));
375 eo_do(obj, eo_wref_del(&wref));
378 eo_do(obj, eo_wref_add(&wref));
379 eo_do(obj2, eo_wref_del(&wref));
381 eo_wref_del_safe(&wref);
385 eo_do(obj, eo_wref_del(&wref));
388 wref = wref2 = wref3 = NULL;
389 eo_do(obj, eo_wref_add(&wref), eo_wref_add(&wref2), eo_wref_add(&wref3));
393 eo_do(obj, eo_wref_del(&wref), eo_wref_del(&wref2), eo_wref_del(&wref3));
398 eo_do(obj, eo_wref_add(&wref2), eo_wref_add(&wref3));
400 eo_do(obj, eo_wref_del(&wref));
402 eo_do(obj, eo_wref_del(&wref2), eo_wref_del(&wref3));
413 _a_set(Eo *obj EINA_UNUSED, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
419 _op_errors_class_constructor(Eo_Class *klass)
421 const Eo_Op_Func_Description func_desc[] = {
422 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_LAST), _a_set),
423 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_LAST + 1), _a_set),
424 EO_OP_FUNC(0x0F010111, _a_set),
428 eo_class_funcs_set(klass, func_desc);
431 START_TEST(eo_op_errors)
435 static const Eo_Class_Description class_desc = {
438 EO_CLASS_TYPE_REGULAR,
439 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
442 _op_errors_class_constructor,
446 const Eo_Class *klass = eo_class_new(&class_desc, SIMPLE_CLASS, NULL);
449 Eo *obj = eo_add(klass, NULL);
451 /* Out of bounds op for a legal class. */
452 fail_if(eo_do(obj, EO_BASE_ID(0x0111)));
455 fail_if(eo_do(obj, 0x0F010111));
457 fail_if(eo_ref_get(obj) != 1);
460 fail_if(eo_ref_get(obj) != 2);
463 fail_if(eo_ref_get(obj) != 3);
466 fail_if(eo_ref_get(obj) != 2);
469 fail_if(eo_ref_get(obj) != 1);
473 obj = eo_add(SIMPLE_CLASS, NULL);
474 fail_if(!eo_do(obj, simple_a_print()));
475 fail_if(!eo_do(obj, simple_a_print()));
476 fail_if(!eo_do(obj, simple_a_set(1)));
484 _fake_free_func(void *data)
493 START_TEST(eo_generic_data)
496 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
499 eo_do(obj, eo_base_data_set("test1", (void *) 1, NULL));
500 eo_do(obj, eo_base_data_get("test1", &data));
501 fail_if(1 != (int) data);
502 eo_do(obj, eo_base_data_del("test1"));
503 eo_do(obj, eo_base_data_get("test1", &data));
506 eo_do(obj, eo_base_data_set("test1", (void *) 1, NULL));
507 eo_do(obj, eo_base_data_set("test2", (void *) 2, NULL));
508 eo_do(obj, eo_base_data_get("test1", &data));
509 fail_if(1 != (int) data);
510 eo_do(obj, eo_base_data_get("test2", &data));
511 fail_if(2 != (int) data);
513 eo_do(obj, eo_base_data_get("test2", &data));
514 fail_if(2 != (int) data);
515 eo_do(obj, eo_base_data_del("test2"));
516 eo_do(obj, eo_base_data_get("test2", &data));
519 eo_do(obj, eo_base_data_get("test1", &data));
520 fail_if(1 != (int) data);
521 eo_do(obj, eo_base_data_del("test1"));
522 eo_do(obj, eo_base_data_get("test1", &data));
526 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
527 eo_do(obj, eo_base_data_get("test3", &data));
529 eo_do(obj, eo_base_data_get("test3", NULL));
530 eo_do(obj, eo_base_data_del("test3"));
534 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
535 eo_do(obj, eo_base_data_set("test3", NULL, _fake_free_func));
539 eo_do(obj, eo_base_data_set(NULL, &a, _fake_free_func));
540 eo_do(obj, eo_base_data_get(NULL, &data));
542 eo_do(obj, eo_base_data_del(NULL));
545 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
546 eo_do(obj, eo_base_data_set("test3", NULL, NULL));
548 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
557 START_TEST(eo_magic_checks)
559 char _buf[sizeof(long)]; /* Just enough to hold eina magic + a bit more. */
563 memset(_buf, 1, sizeof(_buf));
565 Eo *obj = eo_add(SIMPLE_CLASS, (Eo *) buf);
570 obj = eo_add((Eo_Class *) buf, NULL);
573 obj = eo_add(SIMPLE_CLASS, NULL);
576 fail_if(eo_do((Eo *) buf, EO_NOOP));
577 fail_if(eo_do_super((Eo *) buf, EO_NOOP));
578 fail_if(eo_class_get((Eo *) buf));
579 fail_if(eo_class_name_get((Eo_Class*) buf));
580 eo_class_funcs_set((Eo_Class *) buf, NULL);
581 eo_class_do((Eo_Class *) buf, NULL);
582 eo_class_do_super((Eo_Class *) buf, EO_NOOP);
584 fail_if(eo_class_new(NULL, (Eo_Class *) buf), NULL);
586 eo_xref(obj, (Eo *) buf);
587 eo_xunref(obj, (Eo *) buf);
588 eo_xref((Eo *) buf, obj);
589 eo_xunref((Eo *) buf, obj);
592 eo_unref((Eo *) buf);
595 eo_isa((Eo *) buf, SIMPLE_CLASS);
596 eo_isa(obj, (Eo_Class *) buf);
598 fail_if(0 != eo_ref_get((Eo *) buf));
601 eo_do((Eo *) buf, eo_wref_add(&wref));
604 fail_if(eo_parent_get((Eo *) buf));
606 eo_error_set((Eo *) buf);
608 fail_if(eo_data_get((Eo *) buf, SIMPLE_CLASS));
610 eo_composite_attach((Eo *) buf, obj);
611 eo_composite_attach(obj, (Eo *) buf);
612 eo_composite_detach((Eo *) buf, obj);
613 eo_composite_detach(obj, (Eo *) buf);
614 eo_composite_is((Eo *) buf);
616 eo_do(obj, eo_event_callback_forwarder_add(NULL, (Eo *) buf));
617 eo_do(obj, eo_event_callback_forwarder_del(NULL, (Eo *) buf));
619 eo_manual_free_set((Eo *) buf, EINA_TRUE);
620 eo_manual_free((Eo *) buf);
635 static Eo_Op MULTI_BASE_ID;
636 #define MULTI_ID(sub_id) (MULTI_BASE_ID + sub_id)
637 #define multi_a_print() MULTI_ID(MULTI_SUB_ID_A_PRINT)
638 #define multi_class_hi_print() MULTI_ID(MULTI_SUB_ID_CLASS_HI_PRINT)
641 _a_print(Eo *obj EINA_UNUSED, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
647 _class_hi_print(const Eo_Class *klass EINA_UNUSED, va_list *list EINA_UNUSED)
653 MULTI_SUB_ID_A_PRINT,
654 MULTI_SUB_ID_CLASS_HI_PRINT,
659 _eo_multiple_do_class_constructor(Eo_Class *klass)
661 const Eo_Op_Func_Description func_desc[] = {
662 EO_OP_FUNC(MULTI_ID(MULTI_SUB_ID_A_PRINT), _a_print),
663 EO_OP_FUNC_CLASS(MULTI_ID(MULTI_SUB_ID_CLASS_HI_PRINT), _class_hi_print),
667 eo_class_funcs_set(klass, func_desc);
670 static const Eo_Op_Description _eo_multiple_do_op_desc[] = {
671 EO_OP_DESCRIPTION(MULTI_SUB_ID_A_PRINT, "Print property A"),
672 EO_OP_DESCRIPTION_CLASS(MULTI_SUB_ID_CLASS_HI_PRINT, "Print Hi"),
673 EO_OP_DESCRIPTION_SENTINEL
677 START_TEST(eo_multiple_do)
681 /* Usually should be const, not const only for the test... */
682 static Eo_Class_Description class_desc = {
685 EO_CLASS_TYPE_REGULAR,
686 EO_CLASS_DESCRIPTION_OPS(&MULTI_BASE_ID, _eo_multiple_do_op_desc, MULTI_SUB_ID_LAST),
689 _eo_multiple_do_class_constructor,
693 const Eo_Class *klass = eo_class_new(&class_desc, SIMPLE_CLASS, NULL);
696 Eo *obj = eo_add(klass, NULL);
699 fail_if(!eo_do(obj, simple_a_print(), multi_a_print(), multi_a_print()));
700 fail_if(!eo_class_do(klass, simple_class_hi_print(), multi_class_hi_print(), multi_class_hi_print()));
708 START_TEST(eo_add_do_and_custom)
710 Simple_Public_Data *pd = NULL;
714 obj = eo_add_custom(SIMPLE_CLASS, NULL, eo_constructor());
718 obj = eo_add(SIMPLE_CLASS, NULL, simple_a_set(7));
720 pd = eo_data_get(obj, SIMPLE_CLASS);
724 obj = eo_add_custom(SIMPLE_CLASS, NULL, eo_constructor(), simple_a_set(7));
726 pd = eo_data_get(obj, SIMPLE_CLASS);
734 void eo_test_general(TCase *tc)
736 tcase_add_test(tc, eo_generic_data);
737 tcase_add_test(tc, eo_op_errors);
738 tcase_add_test(tc, eo_simple);
739 tcase_add_test(tc, eo_weak_reference);
740 tcase_add_test(tc, eo_refs);
741 tcase_add_test(tc, eo_magic_checks);
742 tcase_add_test(tc, eo_data_fetch);
743 tcase_add_test(tc, eo_man_free);
744 tcase_add_test(tc, eo_composite_tests);
745 tcase_add_test(tc, eo_isa_tests);
746 tcase_add_test(tc, eo_multiple_do);
747 tcase_add_test(tc, eo_add_do_and_custom);