summaryrefslogtreecommitdiff
path: root/src/tests/eina_cxx
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-03-10 12:24:29 +0900
committerCedric BAIL <cedric.bail@samsung.com>2014-03-10 12:35:00 +0900
commit5942207b25d746585c2b9eb93393e1af9dcb0ad7 (patch)
treea330ff947344b205d86453c41cc90e9ffe4a5a0f /src/tests/eina_cxx
parent6bd03923394c77d8b19c54bcb7fd31cd8a1303a0 (diff)
eina-cxx: Added range types for containers
Summary: Added inarray, inlist, ptr_array and ptr_list's range types named: range_inarray, range_inlist, range_ptr_array and range_ptr_list. Each has two "flavours": mutable and not mutable. The const versions are parameterized by a const parameter. For example: range_ptr_list<int const> and the mutable doesn't have the const, so: range_ptr_list<int>. The difference between the two is that the const versions can't modify the elements from the sequence, while the mutable allows so. Also, the const receives a Eina_Array const* while the mutable must have a Eina_Array*. Reviewers: cedric CC: savio, cedric Differential Revision: https://phab.enlightenment.org/D613
Diffstat (limited to 'src/tests/eina_cxx')
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_inarray.cc32
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_inlist.cc31
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_ptrarray.cc31
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_ptrlist.cc31
4 files changed, 125 insertions, 0 deletions
diff --git a/src/tests/eina_cxx/eina_cxx_test_inarray.cc b/src/tests/eina_cxx/eina_cxx_test_inarray.cc
index d2e526c45b..c0f464e036 100644
--- a/src/tests/eina_cxx/eina_cxx_test_inarray.cc
+++ b/src/tests/eina_cxx/eina_cxx_test_inarray.cc
@@ -15,7 +15,9 @@ START_TEST(eina_cxx_inarray_pod_push_back)
15 efl::eina::inarray<int> array; 15 efl::eina::inarray<int> array;
16 16
17 array.push_back(5); 17 array.push_back(5);
18 std::cout << "array size: " << array.size() << std::endl;
18 array.push_back(10); 19 array.push_back(10);
20 std::cout << "array size: " << array.size() << std::endl;
19 array.push_back(15); 21 array.push_back(15);
20 22
21 int result[] = {5, 10, 15}; 23 int result[] = {5, 10, 15};
@@ -372,6 +374,35 @@ START_TEST(eina_cxx_inarray_nonpod_erase)
372} 374}
373END_TEST 375END_TEST
374 376
377START_TEST(eina_cxx_range_inarray)
378{
379 efl::eina::eina_init eina_init;
380
381 efl::eina::inarray<int> array;
382 array.push_back(5);
383 array.push_back(10);
384 array.push_back(15);
385
386 int result[] = {5, 10, 15};
387
388 efl::eina::range_inarray<int> range_array(array);
389
390 ck_assert(range_array.size() == 3);
391 ck_assert(std::equal(range_array.begin(), range_array.end(), result));
392
393 ck_assert(range_array[0] == 5);
394
395 *range_array.begin() = 0;
396
397 int result1[] = {0, 10, 15};
398
399 ck_assert(range_array.size() == 3);
400 ck_assert(std::equal(range_array.begin(), range_array.end(), result1));
401
402 ck_assert(range_array[0] == 0);
403}
404END_TEST
405
375void 406void
376eina_test_inarray(TCase *tc) 407eina_test_inarray(TCase *tc)
377{ 408{
@@ -385,4 +416,5 @@ eina_test_inarray(TCase *tc)
385 tcase_add_test(tc, eina_cxx_inarray_nonpod_insert); 416 tcase_add_test(tc, eina_cxx_inarray_nonpod_insert);
386 tcase_add_test(tc, eina_cxx_inarray_nonpod_erase); 417 tcase_add_test(tc, eina_cxx_inarray_nonpod_erase);
387 tcase_add_test(tc, eina_cxx_inarray_nonpod_constructors); 418 tcase_add_test(tc, eina_cxx_inarray_nonpod_constructors);
419 tcase_add_test(tc, eina_cxx_range_inarray);
388} 420}
diff --git a/src/tests/eina_cxx/eina_cxx_test_inlist.cc b/src/tests/eina_cxx/eina_cxx_test_inlist.cc
index 09934f3f04..e33a783f2f 100644
--- a/src/tests/eina_cxx/eina_cxx_test_inlist.cc
+++ b/src/tests/eina_cxx/eina_cxx_test_inlist.cc
@@ -199,6 +199,36 @@ START_TEST(eina_cxx_inlist_erase)
199} 199}
200END_TEST 200END_TEST
201 201
202START_TEST(eina_cxx_inlist_range)
203{
204 efl::eina::eina_init eina_init;
205
206 efl::eina::inlist<int> list;
207 list.push_back(5);
208 list.push_back(10);
209 list.push_back(15);
210 list.push_back(20);
211 list.push_back(25);
212 list.push_back(30);
213
214 efl::eina::range_inlist<int> range_list(list);
215
216 ck_assert(range_list.size() == 6u);
217
218 int result[] = {5, 10, 15, 20, 25, 30};
219 ck_assert(std::equal(range_list.begin(), range_list.end(), result));
220
221 efl::eina::range_inlist<int const> const_range_list(list);
222
223 ck_assert(const_range_list.size() == 6u);
224 ck_assert(std::equal(range_list.begin(), range_list.end(), result));
225
226 *range_list.begin() = 0;
227 ck_assert(*const_range_list.begin() == 0);
228 ck_assert(*list.begin() == 0);
229}
230END_TEST
231
202void 232void
203eina_test_inlist(TCase *tc) 233eina_test_inlist(TCase *tc)
204{ 234{
@@ -209,4 +239,5 @@ eina_test_inlist(TCase *tc)
209 tcase_add_test(tc, eina_cxx_inlist_insert); 239 tcase_add_test(tc, eina_cxx_inlist_insert);
210 tcase_add_test(tc, eina_cxx_inlist_erase); 240 tcase_add_test(tc, eina_cxx_inlist_erase);
211 tcase_add_test(tc, eina_cxx_inlist_constructors); 241 tcase_add_test(tc, eina_cxx_inlist_constructors);
242 tcase_add_test(tc, eina_cxx_inlist_range);
212} 243}
diff --git a/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc b/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc
index 4e9a13b933..5b4ae40705 100644
--- a/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc
+++ b/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc
@@ -169,6 +169,36 @@ START_TEST(eina_cxx_ptrarray_erase)
169} 169}
170END_TEST 170END_TEST
171 171
172START_TEST(eina_cxx_ptrarray_range)
173{
174 efl::eina::eina_init eina_init;
175
176 efl::eina::ptr_array<int> array;
177 array.push_back(new int(5));
178 array.push_back(new int(10));
179 array.push_back(new int(15));
180 array.push_back(new int(20));
181 array.push_back(new int(25));
182 array.push_back(new int(30));
183
184 efl::eina::range_ptr_array<int> range_array(array);
185
186 ck_assert(range_array.size() == 6u);
187
188 int result[] = {5, 10, 15, 20, 25, 30};
189 ck_assert(std::equal(range_array.begin(), range_array.end(), result));
190
191 efl::eina::range_ptr_array<int const> const_range_array(array);
192
193 ck_assert(const_range_array.size() == 6u);
194 ck_assert(std::equal(range_array.begin(), range_array.end(), result));
195
196 *range_array.begin() = 0;
197 ck_assert(*const_range_array.begin() == 0);
198 ck_assert(*array.begin() == 0);
199}
200END_TEST
201
172void 202void
173eina_test_ptrarray(TCase* tc) 203eina_test_ptrarray(TCase* tc)
174{ 204{
@@ -177,4 +207,5 @@ eina_test_ptrarray(TCase* tc)
177 tcase_add_test(tc, eina_cxx_ptrarray_insert); 207 tcase_add_test(tc, eina_cxx_ptrarray_insert);
178 tcase_add_test(tc, eina_cxx_ptrarray_constructors); 208 tcase_add_test(tc, eina_cxx_ptrarray_constructors);
179 tcase_add_test(tc, eina_cxx_ptrarray_erase); 209 tcase_add_test(tc, eina_cxx_ptrarray_erase);
210 tcase_add_test(tc, eina_cxx_ptrarray_range);
180} 211}
diff --git a/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc b/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc
index c95adc3b21..dbded3ac46 100644
--- a/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc
+++ b/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc
@@ -199,6 +199,36 @@ START_TEST(eina_cxx_ptrlist_erase)
199} 199}
200END_TEST 200END_TEST
201 201
202START_TEST(eina_cxx_ptrlist_range)
203{
204 efl::eina::eina_init eina_init;
205
206 efl::eina::ptr_list<int> list;
207 list.push_back(new int(5));
208 list.push_back(new int(10));
209 list.push_back(new int(15));
210 list.push_back(new int(20));
211 list.push_back(new int(25));
212 list.push_back(new int(30));
213
214 efl::eina::range_ptr_list<int> range_list(list);
215
216 ck_assert(range_list.size() == 6u);
217
218 int result[] = {5, 10, 15, 20, 25, 30};
219 ck_assert(std::equal(range_list.begin(), range_list.end(), result));
220
221 efl::eina::range_ptr_list<int const> const_range_list(list);
222
223 ck_assert(const_range_list.size() == 6u);
224 ck_assert(std::equal(range_list.begin(), range_list.end(), result));
225
226 *range_list.begin() = 0;
227 ck_assert(*const_range_list.begin() == 0);
228 ck_assert(*list.begin() == 0);
229}
230END_TEST
231
202void 232void
203eina_test_ptrlist(TCase* tc) 233eina_test_ptrlist(TCase* tc)
204{ 234{
@@ -209,4 +239,5 @@ eina_test_ptrlist(TCase* tc)
209 tcase_add_test(tc, eina_cxx_ptrlist_insert); 239 tcase_add_test(tc, eina_cxx_ptrlist_insert);
210 tcase_add_test(tc, eina_cxx_ptrlist_constructors); 240 tcase_add_test(tc, eina_cxx_ptrlist_constructors);
211 tcase_add_test(tc, eina_cxx_ptrlist_erase); 241 tcase_add_test(tc, eina_cxx_ptrlist_erase);
242 tcase_add_test(tc, eina_cxx_ptrlist_range);
212} 243}