eolian: add tests for the new owning functions

This commit is contained in:
Marcel Hollerbach 2017-09-22 22:56:31 +02:00
parent fc071d5aa9
commit 79e21e90e0
3 changed files with 115 additions and 0 deletions

View File

@ -0,0 +1,25 @@
struct @free(free_a) Test.A {
t : int;
}
class Owning {
methods {
test1 {
params {
test1 : list<int> @owned;
test2 : iterator<int> @owned;
test3 : hash<int, int> @owned;
test4 : accessor<int> @owned;
}
}
test2 {
params {
test1 : list<ptr(Test.A) @owned> @owned;
test2 : iterator<ptr(Test.A) @owned> @owned;
test3 : hash<int, ptr(Test.A) @owned> @owned;
test4 : accessor<ptr(Test.A) @owned> @owned;
}
}
}
}

View File

@ -0,0 +1,77 @@
void _owning_test1(Eo *obj, Owning_Data *pd, Eina_List *test1, Eina_Iterator *test2, Eina_Hash *test3, Eina_Accessor *test4);
static void
_owning_test1_ownership_fallback(Eina_List *test1, Eina_Iterator *test2, Eina_Hash *test3, Eina_Accessor *test4)
{
eina_list_free(test1);
eina_iterator_free(test2);
eina_hash_free_cb_set(test3,NULL);
eina_hash_free(test3);
eina_accessor_free(test4);
}
EOAPI EFL_VOID_FUNC_BODYV_FALLBACK(owning_test1, _owning_test1_ownership_fallback(test1, test2, test3, test4);, EFL_FUNC_CALL(test1, test2, test3, test4), Eina_List *test1, Eina_Iterator *test2, Eina_Hash *test3, Eina_Accessor *test4);
void _owning_test2(Eo *obj, Owning_Data *pd, Eina_List *test1, Eina_Iterator *test2, Eina_Hash *test3, Eina_Accessor *test4);
static void
_owning_test2_ownership_fallback(Eina_List *test1, Eina_Iterator *test2, Eina_Hash *test3, Eina_Accessor *test4)
{
Test_A *test1_iter;
EINA_LIST_FREE(test1,test1_iter)
{
free_a(test1_iter);
}
Test_A *test2_iter;
EINA_ITERATOR_FOREACH(test2,test2_iter)
{
free_a(test2_iter);
}
eina_hash_free_cb_set(test3,NULL);
eina_hash_free(test3);
Test_A *test4_iter;
unsigned int test4_i = 0;
EINA_ACCESSOR_FOREACH(test4,test4_i,test4_iter)
{
free_a(test4_iter);
}
}
EOAPI EFL_VOID_FUNC_BODYV_FALLBACK(owning_test2, _owning_test2_ownership_fallback(test1, test2, test3, test4);, EFL_FUNC_CALL(test1, test2, test3, test4), Eina_List *test1, Eina_Iterator *test2, Eina_Hash *test3, Eina_Accessor *test4);
static Eina_Bool
_owning_class_initializer(Efl_Class *klass)
{
const Efl_Object_Ops *opsp = NULL, *copsp = NULL;
#ifndef OWNING_EXTRA_OPS
#define OWNING_EXTRA_OPS
#endif
EFL_OPS_DEFINE(ops,
EFL_OBJECT_OP_FUNC(owning_test1, _owning_test1),
EFL_OBJECT_OP_FUNC(owning_test2, _owning_test2),
OWNING_EXTRA_OPS
);
opsp = &ops;
#ifdef OWNING_EXTRA_CLASS_OPS
EFL_OPS_DEFINE(cops, OWNING_EXTRA_CLASS_OPS);
copsp = &cops;
#endif
return efl_class_functions_set(klass, opsp, copsp);
}
static const Efl_Class_Description _owning_class_desc = {
EO_VERSION,
"Owning",
EFL_CLASS_TYPE_REGULAR,
sizeof(Owning_Data),
_owning_class_initializer,
NULL,
NULL
};
EFL_DEFINE_CLASS(owning_class_get, &_owning_class_desc, NULL, NULL);

View File

@ -217,6 +217,18 @@ START_TEST(eolian_function_pointers)
}
END_TEST
START_TEST(owning)
{
char output_filepath[PATH_MAX] = "";
snprintf(output_filepath, PATH_MAX, "%s/eolian_owning",
eina_environment_tmp_get());
_remove_ref(output_filepath, "c");
fail_if(0 != _eolian_gen_execute(PACKAGE_DATA_DIR"/data/owning.eo", "-gc", output_filepath));
fail_if(!_files_compare(PACKAGE_DATA_DIR"/data/owning.eo.c", output_filepath, "c"));
}
END_TEST
void eolian_generation_test(TCase *tc)
{
tcase_add_test(tc, eolian_types_generation);
@ -227,4 +239,5 @@ void eolian_generation_test(TCase *tc)
tcase_add_test(tc, eolian_import);
tcase_add_test(tc, eolian_docs);
tcase_add_test(tc, eolian_function_pointers);
tcase_add_test(tc, owning);
}