2014-11-18 07:24:39 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2016-02-04 06:02:57 -08:00
|
|
|
#include <Eo.h>
|
|
|
|
|
2014-11-18 07:24:39 -08:00
|
|
|
#include "eo_suite.h"
|
|
|
|
#include "eo_error_msgs.h"
|
|
|
|
#include "eo_test_class_simple.h"
|
|
|
|
|
|
|
|
static struct log_ctx ctx;
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
const Efl_Class *klass;
|
2014-11-18 07:24:39 -08:00
|
|
|
|
|
|
|
static void _destructor_unref(Eo *obj, void *class_data EINA_UNUSED)
|
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_destructor(efl_super(obj, klass));
|
2014-11-18 07:24:39 -08:00
|
|
|
|
|
|
|
/* this triggers an eo stack overflow if not correctly protected */
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_unref(obj);
|
2014-11-18 07:24:39 -08:00
|
|
|
}
|
|
|
|
|
2016-09-05 04:31:55 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_destructor_unref_class_initializer(Efl_Class *klass2)
|
|
|
|
{
|
|
|
|
EFL_OPS_DEFINE(ops,
|
2016-09-08 05:08:08 -07:00
|
|
|
EFL_OBJECT_OP_FUNC(efl_destructor, _destructor_unref),
|
2016-09-05 04:31:55 -07:00
|
|
|
);
|
|
|
|
|
2016-09-09 02:53:58 -07:00
|
|
|
return efl_class_functions_set(klass2, &ops, NULL);
|
2016-09-05 04:31:55 -07:00
|
|
|
}
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
START_TEST(efl_destructor_unref)
|
2014-11-18 07:24:39 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_object_init();
|
2014-11-18 07:24:39 -08:00
|
|
|
eina_log_print_cb_set(eo_test_print_cb, &ctx);
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
static Efl_Class_Description class_desc = {
|
2014-11-18 07:24:39 -08:00
|
|
|
EO_VERSION,
|
|
|
|
"Simple",
|
2016-08-15 06:44:41 -07:00
|
|
|
EFL_CLASS_TYPE_REGULAR,
|
2014-11-18 07:24:39 -08:00
|
|
|
0,
|
2016-09-05 04:31:55 -07:00
|
|
|
_destructor_unref_class_initializer,
|
2014-11-18 07:24:39 -08:00
|
|
|
NULL,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
klass = efl_class_new(&class_desc, SIMPLE_CLASS, NULL);
|
2014-11-21 01:20:36 -08:00
|
|
|
fail_if(!klass);
|
2014-11-18 07:24:39 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Eo *obj = efl_add(klass, NULL);
|
2014-11-21 01:20:36 -08:00
|
|
|
fail_if(!obj);
|
2014-11-18 07:24:39 -08:00
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
TEST_EO_ERROR("efl_unref", "Obj:%p. User refcount (%d) < 0. Too many unrefs.");
|
|
|
|
efl_unref(obj);
|
2014-11-18 07:24:39 -08:00
|
|
|
|
|
|
|
eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_object_shutdown();
|
2014-11-18 07:24:39 -08:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
START_TEST(efl_destructor_double_del)
|
2014-12-04 17:19:47 -08:00
|
|
|
{
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_object_init();
|
2014-12-04 17:19:47 -08:00
|
|
|
eina_log_print_cb_set(eo_test_print_cb, &ctx);
|
|
|
|
|
2016-08-10 07:23:04 -07:00
|
|
|
static Efl_Class_Description class_desc = {
|
2014-12-04 17:19:47 -08:00
|
|
|
EO_VERSION,
|
|
|
|
"Simple",
|
2016-08-15 06:44:41 -07:00
|
|
|
EFL_CLASS_TYPE_REGULAR,
|
2014-12-04 17:19:47 -08:00
|
|
|
0,
|
|
|
|
NULL,
|
2016-09-05 04:31:55 -07:00
|
|
|
NULL,
|
2014-12-04 17:19:47 -08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
klass = efl_class_new(&class_desc, SIMPLE_CLASS, NULL);
|
2014-12-04 17:19:47 -08:00
|
|
|
fail_if(!klass);
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
Eo *obj = efl_add(klass, NULL);
|
|
|
|
efl_manual_free_set(obj, EINA_TRUE);
|
2014-12-04 17:19:47 -08:00
|
|
|
fail_if(!obj);
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
TEST_EO_ERROR("efl_unref", "Obj:%p. User refcount (%d) < 0. Too many unrefs.");
|
2016-08-10 07:23:04 -07:00
|
|
|
efl_del(obj);
|
|
|
|
efl_del(obj);
|
2014-12-04 17:19:47 -08:00
|
|
|
|
|
|
|
eina_log_print_cb_set(eina_log_print_cb_stderr, NULL);
|
|
|
|
|
2016-08-15 06:44:41 -07:00
|
|
|
efl_object_shutdown();
|
2014-12-04 17:19:47 -08:00
|
|
|
}
|
|
|
|
END_TEST
|
|
|
|
|
2014-11-18 07:24:39 -08:00
|
|
|
void eo_test_class_behaviour_errors(TCase *tc)
|
|
|
|
{
|
2016-08-10 07:23:04 -07:00
|
|
|
tcase_add_test(tc, efl_destructor_unref);
|
|
|
|
tcase_add_test(tc, efl_destructor_double_del);
|
2014-11-18 07:24:39 -08:00
|
|
|
}
|