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 = {
35 EO_CLASS_TYPE_REGULAR,
36 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
43 const Eo_Class *klass = eo_class_new(&class_desc, 0, 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, 0, EO_BASE_CLASS, NULL);
57 obj = eo_add(klass, NULL);
59 fail_if(eo_data_get(obj, klass));
66 START_TEST(eo_composite_tests)
70 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
72 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
75 eo_composite_object_attach(obj, obj2);
76 eo_parent_set(obj2, NULL);
77 fail_if(eo_composite_is(obj2));
86 START_TEST(eo_static_classes)
90 static const Eo_Op_Description op_desc[] = {
91 EO_OP_DESCRIPTION(SIMPLE_SUB_ID_A_SET, "Set property A"),
92 EO_OP_DESCRIPTION_SENTINEL
95 /* Usually should be const, not const only for the test... */
96 static Eo_Class_Description class_desc = {
98 EO_CLASS_TYPE_REGULAR,
99 EO_CLASS_DESCRIPTION_OPS(NULL, op_desc, 1),
106 const Eo_Class *klass = eo_class_new(&class_desc, 1, EO_BASE_CLASS, NULL);
109 klass = eo_class_new(&class_desc, 1000, EO_BASE_CLASS, NULL);
112 klass = eo_class_new(&class_desc, 2, EO_BASE_CLASS, NULL);
119 static Eina_Bool _man_should_con = EINA_TRUE;
120 static Eina_Bool _man_should_des = EINA_TRUE;
123 _man_con(Eo *obj, void *data EINA_UNUSED, va_list *list EINA_UNUSED)
126 eo_manual_free_set(obj, EINA_TRUE);
127 eo_do_super(obj, eo_constructor());
131 _man_des(Eo *obj, void *data EINA_UNUSED, va_list *list EINA_UNUSED)
133 eo_do_super(obj, eo_destructor());
135 eo_manual_free_set(obj, EINA_FALSE);
140 _man_class_constructor(Eo_Class *klass)
142 const Eo_Op_Func_Description func_desc[] = {
143 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_CONSTRUCTOR), _man_con),
144 EO_OP_FUNC(EO_BASE_ID(EO_BASE_SUB_ID_DESTRUCTOR), _man_des),
148 eo_class_funcs_set(klass, func_desc);
151 START_TEST(eo_man_free)
155 /* Usually should be const, not const only for the test... */
156 static Eo_Class_Description class_desc = {
158 EO_CLASS_TYPE_REGULAR,
159 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
162 _man_class_constructor,
166 const Eo_Class *klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
169 Eo *obj = eo_add(klass, NULL);
173 obj = eo_add(klass, NULL);
178 _man_should_des = EINA_FALSE;
179 klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
182 obj = eo_add(klass, NULL);
188 obj = eo_add(klass, NULL);
193 _man_should_con = EINA_FALSE;
194 klass = eo_class_new(&class_desc, 0, EO_BASE_CLASS, NULL);
197 obj = eo_add(klass, NULL);
202 obj = eo_add(klass, NULL);
204 eo_manual_free_set(obj, EINA_TRUE);
218 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
219 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
220 Eo *obj3 = eo_add(SIMPLE_CLASS, NULL);
223 fail_if(eo_ref_get(obj) != 2);
225 fail_if(eo_ref_get(obj) != 3);
227 eo_xunref(obj, obj2);
228 fail_if(eo_ref_get(obj) != 2);
229 eo_xunref(obj, obj3);
230 fail_if(eo_ref_get(obj) != 1);
233 eo_xunref(obj, obj3);
234 fail_if(eo_ref_get(obj) != 1);
237 fail_if(eo_ref_get(obj) != 2);
239 eo_xunref(obj, obj3);
240 fail_if(eo_ref_get(obj) != 2);
242 eo_xunref(obj, obj2);
243 fail_if(eo_ref_get(obj) != 1);
246 /* Check we don't seg if there's an extra xref. */
254 /* Check hierarchy */
255 obj = eo_add(SIMPLE_CLASS, NULL);
256 obj2 = eo_add(SIMPLE_CLASS, obj);
259 eo_do(obj2, eo_wref_add(&wref));
264 fail_if(!wref); /* Parent is still holding a reference. */
270 /* Just check it doesn't seg atm. */
271 obj = eo_add(SIMPLE_CLASS, NULL);
276 obj = eo_add(SIMPLE_CLASS, NULL);
277 obj2 = eo_add(SIMPLE_CLASS, obj);
287 START_TEST(eo_weak_reference)
291 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
292 Eo *obj2 = eo_add(SIMPLE_CLASS, NULL);
293 Eo *wref, *wref2, *wref3;
294 eo_do(obj, eo_wref_add(&wref));
300 obj = eo_add(SIMPLE_CLASS, NULL);
301 eo_do(obj, eo_wref_add(&wref));
312 obj = eo_add(SIMPLE_CLASS, NULL);
314 eo_do(obj, eo_wref_add(&wref));
315 eo_do(obj, eo_wref_del(&wref));
318 eo_do(obj, eo_wref_add(&wref));
319 eo_do(obj2, eo_wref_del(&wref));
321 eo_wref_del_safe(&wref);
325 eo_do(obj, eo_wref_del(&wref));
328 wref = wref2 = wref3 = NULL;
329 eo_do(obj, eo_wref_add(&wref), eo_wref_add(&wref2), eo_wref_add(&wref3));
333 eo_do(obj, eo_wref_del(&wref), eo_wref_del(&wref2), eo_wref_del(&wref3));
338 eo_do(obj, eo_wref_add(&wref2), eo_wref_add(&wref3));
340 eo_do(obj, eo_wref_del(&wref));
342 eo_do(obj, eo_wref_del(&wref2), eo_wref_del(&wref3));
353 _a_set(Eo *obj EINA_UNUSED, void *class_data EINA_UNUSED, va_list *list EINA_UNUSED)
359 _op_errors_class_constructor(Eo_Class *klass)
361 const Eo_Op_Func_Description func_desc[] = {
362 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_LAST), _a_set),
363 EO_OP_FUNC(SIMPLE_ID(SIMPLE_SUB_ID_LAST + 1), _a_set),
364 EO_OP_FUNC(0x0F010111, _a_set),
368 eo_class_funcs_set(klass, func_desc);
371 START_TEST(eo_op_errors)
375 static const Eo_Class_Description class_desc = {
377 EO_CLASS_TYPE_REGULAR,
378 EO_CLASS_DESCRIPTION_OPS(NULL, NULL, 0),
381 _op_errors_class_constructor,
385 const Eo_Class *klass = eo_class_new(&class_desc, 0, SIMPLE_CLASS, NULL);
388 Eo *obj = eo_add(klass, NULL);
390 /* Out of bounds op for a legal class. */
391 fail_if(eo_do(obj, EO_BASE_ID(0x0111)));
394 fail_if(eo_do(obj, 0x0F010111));
396 fail_if(eo_ref_get(obj) != 1);
399 fail_if(eo_ref_get(obj) != 2);
402 fail_if(eo_ref_get(obj) != 3);
405 fail_if(eo_ref_get(obj) != 2);
408 fail_if(eo_ref_get(obj) != 1);
412 obj = eo_add(SIMPLE_CLASS, NULL);
413 fail_if(!eo_do(obj, simple_a_print()));
414 fail_if(!eo_query(obj, simple_a_print()));
415 fail_if(eo_query(obj, simple_a_set(1)));
423 _fake_free_func(void *data)
432 START_TEST(eo_generic_data)
435 Eo *obj = eo_add(SIMPLE_CLASS, NULL);
438 eo_do(obj, eo_base_data_set("test1", (void *) 1, NULL));
439 eo_do(obj, eo_base_data_get("test1", &data));
440 fail_if(1 != (int) data);
441 eo_do(obj, eo_base_data_del("test1"));
442 eo_do(obj, eo_base_data_get("test1", &data));
445 eo_do(obj, eo_base_data_set("test1", (void *) 1, NULL));
446 eo_do(obj, eo_base_data_set("test2", (void *) 2, NULL));
447 eo_do(obj, eo_base_data_get("test1", &data));
448 fail_if(1 != (int) data);
449 eo_do(obj, eo_base_data_get("test2", &data));
450 fail_if(2 != (int) data);
452 eo_do(obj, eo_base_data_get("test2", &data));
453 fail_if(2 != (int) data);
454 eo_do(obj, eo_base_data_del("test2"));
455 eo_do(obj, eo_base_data_get("test2", &data));
458 eo_do(obj, eo_base_data_get("test1", &data));
459 fail_if(1 != (int) data);
460 eo_do(obj, eo_base_data_del("test1"));
461 eo_do(obj, eo_base_data_get("test1", &data));
465 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
466 eo_do(obj, eo_base_data_get("test3", &data));
468 eo_do(obj, eo_base_data_get("test3", NULL));
469 eo_do(obj, eo_base_data_del("test3"));
473 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
474 eo_do(obj, eo_base_data_set("test3", NULL, _fake_free_func));
478 eo_do(obj, eo_base_data_set(NULL, &a, _fake_free_func));
479 eo_do(obj, eo_base_data_get(NULL, &data));
481 eo_do(obj, eo_base_data_del(NULL));
484 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
485 eo_do(obj, eo_base_data_set("test3", NULL, NULL));
487 eo_do(obj, eo_base_data_set("test3", &a, _fake_free_func));
496 START_TEST(eo_magic_checks)
498 char _buf[sizeof(long)]; /* Just enough to hold eina magic + a bit more. */
502 memset(_buf, 1, sizeof(_buf));
504 Eo *obj = eo_add(SIMPLE_CLASS, (Eo *) buf);
509 obj = eo_add((Eo_Class *) buf, NULL);
512 obj = eo_add(SIMPLE_CLASS, NULL);
515 fail_if(eo_do((Eo *) buf, EO_NOOP));
516 fail_if(eo_do_super((Eo *) buf, EO_NOOP));
517 fail_if(eo_class_get((Eo *) buf));
518 fail_if(eo_class_name_get((Eo_Class*) buf));
519 eo_class_funcs_set((Eo_Class *) buf, NULL);
520 eo_class_do((Eo_Class *) buf, NULL);
521 eo_class_do_super((Eo_Class *) buf, EO_NOOP);
523 fail_if(eo_class_new(NULL, 0, (Eo_Class *) buf), NULL);
525 eo_xref(obj, (Eo *) buf);
526 eo_xunref(obj, (Eo *) buf);
527 eo_xref((Eo *) buf, obj);
528 eo_xunref((Eo *) buf, obj);
531 eo_unref((Eo *) buf);
534 fail_if(0 != eo_ref_get((Eo *) buf));
537 eo_do((Eo *) buf, eo_wref_add(&wref));
540 fail_if(eo_parent_get((Eo *) buf));
542 eo_error_set((Eo *) buf);
544 fail_if(eo_data_get((Eo *) buf, SIMPLE_CLASS));
546 eo_composite_object_attach((Eo *) buf, obj);
547 eo_composite_object_attach(obj, (Eo *) buf);
548 eo_composite_object_detach((Eo *) buf, obj);
549 eo_composite_object_detach(obj, (Eo *) buf);
550 eo_composite_is((Eo *) buf);
552 eo_do(obj, eo_event_callback_forwarder_add(NULL, (Eo *) buf));
553 eo_do(obj, eo_event_callback_forwarder_del(NULL, (Eo *) buf));
555 eo_manual_free_set((Eo *) buf, EINA_TRUE);
556 eo_manual_free((Eo *) buf);
570 void eo_test_general(TCase *tc)
572 tcase_add_test(tc, eo_generic_data);
573 tcase_add_test(tc, eo_op_errors);
574 tcase_add_test(tc, eo_simple);
575 tcase_add_test(tc, eo_weak_reference);
576 tcase_add_test(tc, eo_refs);
577 tcase_add_test(tc, eo_magic_checks);
578 tcase_add_test(tc, eo_data_fetch);
579 tcase_add_test(tc, eo_man_free);
580 tcase_add_test(tc, eo_static_classes);
581 tcase_add_test(tc, eo_composite_tests);