forked from enlightenment/efl
eio: migrate tests to use new Efl.Model API.
This commit is contained in:
parent
702bcd7de9
commit
5b4d64ac13
|
@ -43,68 +43,110 @@ static struct reqs_t reqs;
|
|||
static Ecore_Event_Handler *handler;
|
||||
|
||||
static Eina_Bool
|
||||
exit_func(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
|
||||
{
|
||||
Ecore_Event_Signal_Exit *e;
|
||||
|
||||
e = (Ecore_Event_Signal_Exit *)ev;
|
||||
if (e->interrupt) fprintf(stdout, "Exit: interrupt\n");
|
||||
else if (e->quit) fprintf(stdout, "Exit: quit\n");
|
||||
else if (e->terminate) fprintf(stdout, "Exit: terminate\n");
|
||||
ecore_main_loop_quit();
|
||||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
||||
static void
|
||||
promise_then_count(void *data EINA_UNUSED, Efl_Event const *event)
|
||||
exit_func(void *data EINA_UNUSED, int ev_type EINA_UNUSED, void *ev)
|
||||
{
|
||||
int *total = ((Efl_Future_Event_Success*)event->info)->value;
|
||||
ck_assert_ptr_ne(total, NULL);
|
||||
printf("efl_model_loaded count %d\n", *total); fflush(stdout);
|
||||
Ecore_Event_Signal_Exit *e;
|
||||
|
||||
e = (Ecore_Event_Signal_Exit *)ev;
|
||||
if (e->interrupt) fprintf(stdout, "Exit: interrupt\n");
|
||||
else if (e->quit) fprintf(stdout, "Exit: quit\n");
|
||||
else if (e->terminate) fprintf(stdout, "Exit: terminate\n");
|
||||
ecore_main_loop_quit();
|
||||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
||||
static Eina_Value
|
||||
promise_then_accessor(void *data EINA_UNUSED,
|
||||
const Eina_Value v,
|
||||
const Eina_Future *dead_future EINA_UNUSED)
|
||||
{
|
||||
Eo *child = NULL;
|
||||
unsigned int i, len;
|
||||
|
||||
fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
|
||||
|
||||
EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
|
||||
;
|
||||
|
||||
ecore_main_loop_quit();
|
||||
|
||||
return EINA_VALUE_EMPTY;
|
||||
}
|
||||
|
||||
static Eina_Value
|
||||
listing(void *data,
|
||||
const Eina_Value v EINA_UNUSED,
|
||||
const Eina_Future *dead_future EINA_UNUSED)
|
||||
{
|
||||
Eina_Future *future;
|
||||
Efl_Model *filemodel = data;
|
||||
|
||||
future = efl_model_children_slice_get(filemodel, 0, efl_model_children_count_get(filemodel));
|
||||
future = eina_future_then(future, &promise_then_accessor, NULL);
|
||||
|
||||
return eina_future_as_value(future);
|
||||
}
|
||||
|
||||
static Eina_Future *listingf = NULL;
|
||||
|
||||
static Eina_Value
|
||||
clearup(void *data EINA_UNUSED,
|
||||
const Eina_Value v,
|
||||
const Eina_Future *dead_future EINA_UNUSED)
|
||||
{
|
||||
listingf = NULL;
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
static void
|
||||
promise_then_accessor(void *data EINA_UNUSED, Efl_Event const* event)
|
||||
setup_waiter(Efl_Model *model)
|
||||
{
|
||||
Eina_Accessor *accessor = ((Efl_Future_Event_Success*)event->info)->value;
|
||||
ck_assert_ptr_ne(accessor, NULL);
|
||||
printf("efl_model_loaded accessor %p\n", accessor); fflush(stdout);
|
||||
Efl_Loop *loop = efl_provider_find(model, EFL_LOOP_CLASS);
|
||||
|
||||
Eo* child;
|
||||
int i = 0;
|
||||
EINA_ACCESSOR_FOREACH(accessor, i, child)
|
||||
{
|
||||
printf("efl_model_loaded child: %d pointer %p\n", i, child);
|
||||
}
|
||||
|
||||
ecore_main_loop_quit();
|
||||
if (listingf) return ;
|
||||
listingf = efl_loop_job(loop);
|
||||
listingf = eina_future_then(listingf, listing, model);
|
||||
listingf = eina_future_then(listingf, clearup, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
promise_then_value(void *user EINA_UNUSED, Efl_Event const* event)
|
||||
_property_changed(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
{
|
||||
Eina_Value* value = ((Efl_Future_Event_Success*)event->info)->value;
|
||||
ck_assert_ptr_ne(value, NULL);
|
||||
char *str = eina_value_to_string(value);
|
||||
// Wait and check is_dir
|
||||
Efl_Model_Property_Event *ev = event->info;
|
||||
Efl_Model *filemodel = event->object;
|
||||
const char *property;
|
||||
Eina_Array_Iterator iterator;
|
||||
unsigned int i;
|
||||
|
||||
ck_assert_ptr_ne(str, NULL);
|
||||
printf("efl_model_loaded property: %s\n", str);
|
||||
free(str);
|
||||
|
||||
ecore_main_loop_quit();
|
||||
EINA_ARRAY_ITER_NEXT(ev->changed_properties, i, property, iterator)
|
||||
if (!strcmp(property, "is_dir"))
|
||||
{
|
||||
if (efl_model_children_count_get(filemodel) > 0)
|
||||
setup_waiter(filemodel);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
error_promise_then(void* data EINA_UNUSED, Efl_Event const* event EINA_UNUSED)
|
||||
_child_added(void *data EINA_UNUSED, const Efl_Event *event)
|
||||
{
|
||||
ck_abort_msg(0, "Error Promise cb");
|
||||
ecore_main_loop_quit();
|
||||
// Wait for a child being added to setup a job to list the directory
|
||||
Efl_Model *filemodel = event->object;
|
||||
|
||||
if (efl_model_children_count_get(filemodel) > 0)
|
||||
setup_waiter(filemodel);
|
||||
}
|
||||
|
||||
EFL_CALLBACKS_ARRAY_DEFINE(model,
|
||||
{ EFL_MODEL_EVENT_PROPERTIES_CHANGED, _property_changed },
|
||||
{ EFL_MODEL_EVENT_CHILD_ADDED, _child_added })
|
||||
|
||||
EFL_START_TEST(eio_model_test_test_file)
|
||||
{
|
||||
Eo *filemodel = NULL;
|
||||
Eina_Value *result;
|
||||
char *str;
|
||||
|
||||
memset(&reqs, 0, sizeof(struct reqs_t));
|
||||
|
||||
|
@ -113,34 +155,32 @@ EFL_START_TEST(eio_model_test_test_file)
|
|||
fail_if(!efl_object_init(), "ERROR: Cannot init EO!\n");
|
||||
fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
|
||||
|
||||
filemodel = efl_add(EIO_MODEL_CLASS, efl_main_loop_get(), eio_model_path_set(efl_added, EFL_MODEL_TEST_FILENAME_PATH));
|
||||
filemodel = efl_add(EIO_MODEL_CLASS, efl_main_loop_get(),
|
||||
eio_model_path_set(efl_added, EFL_MODEL_TEST_FILENAME_PATH));
|
||||
fail_if(!filemodel, "ERROR: Cannot init model!\n");
|
||||
|
||||
handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
|
||||
|
||||
Efl_Future *future;
|
||||
result = efl_model_property_get(filemodel, "filename");
|
||||
fail_if(!result);
|
||||
str = eina_value_to_string(result);
|
||||
fail_if(!str);
|
||||
free(str);
|
||||
eina_value_free(result);
|
||||
|
||||
result = efl_model_property_get(filemodel, "size");
|
||||
fail_if(!result);
|
||||
eina_value_free(result);
|
||||
|
||||
result = efl_model_property_get(filemodel, "mtime");
|
||||
fail_if(!result);
|
||||
eina_value_free(result);
|
||||
|
||||
efl_event_callback_array_add(filemodel, model(), NULL);
|
||||
|
||||
future = efl_model_property_get(filemodel, "filename");
|
||||
efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL);
|
||||
ecore_main_loop_begin();
|
||||
|
||||
future = efl_model_property_get(filemodel, "size");
|
||||
efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL);
|
||||
ecore_main_loop_begin();
|
||||
|
||||
future = efl_model_property_get(filemodel, "mtime");
|
||||
efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL);
|
||||
ecore_main_loop_begin();
|
||||
|
||||
future = efl_model_children_slice_get(filemodel, 0, 0);
|
||||
efl_future_then(future, &promise_then_accessor, &error_promise_then, NULL, NULL);
|
||||
ecore_main_loop_begin();
|
||||
|
||||
future = efl_model_children_count_get(filemodel);
|
||||
efl_future_then(future, &promise_then_count, &error_promise_then, NULL, NULL);
|
||||
ecore_main_loop_begin();
|
||||
|
||||
efl_unref(filemodel);
|
||||
efl_del(filemodel);
|
||||
|
||||
eio_shutdown();
|
||||
ecore_shutdown();
|
||||
|
@ -153,4 +193,3 @@ eio_model_test_file(TCase *tc)
|
|||
{
|
||||
tcase_add_test(tc, eio_model_test_test_file);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,94 +16,88 @@ Eina_Tmpstr* temp_filename = NULL;
|
|||
const char* tmpdir = NULL;
|
||||
Eina_Bool children_deleted = EINA_FALSE;
|
||||
|
||||
struct _pair
|
||||
{
|
||||
Eo *parent, *child;
|
||||
};
|
||||
|
||||
void _children_removed_get_value_cb(void* data EINA_UNUSED, Efl_Event const* event)
|
||||
{
|
||||
Efl_Future_Event_Success* info = event->info;
|
||||
Eina_Value* value = info->value;
|
||||
char* filename = eina_value_to_string(value);
|
||||
if(temp_filename && strcmp(filename, temp_filename) == 0)
|
||||
ecore_main_loop_quit();
|
||||
free(filename);
|
||||
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
|
||||
static void
|
||||
_children_removed_cb(void *data EINA_UNUSED, const Efl_Event* event)
|
||||
{
|
||||
if(children_deleted)
|
||||
{
|
||||
Efl_Model_Children_Event* evt = event->info;
|
||||
Efl_Future* future;
|
||||
Efl_Model_Children_Event* evt = event->info;
|
||||
Eina_Value *path;
|
||||
char *str;
|
||||
|
||||
future = efl_model_property_get(evt->child, "path");
|
||||
fail_if(evt->child == NULL);
|
||||
path = efl_model_property_get(evt->child, "path");
|
||||
fail_if(path == NULL);
|
||||
str = eina_value_to_string(path);
|
||||
fail_if(str == NULL);
|
||||
|
||||
efl_future_then(future, _children_removed_get_value_cb, NULL, NULL, NULL);
|
||||
}
|
||||
if (temp_filename && strcmp(str, temp_filename) == 0)
|
||||
ecore_main_loop_quit();
|
||||
|
||||
free(str);
|
||||
eina_value_free(path);
|
||||
}
|
||||
|
||||
struct _added_get_value_data
|
||||
static Eina_Value
|
||||
_children_get(void *data,
|
||||
const Eina_Value v,
|
||||
const Eina_Future *dead_future EINA_UNUSED)
|
||||
{
|
||||
Eo *object, *child;
|
||||
};
|
||||
typedef struct _added_get_value_data added_get_value_data;
|
||||
Efl_Model *filemodel = data;
|
||||
Eo *child = NULL;
|
||||
unsigned int i, len;
|
||||
|
||||
void _children_added_get_value_cb(void* d, Efl_Event const* event)
|
||||
{
|
||||
Efl_Future_Event_Success* info = event->info;
|
||||
Eina_Value* value = info->value;
|
||||
added_get_value_data* data = d;
|
||||
fail_if(eina_value_type_get(&v) != EINA_VALUE_TYPE_ARRAY);
|
||||
|
||||
char* filename = eina_value_to_string(value);
|
||||
|
||||
if(temp_filename && strcmp(temp_filename, filename) == 0)
|
||||
EINA_VALUE_ARRAY_FOREACH(&v, len, i, child)
|
||||
{
|
||||
children_deleted = EINA_TRUE;
|
||||
efl_model_child_del(data->object, data->child);
|
||||
Eina_Value *path;
|
||||
char *str;
|
||||
|
||||
path = efl_model_property_get(child, "path");
|
||||
fail_if(path == NULL);
|
||||
str = eina_value_to_string(path);
|
||||
fail_if(str == NULL);
|
||||
|
||||
if (strcmp(temp_filename, str) == 0)
|
||||
{
|
||||
children_deleted = EINA_TRUE;
|
||||
efl_model_child_del(filemodel, child);
|
||||
}
|
||||
free(str);
|
||||
eina_value_free(path);
|
||||
}
|
||||
free(filename);
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
static void
|
||||
_children_added_cb(void *d EINA_UNUSED, const Efl_Event* event)
|
||||
{
|
||||
Efl_Model_Children_Event* evt = event->info;
|
||||
Efl_Future* future;
|
||||
|
||||
future = efl_model_property_get(evt->child, "path");
|
||||
Eina_Future *future;
|
||||
|
||||
added_get_value_data* data = malloc(sizeof(added_get_value_data));
|
||||
data->object = event->object;
|
||||
data->child = evt->child;
|
||||
efl_future_then(future, _children_added_get_value_cb, NULL, NULL, data);
|
||||
future = efl_model_children_slice_get(event->object, evt->index, 1);
|
||||
eina_future_then(future, _children_get, event->object);
|
||||
}
|
||||
|
||||
static void
|
||||
_create_file(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED)
|
||||
static Eina_Value
|
||||
_create_file(void *data EINA_UNUSED,
|
||||
const Eina_Value v,
|
||||
const Eina_Future *dead_future EINA_UNUSED)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0)
|
||||
{
|
||||
close(fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
_create_file_error(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED)
|
||||
{
|
||||
ck_abort_msg(0, "Error Promise cb called in Create file");
|
||||
ecore_main_loop_quit();
|
||||
return v;
|
||||
}
|
||||
|
||||
EFL_START_TEST(eio_model_test_test_monitor_add)
|
||||
{
|
||||
Eo *filemodel = NULL;
|
||||
Eina_Future* future;
|
||||
|
||||
fail_if(!eina_init(), "ERROR: Cannot init Eina!\n");
|
||||
fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
|
||||
|
@ -112,20 +106,21 @@ EFL_START_TEST(eio_model_test_test_monitor_add)
|
|||
|
||||
tmpdir = eina_environment_tmp_get();
|
||||
|
||||
filemodel = efl_add(EIO_MODEL_CLASS, efl_main_loop_get(), eio_model_path_set(efl_added, tmpdir));
|
||||
filemodel = efl_add(EIO_MODEL_CLASS,
|
||||
efl_main_loop_get(),
|
||||
eio_model_path_set(efl_added, tmpdir));
|
||||
fail_if(!filemodel, "ERROR: Cannot init model!\n");
|
||||
|
||||
efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_ADDED, &_children_added_cb, filemodel);
|
||||
efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_REMOVED, &_children_removed_cb, NULL);
|
||||
|
||||
Efl_Future* future;
|
||||
future = efl_model_children_slice_get(filemodel, 0, 0);
|
||||
future = efl_model_children_slice_get(filemodel, 0, efl_model_children_count_get(filemodel));
|
||||
|
||||
efl_future_then(future, &_create_file, &_create_file_error, NULL, NULL);
|
||||
eina_future_then(future, &_create_file, NULL);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
efl_unref(filemodel);
|
||||
efl_del(filemodel);
|
||||
|
||||
eio_shutdown();
|
||||
ecore_shutdown();
|
||||
|
@ -140,4 +135,3 @@ eio_model_test_monitor_add(TCase *tc)
|
|||
{
|
||||
tcase_add_test(tc, eio_model_test_test_monitor_add);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,26 +19,19 @@ static Eina_Bool direct = EINA_FALSE;
|
|||
#define DONE_CALLED 0xdeadbeef
|
||||
|
||||
static void
|
||||
_access_cb(void *data, Eina_Accessor *access)
|
||||
_access_cb(void *data, Eina_Array *paths)
|
||||
{
|
||||
uint64_t *number_of_listed_files = data;
|
||||
Eina_Stringshare *s;
|
||||
unsigned int count;
|
||||
|
||||
EINA_ACCESSOR_FOREACH(access, count, s)
|
||||
{
|
||||
(*number_of_listed_files)++;
|
||||
}
|
||||
*number_of_listed_files += eina_array_count(paths);
|
||||
}
|
||||
|
||||
static void
|
||||
_progress_cb(void *data, const Efl_Event *ev)
|
||||
_progress_cb(void *data, Eina_Array *entries)
|
||||
{
|
||||
Efl_Future_Event_Progress *p = ev->info;
|
||||
const Eina_Array *batch = p->progress;
|
||||
uint64_t *number_of_listed_files = data;
|
||||
|
||||
(*number_of_listed_files) += eina_array_count(batch);
|
||||
(*number_of_listed_files) += eina_array_count(entries);
|
||||
}
|
||||
|
||||
static Eina_Value
|
||||
|
@ -71,27 +64,42 @@ _future_cb(void *data,
|
|||
return file;
|
||||
}
|
||||
|
||||
static void
|
||||
_done_cb(void *data, const Efl_Event *ev)
|
||||
static Eina_Value
|
||||
_done_cb(void *data,
|
||||
const Eina_Value file,
|
||||
const Eina_Future *dead EINA_UNUSED)
|
||||
{
|
||||
Efl_Future_Event_Success *success = ev->info;
|
||||
uint64_t *files_count = success->value;
|
||||
uint64_t *number_of_listed_files = data;
|
||||
|
||||
fail_if((*number_of_listed_files) != test_count);
|
||||
fail_if(*files_count != test_count);
|
||||
*number_of_listed_files = DONE_CALLED;
|
||||
ecore_main_loop_quit();
|
||||
}
|
||||
if (eina_value_type_get(&file) == EINA_VALUE_TYPE_ERROR)
|
||||
{
|
||||
Eina_Error err = 0;
|
||||
const char *msg;
|
||||
|
||||
static void
|
||||
_error_cb(void *data EINA_UNUSED, const Efl_Event *ev)
|
||||
{
|
||||
Efl_Future_Event_Failure *failure = ev->info;
|
||||
const char *msg = eina_error_msg_get(failure->error);
|
||||
eina_value_error_get(&file, &err);
|
||||
msg = eina_error_msg_get(err);
|
||||
|
||||
EINA_LOG_ERR("error: %s", msg);
|
||||
abort();
|
||||
}
|
||||
else
|
||||
{
|
||||
Eina_Value convert = EINA_VALUE_EMPTY;
|
||||
uint64_t files_count = 0;
|
||||
|
||||
eina_value_setup(&convert, EINA_VALUE_TYPE_ULONG);
|
||||
eina_value_convert(&file, &convert);
|
||||
eina_value_ulong_get(&convert, &files_count);
|
||||
|
||||
fail_if((*number_of_listed_files) != test_count);
|
||||
fail_if(files_count != test_count);
|
||||
|
||||
*number_of_listed_files = DONE_CALLED;
|
||||
}
|
||||
|
||||
EINA_LOG_ERR("error: %s", msg);
|
||||
ecore_main_loop_quit();
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
static Eina_Value
|
||||
|
@ -152,29 +160,30 @@ _stat_done_cb(void *data,
|
|||
}
|
||||
|
||||
static void
|
||||
_test_ls(Efl_Future *(*func)(Eo *obj, const char *path, Eina_Bool recursive),
|
||||
_test_ls(Eina_Future *(*func)(Eo *obj, const char *path, Eina_Bool recursive,
|
||||
void *info_data, EflIoDirectInfo info, Eina_Free_Cb info_free_cb),
|
||||
uint64_t expected_test_count,
|
||||
const char* test_dirname)
|
||||
{
|
||||
Efl_Io_Manager *job = efl_add(EFL_IO_MANAGER_CLASS, efl_main_loop_get());
|
||||
Efl_Future *f = NULL;
|
||||
Eina_Future *f = NULL;
|
||||
uint64_t main_files = 0;
|
||||
|
||||
fail_if(!job);
|
||||
|
||||
f = func(job, test_dirname, EINA_FALSE);
|
||||
f = func(job, test_dirname, EINA_FALSE, &main_files, _progress_cb, NULL);
|
||||
fail_if(!f);
|
||||
test_count = expected_test_count;
|
||||
efl_future_then(f, &_done_cb, &_error_cb, &_progress_cb, &main_files);
|
||||
eina_future_then(f, &_done_cb, &main_files);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
fail_if(main_files != DONE_CALLED);
|
||||
main_files = 0;
|
||||
|
||||
f = func(job, test_dirname, EINA_TRUE);
|
||||
f = func(job, test_dirname, EINA_TRUE, &main_files, _progress_cb, NULL);
|
||||
test_count = expected_test_count + 4;
|
||||
efl_future_then(f, &_done_cb, &_error_cb, &_progress_cb, &main_files);
|
||||
eina_future_then(f, &_done_cb, &main_files);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
||||
|
|
Loading…
Reference in New Issue