31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
#include <vector>
|
|
20 |
#include <algorithm>
|
|
21 |
#include <vector>
|
|
22 |
#include <string>
|
|
23 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
24 |
# include <rope>
|
|
25 |
#endif
|
|
26 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
27 |
# include <slist>
|
|
28 |
#endif
|
|
29 |
#include <list>
|
|
30 |
#include <deque>
|
|
31 |
#include <set>
|
|
32 |
#include <map>
|
|
33 |
#if defined (STLPORT)
|
|
34 |
# include <unordered_set>
|
|
35 |
# include <unordered_map>
|
|
36 |
#endif
|
|
37 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
38 |
# include <hash_set>
|
|
39 |
# include <hash_map>
|
|
40 |
#endif
|
|
41 |
#include <queue>
|
|
42 |
#include <stack>
|
|
43 |
//#include <iostream>
|
|
44 |
|
|
45 |
#include "cppunit/cppunit_proxy.h"
|
|
46 |
|
|
47 |
#if !defined (STLPORT) || defined(_STLP_USE_NAMESPACES)
|
|
48 |
using namespace std;
|
|
49 |
#endif
|
|
50 |
|
|
51 |
//
|
|
52 |
// TestCase class
|
|
53 |
//
|
|
54 |
class MoveConstructorTest : public CPPUNIT_NS::TestCase
|
|
55 |
{
|
|
56 |
CPPUNIT_TEST_SUITE(MoveConstructorTest);
|
|
57 |
CPPUNIT_TEST(move_construct_test);
|
|
58 |
CPPUNIT_TEST(deque_test);
|
|
59 |
#if defined (__DMC__)
|
|
60 |
CPPUNIT_IGNORE;
|
|
61 |
#endif
|
|
62 |
CPPUNIT_TEST(vector_test);
|
|
63 |
CPPUNIT_STOP_IGNORE;
|
|
64 |
CPPUNIT_TEST(move_traits);
|
|
65 |
#if !defined (STLPORT) || defined (_STLP_NO_MOVE_SEMANTIC) || \
|
|
66 |
defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) || \
|
|
67 |
defined (__BORLANDC__) || defined (__DMC__)
|
|
68 |
CPPUNIT_IGNORE;
|
|
69 |
# endif
|
|
70 |
CPPUNIT_TEST(movable_declaration)
|
|
71 |
#if defined (__BORLANDC__)
|
|
72 |
CPPUNIT_STOP_IGNORE;
|
|
73 |
CPPUNIT_TEST(nb_destructor_calls);
|
|
74 |
#endif
|
|
75 |
CPPUNIT_TEST_SUITE_END();
|
|
76 |
|
|
77 |
protected:
|
|
78 |
void move_construct_test();
|
|
79 |
void deque_test();
|
|
80 |
void vector_test();
|
|
81 |
void move_traits();
|
|
82 |
void movable_declaration();
|
|
83 |
void nb_destructor_calls();
|
|
84 |
|
|
85 |
/*
|
|
86 |
template <class _Container>
|
|
87 |
void standard_test1(_Container const& ref_cont) {
|
|
88 |
vector<_Container> vec_cont(1, ref_cont);
|
|
89 |
typedef typename _Container::value_type value_type;
|
|
90 |
value_type *pvalue = &(*vec_cont.front().begin());
|
|
91 |
size_t cur_capacity= vec_cont.capacity();
|
|
92 |
//force reallocation
|
|
93 |
while (cur_capacity == vec_cont.capacity()) {
|
|
94 |
vec_cont.push_back(ref_cont);
|
|
95 |
}
|
|
96 |
bool b=( (pvalue==(&(*vec_cont.front().begin()))) );
|
|
97 |
CPPUNIT_ASSERT(b);
|
|
98 |
}
|
|
99 |
*/
|
|
100 |
};
|
|
101 |
|
|
102 |
CPPUNIT_TEST_SUITE_REGISTRATION(MoveConstructorTest);
|
|
103 |
|
|
104 |
//
|
|
105 |
// tests implementation
|
|
106 |
//
|
|
107 |
void MoveConstructorTest::move_construct_test()
|
|
108 |
{
|
|
109 |
//cout << "vector<vector<int>>";
|
|
110 |
vector<int> const ref_vec(10, 0);
|
|
111 |
vector<vector<int> > v_v_ints(1, ref_vec);
|
|
112 |
|
|
113 |
int *pint = &(v_v_ints.front().front());
|
|
114 |
|
|
115 |
size_t cur_capacity = v_v_ints.capacity();
|
|
116 |
while (v_v_ints.capacity() <= cur_capacity) {
|
|
117 |
v_v_ints.push_back(ref_vec);
|
|
118 |
}
|
|
119 |
|
|
120 |
//v_v_ints has been resized
|
|
121 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
122 |
CPPUNIT_ASSERT((pint == &v_v_ints.front().front()));
|
|
123 |
#endif
|
|
124 |
|
|
125 |
//cout << "vector<vector<int>>::erase";
|
|
126 |
//We need at least 3 elements:
|
|
127 |
while (v_v_ints.size() < 3) {
|
|
128 |
v_v_ints.push_back(ref_vec);
|
|
129 |
}
|
|
130 |
|
|
131 |
//We erase the 2nd
|
|
132 |
pint = &v_v_ints[2].front();
|
|
133 |
v_v_ints.erase(v_v_ints.begin() + 1);
|
|
134 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
135 |
CPPUNIT_ASSERT((pint == &v_v_ints[1].front()));
|
|
136 |
#endif
|
|
137 |
|
|
138 |
//cout << "vector<string>";
|
|
139 |
string const ref_str("ref string, big enough to be a dynamic one");
|
|
140 |
vector<string> vec_strs(1, ref_str);
|
|
141 |
|
|
142 |
char const* pstr = vec_strs.front().c_str();
|
|
143 |
cur_capacity = vec_strs.capacity();
|
|
144 |
while (vec_strs.capacity() <= cur_capacity) {
|
|
145 |
vec_strs.push_back(ref_str);
|
|
146 |
}
|
|
147 |
|
|
148 |
//vec_str has been resized
|
|
149 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
150 |
CPPUNIT_ASSERT((pstr == vec_strs.front().c_str()));
|
|
151 |
#endif
|
|
152 |
|
|
153 |
//cout << "vector<string>::erase";
|
|
154 |
//We need at least 3 elements:
|
|
155 |
while (vec_strs.size() < 3) {
|
|
156 |
vec_strs.push_back(ref_str);
|
|
157 |
}
|
|
158 |
|
|
159 |
//We erase the 2nd
|
|
160 |
pstr = vec_strs[2].c_str();
|
|
161 |
vec_strs.erase(vec_strs.begin() + 1);
|
|
162 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
163 |
CPPUNIT_ASSERT((pstr == vec_strs[1].c_str()));
|
|
164 |
#endif
|
|
165 |
|
|
166 |
//cout << "swap(vector<int>, vector<int>)";
|
|
167 |
vector<int> elem1(10, 0), elem2(10, 0);
|
|
168 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
169 |
int *p1 = &elem1.front();
|
|
170 |
int *p2 = &elem2.front();
|
|
171 |
#endif
|
|
172 |
swap(elem1, elem2);
|
|
173 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
174 |
CPPUNIT_ASSERT(((p1 == &elem2.front()) && (p2 == &elem1.front())));
|
|
175 |
#endif
|
|
176 |
|
|
177 |
{
|
|
178 |
vector<bool> bit_vec(5, true);
|
|
179 |
bit_vec.insert(bit_vec.end(), 5, false);
|
|
180 |
vector<vector<bool> > v_v_bits(1, bit_vec);
|
|
181 |
|
|
182 |
/*
|
|
183 |
* This is a STLport specific test as we are using internal implementation
|
|
184 |
* details to check that the move has been correctly handled. For other
|
|
185 |
* STL implementation it is only a compile check.
|
|
186 |
*/
|
|
187 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
188 |
# if defined (_STLP_DEBUG)
|
|
189 |
unsigned int *punit = v_v_bits.front().begin()._M_iterator._M_p;
|
|
190 |
# else
|
|
191 |
unsigned int *punit = v_v_bits.front().begin()._M_p;
|
|
192 |
# endif
|
|
193 |
#endif
|
|
194 |
|
|
195 |
cur_capacity = v_v_bits.capacity();
|
|
196 |
while (v_v_bits.capacity() <= cur_capacity) {
|
|
197 |
v_v_bits.push_back(bit_vec);
|
|
198 |
}
|
|
199 |
|
|
200 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
201 |
//v_v_bits has been resized
|
|
202 |
# if defined (_STLP_DEBUG)
|
|
203 |
CPPUNIT_ASSERT( punit == v_v_bits.front().begin()._M_iterator._M_p );
|
|
204 |
# else
|
|
205 |
CPPUNIT_ASSERT( punit == v_v_bits.front().begin()._M_p );
|
|
206 |
# endif
|
|
207 |
#endif
|
|
208 |
}
|
|
209 |
|
|
210 |
// zero: don't like this kind of tests
|
|
211 |
// because of template test function
|
|
212 |
// we should find another way to provide
|
|
213 |
// move constructor testing...
|
|
214 |
|
|
215 |
/*
|
|
216 |
standard_test1(list<int>(10));
|
|
217 |
|
|
218 |
|
|
219 |
standard_test1(slist<int>(10));
|
|
220 |
|
|
221 |
standard_test1(deque<int>(10));
|
|
222 |
*/
|
|
223 |
|
|
224 |
/*
|
|
225 |
int int_values[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
|
226 |
|
|
227 |
set<int> int_set(int_values, int_values + sizeof(in_values) / sizeof(int));
|
|
228 |
standard_test1(int_set);
|
|
229 |
|
|
230 |
multiset<int> int_multiset(int_values, int_values + sizeof(in_values) / sizeof(int));
|
|
231 |
standard_test1(int_multiset);
|
|
232 |
*/
|
|
233 |
|
|
234 |
/*
|
|
235 |
CheckFullMoveSupport(string());
|
|
236 |
CheckFullMoveSupport(vector<int>());
|
|
237 |
CheckFullMoveSupport(deque<int>());
|
|
238 |
CheckFullMoveSupport(list<int>());
|
|
239 |
CheckFullMoveSupport(slist<int>());
|
|
240 |
*/
|
|
241 |
}
|
|
242 |
|
|
243 |
void MoveConstructorTest::deque_test()
|
|
244 |
{
|
|
245 |
//Check the insert range method.
|
|
246 |
//To the front:
|
|
247 |
{
|
|
248 |
# if !defined (STLPORT) || !defined (_STLP_DEBUG) || !defined (_STLP_NO_MEMBER_TEMPLATES)
|
|
249 |
deque<vector<int> > vect_deque;
|
|
250 |
vector<int*> bufs;
|
|
251 |
vect_deque.assign(3, vector<int>(10));
|
|
252 |
bufs.push_back(&vect_deque[0].front());
|
|
253 |
bufs.push_back(&vect_deque[1].front());
|
|
254 |
bufs.push_back(&vect_deque[2].front());
|
|
255 |
|
|
256 |
int nb_insert = 5;
|
|
257 |
//Initialize to 1 to generate a front insertion:
|
|
258 |
int pos = 1;
|
|
259 |
while (nb_insert--) {
|
|
260 |
vector<vector<int> > vect_vect(2, vector<int>(10));
|
|
261 |
vect_deque.insert(vect_deque.begin() + pos, vect_vect.begin(), vect_vect.end());
|
|
262 |
bufs.insert(bufs.begin() + pos, &vect_deque[pos].front());
|
|
263 |
bufs.insert(bufs.begin() + pos + 1, &vect_deque[pos + 1].front());
|
|
264 |
++pos;
|
|
265 |
}
|
|
266 |
CPPUNIT_ASSERT( vect_deque.size() == 13 );
|
|
267 |
# if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
268 |
for (int i = 0; i < 5; ++i) {
|
|
269 |
CPPUNIT_ASSERT( bufs[i] == &vect_deque[i].front() );
|
|
270 |
CPPUNIT_ASSERT( bufs[11 - i] == &vect_deque[11 - i].front() );
|
|
271 |
}
|
|
272 |
# endif
|
|
273 |
# endif
|
|
274 |
}
|
|
275 |
|
|
276 |
//To the back
|
|
277 |
{
|
|
278 |
# if !defined (STLPORT) || !defined (_STLP_DEBUG) || !defined (_STLP_NO_MEMBER_TEMPLATES)
|
|
279 |
deque<vector<int> > vect_deque;
|
|
280 |
vector<int*> bufs;
|
|
281 |
vect_deque.assign(3, vector<int>(10));
|
|
282 |
bufs.push_back(&vect_deque[0].front());
|
|
283 |
bufs.push_back(&vect_deque[1].front());
|
|
284 |
bufs.push_back(&vect_deque[2].front());
|
|
285 |
|
|
286 |
int nb_insert = 5;
|
|
287 |
//Initialize to 2 to generate a back insertion:
|
|
288 |
int pos = 2;
|
|
289 |
while (nb_insert--) {
|
|
290 |
vector<vector<int> > vect_vect(2, vector<int>(10));
|
|
291 |
vect_deque.insert(vect_deque.begin() + pos, vect_vect.begin(), vect_vect.end());
|
|
292 |
bufs.insert(bufs.begin() + pos, &vect_deque[pos].front());
|
|
293 |
bufs.insert(bufs.begin() + pos + 1, &vect_deque[pos + 1].front());
|
|
294 |
++pos;
|
|
295 |
}
|
|
296 |
CPPUNIT_ASSERT( vect_deque.size() == 13 );
|
|
297 |
# if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
298 |
for (int i = 0; i < 5; ++i) {
|
|
299 |
CPPUNIT_ASSERT( bufs[i + 1] == &vect_deque[i + 1].front() );
|
|
300 |
CPPUNIT_ASSERT( bufs[12 - i] == &vect_deque[12 - i].front() );
|
|
301 |
}
|
|
302 |
# endif
|
|
303 |
# endif
|
|
304 |
}
|
|
305 |
|
|
306 |
//Check the different erase methods.
|
|
307 |
{
|
|
308 |
deque<vector<int> > vect_deque;
|
|
309 |
vect_deque.assign(20, vector<int>(10));
|
|
310 |
deque<vector<int> >::iterator vdit(vect_deque.begin()), vditEnd(vect_deque.end());
|
|
311 |
vector<int*> bufs;
|
|
312 |
for (; vdit != vditEnd; ++vdit) {
|
|
313 |
bufs.push_back(&vdit->front());
|
|
314 |
}
|
|
315 |
|
|
316 |
{
|
|
317 |
// This check, repeated after each operation, check the deque consistency:
|
|
318 |
deque<vector<int> >::iterator it = vect_deque.end() - 5;
|
|
319 |
int nb_incr = 0;
|
|
320 |
for (; it != vect_deque.end() && nb_incr <= 6; ++nb_incr, ++it) {}
|
|
321 |
CPPUNIT_ASSERT( nb_incr == 5 );
|
|
322 |
}
|
|
323 |
|
|
324 |
{
|
|
325 |
//erase in front:
|
|
326 |
vect_deque.erase(vect_deque.begin() + 2);
|
|
327 |
bufs.erase(bufs.begin() + 2);
|
|
328 |
CPPUNIT_ASSERT( vect_deque.size() == 19 );
|
|
329 |
deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end());
|
|
330 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
331 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
332 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
333 |
}
|
|
334 |
#endif
|
|
335 |
}
|
|
336 |
|
|
337 |
{
|
|
338 |
deque<vector<int> >::iterator it = vect_deque.end() - 5;
|
|
339 |
int nb_incr = 0;
|
|
340 |
for (; it != vect_deque.end() && nb_incr <= 6; ++nb_incr, ++it) {}
|
|
341 |
CPPUNIT_ASSERT( nb_incr == 5 );
|
|
342 |
}
|
|
343 |
|
|
344 |
{
|
|
345 |
//erase in the back:
|
|
346 |
vect_deque.erase(vect_deque.end() - 2);
|
|
347 |
bufs.erase(bufs.end() - 2);
|
|
348 |
CPPUNIT_ASSERT( vect_deque.size() == 18 );
|
|
349 |
deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end());
|
|
350 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
351 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
352 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
353 |
}
|
|
354 |
#endif
|
|
355 |
}
|
|
356 |
|
|
357 |
{
|
|
358 |
deque<vector<int> >::iterator it = vect_deque.end() - 5;
|
|
359 |
int nb_incr = 0;
|
|
360 |
for (; it != vect_deque.end() && nb_incr < 6; ++nb_incr, ++it) {}
|
|
361 |
CPPUNIT_ASSERT( nb_incr == 5 );
|
|
362 |
}
|
|
363 |
|
|
364 |
{
|
|
365 |
//range erase in front
|
|
366 |
vect_deque.erase(vect_deque.begin() + 3, vect_deque.begin() + 5);
|
|
367 |
bufs.erase(bufs.begin() + 3, bufs.begin() + 5);
|
|
368 |
CPPUNIT_ASSERT( vect_deque.size() == 16 );
|
|
369 |
deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end());
|
|
370 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
371 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
372 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
373 |
}
|
|
374 |
#endif
|
|
375 |
}
|
|
376 |
|
|
377 |
{
|
|
378 |
deque<vector<int> >::iterator it = vect_deque.end() - 5;
|
|
379 |
int nb_incr = 0;
|
|
380 |
for (; it != vect_deque.end() && nb_incr <= 6; ++nb_incr, ++it) {}
|
|
381 |
CPPUNIT_ASSERT( nb_incr == 5 );
|
|
382 |
}
|
|
383 |
|
|
384 |
{
|
|
385 |
//range erase in back
|
|
386 |
vect_deque.erase(vect_deque.end() - 5, vect_deque.end() - 3);
|
|
387 |
bufs.erase(bufs.end() - 5, bufs.end() - 3);
|
|
388 |
CPPUNIT_ASSERT( vect_deque.size() == 14 );
|
|
389 |
deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end());
|
|
390 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
391 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
392 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
393 |
}
|
|
394 |
#endif
|
|
395 |
}
|
|
396 |
}
|
|
397 |
|
|
398 |
//Check the insert value(s)
|
|
399 |
{
|
|
400 |
deque<vector<int> > vect_deque;
|
|
401 |
vect_deque.assign(20, vector<int>(10));
|
|
402 |
deque<vector<int> >::iterator vdit(vect_deque.begin()), vditEnd(vect_deque.end());
|
|
403 |
vector<int*> bufs;
|
|
404 |
for (; vdit != vditEnd; ++vdit) {
|
|
405 |
bufs.push_back(&vdit->front());
|
|
406 |
}
|
|
407 |
|
|
408 |
{
|
|
409 |
//2 values in front:
|
|
410 |
vect_deque.insert(vect_deque.begin() + 2, 2, vector<int>(10));
|
|
411 |
bufs.insert(bufs.begin() + 2, &vect_deque[2].front());
|
|
412 |
bufs.insert(bufs.begin() + 3, &vect_deque[3].front());
|
|
413 |
CPPUNIT_ASSERT( vect_deque.size() == 22 );
|
|
414 |
deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end());
|
|
415 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
416 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
417 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
418 |
}
|
|
419 |
#endif
|
|
420 |
}
|
|
421 |
|
|
422 |
{
|
|
423 |
//2 values in back:
|
|
424 |
vect_deque.insert(vect_deque.end() - 2, 2, vector<int>(10));
|
|
425 |
bufs.insert(bufs.end() - 2, &vect_deque[20].front());
|
|
426 |
bufs.insert(bufs.end() - 2, &vect_deque[21].front());
|
|
427 |
CPPUNIT_ASSERT( vect_deque.size() == 24 );
|
|
428 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
429 |
deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end());
|
|
430 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
431 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
432 |
}
|
|
433 |
#endif
|
|
434 |
}
|
|
435 |
|
|
436 |
{
|
|
437 |
//1 value in front:
|
|
438 |
deque<vector<int> >::iterator ret;
|
|
439 |
ret = vect_deque.insert(vect_deque.begin() + 2, vector<int>(10));
|
|
440 |
bufs.insert(bufs.begin() + 2, &vect_deque[2].front());
|
|
441 |
CPPUNIT_ASSERT( vect_deque.size() == 25 );
|
|
442 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
443 |
CPPUNIT_ASSERT( &ret->front() == bufs[2] );
|
|
444 |
deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end());
|
|
445 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
446 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
447 |
}
|
|
448 |
#endif
|
|
449 |
}
|
|
450 |
|
|
451 |
{
|
|
452 |
//1 value in back:
|
|
453 |
deque<vector<int> >::iterator ret;
|
|
454 |
ret = vect_deque.insert(vect_deque.end() - 2, vector<int>(10));
|
|
455 |
bufs.insert(bufs.end() - 2, &vect_deque[23].front());
|
|
456 |
CPPUNIT_ASSERT( vect_deque.size() == 26 );
|
|
457 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
458 |
CPPUNIT_ASSERT( &ret->front() == bufs[23] );
|
|
459 |
deque<vector<int> >::iterator dit(vect_deque.begin()), ditEnd(vect_deque.end());
|
|
460 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
461 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
462 |
}
|
|
463 |
#endif
|
|
464 |
}
|
|
465 |
}
|
|
466 |
}
|
|
467 |
|
|
468 |
void MoveConstructorTest::vector_test()
|
|
469 |
{
|
|
470 |
#if !defined (__DMC__)
|
|
471 |
//Check the insert range method.
|
|
472 |
//To the front:
|
|
473 |
{
|
|
474 |
vector<vector<int> > vect_vector;
|
|
475 |
vector<int*> bufs;
|
|
476 |
vect_vector.assign(3, vector<int>(10));
|
|
477 |
bufs.push_back(&vect_vector[0].front());
|
|
478 |
bufs.push_back(&vect_vector[1].front());
|
|
479 |
bufs.push_back(&vect_vector[2].front());
|
|
480 |
|
|
481 |
int nb_insert = 5;
|
|
482 |
int pos = 1;
|
|
483 |
while (nb_insert--) {
|
|
484 |
vector<vector<int> > vect_vect(2, vector<int>(10));
|
|
485 |
vect_vector.insert(vect_vector.begin() + pos, vect_vect.begin(), vect_vect.end());
|
|
486 |
bufs.insert(bufs.begin() + pos, &vect_vector[pos].front());
|
|
487 |
bufs.insert(bufs.begin() + pos + 1, &vect_vector[pos + 1].front());
|
|
488 |
++pos;
|
|
489 |
}
|
|
490 |
CPPUNIT_ASSERT( vect_vector.size() == 13 );
|
|
491 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
492 |
for (int i = 0; i < 5; ++i) {
|
|
493 |
CPPUNIT_ASSERT( bufs[i] == &vect_vector[i].front() );
|
|
494 |
CPPUNIT_ASSERT( bufs[11 - i] == &vect_vector[11 - i].front() );
|
|
495 |
}
|
|
496 |
#endif
|
|
497 |
}
|
|
498 |
|
|
499 |
//To the back
|
|
500 |
{
|
|
501 |
vector<vector<int> > vect_vector;
|
|
502 |
vector<int*> bufs;
|
|
503 |
vect_vector.assign(3, vector<int>(10));
|
|
504 |
bufs.push_back(&vect_vector[0].front());
|
|
505 |
bufs.push_back(&vect_vector[1].front());
|
|
506 |
bufs.push_back(&vect_vector[2].front());
|
|
507 |
|
|
508 |
int nb_insert = 5;
|
|
509 |
//Initialize to 2 to generate a back insertion:
|
|
510 |
int pos = 2;
|
|
511 |
while (nb_insert--) {
|
|
512 |
vector<vector<int> > vect_vect(2, vector<int>(10));
|
|
513 |
vect_vector.insert(vect_vector.begin() + pos, vect_vect.begin(), vect_vect.end());
|
|
514 |
bufs.insert(bufs.begin() + pos, &vect_vector[pos].front());
|
|
515 |
bufs.insert(bufs.begin() + pos + 1, &vect_vector[pos + 1].front());
|
|
516 |
++pos;
|
|
517 |
}
|
|
518 |
CPPUNIT_ASSERT( vect_vector.size() == 13 );
|
|
519 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
520 |
for (int i = 0; i < 5; ++i) {
|
|
521 |
CPPUNIT_ASSERT( bufs[i + 1] == &vect_vector[i + 1].front() );
|
|
522 |
CPPUNIT_ASSERT( bufs[12 - i] == &vect_vector[12 - i].front() );
|
|
523 |
}
|
|
524 |
#endif
|
|
525 |
}
|
|
526 |
|
|
527 |
//Check the different erase methods.
|
|
528 |
{
|
|
529 |
vector<vector<int> > vect_vector;
|
|
530 |
vect_vector.assign(20, vector<int>(10));
|
|
531 |
vector<vector<int> >::iterator vdit(vect_vector.begin()), vditEnd(vect_vector.end());
|
|
532 |
vector<int*> bufs;
|
|
533 |
for (; vdit != vditEnd; ++vdit) {
|
|
534 |
bufs.push_back(&vdit->front());
|
|
535 |
}
|
|
536 |
|
|
537 |
{
|
|
538 |
// This check, repeated after each operation, check the vector consistency:
|
|
539 |
vector<vector<int> >::iterator it = vect_vector.end() - 5;
|
|
540 |
int nb_incr = 0;
|
|
541 |
for (; it != vect_vector.end() && nb_incr <= 6; ++nb_incr, ++it) {}
|
|
542 |
CPPUNIT_ASSERT( nb_incr == 5 );
|
|
543 |
}
|
|
544 |
|
|
545 |
{
|
|
546 |
//erase in front:
|
|
547 |
vect_vector.erase(vect_vector.begin() + 2);
|
|
548 |
bufs.erase(bufs.begin() + 2);
|
|
549 |
CPPUNIT_ASSERT( vect_vector.size() == 19 );
|
|
550 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
551 |
vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end());
|
|
552 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
553 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
554 |
}
|
|
555 |
#endif
|
|
556 |
}
|
|
557 |
|
|
558 |
{
|
|
559 |
vector<vector<int> >::iterator it = vect_vector.end() - 5;
|
|
560 |
int nb_incr = 0;
|
|
561 |
for (; it != vect_vector.end() && nb_incr <= 6; ++nb_incr, ++it) {}
|
|
562 |
CPPUNIT_ASSERT( nb_incr == 5 );
|
|
563 |
}
|
|
564 |
|
|
565 |
{
|
|
566 |
//erase in the back:
|
|
567 |
vect_vector.erase(vect_vector.end() - 2);
|
|
568 |
bufs.erase(bufs.end() - 2);
|
|
569 |
CPPUNIT_ASSERT( vect_vector.size() == 18 );
|
|
570 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
571 |
vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end());
|
|
572 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
573 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
574 |
}
|
|
575 |
#endif
|
|
576 |
}
|
|
577 |
|
|
578 |
{
|
|
579 |
vector<vector<int> >::iterator it = vect_vector.end() - 5;
|
|
580 |
int nb_incr = 0;
|
|
581 |
for (; it != vect_vector.end() && nb_incr < 6; ++nb_incr, ++it) {}
|
|
582 |
CPPUNIT_ASSERT( nb_incr == 5 );
|
|
583 |
}
|
|
584 |
|
|
585 |
{
|
|
586 |
//range erase in front
|
|
587 |
vect_vector.erase(vect_vector.begin() + 3, vect_vector.begin() + 5);
|
|
588 |
bufs.erase(bufs.begin() + 3, bufs.begin() + 5);
|
|
589 |
CPPUNIT_ASSERT( vect_vector.size() == 16 );
|
|
590 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
591 |
vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end());
|
|
592 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
593 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
594 |
}
|
|
595 |
#endif
|
|
596 |
}
|
|
597 |
|
|
598 |
{
|
|
599 |
vector<vector<int> >::iterator it = vect_vector.end() - 5;
|
|
600 |
int nb_incr = 0;
|
|
601 |
for (; it != vect_vector.end() && nb_incr <= 6; ++nb_incr, ++it) {}
|
|
602 |
CPPUNIT_ASSERT( nb_incr == 5 );
|
|
603 |
}
|
|
604 |
|
|
605 |
{
|
|
606 |
//range erase in back
|
|
607 |
vect_vector.erase(vect_vector.end() - 5, vect_vector.end() - 3);
|
|
608 |
bufs.erase(bufs.end() - 5, bufs.end() - 3);
|
|
609 |
CPPUNIT_ASSERT( vect_vector.size() == 14 );
|
|
610 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
611 |
vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end());
|
|
612 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
613 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
614 |
}
|
|
615 |
#endif
|
|
616 |
}
|
|
617 |
}
|
|
618 |
|
|
619 |
//Check the insert value(s)
|
|
620 |
{
|
|
621 |
vector<vector<int> > vect_vector;
|
|
622 |
vect_vector.assign(20, vector<int>(10));
|
|
623 |
vector<vector<int> >::iterator vdit(vect_vector.begin()), vditEnd(vect_vector.end());
|
|
624 |
vector<int*> bufs;
|
|
625 |
for (; vdit != vditEnd; ++vdit) {
|
|
626 |
bufs.push_back(&vdit->front());
|
|
627 |
}
|
|
628 |
|
|
629 |
{
|
|
630 |
//2 values in front:
|
|
631 |
vect_vector.insert(vect_vector.begin() + 2, 2, vector<int>(10));
|
|
632 |
bufs.insert(bufs.begin() + 2, &vect_vector[2].front());
|
|
633 |
bufs.insert(bufs.begin() + 3, &vect_vector[3].front());
|
|
634 |
CPPUNIT_ASSERT( vect_vector.size() == 22 );
|
|
635 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
636 |
vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end());
|
|
637 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
638 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
639 |
}
|
|
640 |
#endif
|
|
641 |
}
|
|
642 |
|
|
643 |
{
|
|
644 |
//2 values in back:
|
|
645 |
vect_vector.insert(vect_vector.end() - 2, 2, vector<int>(10));
|
|
646 |
bufs.insert(bufs.end() - 2, &vect_vector[20].front());
|
|
647 |
bufs.insert(bufs.end() - 2, &vect_vector[21].front());
|
|
648 |
CPPUNIT_ASSERT( vect_vector.size() == 24 );
|
|
649 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
650 |
vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end());
|
|
651 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
652 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
653 |
}
|
|
654 |
#endif
|
|
655 |
}
|
|
656 |
|
|
657 |
{
|
|
658 |
//1 value in front:
|
|
659 |
vector<vector<int> >::iterator ret;
|
|
660 |
ret = vect_vector.insert(vect_vector.begin() + 2, vector<int>(10));
|
|
661 |
bufs.insert(bufs.begin() + 2, &vect_vector[2].front());
|
|
662 |
CPPUNIT_ASSERT( vect_vector.size() == 25 );
|
|
663 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
664 |
CPPUNIT_ASSERT( &ret->front() == bufs[2] );
|
|
665 |
vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end());
|
|
666 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
667 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
668 |
}
|
|
669 |
#endif
|
|
670 |
}
|
|
671 |
|
|
672 |
{
|
|
673 |
//1 value in back:
|
|
674 |
vector<vector<int> >::iterator ret;
|
|
675 |
ret = vect_vector.insert(vect_vector.end() - 2, vector<int>(10));
|
|
676 |
bufs.insert(bufs.end() - 2, &vect_vector[23].front());
|
|
677 |
CPPUNIT_ASSERT( vect_vector.size() == 26 );
|
|
678 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
679 |
CPPUNIT_ASSERT( &ret->front() == bufs[23] );
|
|
680 |
vector<vector<int> >::iterator dit(vect_vector.begin()), ditEnd(vect_vector.end());
|
|
681 |
for (size_t i = 0; dit != ditEnd; ++dit, ++i) {
|
|
682 |
CPPUNIT_ASSERT( bufs[i] == &dit->front() );
|
|
683 |
}
|
|
684 |
#endif
|
|
685 |
}
|
|
686 |
}
|
|
687 |
|
|
688 |
//The following tests are checking move contructor implementations:
|
|
689 |
const string long_str("long enough string to force dynamic allocation");
|
|
690 |
{
|
|
691 |
//vector move contructor:
|
|
692 |
vector<vector<string> > vect(10, vector<string>(10, long_str));
|
|
693 |
vector<string> strs;
|
|
694 |
size_t index = 0;
|
|
695 |
while (true) {
|
|
696 |
vector<vector<string> >::iterator it(vect.begin());
|
|
697 |
advance(it, index % vect.size());
|
|
698 |
strs.push_back(it->front());
|
|
699 |
it->erase(it->begin());
|
|
700 |
if (it->empty()) {
|
|
701 |
vect.erase(it);
|
|
702 |
if (vect.empty())
|
|
703 |
break;
|
|
704 |
}
|
|
705 |
index += 3;
|
|
706 |
}
|
|
707 |
CPPUNIT_ASSERT( strs.size() == 10 * 10 );
|
|
708 |
vector<string>::iterator it(strs.begin()), itEnd(strs.end());
|
|
709 |
for (; it != itEnd; ++it) {
|
|
710 |
CPPUNIT_ASSERT( *it == long_str );
|
|
711 |
}
|
|
712 |
}
|
|
713 |
|
|
714 |
{
|
|
715 |
//deque move contructor:
|
|
716 |
vector<deque<string> > vect(10, deque<string>(10, long_str));
|
|
717 |
vector<string> strs;
|
|
718 |
size_t index = 0;
|
|
719 |
while (true) {
|
|
720 |
vector<deque<string> >::iterator it(vect.begin());
|
|
721 |
advance(it, index % vect.size());
|
|
722 |
strs.push_back(it->front());
|
|
723 |
it->pop_front();
|
|
724 |
if (it->empty()) {
|
|
725 |
vect.erase(it);
|
|
726 |
if (vect.empty())
|
|
727 |
break;
|
|
728 |
}
|
|
729 |
index += 3;
|
|
730 |
}
|
|
731 |
CPPUNIT_ASSERT( strs.size() == 10 * 10 );
|
|
732 |
vector<string>::iterator it(strs.begin()), itEnd(strs.end());
|
|
733 |
for (; it != itEnd; ++it) {
|
|
734 |
CPPUNIT_ASSERT( *it == long_str );
|
|
735 |
}
|
|
736 |
}
|
|
737 |
|
|
738 |
{
|
|
739 |
//list move contructor:
|
|
740 |
vector<list<string> > vect(10, list<string>(10, long_str));
|
|
741 |
vector<string> strs;
|
|
742 |
size_t index = 0;
|
|
743 |
while (true) {
|
|
744 |
vector<list<string> >::iterator it(vect.begin());
|
|
745 |
advance(it, index % vect.size());
|
|
746 |
strs.push_back(it->front());
|
|
747 |
it->pop_front();
|
|
748 |
if (it->empty()) {
|
|
749 |
vect.erase(it);
|
|
750 |
if (vect.empty())
|
|
751 |
break;
|
|
752 |
}
|
|
753 |
index += 3;
|
|
754 |
}
|
|
755 |
CPPUNIT_ASSERT( strs.size() == 10 * 10 );
|
|
756 |
vector<string>::iterator it(strs.begin()), itEnd(strs.end());
|
|
757 |
for (; it != itEnd; ++it) {
|
|
758 |
CPPUNIT_ASSERT( *it == long_str );
|
|
759 |
}
|
|
760 |
}
|
|
761 |
|
|
762 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
763 |
{
|
|
764 |
//slist move contructor:
|
|
765 |
vector<slist<string> > vect(10, slist<string>(10, long_str));
|
|
766 |
vector<string> strs;
|
|
767 |
size_t index = 0;
|
|
768 |
while (true) {
|
|
769 |
vector<slist<string> >::iterator it(vect.begin());
|
|
770 |
advance(it, index % vect.size());
|
|
771 |
strs.push_back(it->front());
|
|
772 |
it->pop_front();
|
|
773 |
if (it->empty()) {
|
|
774 |
vect.erase(it);
|
|
775 |
if (vect.empty())
|
|
776 |
break;
|
|
777 |
}
|
|
778 |
index += 3;
|
|
779 |
}
|
|
780 |
CPPUNIT_ASSERT( strs.size() == 10 * 10 );
|
|
781 |
vector<string>::iterator it(strs.begin()), itEnd(strs.end());
|
|
782 |
for (; it != itEnd; ++it) {
|
|
783 |
CPPUNIT_ASSERT( *it == long_str );
|
|
784 |
}
|
|
785 |
}
|
|
786 |
#endif
|
|
787 |
|
|
788 |
{
|
|
789 |
//binary tree move contructor:
|
|
790 |
multiset<string> ref;
|
|
791 |
for (size_t i = 0; i < 10; ++i) {
|
|
792 |
ref.insert(long_str);
|
|
793 |
}
|
|
794 |
vector<multiset<string> > vect(10, ref);
|
|
795 |
vector<string> strs;
|
|
796 |
size_t index = 0;
|
|
797 |
while (true) {
|
|
798 |
vector<multiset<string> >::iterator it(vect.begin());
|
|
799 |
advance(it, index % vect.size());
|
|
800 |
strs.push_back(*it->begin());
|
|
801 |
it->erase(it->begin());
|
|
802 |
if (it->empty()) {
|
|
803 |
vect.erase(it);
|
|
804 |
if (vect.empty())
|
|
805 |
break;
|
|
806 |
}
|
|
807 |
index += 3;
|
|
808 |
}
|
|
809 |
CPPUNIT_ASSERT( strs.size() == 10 * 10 );
|
|
810 |
vector<string>::iterator it(strs.begin()), itEnd(strs.end());
|
|
811 |
for (; it != itEnd; ++it) {
|
|
812 |
CPPUNIT_ASSERT( *it == long_str );
|
|
813 |
}
|
|
814 |
}
|
|
815 |
# endif /* __DMC__ */
|
|
816 |
|
|
817 |
#if defined (STLPORT)
|
|
818 |
# if !defined (__BORLANDC__) && !defined (__DMC__)
|
|
819 |
{
|
|
820 |
//hash container move contructor:
|
|
821 |
unordered_multiset<string> ref;
|
|
822 |
for (size_t i = 0; i < 10; ++i) {
|
|
823 |
ref.insert(long_str);
|
|
824 |
}
|
|
825 |
vector<unordered_multiset<string> > vect(10, ref);
|
|
826 |
vector<string> strs;
|
|
827 |
size_t index = 0;
|
|
828 |
while (true) {
|
|
829 |
vector<unordered_multiset<string> >::iterator it(vect.begin());
|
|
830 |
advance(it, index % vect.size());
|
|
831 |
strs.push_back(*it->begin());
|
|
832 |
it->erase(it->begin());
|
|
833 |
if (it->empty()) {
|
|
834 |
vect.erase(it);
|
|
835 |
if (vect.empty())
|
|
836 |
break;
|
|
837 |
}
|
|
838 |
index += 3;
|
|
839 |
}
|
|
840 |
CPPUNIT_ASSERT( strs.size() == 10 * 10 );
|
|
841 |
vector<string>::iterator it(strs.begin()), itEnd(strs.end());
|
|
842 |
for (; it != itEnd; ++it) {
|
|
843 |
CPPUNIT_ASSERT( *it == long_str );
|
|
844 |
}
|
|
845 |
}
|
|
846 |
# endif
|
|
847 |
#endif
|
|
848 |
}
|
|
849 |
|
|
850 |
struct MovableStruct {
|
|
851 |
MovableStruct() { ++nb_dft_construct_call; }
|
|
852 |
MovableStruct(MovableStruct const&) { ++nb_cpy_construct_call; }
|
|
853 |
# if defined (STLPORT)
|
|
854 |
MovableStruct(__move_source<MovableStruct>) { ++nb_mv_construct_call; }
|
|
855 |
# endif
|
|
856 |
~MovableStruct() { ++nb_destruct_call; }
|
|
857 |
|
|
858 |
MovableStruct& operator = (const MovableStruct&) {
|
|
859 |
++nb_assignment_call;
|
|
860 |
return *this;
|
|
861 |
}
|
|
862 |
|
|
863 |
static void reset() {
|
|
864 |
nb_dft_construct_call = nb_cpy_construct_call = nb_mv_construct_call = 0;
|
|
865 |
nb_assignment_call = 0;
|
|
866 |
nb_destruct_call = 0;
|
|
867 |
}
|
|
868 |
|
|
869 |
static size_t nb_dft_construct_call;
|
|
870 |
static size_t nb_cpy_construct_call;
|
|
871 |
static size_t nb_mv_construct_call;
|
|
872 |
static size_t nb_assignment_call;
|
|
873 |
static size_t nb_destruct_call;
|
|
874 |
|
|
875 |
//Dummy data just to control struct sizeof
|
|
876 |
//As node allocator implementation align memory blocks on 2 * sizeof(void*)
|
|
877 |
//we give MovableStruct the same size in order to have expected allocation
|
|
878 |
//and not more
|
|
879 |
void* dummy_data[2];
|
|
880 |
};
|
|
881 |
|
|
882 |
size_t MovableStruct::nb_dft_construct_call = 0;
|
|
883 |
size_t MovableStruct::nb_cpy_construct_call = 0;
|
|
884 |
size_t MovableStruct::nb_mv_construct_call = 0;
|
|
885 |
size_t MovableStruct::nb_assignment_call = 0;
|
|
886 |
size_t MovableStruct::nb_destruct_call = 0;
|
|
887 |
|
|
888 |
# if defined (STLPORT)
|
|
889 |
namespace std {
|
|
890 |
_STLP_TEMPLATE_NULL
|
|
891 |
struct __move_traits<MovableStruct> {
|
|
892 |
typedef __true_type implemented;
|
|
893 |
typedef __false_type complete;
|
|
894 |
};
|
|
895 |
}
|
|
896 |
# endif
|
|
897 |
|
|
898 |
struct CompleteMovableStruct {
|
|
899 |
CompleteMovableStruct() { ++nb_dft_construct_call; }
|
|
900 |
CompleteMovableStruct(CompleteMovableStruct const&) { ++nb_cpy_construct_call; }
|
|
901 |
# if defined (STLPORT)
|
|
902 |
CompleteMovableStruct(__move_source<CompleteMovableStruct>) { ++nb_mv_construct_call; }
|
|
903 |
# endif
|
|
904 |
~CompleteMovableStruct() { ++nb_destruct_call; }
|
|
905 |
|
|
906 |
CompleteMovableStruct& operator = (const CompleteMovableStruct&) {
|
|
907 |
++nb_assignment_call;
|
|
908 |
return *this;
|
|
909 |
}
|
|
910 |
static void reset() {
|
|
911 |
nb_dft_construct_call = nb_cpy_construct_call = nb_mv_construct_call = 0;
|
|
912 |
nb_assignment_call = 0;
|
|
913 |
nb_destruct_call = 0;
|
|
914 |
}
|
|
915 |
|
|
916 |
static size_t nb_dft_construct_call;
|
|
917 |
static size_t nb_cpy_construct_call;
|
|
918 |
static size_t nb_mv_construct_call;
|
|
919 |
static size_t nb_assignment_call;
|
|
920 |
static size_t nb_destruct_call;
|
|
921 |
|
|
922 |
//See MovableStruct
|
|
923 |
void* dummy_data[2];
|
|
924 |
};
|
|
925 |
|
|
926 |
size_t CompleteMovableStruct::nb_dft_construct_call = 0;
|
|
927 |
size_t CompleteMovableStruct::nb_cpy_construct_call = 0;
|
|
928 |
size_t CompleteMovableStruct::nb_mv_construct_call = 0;
|
|
929 |
size_t CompleteMovableStruct::nb_assignment_call = 0;
|
|
930 |
size_t CompleteMovableStruct::nb_destruct_call = 0;
|
|
931 |
|
|
932 |
# if defined (STLPORT)
|
|
933 |
namespace std {
|
|
934 |
_STLP_TEMPLATE_NULL
|
|
935 |
struct __move_traits<CompleteMovableStruct> {
|
|
936 |
typedef __true_type implemented;
|
|
937 |
typedef __true_type complete;
|
|
938 |
};
|
|
939 |
}
|
|
940 |
# endif
|
|
941 |
|
|
942 |
void MoveConstructorTest::move_traits()
|
|
943 |
{
|
|
944 |
{
|
|
945 |
{
|
|
946 |
vector<MovableStruct> vect;
|
|
947 |
vect.push_back(MovableStruct());
|
|
948 |
vect.push_back(MovableStruct());
|
|
949 |
vect.push_back(MovableStruct());
|
|
950 |
vect.push_back(MovableStruct());
|
|
951 |
|
|
952 |
// vect contains 4 elements
|
|
953 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 4 );
|
|
954 |
#if defined (STLPORT)
|
|
955 |
# if !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
956 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 );
|
|
957 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 3 );
|
|
958 |
# else
|
|
959 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 7 );
|
|
960 |
# endif
|
|
961 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 7 );
|
|
962 |
#elif !defined (_MSC_VER)
|
|
963 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 7 );
|
|
964 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 7 );
|
|
965 |
#else
|
|
966 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 14 );
|
|
967 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 14 );
|
|
968 |
#endif
|
|
969 |
CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 0 );
|
|
970 |
|
|
971 |
// Following test violate requirements to sequiences (23.1.1 Table 67)
|
|
972 |
/*
|
|
973 |
vect.insert(vect.begin() + 2, vect.begin(), vect.end());
|
|
974 |
// vect contains 8 elements
|
|
975 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 4 );
|
|
976 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 8 );
|
|
977 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 7 );
|
|
978 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 11 );
|
|
979 |
*/
|
|
980 |
|
|
981 |
MovableStruct::reset();
|
|
982 |
vector<MovableStruct> v2 = vect;
|
|
983 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 0 );
|
|
984 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 );
|
|
985 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 );
|
|
986 |
CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 0 );
|
|
987 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 0 );
|
|
988 |
|
|
989 |
MovableStruct::reset();
|
|
990 |
vect.insert(vect.begin() + 2, v2.begin(), v2.end() );
|
|
991 |
|
|
992 |
// vect contains 8 elements
|
|
993 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 0 );
|
|
994 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
995 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 );
|
|
996 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 4 );
|
|
997 |
#else
|
|
998 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 8 );
|
|
999 |
#endif
|
|
1000 |
CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 0 );
|
|
1001 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 4 );
|
|
1002 |
|
|
1003 |
MovableStruct::reset();
|
|
1004 |
vect.erase(vect.begin(), vect.begin() + 2 );
|
|
1005 |
|
|
1006 |
// vect contains 6 elements
|
|
1007 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1008 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 6 );
|
|
1009 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 8 );
|
|
1010 |
#else
|
|
1011 |
CPPUNIT_ASSERT_EQUAL( MovableStruct::nb_assignment_call, 6 );
|
|
1012 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 );
|
|
1013 |
#endif
|
|
1014 |
|
|
1015 |
MovableStruct::reset();
|
|
1016 |
vect.erase(vect.end() - 2, vect.end());
|
|
1017 |
|
|
1018 |
// vect contains 4 elements
|
|
1019 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 );
|
|
1020 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 );
|
|
1021 |
|
|
1022 |
MovableStruct::reset();
|
|
1023 |
vect.erase(vect.begin());
|
|
1024 |
|
|
1025 |
// vect contains 3 elements
|
|
1026 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1027 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 3 );
|
|
1028 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 4 );
|
|
1029 |
#else
|
|
1030 |
CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 3 );
|
|
1031 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 1 );
|
|
1032 |
#endif
|
|
1033 |
|
|
1034 |
MovableStruct::reset();
|
|
1035 |
}
|
|
1036 |
//vect with 3 elements and v2 with 4 elements are now out of scope
|
|
1037 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 3 + 4 );
|
|
1038 |
}
|
|
1039 |
|
|
1040 |
{
|
|
1041 |
{
|
|
1042 |
vector<CompleteMovableStruct> vect;
|
|
1043 |
vect.push_back(CompleteMovableStruct());
|
|
1044 |
vect.push_back(CompleteMovableStruct());
|
|
1045 |
vect.push_back(CompleteMovableStruct());
|
|
1046 |
vect.push_back(CompleteMovableStruct());
|
|
1047 |
|
|
1048 |
// vect contains 4 elements
|
|
1049 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 4 );
|
|
1050 |
#if defined (STLPORT)
|
|
1051 |
# if !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1052 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 );
|
|
1053 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 3 );
|
|
1054 |
# else
|
|
1055 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 7 );
|
|
1056 |
# endif
|
|
1057 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 );
|
|
1058 |
#elif !defined (_MSC_VER)
|
|
1059 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 7 );
|
|
1060 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 7 );
|
|
1061 |
#else
|
|
1062 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 14 );
|
|
1063 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 14 );
|
|
1064 |
#endif
|
|
1065 |
|
|
1066 |
// Following test violate requirements to sequiences (23.1.1 Table 67)
|
|
1067 |
/*
|
|
1068 |
vect.insert(vect.begin() + 2, vect.begin(), vect.end());
|
|
1069 |
|
|
1070 |
// vect contains 8 elements
|
|
1071 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 4 );
|
|
1072 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 8 );
|
|
1073 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 7 );
|
|
1074 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 );
|
|
1075 |
*/
|
|
1076 |
|
|
1077 |
CompleteMovableStruct::reset();
|
|
1078 |
vector<CompleteMovableStruct> v2 = vect;
|
|
1079 |
|
|
1080 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 0 );
|
|
1081 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 );
|
|
1082 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 );
|
|
1083 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 0 );
|
|
1084 |
|
|
1085 |
CompleteMovableStruct::reset();
|
|
1086 |
vect.insert(vect.begin() + 2, v2.begin(), v2.end());
|
|
1087 |
|
|
1088 |
// vect contains 8 elements
|
|
1089 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 0 );
|
|
1090 |
#if defined (STLPORT)
|
|
1091 |
# if !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1092 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 );
|
|
1093 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 4 );
|
|
1094 |
# else
|
|
1095 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 8 );
|
|
1096 |
# endif
|
|
1097 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 0 );
|
|
1098 |
#else
|
|
1099 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 8 );
|
|
1100 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 );
|
|
1101 |
#endif
|
|
1102 |
|
|
1103 |
CompleteMovableStruct::reset();
|
|
1104 |
vect.erase(vect.begin(), vect.begin() + 2);
|
|
1105 |
|
|
1106 |
// vect contains 6 elements
|
|
1107 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1108 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 6 );
|
|
1109 |
#else
|
|
1110 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 6 );
|
|
1111 |
#endif
|
|
1112 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 2 );
|
|
1113 |
|
|
1114 |
CompleteMovableStruct::reset();
|
|
1115 |
vect.erase(vect.end() - 2, vect.end());
|
|
1116 |
|
|
1117 |
// vect contains 4 elements
|
|
1118 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 );
|
|
1119 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 2 );
|
|
1120 |
|
|
1121 |
CompleteMovableStruct::reset();
|
|
1122 |
vect.erase(vect.begin());
|
|
1123 |
|
|
1124 |
// vect contains 3 elements
|
|
1125 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1126 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 3 );
|
|
1127 |
#else
|
|
1128 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 3 );
|
|
1129 |
#endif
|
|
1130 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 1 );
|
|
1131 |
|
|
1132 |
CompleteMovableStruct::reset();
|
|
1133 |
}
|
|
1134 |
//vect with 3 elements and v2 with 4 elements are now out of scope
|
|
1135 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 3 + 4 );
|
|
1136 |
}
|
|
1137 |
|
|
1138 |
{
|
|
1139 |
MovableStruct::reset();
|
|
1140 |
{
|
|
1141 |
deque<MovableStruct> deq;
|
|
1142 |
deq.push_back(MovableStruct());
|
|
1143 |
deq.push_back(MovableStruct());
|
|
1144 |
deq.push_back(MovableStruct());
|
|
1145 |
deq.push_back(MovableStruct());
|
|
1146 |
|
|
1147 |
// deq contains 4 elements
|
|
1148 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 4 );
|
|
1149 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 );
|
|
1150 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 );
|
|
1151 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 4 );
|
|
1152 |
|
|
1153 |
// Following test violate requirements to sequiences (23.1.1 Table 67)
|
|
1154 |
/*
|
|
1155 |
deq.insert(deq.begin() + 2, deq.begin(), deq.end());
|
|
1156 |
// deq contains 8 elements
|
|
1157 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 4 );
|
|
1158 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 8 );
|
|
1159 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 7 );
|
|
1160 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 11 );
|
|
1161 |
*/
|
|
1162 |
|
|
1163 |
MovableStruct::reset();
|
|
1164 |
deque<MovableStruct> d2 = deq;
|
|
1165 |
|
|
1166 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 0 );
|
|
1167 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 );
|
|
1168 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 );
|
|
1169 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 0 );
|
|
1170 |
|
|
1171 |
MovableStruct::reset();
|
|
1172 |
deq.insert(deq.begin() + 2, d2.begin(), d2.end() );
|
|
1173 |
|
|
1174 |
// deq contains 8 elements
|
|
1175 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 0 );
|
|
1176 |
CPPUNIT_ASSERT( MovableStruct::nb_cpy_construct_call == 4 );
|
|
1177 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1178 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 2 );
|
|
1179 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 );
|
|
1180 |
#else
|
|
1181 |
CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 2 );
|
|
1182 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 0 );
|
|
1183 |
#endif
|
|
1184 |
|
|
1185 |
MovableStruct::reset();
|
|
1186 |
deq.erase(deq.begin() + 1, deq.begin() + 3 );
|
|
1187 |
|
|
1188 |
// deq contains 6 elements
|
|
1189 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1190 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 1 );
|
|
1191 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 3 );
|
|
1192 |
#else
|
|
1193 |
//Following check is highly deque implementation dependant so
|
|
1194 |
//it might not always work...
|
|
1195 |
CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 1 );
|
|
1196 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 );
|
|
1197 |
#endif
|
|
1198 |
|
|
1199 |
MovableStruct::reset();
|
|
1200 |
deq.erase(deq.end() - 3, deq.end() - 1);
|
|
1201 |
|
|
1202 |
// deq contains 4 elements
|
|
1203 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1204 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 1 );
|
|
1205 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 3 );
|
|
1206 |
#else
|
|
1207 |
CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 1 );
|
|
1208 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 2 );
|
|
1209 |
#endif
|
|
1210 |
|
|
1211 |
MovableStruct::reset();
|
|
1212 |
deq.erase(deq.begin());
|
|
1213 |
|
|
1214 |
// deq contains 3 elements
|
|
1215 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1216 |
CPPUNIT_ASSERT( MovableStruct::nb_mv_construct_call == 0 );
|
|
1217 |
#else
|
|
1218 |
CPPUNIT_ASSERT( MovableStruct::nb_assignment_call == 0 );
|
|
1219 |
#endif
|
|
1220 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 1 );
|
|
1221 |
|
|
1222 |
MovableStruct::reset();
|
|
1223 |
}
|
|
1224 |
//deq with 3 elements and d2 with 4 elements are now out of scope
|
|
1225 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 3 + 4 );
|
|
1226 |
}
|
|
1227 |
|
|
1228 |
{
|
|
1229 |
CompleteMovableStruct::reset();
|
|
1230 |
{
|
|
1231 |
deque<CompleteMovableStruct> deq;
|
|
1232 |
deq.push_back(CompleteMovableStruct());
|
|
1233 |
deq.push_back(CompleteMovableStruct());
|
|
1234 |
deq.push_back(CompleteMovableStruct());
|
|
1235 |
deq.push_back(CompleteMovableStruct());
|
|
1236 |
|
|
1237 |
// deq contains 4 elements
|
|
1238 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 4 );
|
|
1239 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 );
|
|
1240 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 );
|
|
1241 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 );
|
|
1242 |
|
|
1243 |
// Following test violate requirements to sequiences (23.1.1 Table 67)
|
|
1244 |
/*
|
|
1245 |
deq.insert(deq.begin() + 2, deq.begin(), deq.end());
|
|
1246 |
|
|
1247 |
// deq contains 8 elements
|
|
1248 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 4 );
|
|
1249 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 8 );
|
|
1250 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 7 );
|
|
1251 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 4 );
|
|
1252 |
*/
|
|
1253 |
|
|
1254 |
CompleteMovableStruct::reset();
|
|
1255 |
deque<CompleteMovableStruct> d2 = deq;
|
|
1256 |
|
|
1257 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 0 );
|
|
1258 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 );
|
|
1259 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 );
|
|
1260 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 0 );
|
|
1261 |
|
|
1262 |
CompleteMovableStruct::reset();
|
|
1263 |
deq.insert(deq.begin() + 2, d2.begin(), d2.end());
|
|
1264 |
|
|
1265 |
// deq contains 8 elements
|
|
1266 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_dft_construct_call == 0 );
|
|
1267 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_cpy_construct_call == 4 );
|
|
1268 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1269 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 2 );
|
|
1270 |
#else
|
|
1271 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 2 );
|
|
1272 |
#endif
|
|
1273 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 0 );
|
|
1274 |
|
|
1275 |
CompleteMovableStruct::reset();
|
|
1276 |
deq.erase(deq.begin() + 1, deq.begin() + 3);
|
|
1277 |
|
|
1278 |
// deq contains 6 elements
|
|
1279 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1280 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 1 );
|
|
1281 |
#else
|
|
1282 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 1 );
|
|
1283 |
#endif
|
|
1284 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 2 );
|
|
1285 |
|
|
1286 |
CompleteMovableStruct::reset();
|
|
1287 |
deq.erase(deq.end() - 3, deq.end() - 1);
|
|
1288 |
|
|
1289 |
// deq contains 4 elements
|
|
1290 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1291 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 1 );
|
|
1292 |
#else
|
|
1293 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 1 );
|
|
1294 |
#endif
|
|
1295 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 2 );
|
|
1296 |
|
|
1297 |
CompleteMovableStruct::reset();
|
|
1298 |
deq.erase(deq.begin());
|
|
1299 |
|
|
1300 |
// deq contains 3 elements
|
|
1301 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_mv_construct_call == 0 );
|
|
1302 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_assignment_call == 0 );
|
|
1303 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 1 );
|
|
1304 |
|
|
1305 |
CompleteMovableStruct::reset();
|
|
1306 |
}
|
|
1307 |
//deq with 3 elements and v2 with 4 elements are now out of scope
|
|
1308 |
CPPUNIT_ASSERT( CompleteMovableStruct::nb_destruct_call == 3 + 4 );
|
|
1309 |
}
|
|
1310 |
}
|
|
1311 |
|
|
1312 |
#if defined (STLPORT) && !defined (_STLP_NO_MOVE_SEMANTIC)
|
|
1313 |
|
|
1314 |
# if defined (__GNUC__) && defined (_STLP_USE_NAMESPACES)
|
|
1315 |
// libstdc++ sometimes exposed its own __true_type in
|
|
1316 |
// global namespace resulting in an ambiguity.
|
|
1317 |
# define __true_type std::__true_type
|
|
1318 |
# define __false_type std::__false_type
|
|
1319 |
# endif
|
|
1320 |
|
|
1321 |
static bool type_to_bool(__true_type)
|
|
1322 |
{ return true; }
|
|
1323 |
static bool type_to_bool(__false_type)
|
|
1324 |
{ return false; }
|
|
1325 |
|
|
1326 |
template <class _Tp>
|
|
1327 |
static bool is_movable(const _Tp&) {
|
|
1328 |
#if defined (__BORLANDC__) || defined (__SYMBIAN32__)
|
|
1329 |
return __type2bool<typename __move_traits<_Tp>::implemented>::_Ret != 0;
|
|
1330 |
#else
|
|
1331 |
typedef typename __move_traits<_Tp>::implemented _MovableTp;
|
|
1332 |
return type_to_bool(_MovableTp());
|
|
1333 |
#endif
|
|
1334 |
}
|
|
1335 |
|
|
1336 |
template <class _Tp>
|
|
1337 |
static bool is_move_complete(const _Tp&) {
|
|
1338 |
typedef __move_traits<_Tp> _TpMoveTraits;
|
|
1339 |
#if defined (__BORLANDC__) || defined (__SYMBIAN32__)
|
|
1340 |
return __type2bool<typename __move_traits<_Tp>::complete>::_Ret != 0;
|
|
1341 |
#else
|
|
1342 |
typedef typename _TpMoveTraits::complete _TpMoveComplete;
|
|
1343 |
return type_to_bool(_TpMoveComplete());
|
|
1344 |
#endif
|
|
1345 |
}
|
|
1346 |
|
|
1347 |
struct specially_allocated_struct {
|
|
1348 |
bool operator < (specially_allocated_struct) const;
|
|
1349 |
};
|
|
1350 |
|
|
1351 |
struct struct_with_specialized_less {};
|
|
1352 |
|
|
1353 |
namespace std
|
|
1354 |
{
|
|
1355 |
_STLP_TEMPLATE_NULL
|
|
1356 |
class allocator<specially_allocated_struct>
|
|
1357 |
{
|
|
1358 |
//This allocator just represent what a STLport could do and in this
|
|
1359 |
//case the STL containers implemented with it should still be movable
|
|
1360 |
//but not completely as we cannot do any hypothesis on what is in this
|
|
1361 |
//allocator.
|
|
1362 |
public:
|
|
1363 |
typedef specially_allocated_struct value_type;
|
|
1364 |
typedef value_type * pointer;
|
|
1365 |
typedef const value_type* const_pointer;
|
|
1366 |
typedef value_type& reference;
|
|
1367 |
typedef const value_type& const_reference;
|
|
1368 |
typedef size_t size_type;
|
|
1369 |
typedef ptrdiff_t difference_type;
|
|
1370 |
#if defined (_STLP_MEMBER_TEMPLATE_CLASSES)
|
|
1371 |
template <class _Tp1> struct rebind {
|
|
1372 |
typedef allocator<_Tp1> other;
|
|
1373 |
};
|
|
1374 |
#endif
|
|
1375 |
allocator() _STLP_NOTHROW {}
|
|
1376 |
#if defined (_STLP_MEMBER_TEMPLATES)
|
|
1377 |
template <class _Tp1> allocator(const allocator<_Tp1>&) _STLP_NOTHROW {}
|
|
1378 |
#endif
|
|
1379 |
allocator(const allocator&) _STLP_NOTHROW {}
|
|
1380 |
~allocator() _STLP_NOTHROW {}
|
|
1381 |
pointer address(reference __x) const { return &__x; }
|
|
1382 |
const_pointer address(const_reference __x) const { return &__x; }
|
|
1383 |
pointer allocate(size_type, const void* = 0) { return 0; }
|
|
1384 |
void deallocate(pointer, size_type) {}
|
|
1385 |
size_type max_size() const _STLP_NOTHROW { return 0; }
|
|
1386 |
void construct(pointer, const_reference) {}
|
|
1387 |
void destroy(pointer) {}
|
|
1388 |
};
|
|
1389 |
|
|
1390 |
_STLP_TEMPLATE_NULL
|
|
1391 |
struct less<struct_with_specialized_less> {
|
|
1392 |
bool operator() (struct_with_specialized_less const&,
|
|
1393 |
struct_with_specialized_less const&) const;
|
|
1394 |
};
|
|
1395 |
}
|
|
1396 |
#endif
|
|
1397 |
|
|
1398 |
void MoveConstructorTest::movable_declaration()
|
|
1399 |
{
|
|
1400 |
#if defined (STLPORT) && !defined (_STLP_DONT_SIMULATE_PARTIAL_SPEC_FOR_TYPE_TRAITS) && \
|
|
1401 |
!defined (_STLP_NO_MOVE_SEMANTIC) && \
|
|
1402 |
!defined (__DMC__)
|
|
1403 |
//This test purpose is to check correct detection of the STL movable
|
|
1404 |
//traits declaration
|
|
1405 |
{
|
|
1406 |
//string, wstring:
|
|
1407 |
CPPUNIT_ASSERT( is_movable(string()) );
|
|
1408 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1409 |
CPPUNIT_ASSERT( is_move_complete(string()) );
|
|
1410 |
# else
|
|
1411 |
CPPUNIT_ASSERT( !is_move_complete(string()) );
|
|
1412 |
# endif
|
|
1413 |
# if defined (_STLP_HAS_WCHAR_T)
|
|
1414 |
CPPUNIT_ASSERT( is_movable(wstring()) );
|
|
1415 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1416 |
CPPUNIT_ASSERT( is_move_complete(wstring()) );
|
|
1417 |
# else
|
|
1418 |
CPPUNIT_ASSERT( !is_move_complete(wstring()) );
|
|
1419 |
# endif
|
|
1420 |
# endif
|
|
1421 |
}
|
|
1422 |
|
|
1423 |
# if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
1424 |
{
|
|
1425 |
//crope, wrope:
|
|
1426 |
CPPUNIT_ASSERT( is_movable(crope()) );
|
|
1427 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1428 |
CPPUNIT_ASSERT( is_move_complete(crope()) );
|
|
1429 |
# else
|
|
1430 |
CPPUNIT_ASSERT( !is_move_complete(crope()) );
|
|
1431 |
# endif
|
|
1432 |
# if defined (_STLP_HAS_WCHAR_T)
|
|
1433 |
CPPUNIT_ASSERT( is_movable(wrope()) );
|
|
1434 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1435 |
CPPUNIT_ASSERT( is_move_complete(wrope()) );
|
|
1436 |
# else
|
|
1437 |
CPPUNIT_ASSERT( !is_move_complete(wrope()) );
|
|
1438 |
# endif
|
|
1439 |
# endif
|
|
1440 |
}
|
|
1441 |
# endif
|
|
1442 |
|
|
1443 |
{
|
|
1444 |
//vector:
|
|
1445 |
CPPUNIT_ASSERT( is_movable(vector<char>()) );
|
|
1446 |
CPPUNIT_ASSERT( is_movable(vector<specially_allocated_struct>()) );
|
|
1447 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1448 |
CPPUNIT_ASSERT( is_move_complete(vector<char>()) );
|
|
1449 |
CPPUNIT_ASSERT( !is_move_complete(vector<specially_allocated_struct>()) );
|
|
1450 |
# else
|
|
1451 |
CPPUNIT_ASSERT( !is_move_complete(vector<char>()) );
|
|
1452 |
# endif
|
|
1453 |
}
|
|
1454 |
|
|
1455 |
{
|
|
1456 |
//deque:
|
|
1457 |
CPPUNIT_ASSERT( is_movable(deque<char>()) );
|
|
1458 |
CPPUNIT_ASSERT( is_movable(deque<specially_allocated_struct>()) );
|
|
1459 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1460 |
CPPUNIT_ASSERT( is_move_complete(deque<char>()) );
|
|
1461 |
CPPUNIT_ASSERT( !is_move_complete(deque<specially_allocated_struct>()) );
|
|
1462 |
# else
|
|
1463 |
CPPUNIT_ASSERT( !is_move_complete(deque<char>()) );
|
|
1464 |
# endif
|
|
1465 |
}
|
|
1466 |
|
|
1467 |
{
|
|
1468 |
//list:
|
|
1469 |
CPPUNIT_ASSERT( is_movable(list<char>()) );
|
|
1470 |
CPPUNIT_ASSERT( is_movable(list<specially_allocated_struct>()) );
|
|
1471 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1472 |
CPPUNIT_ASSERT( is_move_complete(list<char>()) );
|
|
1473 |
CPPUNIT_ASSERT( !is_move_complete(list<specially_allocated_struct>()) );
|
|
1474 |
# else
|
|
1475 |
CPPUNIT_ASSERT( !is_move_complete(list<char>()) );
|
|
1476 |
# endif
|
|
1477 |
}
|
|
1478 |
|
|
1479 |
#if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
1480 |
{
|
|
1481 |
//slist:
|
|
1482 |
CPPUNIT_ASSERT( is_movable(slist<char>()) );
|
|
1483 |
CPPUNIT_ASSERT( is_movable(slist<specially_allocated_struct>()) );
|
|
1484 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1485 |
CPPUNIT_ASSERT( is_move_complete(slist<char>()) );
|
|
1486 |
CPPUNIT_ASSERT( !is_move_complete(slist<specially_allocated_struct>()) );
|
|
1487 |
# else
|
|
1488 |
CPPUNIT_ASSERT( !is_move_complete(slist<char>()) );
|
|
1489 |
# endif
|
|
1490 |
}
|
|
1491 |
#endif
|
|
1492 |
|
|
1493 |
{
|
|
1494 |
//queue:
|
|
1495 |
CPPUNIT_ASSERT( is_movable(queue<char>()) );
|
|
1496 |
CPPUNIT_ASSERT( is_movable(queue<specially_allocated_struct>()) );
|
|
1497 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1498 |
CPPUNIT_ASSERT( is_move_complete(queue<char>()) );
|
|
1499 |
CPPUNIT_ASSERT( !is_move_complete(queue<specially_allocated_struct>()) );
|
|
1500 |
# else
|
|
1501 |
CPPUNIT_ASSERT( !is_move_complete(queue<char>()) );
|
|
1502 |
# endif
|
|
1503 |
}
|
|
1504 |
|
|
1505 |
{
|
|
1506 |
//stack:
|
|
1507 |
CPPUNIT_ASSERT( is_movable(stack<char>()) );
|
|
1508 |
CPPUNIT_ASSERT( is_movable(stack<specially_allocated_struct>()) );
|
|
1509 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1510 |
CPPUNIT_ASSERT( is_move_complete(stack<char>()) );
|
|
1511 |
CPPUNIT_ASSERT( !is_move_complete(stack<specially_allocated_struct>()) );
|
|
1512 |
# else
|
|
1513 |
CPPUNIT_ASSERT( !is_move_complete(stack<char>()) );
|
|
1514 |
# endif
|
|
1515 |
}
|
|
1516 |
|
|
1517 |
{
|
|
1518 |
//associative containers, set multiset, map, multimap:
|
|
1519 |
|
|
1520 |
//For associative containers it is important that less is correctly recognize as
|
|
1521 |
//the STLport less or a user specialized less:
|
|
1522 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1523 |
CPPUNIT_ASSERT( is_move_complete(less<char>()) );
|
|
1524 |
# endif
|
|
1525 |
CPPUNIT_ASSERT( !is_move_complete(less<struct_with_specialized_less>()) );
|
|
1526 |
|
|
1527 |
//set
|
|
1528 |
CPPUNIT_ASSERT( is_movable(set<char>()) );
|
|
1529 |
CPPUNIT_ASSERT( is_movable(set<specially_allocated_struct>()) );
|
|
1530 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1531 |
CPPUNIT_ASSERT( is_move_complete(set<char>()) );
|
|
1532 |
CPPUNIT_ASSERT( !is_move_complete(set<specially_allocated_struct>()) );
|
|
1533 |
# else
|
|
1534 |
CPPUNIT_ASSERT( !is_move_complete(set<char>()) );
|
|
1535 |
# endif
|
|
1536 |
|
|
1537 |
//multiset
|
|
1538 |
CPPUNIT_ASSERT( is_movable(multiset<char>()) );
|
|
1539 |
CPPUNIT_ASSERT( is_movable(multiset<specially_allocated_struct>()) );
|
|
1540 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1541 |
CPPUNIT_ASSERT( is_move_complete(multiset<char>()) );
|
|
1542 |
CPPUNIT_ASSERT( !is_move_complete(multiset<specially_allocated_struct>()) );
|
|
1543 |
# else
|
|
1544 |
CPPUNIT_ASSERT( !is_move_complete(multiset<char>()) );
|
|
1545 |
# endif
|
|
1546 |
|
|
1547 |
//map
|
|
1548 |
CPPUNIT_ASSERT( is_movable(map<char, char>()) );
|
|
1549 |
CPPUNIT_ASSERT( is_movable(map<specially_allocated_struct, char>()) );
|
|
1550 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1551 |
CPPUNIT_ASSERT( is_move_complete(map<char, char>()) );
|
|
1552 |
//Here even if allocator has been specialized for specially_allocated_struct
|
|
1553 |
//this pecialization won't be used in default map instanciation as the default
|
|
1554 |
//allocator is allocator<pair<specially_allocated_struct, char> >
|
|
1555 |
CPPUNIT_ASSERT( is_move_complete(map<specially_allocated_struct, char>()) );
|
|
1556 |
# else
|
|
1557 |
CPPUNIT_ASSERT( !is_move_complete(map<char, char>()) );
|
|
1558 |
# endif
|
|
1559 |
|
|
1560 |
//multimap
|
|
1561 |
CPPUNIT_ASSERT( is_movable(multimap<char, char>()) );
|
|
1562 |
CPPUNIT_ASSERT( is_movable(multimap<specially_allocated_struct, char>()) );
|
|
1563 |
# if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
|
1564 |
CPPUNIT_ASSERT( is_move_complete(multimap<char, char>()) );
|
|
1565 |
//Idem map remark
|
|
1566 |
CPPUNIT_ASSERT( is_move_complete(multimap<specially_allocated_struct, char>()) );
|
|
1567 |
# else
|
|
1568 |
CPPUNIT_ASSERT( !is_move_complete(multimap<char, char>()) );
|
|
1569 |
# endif
|
|
1570 |
}
|
|
1571 |
|
|
1572 |
# if defined (STLPORT)
|
|
1573 |
{
|
|
1574 |
//hashed containers, unordered_set unordered_multiset, unordered_map, unordered_multimap,
|
|
1575 |
// hash_set, hash_multiset, hash_map, hash_multimap:
|
|
1576 |
|
|
1577 |
//We only check that they are movable, completness is not yet supported
|
|
1578 |
CPPUNIT_ASSERT( is_movable(unordered_set<char>()) );
|
|
1579 |
CPPUNIT_ASSERT( is_movable(unordered_multiset<char>()) );
|
|
1580 |
CPPUNIT_ASSERT( is_movable(unordered_map<char, char>()) );
|
|
1581 |
CPPUNIT_ASSERT( is_movable(unordered_multimap<char, char>()) );
|
|
1582 |
# if defined (STLPORT) && !defined (_STLP_NO_EXTENSIONS)
|
|
1583 |
CPPUNIT_ASSERT( is_movable(hash_set<char>()) );
|
|
1584 |
CPPUNIT_ASSERT( is_movable(hash_multiset<char>()) );
|
|
1585 |
CPPUNIT_ASSERT( is_movable(hash_map<char, char>()) );
|
|
1586 |
CPPUNIT_ASSERT( is_movable(hash_multimap<char, char>()) );
|
|
1587 |
# endif
|
|
1588 |
}
|
|
1589 |
# endif
|
|
1590 |
# endif
|
|
1591 |
}
|
|
1592 |
|
|
1593 |
#if defined (__BORLANDC__)
|
|
1594 |
/* Specific Borland test case to show a really weird compiler behavior.
|
|
1595 |
*/
|
|
1596 |
class Standalone
|
|
1597 |
{
|
|
1598 |
public:
|
|
1599 |
//Uncomment following to pass the test
|
|
1600 |
//Standalone() {}
|
|
1601 |
~Standalone() {}
|
|
1602 |
|
|
1603 |
MovableStruct movableStruct;
|
|
1604 |
vector<int> intVector;
|
|
1605 |
};
|
|
1606 |
|
|
1607 |
void MoveConstructorTest::nb_destructor_calls()
|
|
1608 |
{
|
|
1609 |
MovableStruct::reset();
|
|
1610 |
|
|
1611 |
try
|
|
1612 |
{
|
|
1613 |
Standalone standalone;
|
|
1614 |
throw "some exception";
|
|
1615 |
MovableStruct movableStruct;
|
|
1616 |
}
|
|
1617 |
catch (const char*)
|
|
1618 |
{
|
|
1619 |
CPPUNIT_ASSERT( MovableStruct::nb_dft_construct_call == 1 );
|
|
1620 |
CPPUNIT_ASSERT( MovableStruct::nb_destruct_call == 1 );
|
|
1621 |
}
|
|
1622 |
}
|
|
1623 |
#endif
|