summaryrefslogtreecommitdiff
path: root/src/tests/eio
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-09-29 13:12:09 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-09-29 13:12:27 -0300
commit1a2014a12234593f4ba27f2f76f87dc481447e7c (patch)
treee7d76fed06f8d4981dbb84c827b1c45970d0b1d3 /src/tests/eio
parent6a5ae00ffaa20b6c1ccdd7891039d76b51099ced (diff)
efl: Update Efl.Model to use new Efl_Promise and Efl_Future
Replaced all Eina_Promise_Owner and Eina_Promise with Efl_Promise and Efl_Future.
Diffstat (limited to 'src/tests/eio')
-rw-r--r--src/tests/eio/eio_model_test_file.c38
-rw-r--r--src/tests/eio/eio_model_test_monitor_add.c72
2 files changed, 64 insertions, 46 deletions
diff --git a/src/tests/eio/eio_model_test_file.c b/src/tests/eio/eio_model_test_file.c
index ce06bb957c..9ce082183d 100644
--- a/src/tests/eio/eio_model_test_file.c
+++ b/src/tests/eio/eio_model_test_file.c
@@ -57,18 +57,18 @@ static Eina_Bool
57 } 57 }
58 58
59static void 59static void
60promise_then_count(void *data EINA_UNUSED, void *p) 60promise_then_count(void *data EINA_UNUSED, Efl_Event const *event)
61{ 61{
62 int *total = p; 62 int *total = ((Efl_Future_Event_Success*)event->info)->value;
63 ck_assert_ptr_ne(total, NULL); 63 ck_assert_ptr_ne(total, NULL);
64 printf("efl_model_loaded count %d\n", *total); fflush(stdout); 64 printf("efl_model_loaded count %d\n", *total); fflush(stdout);
65 ecore_main_loop_quit(); 65 ecore_main_loop_quit();
66} 66}
67 67
68static void 68static void
69promise_then_accessor(void *data EINA_UNUSED, void* p) 69promise_then_accessor(void *data EINA_UNUSED, Efl_Event const* event)
70{ 70{
71 Eina_Accessor *accessor = p; 71 Eina_Accessor *accessor = ((Efl_Future_Event_Success*)event->info)->value;
72 ck_assert_ptr_ne(accessor, NULL); 72 ck_assert_ptr_ne(accessor, NULL);
73 printf("efl_model_loaded accessor %p\n", accessor); fflush(stdout); 73 printf("efl_model_loaded accessor %p\n", accessor); fflush(stdout);
74 74
@@ -83,9 +83,9 @@ promise_then_accessor(void *data EINA_UNUSED, void* p)
83} 83}
84 84
85static void 85static void
86promise_then_value(void *user EINA_UNUSED, void *p) 86promise_then_value(void *user EINA_UNUSED, Efl_Event const* event)
87{ 87{
88 Eina_Value* value = p; 88 Eina_Value* value = ((Efl_Future_Event_Success*)event->info)->value;
89 ck_assert_ptr_ne(value, NULL); 89 ck_assert_ptr_ne(value, NULL);
90 char *str = eina_value_to_string(value); 90 char *str = eina_value_to_string(value);
91 91
@@ -97,7 +97,7 @@ promise_then_value(void *user EINA_UNUSED, void *p)
97} 97}
98 98
99static void 99static void
100error_promise_then(void* data EINA_UNUSED, Eina_Error error EINA_UNUSED) 100error_promise_then(void* data EINA_UNUSED, Efl_Event const* event EINA_UNUSED)
101{ 101{
102 ck_abort_msg(0, "Error Promise cb"); 102 ck_abort_msg(0, "Error Promise cb");
103 ecore_main_loop_quit(); 103 ecore_main_loop_quit();
@@ -114,31 +114,31 @@ START_TEST(eio_model_test_test_file)
114 fail_if(!efl_object_init(), "ERROR: Cannot init EO!\n"); 114 fail_if(!efl_object_init(), "ERROR: Cannot init EO!\n");
115 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n"); 115 fail_if(!eio_init(), "ERROR: Cannot init EIO!\n");
116 116
117 filemodel = efl_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(efl_added, EFL_MODEL_TEST_FILENAME_PATH)); 117 filemodel = efl_add(EIO_MODEL_CLASS, ecore_main_loop_get(), eio_model_path_set(efl_added, EFL_MODEL_TEST_FILENAME_PATH));
118 fail_if(!filemodel, "ERROR: Cannot init model!\n"); 118 fail_if(!filemodel, "ERROR: Cannot init model!\n");
119 119
120 handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL); 120 handler = ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, exit_func, NULL);
121 121
122 Eina_Promise *promise; 122 Efl_Future *future;
123 123
124 promise = efl_model_property_get(filemodel, "filename"); 124 future = efl_model_property_get(filemodel, "filename");
125 eina_promise_then(promise, &promise_then_value, &error_promise_then, NULL); 125 efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL);
126 ecore_main_loop_begin(); 126 ecore_main_loop_begin();
127 127
128 promise = efl_model_property_get(filemodel, "size"); 128 future = efl_model_property_get(filemodel, "size");
129 eina_promise_then(promise, &promise_then_value, &error_promise_then, NULL); 129 efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL);
130 ecore_main_loop_begin(); 130 ecore_main_loop_begin();
131 131
132 promise = efl_model_property_get(filemodel, "mtime"); 132 future = efl_model_property_get(filemodel, "mtime");
133 eina_promise_then(promise, &promise_then_value, &error_promise_then, NULL); 133 efl_future_then(future, &promise_then_value, &error_promise_then, NULL, NULL);
134 ecore_main_loop_begin(); 134 ecore_main_loop_begin();
135 135
136 promise = efl_model_children_slice_get(filemodel, 0, 0); 136 future = efl_model_children_slice_get(filemodel, 0, 0);
137 eina_promise_then(promise, &promise_then_accessor, &error_promise_then, NULL); 137 efl_future_then(future, &promise_then_accessor, &error_promise_then, NULL, NULL);
138 ecore_main_loop_begin(); 138 ecore_main_loop_begin();
139 139
140 promise = efl_model_children_count_get(filemodel); 140 future = efl_model_children_count_get(filemodel);
141 eina_promise_then(promise, &promise_then_count, &error_promise_then, NULL); 141 efl_future_then(future, &promise_then_count, &error_promise_then, NULL, NULL);
142 ecore_main_loop_begin(); 142 ecore_main_loop_begin();
143 143
144 efl_unref(filemodel); 144 efl_unref(filemodel);
diff --git a/src/tests/eio/eio_model_test_monitor_add.c b/src/tests/eio/eio_model_test_monitor_add.c
index 2973dbaf89..db3436868d 100644
--- a/src/tests/eio/eio_model_test_monitor_add.c
+++ b/src/tests/eio/eio_model_test_monitor_add.c
@@ -21,61 +21,81 @@ struct _pair
21 Eo *parent, *child; 21 Eo *parent, *child;
22}; 22};
23 23
24void _children_removed_get_value_cb(void* data EINA_UNUSED, Efl_Event const* event)
25{
26 Efl_Future_Event_Success* info = event->info;
27 Eina_Value* value = info->value;
28 char* filename = eina_value_to_string(value);
29 if(temp_filename && strcmp(filename, temp_filename) == 0)
30 ecore_main_loop_quit();
31 free(filename);
32
33 ecore_main_loop_quit();
34}
35
24static void 36static void
25_children_removed_cb(void *data EINA_UNUSED, const Efl_Event* event) 37_children_removed_cb(void *data EINA_UNUSED, const Efl_Event* event)
26{ 38{
27 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__);
28 if(children_deleted) 39 if(children_deleted)
29 { 40 {
30 Efl_Model_Children_Event* evt = event->info; 41 Efl_Model_Children_Event* evt = event->info;
42 Efl_Future* future;
31 43
32 Eina_Promise* promise; 44 future = efl_model_property_get(evt->child, "path");
33 promise = efl_model_property_get(evt->child, "path");
34 Eina_Value const* value = eina_promise_value_get(promise);
35 char* filename = eina_value_to_string(value);
36 45
37 if(temp_filename && strcmp(filename, temp_filename) == 0) 46 efl_future_then(future, _children_removed_get_value_cb, NULL, NULL, NULL);
38 ecore_main_loop_quit();
39 free(filename);
40 eina_promise_unref(promise);
41 } 47 }
42} 48}
43 49
44static void 50struct _added_get_value_data
45_children_added_cb(void *data EINA_UNUSED, const Efl_Event* event)
46{ 51{
47 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__); 52 Eo *object, *child;
48 Efl_Model_Children_Event* evt = event->info; 53};
54typedef struct _added_get_value_data added_get_value_data;
55
56void _children_added_get_value_cb(void* d, Efl_Event const* event)
57{
58 Efl_Future_Event_Success* info = event->info;
59 Eina_Value* value = info->value;
60 added_get_value_data* data = d;
49 61
50 Eina_Promise* promise;
51 promise = efl_model_property_get(evt->child, "path");
52 Eina_Value const* value = eina_promise_value_get(promise);
53 char* filename = eina_value_to_string(value); 62 char* filename = eina_value_to_string(value);
54 63
55 if(temp_filename && strcmp(temp_filename, filename) == 0) 64 if(temp_filename && strcmp(temp_filename, filename) == 0)
56 { 65 {
57 children_deleted = EINA_TRUE; 66 children_deleted = EINA_TRUE;
58 efl_model_child_del(event->object, evt->child); 67 efl_model_child_del(data->object, data->child);
59 } 68 }
60 free(filename); 69 free(filename);
70}
61 71
62 eina_promise_unref(promise); 72static void
73_children_added_cb(void *d EINA_UNUSED, const Efl_Event* event)
74{
75 Efl_Model_Children_Event* evt = event->info;
76 Efl_Future* future;
77
78 future = efl_model_property_get(evt->child, "path");
79
80 added_get_value_data* data = malloc(sizeof(added_get_value_data));
81 data->object = event->object;
82 data->child = evt->child;
83 efl_future_then(future, _children_added_get_value_cb, NULL, NULL, data);
63} 84}
64 85
65static void 86static void
66_create_file(void *data EINA_UNUSED, void* value EINA_UNUSED) 87_create_file(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED)
67{ 88{
68 int fd; 89 int fd;
69 if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0) 90 if((fd = eina_file_mkstemp("prefixXXXXXX.ext", &temp_filename)) > 0)
70 { 91 {
71 fprintf(stderr, __FILE__ ":%d %s\n", __LINE__, __func__);
72 close(fd); 92 close(fd);
73 } 93 }
74} 94}
75 95
76 96
77static void 97static void
78_create_file_error(void *data EINA_UNUSED, Eina_Error value EINA_UNUSED) 98_create_file_error(void *data EINA_UNUSED, Efl_Event const* event EINA_UNUSED)
79{ 99{
80 ck_abort_msg(0, "Error Promise cb called in Create file"); 100 ck_abort_msg(0, "Error Promise cb called in Create file");
81 ecore_main_loop_quit(); 101 ecore_main_loop_quit();
@@ -85,8 +105,6 @@ START_TEST(eio_model_test_test_monitor_add)
85{ 105{
86 Eo *filemodel = NULL; 106 Eo *filemodel = NULL;
87 107
88 fprintf(stderr, "efl_model_test_test_monitor_add\n");
89
90 fail_if(!eina_init(), "ERROR: Cannot init Eina!\n"); 108 fail_if(!eina_init(), "ERROR: Cannot init Eina!\n");
91 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n"); 109 fail_if(!ecore_init(), "ERROR: Cannot init Ecore!\n");
92 fail_if(!efl_object_init(), "ERROR: Cannot init EO!\n"); 110 fail_if(!efl_object_init(), "ERROR: Cannot init EO!\n");
@@ -94,16 +112,16 @@ START_TEST(eio_model_test_test_monitor_add)
94 112
95 tmpdir = eina_environment_tmp_get(); 113 tmpdir = eina_environment_tmp_get();
96 114
97 filemodel = efl_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(efl_added, tmpdir)); 115 filemodel = efl_add(EIO_MODEL_CLASS, ecore_main_loop_get(), eio_model_path_set(efl_added, tmpdir));
98 fail_if(!filemodel, "ERROR: Cannot init model!\n"); 116 fail_if(!filemodel, "ERROR: Cannot init model!\n");
99 117
100 efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_ADDED, &_children_added_cb, filemodel); 118 efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_ADDED, &_children_added_cb, filemodel);
101 efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_REMOVED, &_children_removed_cb, NULL); 119 efl_event_callback_add(filemodel, EFL_MODEL_EVENT_CHILD_REMOVED, &_children_removed_cb, NULL);
102 120
103 Eina_Promise* promise; 121 Efl_Future* future;
104 promise = efl_model_children_slice_get(filemodel, 0, 0); 122 future = efl_model_children_slice_get(filemodel, 0, 0);
105 123
106 eina_promise_then(promise, &_create_file, &_create_file_error, NULL); 124 efl_future_then(future, &_create_file, &_create_file_error, NULL, NULL);
107 125
108 ecore_main_loop_begin(); 126 ecore_main_loop_begin();
109 127