summaryrefslogtreecommitdiff
path: root/src/tests/ecore_cxx
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-03-07 14:33:07 +0900
committerCedric BAIL <cedric.bail@samsung.com>2014-03-07 14:37:03 +0900
commit4105c002b3161d67600a22b2f570c4969a6b36b2 (patch)
treece0cad97592fc238955a1eaa416e36f594f55418 /src/tests/ecore_cxx
parentbc0a54c57c21bb0a03a4413c8c7deb642d88328c (diff)
ecore-cxx: add support for exceptions.
Summary: Added support for exceptions on ecore_main_loop_thread_safe_call_async and ecore_main_loop_thread_safe_call_sync. Also optimized the transport of the return value through a parameter on ecore_main_loop_thread_safe_call_sync. ecore-cxx: Changed uses of alignas for aligned_storage in C++11 Reviewers: cedric, raster CC: savio, cedric Differential Revision: https://phab.enlightenment.org/D593 Signed-off-by: Cedric BAIL <cedric.bail@samsung.com>
Diffstat (limited to 'src/tests/ecore_cxx')
-rw-r--r--src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc91
1 files changed, 81 insertions, 10 deletions
diff --git a/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc b/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc
index bc2b78d4f3..9be7d73706 100644
--- a/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc
+++ b/src/tests/ecore_cxx/ecore_cxx_test_safe_call.cc
@@ -8,19 +8,28 @@
8 8
9#include <check.h> 9#include <check.h>
10 10
11void call_async(efl::eina::mutex& mutex, efl::eina::condition_variable& cond, bool& done) 11void call_async(efl::eina::mutex& mutex, efl::eina::condition_variable& cond, int& done)
12{ 12{
13 efl::ecore::main_loop_thread_safe_call_async 13 efl::ecore::main_loop_thread_safe_call_async
14 ( 14 (
15 [&mutex,&cond,&done] 15 [&mutex,&cond,&done]
16 { 16 {
17 std::cout << "yeah" << std::endl; 17 std::cout << "yeah" << std::endl;
18 ecore_main_loop_quit();
19 efl::eina::unique_lock<efl::eina::mutex> l(mutex); 18 efl::eina::unique_lock<efl::eina::mutex> l(mutex);
20 std::cout << "mutex locked" << std::endl; 19 ++done;
21 done = true; 20 }
21 );
22
23 efl::ecore::main_loop_thread_safe_call_async
24 (
25 [&mutex,&cond,&done]
26 {
27 std::cout << "yeah2" << std::endl;
28 efl::eina::unique_lock<efl::eina::mutex> l(mutex);
29 ++done;
22 cond.notify_one(); 30 cond.notify_one();
23 std::cout << "exiting" << std::endl; 31 ecore_main_loop_quit();
32 throw std::bad_alloc();
24 } 33 }
25 ); 34 );
26} 35}
@@ -31,7 +40,7 @@ START_TEST(ecore_cxx_safe_call_async)
31 40
32 efl::eina::mutex mutex; 41 efl::eina::mutex mutex;
33 efl::eina::condition_variable cond; 42 efl::eina::condition_variable cond;
34 bool done = false; 43 int done = 0;
35 efl::eina::thread thread(&call_async, std::ref(mutex), std::ref(cond), std::ref(done)); 44 efl::eina::thread thread(&call_async, std::ref(mutex), std::ref(cond), std::ref(done));
36 45
37 ecore_main_loop_begin(); 46 ecore_main_loop_begin();
@@ -43,13 +52,15 @@ START_TEST(ecore_cxx_safe_call_async)
43 std::cout << "joined" << std::endl; 52 std::cout << "joined" << std::endl;
44 53
45 efl::eina::unique_lock<efl::eina::mutex> l(mutex); 54 efl::eina::unique_lock<efl::eina::mutex> l(mutex);
46 while(!done) 55 while(done != 2)
47 { 56 {
48 std::cout << "waiting" << std::endl; 57 std::cout << "wait" << std::endl;
49 cond.wait(l); 58 cond.wait(l);
50 std::cout << "waited" << std::endl; 59 std::cout << "waited" << std::endl;
51 } 60 }
52 61
62 ck_assert( ::eina_error_get() == ::EINA_ERROR_OUT_OF_MEMORY);
63 ::eina_error_set(0);
53 std::cout << "end of ecore_cxx_safe_call_async" << std::endl; 64 std::cout << "end of ecore_cxx_safe_call_async" << std::endl;
54} 65}
55END_TEST 66END_TEST
@@ -111,7 +122,14 @@ struct big_nonpod : big_pod
111 122
112void call_sync_int() 123void call_sync_int()
113{ 124{
114 std::cout << "call_sync_init" << std::endl; 125 efl::ecore::main_loop_thread_safe_call_sync
126 (
127 [] () -> void
128 {
129 ck_assert( ::eina_error_get() == 0);
130 }
131 );
132
115 int r1 = 133 int r1 =
116 efl::ecore::main_loop_thread_safe_call_sync 134 efl::ecore::main_loop_thread_safe_call_sync
117 ( 135 (
@@ -122,6 +140,37 @@ void call_sync_int()
122 ); 140 );
123 ck_assert(r1 == 1); 141 ck_assert(r1 == 1);
124 142
143 try
144 {
145 efl::ecore::main_loop_thread_safe_call_sync
146 (
147 [] () -> int
148 {
149 throw std::bad_alloc();
150 }
151 );
152 ck_assert(false);
153 }
154 catch(std::bad_alloc const& e)
155 {
156 }
157
158 try
159 {
160 efl::ecore::main_loop_thread_safe_call_sync
161 (
162 [] () -> int
163 {
164 ::eina_error_set( ::EINA_ERROR_OUT_OF_MEMORY);
165 return 0;
166 }
167 );
168 ck_assert(false);
169 }
170 catch(std::system_error const& e)
171 {
172 }
173
125 std::cout << "big_pod" << std::endl; 174 std::cout << "big_pod" << std::endl;
126 175
127 big_pod r2 = 176 big_pod r2 =
@@ -160,7 +209,6 @@ void call_sync_int()
160 [] () -> big_nonpod 209 [] () -> big_nonpod
161 { 210 {
162 std::cout << "before quit" << std::endl; 211 std::cout << "before quit" << std::endl;
163 ecore_main_loop_quit();
164 std::cout << "are we calling here" << std::endl; 212 std::cout << "are we calling here" << std::endl;
165 return big_nonpod(); 213 return big_nonpod();
166 } 214 }
@@ -169,6 +217,29 @@ void call_sync_int()
169 std::cout << "constructor_called: " << constructor_called << std::endl; 217 std::cout << "constructor_called: " << constructor_called << std::endl;
170 std::cout << "destructor_called: " << destructor_called << std::endl; 218 std::cout << "destructor_called: " << destructor_called << std::endl;
171 ck_assert(constructor_called == destructor_called); 219 ck_assert(constructor_called == destructor_called);
220
221 {
222 try
223 {
224 efl::ecore::main_loop_thread_safe_call_sync
225 (
226 [] () -> big_nonpod
227 {
228 std::cout << "before quit" << std::endl;
229 ecore_main_loop_quit();
230 std::cout << "are we calling here" << std::endl;
231 throw std::bad_alloc();
232 }
233 );
234 ck_assert(false);
235 }
236 catch(std::bad_alloc const& e)
237 {
238 }
239 }
240 std::cout << "constructor_called: " << constructor_called << std::endl;
241 std::cout << "destructor_called: " << destructor_called << std::endl;
242 ck_assert(constructor_called == destructor_called);
172} 243}
173 244
174START_TEST(ecore_cxx_safe_call_sync) 245START_TEST(ecore_cxx_safe_call_sync)