summaryrefslogtreecommitdiff
path: root/src/tests/eina_cxx
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2014-02-25 17:24:32 -0300
committerCedric Bail <cedric.bail@free.fr>2014-02-25 18:05:01 -0300
commitf279225a6300063c0bc6a47dedd3036ac72e89a6 (patch)
tree796dadba6c7cfaf301f89b24086a1d05647825b7 /src/tests/eina_cxx
parentd63507446fcd9ee1fd90373f5d1207f71cfb8f74 (diff)
eina: add a C++ bindings to Eina @feature.
The goal of this library is to make the life of C++ developers easier when having to manipulate Eina datatype by providing a layer to abstract those data type in C++. Check examples for now. Documentation will come soon, but we are pushing that rather sooner to get feedback on those bindings. As you will notice, this library is just composed of headers. There is no .so and we do think it is better this way. Reducing ABI and API stability issue for applications developers who are the primary target of this binding. Also please note that you will need to have C++11 to use this binding. Signed-off-by: Cedric Bail <cedric.bail@free.fr>
Diffstat (limited to 'src/tests/eina_cxx')
-rw-r--r--src/tests/eina_cxx/eina_cxx_suite.cc125
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_accessor.cc102
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_eina_value.cc191
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_error.cc72
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_inarray.cc388
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_inlist.cc212
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_iterator.cc34
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_ptrarray.cc180
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_ptrlist.cc212
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_stringshare.cc32
-rw-r--r--src/tests/eina_cxx/eina_cxx_test_thread.cc127
11 files changed, 1675 insertions, 0 deletions
diff --git a/src/tests/eina_cxx/eina_cxx_suite.cc b/src/tests/eina_cxx/eina_cxx_suite.cc
new file mode 100644
index 0000000000..a9c20dc61a
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_suite.cc
@@ -0,0 +1,125 @@
1
2#include "Eina.hh"
3
4#include <cassert>
5#include <algorithm>
6
7#include <check.h>
8
9void eina_test_inlist(TCase* tc);
10void eina_test_inarray(TCase* tc);
11void eina_test_ptrlist(TCase* tc);
12void eina_test_ptrarray(TCase* tc);
13void eina_test_iterator(TCase* tc);
14void eina_test_stringshare(TCase* tc);
15void eina_test_error(TCase* tc);
16void eina_test_accessor(TCase* tc);
17void eina_test_thread(TCase* tc);
18void eina_test_eina_value(TCase* tc);
19
20typedef struct _Eina_Test_Case Eina_Test_Case;
21struct _Eina_Test_Case
22{
23 const char *test_case;
24 void (*build)(TCase *tc);
25};
26
27static const Eina_Test_Case etc[] = {
28 { "Ptr_List", eina_test_ptrlist },
29 { "Ptr_Array", eina_test_ptrarray },
30 { "Inlist", eina_test_inlist },
31 { "Inarray", eina_test_inarray },
32 { "Iterator", eina_test_iterator },
33 { "Stringshare", eina_test_stringshare },
34 { "Error", eina_test_error },
35 { "Accessor", eina_test_accessor },
36 { "Thread", eina_test_thread },
37 { "EinaValue", eina_test_eina_value },
38 { NULL, NULL }
39};
40
41static void
42_list_tests(void)
43{
44 const Eina_Test_Case *itr = etc;
45 fputs("Available Test Cases:\n", stderr);
46 for (; itr->test_case; itr++)
47 fprintf(stderr, "\t%s\n", itr->test_case);
48}
49
50static Eina_Bool
51_use_test(int argc, const char **argv, const char *test_case)
52{
53 if (argc < 1)
54 return 1;
55
56 for (; argc > 0; argc--, argv++)
57 if (strcmp(test_case, *argv) == 0)
58 return 1;
59
60 return 0;
61}
62
63Suite *
64eina_build_suite(int argc, const char **argv)
65{
66 TCase *tc;
67 Suite *s;
68 int i;
69
70 s = suite_create("Eina");
71
72 for (i = 0; etc[i].test_case; ++i)
73 {
74 if (!_use_test(argc, argv, etc[i].test_case))
75 continue;
76
77 tc = tcase_create(etc[i].test_case);
78 tcase_set_timeout(tc, 0);
79
80 etc[i].build(tc);
81 suite_add_tcase(s, tc);
82 }
83
84 return s;
85}
86
87int main(int argc, char* argv[])
88{
89 Suite *s;
90 SRunner *sr;
91 int i, failed_count;
92
93 for (i = 1; i < argc; i++)
94 if ((strcmp(argv[i], "-h") == 0) ||
95 (strcmp(argv[i], "--help") == 0))
96 {
97 fprintf(stderr, "Usage:\n\t%s [test_case1 .. [test_caseN]]\n",
98 argv[0]);
99 _list_tests();
100 return 0;
101 }
102 else if ((strcmp(argv[i], "-l") == 0) ||
103 (strcmp(argv[i], "--list") == 0))
104 {
105 _list_tests();
106 return 0;
107 }
108
109 putenv(const_cast<char*>("EFL_RUN_IN_TREE=1"));
110
111 s = eina_build_suite(argc - 1, (const char **)argv + 1);
112 sr = srunner_create(s);
113
114 srunner_set_xml(sr, TESTS_BUILD_DIR "/check-results.xml");
115
116 eina_init();
117
118 srunner_run_all(sr, CK_ENV);
119 failed_count = srunner_ntests_failed(sr);
120 srunner_free(sr);
121
122 eina_shutdown();
123
124 return (failed_count == 0) ? 0 : 255;
125}
diff --git a/src/tests/eina_cxx/eina_cxx_test_accessor.cc b/src/tests/eina_cxx/eina_cxx_test_accessor.cc
new file mode 100644
index 0000000000..21ad5e09da
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_accessor.cc
@@ -0,0 +1,102 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5
6#include <check.h>
7
8START_TEST(eina_cxx_accessor_indexing)
9{
10 efl::eina::ptr_list<int> list;
11 list.push_back(new int(5));
12 list.push_back(new int(10));
13 list.push_back(new int(15));
14 list.push_back(new int(20));
15
16 efl::eina::accessor<int> accessor(list.accessor());
17
18 ck_assert(accessor[0] == 5);
19 ck_assert(accessor[1] == 10);
20 ck_assert(accessor[2] == 15);
21 ck_assert(accessor[3] == 20);
22}
23END_TEST
24
25START_TEST(eina_cxx_accessor_iterator)
26{
27 efl::eina::ptr_list<int> list;
28 list.push_back(new int(5));
29 list.push_back(new int(10));
30 list.push_back(new int(15));
31 list.push_back(new int(20));
32
33 std::size_t pos = 0u;
34 for(efl::eina::accessor_iterator<int> first (list.accessor())
35 , last (list.accessor(), list.size()); first != last; ++first, ++pos)
36 {
37 ck_assert(pos != 0u || *first == 5);
38 ck_assert(pos != 1u || *first == 10);
39 ck_assert(pos != 2u || *first == 15);
40 ck_assert(pos != 3u || *first == 20);
41 }
42}
43END_TEST
44
45START_TEST(eina_cxx_accessor_relops)
46{
47 efl::eina::ptr_list<int> list;
48 list.push_back(new int(5));
49 list.push_back(new int(10));
50 list.push_back(new int(15));
51 list.push_back(new int(20));
52
53 efl::eina::accessor_iterator<int> first (list.accessor())
54 , second(list.accessor(), 1u)
55 , third(list.accessor(), 2u)
56 , fourth(list.accessor(), 3u)
57 ;
58 ck_assert(!(first < first)); ck_assert(first < second);
59 ck_assert(first < third); ck_assert(first < fourth);
60 ck_assert(!(second < first)); ck_assert(!(second < second));
61 ck_assert(second < third); ck_assert(second < fourth);
62 ck_assert(!(third < first)); ck_assert(!(third < second));
63 ck_assert(!(third < third)); ck_assert(third < fourth);
64 ck_assert(!(fourth < first)); ck_assert(!(fourth < second));
65 ck_assert(!(fourth < third)); ck_assert(!(fourth < fourth));
66
67 ck_assert(first <= first); ck_assert(first <= second);
68 ck_assert(first <= third); ck_assert(first <= fourth);
69 ck_assert(!(second <= first)); ck_assert(second <= second);
70 ck_assert(second <= third); ck_assert(second <= fourth);
71 ck_assert(!(third <= first)); ck_assert(!(third <= second));
72 ck_assert(third <= third); ck_assert(third <= fourth);
73 ck_assert(!(fourth <= first)); ck_assert(!(fourth <= second));
74 ck_assert(!(fourth <= third)); ck_assert(fourth <= fourth);
75
76 ck_assert(!(first > first)); ck_assert(!(first > second));
77 ck_assert(!(first > third)); ck_assert(!(first > fourth));
78 ck_assert(second > first); ck_assert(!(second > second));
79 ck_assert(!(second > third)); ck_assert(!(second > fourth));
80 ck_assert(third > first); ck_assert(third > second);
81 ck_assert(!(third > third)); ck_assert(!(third > fourth));
82 ck_assert(fourth > first); ck_assert(fourth > second);
83 ck_assert(fourth > third); ck_assert(!(fourth > fourth));
84
85 ck_assert(first >= first); ck_assert(!(first >= second));
86 ck_assert(!(first >= third)); ck_assert(!(first >= fourth));
87 ck_assert(second >= first); ck_assert(second >= second);
88 ck_assert(!(second >= third)); ck_assert(!(second >= fourth));
89 ck_assert(third >= first); ck_assert(third >= second);
90 ck_assert(third >= third); ck_assert(!(third >= fourth));
91 ck_assert(fourth >= first); ck_assert(fourth >= second);
92 ck_assert(fourth >= third); ck_assert(fourth >= fourth);
93}
94END_TEST
95
96void
97eina_test_accessor(TCase* tc)
98{
99 tcase_add_test(tc, eina_cxx_accessor_indexing);
100 tcase_add_test(tc, eina_cxx_accessor_iterator);
101 tcase_add_test(tc, eina_cxx_accessor_relops);
102}
diff --git a/src/tests/eina_cxx/eina_cxx_test_eina_value.cc b/src/tests/eina_cxx/eina_cxx_test_eina_value.cc
new file mode 100644
index 0000000000..f9ddd2e6d4
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_eina_value.cc
@@ -0,0 +1,191 @@
1
2#include "Eina.hh"
3
4#include <check.h>
5
6START_TEST(eina_cxx_eina_value_constructors)
7{
8 efl::eina::eina_init init;
9
10 efl::eina::eina_value v;
11
12 char c = 'c';
13 efl::eina::eina_value vchar(c);
14
15 short s = 5;
16 efl::eina::eina_value vshort(s);
17
18 efl::eina::eina_value vint(5);
19
20 efl::eina::eina_value vlong(5l);
21
22 unsigned char uc = 'b';
23 efl::eina::eina_value vuchar(uc);
24
25 unsigned short us = 5;
26 efl::eina::eina_value vushort(us);
27
28 efl::eina::eina_value vuint(5u);
29
30 efl::eina::eina_value vulong(5ul);
31
32 efl::eina::eina_value vu64(uint64_t(5ul));
33
34 efl::eina::eina_value vfloat(5.0f);
35
36 efl::eina::eina_value vdouble(5.0);
37}
38END_TEST
39
40START_TEST(eina_cxx_eina_value_get)
41{
42 efl::eina::eina_init init;
43
44 char c = 'c';
45 efl::eina::eina_value vchar(c);
46 ck_assert(efl::eina::get<char>(vchar) == 'c');
47
48 short s = 5;
49 efl::eina::eina_value vshort(s);
50 ck_assert(efl::eina::get<short>(vshort) == 5);
51
52 efl::eina::eina_value vint(6);
53 ck_assert(efl::eina::get<int>(vint) == 6);
54
55 efl::eina::eina_value vlong(7l);
56 ck_assert(efl::eina::get<long>(vlong) == 7l);
57
58 unsigned char uc = 'b';
59 efl::eina::eina_value vuchar(uc);
60 ck_assert(efl::eina::get<unsigned char>(vuchar) == 'b');
61
62 unsigned short us = 8;
63 efl::eina::eina_value vushort(us);
64 ck_assert(efl::eina::get<unsigned short>(vushort) == 8);
65
66 efl::eina::eina_value vuint(9u);
67 ck_assert(efl::eina::get<unsigned int>(vuint) == 9u);
68
69 efl::eina::eina_value vulong(10ul);
70 ck_assert(efl::eina::get<unsigned long>(vulong) == 10ul);
71
72 efl::eina::eina_value vu64((uint64_t)10ul);
73 ck_assert(efl::eina::get<uint64_t>(vu64) == 10ul);
74
75 efl::eina::eina_value vfloat(11.0f);
76 ck_assert(efl::eina::get<float>(vfloat) == 11.0f);
77
78 efl::eina::eina_value vdouble(12.0);
79 ck_assert(efl::eina::get<double>(vdouble) == 12.0f);
80}
81END_TEST
82
83START_TEST(eina_cxx_eina_value_wrong_get)
84{
85 efl::eina::eina_init init;
86
87 char c = 'c';
88 efl::eina::eina_value vchar(c);
89 try
90 {
91 efl::eina::get<int>(vchar);
92 std::abort();
93 }
94 catch(efl::eina::system_error const&)
95 {
96 }
97}
98END_TEST
99
100START_TEST(eina_cxx_eina_value_comparison_operators)
101{
102 efl::eina::eina_init init;
103
104 efl::eina::eina_value v;
105
106 char c = 5;
107 efl::eina::eina_value vchar(c);
108
109 short s = 5;
110 efl::eina::eina_value vshort(s);
111
112 efl::eina::eina_value vint(5);
113
114 efl::eina::eina_value vlong(5l);
115
116 unsigned char uc = 5;
117 efl::eina::eina_value vuchar(uc);
118
119 unsigned short us = 5;
120 efl::eina::eina_value vushort(us);
121
122 efl::eina::eina_value vuint(5u);
123
124 efl::eina::eina_value vulong(5ul);
125
126 efl::eina::eina_value vu64((uint64_t)5ul);
127
128 efl::eina::eina_value vfloat(5.0f);
129
130 efl::eina::eina_value vdouble(5.0);
131
132 ck_assert(vchar == vchar);
133 ck_assert(vshort == vshort);
134 ck_assert(vint == vint);
135 ck_assert(vlong == vlong);
136 ck_assert(vuchar == vuchar);
137 ck_assert(vushort == vushort);
138 ck_assert(vuint == vuint);
139 ck_assert(vulong == vulong);
140 ck_assert(vu64 == vu64);
141 ck_assert(vfloat == vfloat);
142 ck_assert(vdouble == vdouble);
143
144 ck_assert(vchar != vshort);
145 ck_assert(vshort != vint);
146 ck_assert(vint != vlong);
147 ck_assert(vlong != vuchar);
148 ck_assert(vuchar != vushort);
149 ck_assert(vushort != vuint);
150 ck_assert(vuint != vulong);
151 ck_assert(vulong != vfloat);
152 ck_assert(vfloat != vdouble);
153 ck_assert(vdouble != vchar);
154
155 ck_assert(vchar != vuchar);
156 ck_assert(vshort != vushort);
157 ck_assert(vint != vuint);
158 ck_assert(vlong != vulong);
159 ck_assert(vfloat != vdouble);
160 ck_assert(vdouble != vfloat);
161}
162END_TEST
163
164START_TEST(eina_cxx_eina_value_copying)
165{
166 char c = 5;
167
168 efl::eina::eina_value vchar(c);
169 efl::eina::eina_value vchar2(vchar);
170 ck_assert(vchar == vchar2);
171 ck_assert(efl::eina::get<char>(vchar) == 5);
172 ck_assert(efl::eina::get<char>(vchar2) == 5);
173
174 efl::eina::eina_value vint(10);
175 vchar = vint;
176 ck_assert(vchar != vchar2);
177 ck_assert(vint == vchar);
178 ck_assert(efl::eina::get<int>(vchar) == 10);
179 ck_assert(efl::eina::get<int>(vint) == 10);
180}
181END_TEST
182
183void
184eina_test_eina_value(TCase* tc)
185{
186 tcase_add_test(tc, eina_cxx_eina_value_constructors);
187 tcase_add_test(tc, eina_cxx_eina_value_get);
188 tcase_add_test(tc, eina_cxx_eina_value_wrong_get);
189 tcase_add_test(tc, eina_cxx_eina_value_comparison_operators);
190 tcase_add_test(tc, eina_cxx_eina_value_copying);
191}
diff --git a/src/tests/eina_cxx/eina_cxx_test_error.cc b/src/tests/eina_cxx/eina_cxx_test_error.cc
new file mode 100644
index 0000000000..fb3a6aa7ae
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_error.cc
@@ -0,0 +1,72 @@
1
2#include "Eina.hh"
3
4#include <check.h>
5
6Eina_Error my_error, my_error_2;
7
8START_TEST(eina_cxx_get_error)
9{
10 efl::eina::eina_init eina_init;
11
12 my_error = ::eina_error_msg_static_register("Message 1");
13
14 ::eina_error_set(0);
15
16 efl::eina::error_code ec1 = efl::eina::get_error_code();
17 ck_assert(!ec1);
18
19 ::eina_error_set(my_error);
20
21 efl::eina::error_code ec2 = efl::eina::get_error_code();
22 ck_assert(!!ec2);
23
24 ck_assert(ec2.message() == "Message 1");
25
26 ::eina_error_set(EINA_ERROR_OUT_OF_MEMORY);
27
28 efl::eina::error_code ec3 = efl::eina::get_error_code();
29 ck_assert(!!ec3);
30
31 ck_assert(ec3.message() == "Out of memory");
32}
33END_TEST
34
35START_TEST(eina_cxx_throw_on_error)
36{
37 efl::eina::eina_init eina_init;
38
39 ::eina_error_set(my_error_2);
40 my_error_2 = ::eina_error_msg_static_register("Message 2");
41
42 ::eina_error_set(0);
43 try
44 {
45 efl::eina::throw_on_error();
46 }
47 catch(std::exception const&)
48 {
49 std::abort();
50 }
51
52 ::eina_error_set(my_error_2);
53 try
54 {
55 efl::eina::throw_on_error();
56 std::abort();
57 }
58 catch(efl::eina::system_error const& e)
59 {
60 ck_assert(e.code().value() == my_error_2);
61 ck_assert(e.code().message() == "Message 2");
62 ck_assert(!efl::eina::get_error_code());
63 }
64}
65END_TEST
66
67void
68eina_test_error(TCase *tc)
69{
70 tcase_add_test(tc, eina_cxx_get_error);
71 tcase_add_test(tc, eina_cxx_throw_on_error);
72}
diff --git a/src/tests/eina_cxx/eina_cxx_test_inarray.cc b/src/tests/eina_cxx/eina_cxx_test_inarray.cc
new file mode 100644
index 0000000000..d2e526c45b
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_inarray.cc
@@ -0,0 +1,388 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5#include <functional>
6
7#include <iostream>
8
9#include <check.h>
10
11START_TEST(eina_cxx_inarray_pod_push_back)
12{
13 efl::eina::eina_init eina_init;
14
15 efl::eina::inarray<int> array;
16
17 array.push_back(5);
18 array.push_back(10);
19 array.push_back(15);
20
21 int result[] = {5, 10, 15};
22
23 ck_assert(array.size() == 3);
24 ck_assert(std::equal(array.begin(), array.end(), result));
25}
26END_TEST
27
28START_TEST(eina_cxx_inarray_pod_pop_back)
29{
30 efl::eina::eina_init eina_init;
31
32 efl::eina::inarray<int> array;
33
34 array.push_back(5);
35 array.push_back(10);
36 array.push_back(15);
37 array.pop_back();
38
39 int result[] = {5, 10};
40
41 ck_assert(array.size() == 2);
42 ck_assert(std::equal(array.begin(), array.end(), result));
43}
44END_TEST
45
46START_TEST(eina_cxx_inarray_pod_insert)
47{
48 efl::eina::eina_init eina_init;
49
50 efl::eina::inarray<int> array;
51
52 efl::eina::inarray<int>::iterator it;
53
54 it = array.insert(array.end(), 5); // first element
55 ck_assert(it != array.end());
56 ++it;
57 ck_assert(it == array.end());
58
59 it = array.insert(array.end(), 10); // equivalent to push_back
60 ck_assert(it != array.end());
61 ++it;
62 ck_assert(it == array.end());
63
64 it = array.insert(array.begin(), 15); // equivalent to push_front
65 ck_assert(it == array.begin());
66
67 it = array.end();
68 --it;
69 array.insert(it, 20); // insert before the last element
70
71 int result[] = {15, 5, 20, 10};
72
73 ck_assert(array.size() == 4);
74 ck_assert(std::equal(array.begin(), array.end(), result));
75
76 efl::eina::inarray<int> array2;
77 it = array2.insert(array2.end(), array.begin(), array.end());
78 ck_assert(it == array2.begin());
79 ck_assert(array == array2);
80
81 efl::eina::inarray<int> array3;
82 array3.push_back(1);
83 it = array3.insert(array3.end(), array.begin(), array.end());
84 ck_assert(array3.size() == 5);
85 ck_assert(array3.front() == 1);
86 it = array3.begin();
87 ++it;
88 ck_assert(std::equal(it, array3.end(), array.begin()));
89
90 efl::eina::inarray<int> array4;
91 array4.push_back(1);
92 it = array4.insert(array4.begin(), array.begin(), array.end());
93 ck_assert(array4.size() == 5);
94 ck_assert(array4.back() == 1);
95 ck_assert(std::equal(array.begin(), array.end(), array4.begin()));
96}
97END_TEST
98
99START_TEST(eina_cxx_inarray_pod_constructors)
100{
101 efl::eina::eina_init eina_init;
102
103 efl::eina::inarray<int> array1;
104 ck_assert(array1.empty());
105
106 efl::eina::inarray<int> array2(10, 5);
107 ck_assert(array2.size() == 10);
108 ck_assert(std::find_if(array2.begin(), array2.end()
109 , std::not1(std::bind1st(std::equal_to<int>(), 5))) == array2.end());
110
111 efl::eina::inarray<int> array3(array2);
112 ck_assert(array2 == array3);
113
114 efl::eina::inarray<int> array4(array2.begin(), array2.end());
115 ck_assert(array2 == array4);
116}
117END_TEST
118
119START_TEST(eina_cxx_inarray_pod_erase)
120{
121 efl::eina::eina_init eina_init;
122
123 efl::eina::inarray<int> array1;
124 array1.push_back(5);
125 array1.push_back(10);
126 array1.push_back(15);
127 array1.push_back(20);
128 array1.push_back(25);
129 array1.push_back(30);
130
131 efl::eina::inarray<int>::iterator it = array1.begin(), it2;
132
133 it = array1.erase(it);
134 ck_assert(it == array1.begin());
135 ck_assert(array1.size() == 5);
136 ck_assert(array1.front() == 10);
137
138 it = array1.begin() + 1;
139 ck_assert(*it == 15);
140 it = array1.erase(it);
141 ck_assert(*it == 20);
142 ck_assert(array1.size() == 4);
143
144 it = array1.end() - 1;
145 it = array1.erase(it);
146 ck_assert(it == array1.end());
147 ck_assert(array1.size() == 3);
148 ck_assert(array1.back() == 25);
149
150 it = array1.begin() + 1;
151 it2 = array1.end() - 1;
152 it = array1.erase(it, it2);
153 it2 = array1.end() -1;
154 ck_assert(it == it2);
155 ck_assert(array1.size() == 2);
156 ck_assert(array1.front() == 10);
157 ck_assert(array1.back() == 25);
158}
159END_TEST
160
161unsigned int constructors_called = 0u;
162unsigned int destructors_called = 0u;
163
164struct non_pod
165{
166 non_pod(int x)
167 : x(new int(x))
168 {
169 ++::constructors_called;
170 }
171 ~non_pod()
172 {
173 ++::destructors_called;
174 delete x;
175 }
176 non_pod(non_pod const& other)
177 {
178 ++::constructors_called;
179 x = new int(*other.x);
180 }
181 non_pod& operator=(non_pod const& other)
182 {
183 delete x;
184 x = new int(*other.x);
185 return *this;
186 }
187
188 int* x;
189};
190
191bool operator==(non_pod lhs, non_pod rhs)
192{
193 return *lhs.x == *rhs.x;
194}
195
196START_TEST(eina_cxx_inarray_nonpod_push_back)
197{
198 efl::eina::eina_init eina_init;
199 {
200 efl::eina::inarray<non_pod> array;
201
202 array.push_back(5);
203 array.push_back(10);
204 array.push_back(15);
205
206 int result[] = {5, 10, 15};
207
208 ck_assert(array.size() == 3);
209 ck_assert(std::equal(array.begin(), array.end(), result));
210 }
211 std::cout << "constructors called " << ::constructors_called
212 << "\ndestructors called " << ::destructors_called << std::endl;
213 ck_assert(::constructors_called == ::destructors_called);
214 ::constructors_called = ::destructors_called = 0;
215}
216END_TEST
217
218START_TEST(eina_cxx_inarray_nonpod_pop_back)
219{
220 {
221 efl::eina::eina_init eina_init;
222
223 efl::eina::inarray<non_pod> array;
224
225 array.push_back(5);
226 array.push_back(10);
227 array.push_back(15);
228 array.pop_back();
229
230 int result[] = {5, 10};
231
232 ck_assert(array.size() == 2);
233 ck_assert(std::equal(array.begin(), array.end(), result));
234 }
235 std::cout << "constructors called " << ::constructors_called
236 << "\ndestructors called " << ::destructors_called << std::endl;
237 ck_assert(::constructors_called == ::destructors_called);
238 ::constructors_called = ::destructors_called = 0;
239}
240END_TEST
241
242START_TEST(eina_cxx_inarray_nonpod_insert)
243{
244 {
245 efl::eina::eina_init eina_init;
246
247 efl::eina::inarray<non_pod> array;
248
249 efl::eina::inarray<non_pod>::iterator it;
250
251 it = array.insert(array.end(), 5); // first element
252 ck_assert(it != array.end());
253 ++it;
254 ck_assert(it == array.end());
255
256 it = array.insert(array.end(), 10); // equivalent to push_back
257 ck_assert(it != array.end());
258 ++it;
259 ck_assert(it == array.end());
260
261 it = array.insert(array.begin(), 15); // equivalent to push_front
262 ck_assert(it == array.begin());
263
264 it = array.end();
265 --it;
266 array.insert(it, 20); // insert before the last element
267
268 int result[] = {15, 5, 20, 10};
269
270 ck_assert(array.size() == 4);
271 ck_assert(std::equal(array.begin(), array.end(), result));
272
273 efl::eina::inarray<non_pod> array2;
274 it = array2.insert(array2.end(), array.begin(), array.end());
275 ck_assert(it == array2.begin());
276 ck_assert(array == array2);
277
278 efl::eina::inarray<non_pod> array3;
279 array3.push_back(1);
280 it = array3.insert(array3.end(), array.begin(), array.end());
281 ck_assert(array3.size() == 5);
282 ck_assert(array3.front() == 1);
283 it = array3.begin();
284 ++it;
285 ck_assert(std::equal(it, array3.end(), array.begin()));
286
287 efl::eina::inarray<non_pod> array4;
288 array4.push_back(1);
289 it = array4.insert(array4.begin(), array.begin(), array.end());
290 ck_assert(array4.size() == 5);
291 ck_assert(array4.back() == 1);
292 ck_assert(std::equal(array.begin(), array.end(), array4.begin()));
293 }
294 std::cout << "constructors called " << ::constructors_called
295 << "\ndestructors called " << ::destructors_called << std::endl;
296 ck_assert(::constructors_called == ::destructors_called);
297 ::constructors_called = ::destructors_called = 0;
298}
299END_TEST
300
301START_TEST(eina_cxx_inarray_nonpod_constructors)
302{
303 {
304 efl::eina::eina_init eina_init;
305
306 efl::eina::inarray<non_pod> array1;
307 ck_assert(array1.empty());
308
309 efl::eina::inarray<non_pod> array2(10, 5);
310 ck_assert(array2.size() == 10);
311 ck_assert(std::find_if(array2.begin(), array2.end()
312 , std::not1(std::bind1st(std::equal_to<non_pod>(), 5))) == array2.end());
313
314 efl::eina::inarray<non_pod> array3(array2);
315 ck_assert(array2 == array3);
316
317 efl::eina::inarray<non_pod> array4(array2.begin(), array2.end());
318 ck_assert(array2 == array4);
319 }
320 std::cout << "constructors called " << ::constructors_called
321 << "\ndestructors called " << ::destructors_called << std::endl;
322 ck_assert(::constructors_called == ::destructors_called);
323 ::constructors_called = ::destructors_called = 0;
324}
325END_TEST
326
327START_TEST(eina_cxx_inarray_nonpod_erase)
328{
329 {
330 efl::eina::eina_init eina_init;
331
332 efl::eina::inarray<non_pod> array1;
333 array1.push_back(5);
334 array1.push_back(10);
335 array1.push_back(15);
336 array1.push_back(20);
337 array1.push_back(25);
338 array1.push_back(30);
339
340 efl::eina::inarray<non_pod>::iterator it = array1.begin(), it2;
341
342 it = array1.erase(it);
343 ck_assert(it == array1.begin());
344 ck_assert(array1.size() == 5);
345 ck_assert(array1.front() == 10);
346
347 it = array1.begin() + 1;
348 ck_assert(*it == 15);
349 it = array1.erase(it);
350 ck_assert(*it == 20);
351 ck_assert(array1.size() == 4);
352
353 it = array1.end() - 1;
354 it = array1.erase(it);
355 ck_assert(it == array1.end());
356 ck_assert(array1.size() == 3);
357 ck_assert(array1.back() == 25);
358
359 it = array1.begin() + 1;
360 it2 = array1.end() - 1;
361 it = array1.erase(it, it2);
362 it2 = array1.end() -1;
363 ck_assert(it == it2);
364 ck_assert(array1.size() == 2);
365 ck_assert(array1.front() == 10);
366 ck_assert(array1.back() == 25);
367 }
368 std::cout << "constructors called " << ::constructors_called
369 << "\ndestructors called " << ::destructors_called << std::endl;
370 ck_assert(::constructors_called == ::destructors_called);
371 ::constructors_called = ::destructors_called = 0;
372}
373END_TEST
374
375void
376eina_test_inarray(TCase *tc)
377{
378 tcase_add_test(tc, eina_cxx_inarray_pod_push_back);
379 tcase_add_test(tc, eina_cxx_inarray_pod_pop_back);
380 tcase_add_test(tc, eina_cxx_inarray_pod_insert);
381 tcase_add_test(tc, eina_cxx_inarray_pod_erase);
382 tcase_add_test(tc, eina_cxx_inarray_pod_constructors);
383 tcase_add_test(tc, eina_cxx_inarray_nonpod_push_back);
384 tcase_add_test(tc, eina_cxx_inarray_nonpod_pop_back);
385 tcase_add_test(tc, eina_cxx_inarray_nonpod_insert);
386 tcase_add_test(tc, eina_cxx_inarray_nonpod_erase);
387 tcase_add_test(tc, eina_cxx_inarray_nonpod_constructors);
388}
diff --git a/src/tests/eina_cxx/eina_cxx_test_inlist.cc b/src/tests/eina_cxx/eina_cxx_test_inlist.cc
new file mode 100644
index 0000000000..09934f3f04
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_inlist.cc
@@ -0,0 +1,212 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5#include <functional>
6
7#include <check.h>
8
9START_TEST(eina_cxx_inlist_push_back)
10{
11 efl::eina::eina_init eina_init;
12
13 efl::eina::inlist<int> list;
14
15 list.push_back(5);
16 list.push_back(10);
17 list.push_back(15);
18
19 int result[] = {5, 10, 15};
20
21 ck_assert(list.size() == 3);
22 ck_assert(std::equal(list.begin(), list.end(), result));
23}
24END_TEST
25
26START_TEST(eina_cxx_inlist_pop_back)
27{
28 efl::eina::eina_init eina_init;
29
30 efl::eina::inlist<int> list;
31
32 list.push_back(5);
33 list.push_back(10);
34 list.push_back(15);
35 list.pop_back();
36
37 int result[] = {5, 10};
38
39 ck_assert(list.size() == 2);
40 ck_assert(std::equal(list.begin(), list.end(), result));
41}
42END_TEST
43
44START_TEST(eina_cxx_inlist_push_front)
45{
46 efl::eina::eina_init eina_init;
47
48 efl::eina::inlist<int> list;
49
50 list.push_front(5);
51 list.push_front(10);
52 list.push_front(15);
53
54 int result[] = {15, 10, 5};
55
56 ck_assert(list.size() == 3);
57 ck_assert(std::equal(list.begin(), list.end(), result));
58}
59END_TEST
60
61START_TEST(eina_cxx_inlist_pop_front)
62{
63 efl::eina::eina_init eina_init;
64
65 efl::eina::inlist<int> list;
66
67 list.push_front(5);
68 list.push_front(10);
69 list.push_front(15);
70 list.pop_front();
71
72 int result[] = {10, 5};
73
74 ck_assert(list.size() == 2);
75 ck_assert(std::equal(list.begin(), list.end(), result));
76}
77END_TEST
78
79START_TEST(eina_cxx_inlist_insert)
80{
81 efl::eina::eina_init eina_init;
82
83 efl::eina::inlist<int> list;
84
85 efl::eina::inlist<int>::iterator it;
86
87 it = list.insert(list.end(), 5); // first element
88 ck_assert(it != list.end());
89 ++it;
90 ck_assert(it == list.end());
91
92 it = list.insert(list.end(), 10); // equivalent to push_back
93 ck_assert(it != list.end());
94 ++it;
95 ck_assert(it == list.end());
96
97 it = list.insert(list.begin(), 15); // equivalent to push_front
98 ck_assert(it == list.begin());
99
100 it = list.end();
101 --it;
102 list.insert(it, 20); // insert before the last element
103
104 int result[] = {15, 5, 20, 10};
105
106 ck_assert(list.size() == 4);
107 ck_assert(std::equal(list.begin(), list.end(), result));
108
109 efl::eina::inlist<int> list2;
110 it = list2.insert(list2.end(), list.begin(), list.end());
111 ck_assert(it == list2.begin());
112 ck_assert(list == list2);
113
114 efl::eina::inlist<int> list3;
115 list3.push_back(1);
116 it = list3.insert(list3.end(), list.begin(), list.end());
117 ck_assert(list3.size() == 5);
118 ck_assert(list3.front() == 1);
119 it = list3.begin();
120 ++it;
121 ck_assert(std::equal(it, list3.end(), list.begin()));
122
123 efl::eina::inlist<int> list4;
124 list4.push_back(1);
125 it = list4.insert(list4.begin(), list.begin(), list.end());
126 ck_assert(list4.size() == 5);
127 ck_assert(list4.back() == 1);
128 ck_assert(std::equal(list.begin(), list.end(), list4.begin()));
129}
130END_TEST
131
132START_TEST(eina_cxx_inlist_constructors)
133{
134 efl::eina::eina_init eina_init;
135
136 efl::eina::inlist<int> list1;
137 ck_assert(list1.empty());
138
139 efl::eina::inlist<int> list2(10, 5);
140 ck_assert(list2.size() == 10);
141 ck_assert(std::find_if(list2.begin(), list2.end()
142 , std::not1(std::bind1st(std::equal_to<int>(), 5))) == list2.end());
143
144 efl::eina::inlist<int> list3(list2);
145 ck_assert(list2 == list3);
146
147 efl::eina::inlist<int> list4(list2.begin(), list2.end());
148 ck_assert(list2 == list4);
149}
150END_TEST
151
152START_TEST(eina_cxx_inlist_erase)
153{
154 efl::eina::eina_init eina_init;
155
156 efl::eina::inlist<int> list1;
157 list1.push_back(5);
158 list1.push_back(10);
159 list1.push_back(15);
160 list1.push_back(20);
161 list1.push_back(25);
162 list1.push_back(30);
163
164 efl::eina::inlist<int>::iterator it = list1.begin(), it2;
165
166 it = list1.erase(it);
167 ck_assert(it == list1.begin());
168 ck_assert(list1.size() == 5);
169 ck_assert(list1.front() == 10);
170
171 it = list1.begin();
172 it2 = list1.begin();
173 ++it;
174 ++it2; ++it2;
175 ck_assert(*it2 == 20);
176 it = list1.erase(it);
177 ck_assert(it == it2);
178 ck_assert(list1.size() == 4);
179 ck_assert(*it2 == 20);
180
181 it = list1.end();
182 --it;
183 it = list1.erase(it);
184 ck_assert(it == list1.end());
185 ck_assert(list1.size() == 3);
186 ck_assert(list1.back() == 25);
187
188 it = list1.begin();
189 ++it;
190 it2 = list1.end();
191 --it2;
192 it = list1.erase(it, it2);
193 it2 = list1.end();
194 --it2;
195 ck_assert(it == it2);
196 ck_assert(list1.size() == 2);
197 ck_assert(list1.front() == 10);
198 ck_assert(list1.back() == 25);
199}
200END_TEST
201
202void
203eina_test_inlist(TCase *tc)
204{
205 tcase_add_test(tc, eina_cxx_inlist_push_back);
206 tcase_add_test(tc, eina_cxx_inlist_push_front);
207 tcase_add_test(tc, eina_cxx_inlist_pop_back);
208 tcase_add_test(tc, eina_cxx_inlist_pop_front);
209 tcase_add_test(tc, eina_cxx_inlist_insert);
210 tcase_add_test(tc, eina_cxx_inlist_erase);
211 tcase_add_test(tc, eina_cxx_inlist_constructors);
212}
diff --git a/src/tests/eina_cxx/eina_cxx_test_iterator.cc b/src/tests/eina_cxx/eina_cxx_test_iterator.cc
new file mode 100644
index 0000000000..ee4b356a7b
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_iterator.cc
@@ -0,0 +1,34 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5
6#include <check.h>
7
8START_TEST(eina_cxx_iterator_equal)
9{
10 efl::eina::eina_init eina_init;
11
12 efl::eina::ptr_list<int> list;
13 ck_assert(list.size() == 0);
14 ck_assert(list.empty());
15
16 list.push_back(new int(5));
17 list.push_back(new int(10));
18 list.push_back(new int(15));
19 list.push_back(new int(20));
20
21 efl::eina::iterator<int> iterator = list.ibegin()
22 , last_iterator = list.iend();
23
24 int result[] = {5, 10, 15, 20};
25
26 ck_assert(std::equal(iterator, last_iterator, result));
27}
28END_TEST
29
30void
31eina_test_iterator(TCase *tc)
32{
33 tcase_add_test(tc, eina_cxx_iterator_equal);
34}
diff --git a/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc b/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc
new file mode 100644
index 0000000000..4e9a13b933
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_ptrarray.cc
@@ -0,0 +1,180 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5
6#include <check.h>
7
8START_TEST(eina_cxx_ptrarray_push_back)
9{
10 efl::eina::eina_init eina_init;
11
12 efl::eina::ptr_array<int> array;
13
14 array.push_back(new int(5));
15 array.push_back(new int(10));
16 array.push_back(new int(15));
17
18 int result[] = {5, 10, 15};
19
20 ck_assert(array.size() == 3);
21 ck_assert(std::equal(array.begin(), array.end(), result));
22}
23END_TEST
24
25START_TEST(eina_cxx_ptrarray_pop_back)
26{
27 efl::eina::eina_init eina_init;
28
29 efl::eina::ptr_array<int> array;
30
31 array.push_back(new int(5));
32 array.push_back(new int(10));
33 array.push_back(new int(15));
34 array.pop_back();
35
36 int result[] = {5, 10};
37
38 ck_assert(array.size() == 2);
39 ck_assert(std::equal(array.begin(), array.end(), result));
40}
41END_TEST
42
43START_TEST(eina_cxx_ptrarray_insert)
44{
45 efl::eina::eina_init eina_init;
46
47 efl::eina::ptr_array<int> array;
48 ck_assert(std::distance(array.begin(), array.end()) == 0u);
49
50 efl::eina::ptr_array<int>::iterator it;
51
52 it = array.insert(array.end(), new int(5)); // first element
53 ck_assert(it != array.end());
54 ++it;
55 ck_assert(it == array.end());
56 ck_assert(array[0] == 5);
57 ck_assert(std::distance(array.begin(), array.end()) == 1u);
58
59 it = array.insert(array.end(), new int(10)); // equivalent to push_back
60 ck_assert(it != array.end());
61 ++it;
62 ck_assert(it == array.end());
63 ck_assert(array[0] == 5);
64 ck_assert(array[1] == 10);
65 ck_assert(std::distance(array.begin(), array.end()) == 2u);
66
67 it = array.insert(array.begin(), new int(15)); // equivalent to push_front
68 ck_assert(it == array.begin());
69
70 ck_assert(array[1] == 5);
71 ck_assert(array[2] == 10);
72 ck_assert(array[0] == 15);
73 ck_assert(std::distance(array.begin(), array.end()) == 3u);
74
75 array.insert(array.end() - 1, new int(20)); // insert before the last element
76 ck_assert(array[0] == 15);
77 ck_assert(array[1] == 5);
78 ck_assert(array[2] == 20);
79 ck_assert(array[3] == 10);
80 ck_assert(std::distance(array.begin(), array.end()) == 4u);
81
82 int result[] = {15, 5, 20, 10};
83
84 ck_assert(array.size() == 4);
85 ck_assert(std::distance(array.begin(), array.end()) == 4u);
86 ck_assert(std::equal(array.begin(), array.end(), result));
87
88 efl::eina::ptr_array<int, efl::eina::heap_copy_allocator> array2;
89 it = array2.insert(array2.end(), array.begin(), array.end());
90 ck_assert(it == array2.begin());
91 ck_assert(array == array2);
92
93
94 efl::eina::ptr_array<int, efl::eina::heap_copy_allocator> array3;
95 array3.push_back(1);
96 it = array3.insert(array3.end(), array.begin(), array.end());
97 ck_assert(array3.size() == 5);
98 ck_assert(array3.front() == 1);
99 it = array3.begin();
100 ++it;
101 ck_assert(std::equal(it, array3.end(), array.begin()));
102
103 efl::eina::ptr_array<int, efl::eina::heap_copy_allocator> array4;
104 array4.push_back(1);
105 it = array4.insert(array4.begin(), array.begin(), array.end());
106 ck_assert(array4.size() == 5);
107 ck_assert(array4.back() == 1);
108 ck_assert(std::equal(array.begin(), array.end(), array4.begin()));
109}
110END_TEST
111
112START_TEST(eina_cxx_ptrarray_constructors)
113{
114 efl::eina::eina_init eina_init;
115
116 efl::eina::ptr_array<int> array1;
117 ck_assert(array1.empty());
118
119 efl::eina::ptr_array<int, efl::eina::heap_copy_allocator> array2(10, 5);
120 ck_assert(array2.size() == 10);
121 ck_assert(std::find_if(array2.begin(), array2.end()
122 , std::not1(std::bind1st(std::equal_to<int>(), 5))) == array2.end());
123
124 efl::eina::ptr_array<int, efl::eina::heap_copy_allocator> array3(array2);
125 ck_assert(array2 == array3);
126
127 efl::eina::ptr_array<int, efl::eina::heap_copy_allocator> array4
128 (array2.begin(), array2.end());
129 ck_assert(array2 == array4);
130}
131END_TEST
132
133START_TEST(eina_cxx_ptrarray_erase)
134{
135 efl::eina::eina_init eina_init;
136
137 efl::eina::ptr_array<int> array1;
138 array1.push_back(new int(5));
139 array1.push_back(new int(10));
140 array1.push_back(new int(15));
141 array1.push_back(new int(20));
142 array1.push_back(new int(25));
143 array1.push_back(new int(30));
144
145 int result[] = {5, 10, 15, 20, 25, 30};
146 ck_assert(std::equal(array1.begin(), array1.end(), result));
147
148 efl::eina::ptr_array<int>::iterator it = array1.erase(array1.begin());
149 ck_assert(it == array1.begin());
150 ck_assert(array1.size() == 5);
151 ck_assert(array1.front() == 10);
152
153 ck_assert(std::equal(array1.begin(), array1.end(), &result[1]));
154
155 it = array1.erase(array1.begin() + 1);
156 ck_assert(*it == 20);
157 ck_assert(array1.size() == 4);
158
159 it = array1.erase(array1.end() - 1);
160 ck_assert(it == array1.end());
161 ck_assert(array1.size() == 3);
162 ck_assert(array1.back() == 25);
163
164 it = array1.erase(array1.begin() + 1, array1.end() - 1);
165 ck_assert(it == array1.end() - 1);
166 ck_assert(array1.size() == 2);
167 ck_assert(array1.front() == 10);
168 ck_assert(array1.back() == 25);
169}
170END_TEST
171
172void
173eina_test_ptrarray(TCase* tc)
174{
175 tcase_add_test(tc, eina_cxx_ptrarray_push_back);
176 tcase_add_test(tc, eina_cxx_ptrarray_pop_back);
177 tcase_add_test(tc, eina_cxx_ptrarray_insert);
178 tcase_add_test(tc, eina_cxx_ptrarray_constructors);
179 tcase_add_test(tc, eina_cxx_ptrarray_erase);
180}
diff --git a/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc b/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc
new file mode 100644
index 0000000000..c95adc3b21
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_ptrlist.cc
@@ -0,0 +1,212 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5
6#include <check.h>
7
8START_TEST(eina_cxx_ptrlist_push_back)
9{
10 efl::eina::eina_init eina_init;
11
12 efl::eina::ptr_list<int> list;
13
14 list.push_back(new int(5));
15 list.push_back(new int(10));
16 list.push_back(new int(15));
17
18 int result[] = {5, 10, 15};
19
20 ck_assert(list.size() == 3);
21 ck_assert(std::equal(list.begin(), list.end(), result));
22}
23END_TEST
24
25START_TEST(eina_cxx_ptrlist_pop_back)
26{
27 efl::eina::eina_init eina_init;
28
29 efl::eina::ptr_list<int> list;
30
31 list.push_back(new int(5));
32 list.push_back(new int(10));
33 list.push_back(new int(15));
34 list.pop_back();
35
36 int result[] = {5, 10};
37
38 ck_assert(list.size() == 2);
39 ck_assert(std::equal(list.begin(), list.end(), result));
40}
41END_TEST
42
43START_TEST(eina_cxx_ptrlist_push_front)
44{
45 efl::eina::eina_init eina_init;
46
47 efl::eina::ptr_list<int> list;
48
49 list.push_front(new int(5));
50 list.push_front(new int(10));
51 list.push_front(new int(15));
52
53 int result[] = {15, 10, 5};
54
55 ck_assert(list.size() == 3);
56 ck_assert(std::equal(list.begin(), list.end(), result));
57}
58END_TEST
59
60START_TEST(eina_cxx_ptrlist_pop_front)
61{
62 efl::eina::eina_init eina_init;
63
64 efl::eina::ptr_list<int> list;
65
66 list.push_front(new int(5));
67 list.push_front(new int(10));
68 list.push_front(new int(15));
69 list.pop_front();
70
71 int result[] = {10, 5};
72
73 ck_assert(list.size() == 2);
74 ck_assert(std::equal(list.begin(), list.end(), result));
75}
76END_TEST
77
78START_TEST(eina_cxx_ptrlist_insert)
79{
80 efl::eina::eina_init eina_init;
81
82 efl::eina::ptr_list<int> list;
83
84 efl::eina::ptr_list<int>::iterator it;
85
86 it = list.insert(list.end(), new int(5)); // first element
87 ck_assert(it != list.end());
88 ++it;
89 ck_assert(it == list.end());
90
91 it = list.insert(list.end(), new int(10)); // equivalent to push_back
92 ck_assert(it != list.end());
93 ++it;
94 ck_assert(it == list.end());
95
96 it = list.insert(list.begin(), new int(15)); // equivalent to push_front
97 ck_assert(it == list.begin());
98
99 it = list.end();
100 --it;
101 list.insert(it, new int(20)); // insert before the last element
102
103 int result[] = {15, 5, 20, 10};
104
105 ck_assert(list.size() == 4);
106 ck_assert(std::equal(list.begin(), list.end(), result));
107
108 efl::eina::ptr_list<int, efl::eina::heap_copy_allocator> list2;
109 it = list2.insert(list2.end(), list.begin(), list.end());
110 ck_assert(it == list2.begin());
111 ck_assert(list == list2);
112
113 efl::eina::ptr_list<int, efl::eina::heap_copy_allocator> list3;
114 list3.push_back(1);
115 it = list3.insert(list3.end(), list.begin(), list.end());
116 ck_assert(list3.size() == 5);
117 ck_assert(list3.front() == 1);
118 it = list3.begin();
119 ++it;
120 ck_assert(std::equal(it, list3.end(), list.begin()));
121
122 efl::eina::ptr_list<int, efl::eina::heap_copy_allocator> list4;
123 list4.push_back(1);
124 it = list4.insert(list4.begin(), list.begin(), list.end());
125 ck_assert(list4.size() == 5);
126 ck_assert(list4.back() == 1);
127 ck_assert(std::equal(list.begin(), list.end(), list4.begin()));
128}
129END_TEST
130
131START_TEST(eina_cxx_ptrlist_constructors)
132{
133 efl::eina::eina_init eina_init;
134
135 efl::eina::ptr_list<int> list1;
136 ck_assert(list1.empty());
137
138 efl::eina::ptr_list<int, efl::eina::heap_copy_allocator> list2(10, 5);
139 ck_assert(list2.size() == 10);
140 ck_assert(std::find_if(list2.begin(), list2.end()
141 , std::not1(std::bind1st(std::equal_to<int>(), 5))) == list2.end());
142
143 efl::eina::ptr_list<int, efl::eina::heap_copy_allocator> list3(list2);
144 ck_assert(list2 == list3);
145
146 efl::eina::ptr_list<int, efl::eina::heap_copy_allocator> list4
147 (list2.begin(), list2.end());
148 ck_assert(list2 == list4);
149}
150END_TEST
151
152START_TEST(eina_cxx_ptrlist_erase)
153{
154 efl::eina::eina_init eina_init;
155
156 efl::eina::ptr_list<int> list1;
157 list1.push_back(new int(5));
158 list1.push_back(new int(10));
159 list1.push_back(new int(15));
160 list1.push_back(new int(20));
161 list1.push_back(new int(25));
162 list1.push_back(new int(30));
163
164 efl::eina::ptr_list<int>::iterator it = list1.begin(), it2;
165
166 it = list1.erase(it);
167 ck_assert(it == list1.begin());
168 ck_assert(list1.size() == 5);
169 ck_assert(list1.front() == 10);
170
171 it = list1.begin();
172 it2 = list1.begin();
173 ++it;
174 ++it2; ++it2;
175 ck_assert(*it2 == 20);
176 it = list1.erase(it);
177 ck_assert(it == it2);
178 ck_assert(list1.size() == 4);
179 ck_assert(*it2 == 20);
180
181 it = list1.end();
182 --it;
183 it = list1.erase(it);
184 ck_assert(it == list1.end());
185 ck_assert(list1.size() == 3);
186 ck_assert(list1.back() == 25);
187
188 it = list1.begin();
189 ++it;
190 it2 = list1.end();
191 --it2;
192 it = list1.erase(it, it2);
193 it2 = list1.end();
194 --it2;
195 ck_assert(it == it2);
196 ck_assert(list1.size() == 2);
197 ck_assert(list1.front() == 10);
198 ck_assert(list1.back() == 25);
199}
200END_TEST
201
202void
203eina_test_ptrlist(TCase* tc)
204{
205 tcase_add_test(tc, eina_cxx_ptrlist_push_back);
206 tcase_add_test(tc, eina_cxx_ptrlist_pop_back);
207 tcase_add_test(tc, eina_cxx_ptrlist_push_front);
208 tcase_add_test(tc, eina_cxx_ptrlist_pop_front);
209 tcase_add_test(tc, eina_cxx_ptrlist_insert);
210 tcase_add_test(tc, eina_cxx_ptrlist_constructors);
211 tcase_add_test(tc, eina_cxx_ptrlist_erase);
212}
diff --git a/src/tests/eina_cxx/eina_cxx_test_stringshare.cc b/src/tests/eina_cxx/eina_cxx_test_stringshare.cc
new file mode 100644
index 0000000000..1215431712
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_stringshare.cc
@@ -0,0 +1,32 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5#include <functional>
6
7#include <check.h>
8
9START_TEST(eina_cxx_stringshare_constructors)
10{
11 efl::eina::eina_init eina_init;
12
13 efl::eina::stringshare string1;
14 ck_assert(string1.empty());
15
16 efl::eina::stringshare string2("string");
17 ck_assert(string2.size() == 6);
18 ck_assert(string2 == "string");
19
20 efl::eina::stringshare string3(string2);
21 ck_assert(string2 == string3);
22
23 efl::eina::stringshare string4(string3.begin(), string3.end());
24 ck_assert(string2 == string3);
25}
26END_TEST
27
28void
29eina_test_stringshare(TCase *tc)
30{
31 tcase_add_test(tc, eina_cxx_stringshare_constructors);
32}
diff --git a/src/tests/eina_cxx/eina_cxx_test_thread.cc b/src/tests/eina_cxx/eina_cxx_test_thread.cc
new file mode 100644
index 0000000000..1a749359b2
--- /dev/null
+++ b/src/tests/eina_cxx/eina_cxx_test_thread.cc
@@ -0,0 +1,127 @@
1
2#include "Eina.hh"
3
4#include <algorithm>
5
6#include <check.h>
7
8bool no_args = false
9 , args_1 = false
10 , args_2 = false;
11
12void thread_no_args()
13{
14 no_args = true;
15}
16
17struct test
18{
19 int x;
20};
21
22void thread_1_arg(int a0)
23{
24 args_1 = true;
25 ck_assert(a0 == 5);
26}
27
28void thread_2_arg(int a0, test t)
29{
30 args_2 = true;
31 ck_assert(a0 == 5);
32 ck_assert(t.x == 10);
33}
34
35START_TEST(eina_cxx_thread_constructors)
36{
37 efl::eina::eina_init init;
38 efl::eina::eina_threads_init threads_init;
39 {
40 efl::eina::thread default_constructed_thread;
41 ck_assert(default_constructed_thread.get_id() == efl::eina::thread::id());
42 }
43
44 {
45 efl::eina::thread thread_no_args(&::thread_no_args);
46 thread_no_args.join();
47 ck_assert( ::no_args);
48 }
49
50 {
51 efl::eina::thread thread_1_arg(&::thread_1_arg, 5);
52 thread_1_arg.join();
53 ck_assert( ::args_1);
54 }
55
56 {
57 test t = {10};
58 efl::eina::thread thread_2_arg(&::thread_2_arg, 5, t);
59 thread_2_arg.join();
60 ck_assert( ::args_2);
61 }
62}
63END_TEST
64
65START_TEST(eina_cxx_thread_mutexes)
66{
67 efl::eina::mutex m;
68
69 {
70 efl::eina::unique_lock<efl::eina::mutex> lock1(m);
71 ck_assert(lock1.owns_lock());
72
73 lock1.unlock();
74 ck_assert(!lock1.owns_lock());
75
76 ck_assert(lock1.try_lock());
77 ck_assert(lock1.owns_lock());
78 lock1.unlock();
79
80 lock1.lock();
81 ck_assert(lock1.owns_lock());
82 }
83
84 {
85 efl::eina::lock_guard<efl::eina::mutex> lock1(m);
86 }
87}
88END_TEST
89
90bool b = false;
91
92void condition_thread(efl::eina::mutex& condition_mutex
93 , efl::eina::condition_variable& condition_condition)
94{
95 efl::eina::unique_lock<efl::eina::mutex> l( condition_mutex);
96 b = true;
97 condition_condition.notify_one();
98}
99
100START_TEST(eina_cxx_thread_conditional)
101{
102 efl::eina::mutex m;
103
104 efl::eina::mutex condition_mutex;
105 efl::eina::condition_variable condition_condition;
106
107 efl::eina::unique_lock<efl::eina::mutex> l( condition_mutex);
108 efl::eina::thread thread(&condition_thread, std::ref(condition_mutex), std::ref(condition_condition));
109
110 while(!b)
111 {
112 ck_assert(l.owns_lock());
113 condition_condition.wait(l);
114 ck_assert(l.owns_lock());
115 }
116
117 thread.join();
118}
119END_TEST
120
121void
122eina_test_thread(TCase* tc)
123{
124 tcase_add_test(tc, eina_cxx_thread_constructors);
125 tcase_add_test(tc, eina_cxx_thread_mutexes);
126 tcase_add_test(tc, eina_cxx_thread_conditional);
127}