1 | // |
2 | // local_sp_test.cpp |
3 | // |
4 | // Copyright 2002, 2003, 2017 Peter Dimov |
5 | // |
6 | // Distributed under the Boost Software License, Version 1.0. |
7 | // See accompanying file LICENSE_1_0.txt or copy at |
8 | // http://www.boost.org/LICENSE_1_0.txt |
9 | // |
10 | |
11 | #include <boost/smart_ptr/local_shared_ptr.hpp> |
12 | #include <boost/smart_ptr/shared_ptr.hpp> |
13 | #include <boost/smart_ptr/weak_ptr.hpp> |
14 | #include <boost/core/lightweight_test.hpp> |
15 | |
16 | struct X |
17 | { |
18 | static long instances; |
19 | |
20 | X() |
21 | { |
22 | ++instances; |
23 | } |
24 | |
25 | ~X() |
26 | { |
27 | --instances; |
28 | } |
29 | |
30 | private: |
31 | |
32 | X( X const & ); |
33 | X & operator=( X const & ); |
34 | }; |
35 | |
36 | long X::instances = 0; |
37 | |
38 | class incomplete; |
39 | |
40 | // default constructor |
41 | |
42 | static void default_constructor() |
43 | { |
44 | { |
45 | boost::local_shared_ptr<int> p; |
46 | |
47 | BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); |
48 | BOOST_TEST_EQ( p.local_use_count(), 0 ); |
49 | } |
50 | |
51 | { |
52 | boost::local_shared_ptr<void> p; |
53 | |
54 | BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); |
55 | BOOST_TEST_EQ( p.local_use_count(), 0 ); |
56 | } |
57 | |
58 | { |
59 | boost::local_shared_ptr<incomplete> p; |
60 | |
61 | BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); |
62 | BOOST_TEST_EQ( p.local_use_count(), 0 ); |
63 | } |
64 | |
65 | BOOST_TEST( X::instances == 0 ); |
66 | |
67 | { |
68 | boost::local_shared_ptr<X> p; |
69 | |
70 | BOOST_TEST( X::instances == 0 ); |
71 | |
72 | BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); |
73 | BOOST_TEST_EQ( p.local_use_count(), 0 ); |
74 | } |
75 | } |
76 | |
77 | // nullptr_constructor |
78 | |
79 | static void nullptr_constructor() |
80 | { |
81 | #if !defined( BOOST_NO_CXX11_NULLPTR ) |
82 | |
83 | { |
84 | boost::local_shared_ptr<int> p( nullptr ); |
85 | |
86 | BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); |
87 | BOOST_TEST_EQ( p.local_use_count(), 0 ); |
88 | } |
89 | |
90 | { |
91 | boost::local_shared_ptr<void> p( nullptr ); |
92 | |
93 | BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); |
94 | BOOST_TEST_EQ( p.local_use_count(), 0 ); |
95 | } |
96 | |
97 | { |
98 | boost::local_shared_ptr<incomplete> p( nullptr ); |
99 | |
100 | BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); |
101 | BOOST_TEST_EQ( p.local_use_count(), 0 ); |
102 | } |
103 | |
104 | BOOST_TEST( X::instances == 0 ); |
105 | |
106 | { |
107 | boost::local_shared_ptr<X> p( nullptr ); |
108 | |
109 | BOOST_TEST( X::instances == 0 ); |
110 | |
111 | |
112 | BOOST_TEST_EQ( p.get(), static_cast<void*>(0) ); |
113 | BOOST_TEST_EQ( p.local_use_count(), 0 ); |
114 | } |
115 | |
116 | #endif |
117 | } |
118 | |
119 | // pointer constructor |
120 | |
121 | template<class T, class U> static void pc0_test_() |
122 | { |
123 | boost::local_shared_ptr<T> p( static_cast<U*>( 0 ) ); |
124 | |
125 | BOOST_TEST( p? false: true ); |
126 | BOOST_TEST( !p ); |
127 | BOOST_TEST( p.get() == 0 ); |
128 | BOOST_TEST( p.local_use_count() == 1 ); |
129 | } |
130 | |
131 | template<class T> static void pc0_test() |
132 | { |
133 | pc0_test_<T, T>(); |
134 | pc0_test_<T const, T const>(); |
135 | pc0_test_<T volatile, T volatile>(); |
136 | pc0_test_<T const volatile, T const volatile>(); |
137 | |
138 | pc0_test_<T const, T>(); |
139 | pc0_test_<T volatile, T>(); |
140 | pc0_test_<T const volatile, T>(); |
141 | |
142 | pc0_test_<void, T>(); |
143 | pc0_test_<void const, T>(); |
144 | pc0_test_<void volatile, T>(); |
145 | pc0_test_<void const volatile, T>(); |
146 | } |
147 | |
148 | template<class T, class U> static void pc1_test_() |
149 | { |
150 | boost::local_shared_ptr<T> p( new U() ); |
151 | |
152 | BOOST_TEST( p? true: false ); |
153 | BOOST_TEST( !!p ); |
154 | BOOST_TEST( p.get() != 0 ); |
155 | BOOST_TEST( p.local_use_count() == 1 ); |
156 | } |
157 | |
158 | template<class T> static void pc1_test() |
159 | { |
160 | pc1_test_<T, T>(); |
161 | pc1_test_<T const, T const>(); |
162 | pc1_test_<T volatile, T volatile>(); |
163 | pc1_test_<T const volatile, T const volatile>(); |
164 | |
165 | pc1_test_<T const, T>(); |
166 | pc1_test_<T volatile, T>(); |
167 | pc1_test_<T const volatile, T>(); |
168 | |
169 | pc1_test_<void, T>(); |
170 | pc1_test_<void const, T>(); |
171 | pc1_test_<void volatile, T>(); |
172 | pc1_test_<void const volatile, T>(); |
173 | } |
174 | |
175 | static void pointer_constructor() |
176 | { |
177 | pc0_test<int>(); |
178 | pc0_test<X>(); |
179 | |
180 | pc1_test<int>(); |
181 | |
182 | BOOST_TEST( X::instances == 0 ); |
183 | |
184 | pc1_test<X>(); |
185 | |
186 | BOOST_TEST( X::instances == 0 ); |
187 | } |
188 | |
189 | // deleter constructor |
190 | |
191 | int m = 0; |
192 | |
193 | void deleter2( int * p ) |
194 | { |
195 | BOOST_TEST( p == &m ); |
196 | ++*p; |
197 | } |
198 | |
199 | template<class T> static void deleter2_test_() |
200 | { |
201 | { |
202 | m = 0; |
203 | boost::local_shared_ptr<T> p( &m, deleter2 ); |
204 | |
205 | BOOST_TEST( p? true: false ); |
206 | BOOST_TEST( !!p ); |
207 | BOOST_TEST( p.get() == &m ); |
208 | BOOST_TEST( p.local_use_count() == 1 ); |
209 | } |
210 | |
211 | BOOST_TEST( m == 1 ); |
212 | } |
213 | |
214 | static void deleter_constructor() |
215 | { |
216 | deleter2_test_<int>(); |
217 | deleter2_test_<int const>(); |
218 | deleter2_test_<int volatile>(); |
219 | deleter2_test_<int const volatile>(); |
220 | |
221 | deleter2_test_<void>(); |
222 | deleter2_test_<void const>(); |
223 | deleter2_test_<void volatile>(); |
224 | deleter2_test_<void const volatile>(); |
225 | } |
226 | |
227 | // nullptr_deleter_constructor |
228 | |
229 | #if !defined( BOOST_NO_CXX11_NULLPTR ) |
230 | |
231 | void deleter3( boost::detail::sp_nullptr_t ) |
232 | { |
233 | ++m; |
234 | } |
235 | |
236 | template<class T> static void deleter3_test_() |
237 | { |
238 | { |
239 | m = 0; |
240 | boost::local_shared_ptr<T> p( nullptr, deleter3 ); |
241 | |
242 | BOOST_TEST( !p ); |
243 | BOOST_TEST( p.get() == 0 ); |
244 | BOOST_TEST( p.local_use_count() == 1 ); |
245 | } |
246 | |
247 | BOOST_TEST( m == 1 ); |
248 | } |
249 | |
250 | static void nullptr_deleter_constructor() |
251 | { |
252 | deleter3_test_<int>(); |
253 | deleter3_test_<int const>(); |
254 | deleter3_test_<int volatile>(); |
255 | deleter3_test_<int const volatile>(); |
256 | |
257 | deleter3_test_<void>(); |
258 | deleter3_test_<void const>(); |
259 | deleter3_test_<void volatile>(); |
260 | deleter3_test_<void const volatile>(); |
261 | } |
262 | |
263 | #else |
264 | |
265 | static void nullptr_deleter_constructor() |
266 | { |
267 | } |
268 | |
269 | #endif |
270 | |
271 | // allocator constructor |
272 | |
273 | template<class T> static void allocator_test_() |
274 | { |
275 | { |
276 | m = 0; |
277 | boost::local_shared_ptr<T> p( &m, deleter2, std::allocator<void>() ); |
278 | |
279 | BOOST_TEST( p? true: false ); |
280 | BOOST_TEST( !!p ); |
281 | BOOST_TEST( p.get() == &m ); |
282 | BOOST_TEST( p.local_use_count() == 1 ); |
283 | } |
284 | |
285 | BOOST_TEST( m == 1 ); |
286 | } |
287 | |
288 | static void allocator_constructor() |
289 | { |
290 | allocator_test_<int>(); |
291 | allocator_test_<int const>(); |
292 | allocator_test_<int volatile>(); |
293 | allocator_test_<int const volatile>(); |
294 | |
295 | allocator_test_<void>(); |
296 | allocator_test_<void const>(); |
297 | allocator_test_<void volatile>(); |
298 | allocator_test_<void const volatile>(); |
299 | } |
300 | |
301 | // nullptr_allocator_constructor |
302 | |
303 | #if !defined( BOOST_NO_CXX11_NULLPTR ) |
304 | |
305 | template<class T> static void allocator3_test_() |
306 | { |
307 | { |
308 | m = 0; |
309 | boost::local_shared_ptr<T> p( nullptr, deleter3, std::allocator<void>() ); |
310 | |
311 | BOOST_TEST( !p ); |
312 | BOOST_TEST( p.get() == 0 ); |
313 | BOOST_TEST( p.local_use_count() == 1 ); |
314 | } |
315 | |
316 | BOOST_TEST( m == 1 ); |
317 | } |
318 | |
319 | static void nullptr_allocator_constructor() |
320 | { |
321 | allocator3_test_<int>(); |
322 | allocator3_test_<int const>(); |
323 | allocator3_test_<int volatile>(); |
324 | allocator3_test_<int const volatile>(); |
325 | |
326 | allocator3_test_<void>(); |
327 | allocator3_test_<void const>(); |
328 | allocator3_test_<void volatile>(); |
329 | allocator3_test_<void const volatile>(); |
330 | } |
331 | |
332 | #else |
333 | |
334 | static void nullptr_allocator_constructor() |
335 | { |
336 | } |
337 | |
338 | #endif |
339 | |
340 | // copy constructor |
341 | |
342 | template<class T> static void empty_copy_test() |
343 | { |
344 | boost::local_shared_ptr<T> p1; |
345 | |
346 | BOOST_TEST_EQ( p1.get(), static_cast<void*>(0) ); |
347 | BOOST_TEST_EQ( p1.local_use_count(), 0 ); |
348 | |
349 | boost::local_shared_ptr<T> p2( p1 ); |
350 | |
351 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
352 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
353 | |
354 | boost::local_shared_ptr<T const> p3( p1 ); |
355 | |
356 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
357 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
358 | |
359 | boost::local_shared_ptr<void> p4( p1 ); |
360 | |
361 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
362 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
363 | |
364 | boost::local_shared_ptr<void const> p5( p3 ); |
365 | |
366 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
367 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
368 | } |
369 | |
370 | template<class T, class U> static void test_nonempty_copy( boost::local_shared_ptr<U> const & p1 ) |
371 | { |
372 | long k = p1.local_use_count(); |
373 | |
374 | { |
375 | boost::local_shared_ptr<T> p2( p1 ); |
376 | |
377 | BOOST_TEST( p2.get() == p1.get() ); |
378 | BOOST_TEST( p2.local_use_count() == p1.local_use_count() ); |
379 | BOOST_TEST( p2.local_use_count() == k + 1 ); |
380 | } |
381 | |
382 | BOOST_TEST( p1.local_use_count() == k ); |
383 | } |
384 | |
385 | template<class T> static void null_copy_test() |
386 | { |
387 | boost::local_shared_ptr<T> p1( static_cast<T*>(0) ); |
388 | |
389 | test_nonempty_copy<T>( p1 ); |
390 | test_nonempty_copy<T const>( p1 ); |
391 | test_nonempty_copy<T volatile>( p1 ); |
392 | test_nonempty_copy<T const volatile>( p1 ); |
393 | test_nonempty_copy<void>( p1 ); |
394 | test_nonempty_copy<void const>( p1 ); |
395 | test_nonempty_copy<void volatile>( p1 ); |
396 | test_nonempty_copy<void const volatile>( p1 ); |
397 | } |
398 | |
399 | template<class T> static void new_copy_test() |
400 | { |
401 | boost::local_shared_ptr<T> p1( new T() ); |
402 | |
403 | test_nonempty_copy<T>( p1 ); |
404 | test_nonempty_copy<T const>( p1 ); |
405 | test_nonempty_copy<T volatile>( p1 ); |
406 | test_nonempty_copy<T const volatile>( p1 ); |
407 | test_nonempty_copy<void>( p1 ); |
408 | test_nonempty_copy<void const>( p1 ); |
409 | test_nonempty_copy<void volatile>( p1 ); |
410 | test_nonempty_copy<void const volatile>( p1 ); |
411 | } |
412 | |
413 | static void copy_constructor() |
414 | { |
415 | empty_copy_test<int>(); |
416 | empty_copy_test<incomplete>(); |
417 | empty_copy_test<X>(); |
418 | |
419 | BOOST_TEST( X::instances == 0 ); |
420 | |
421 | null_copy_test<int>(); |
422 | null_copy_test<X>(); |
423 | |
424 | BOOST_TEST( X::instances == 0 ); |
425 | |
426 | new_copy_test<int>(); |
427 | new_copy_test<X>(); |
428 | |
429 | BOOST_TEST( X::instances == 0 ); |
430 | } |
431 | |
432 | // move constructor |
433 | |
434 | #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) |
435 | |
436 | template<class T> static void empty_move_test() |
437 | { |
438 | boost::local_shared_ptr<T> p2(( boost::local_shared_ptr<T>() )); |
439 | |
440 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
441 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
442 | |
443 | boost::local_shared_ptr<T const> p3(( boost::local_shared_ptr<T>() )); |
444 | |
445 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
446 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
447 | |
448 | boost::local_shared_ptr<void> p4(( boost::local_shared_ptr<T>() )); |
449 | |
450 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
451 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
452 | |
453 | boost::local_shared_ptr<void const> p5( std::move(p3) ); |
454 | |
455 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
456 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
457 | } |
458 | |
459 | template<class T, class U> static void test_nonempty_move( boost::local_shared_ptr<U> && p1 ) |
460 | { |
461 | U* q = p1.get(); |
462 | long k = p1.local_use_count(); |
463 | |
464 | boost::local_shared_ptr<T> p2( std::move(p1) ); |
465 | |
466 | BOOST_TEST( p2.get() == q ); |
467 | BOOST_TEST( p2.local_use_count() == k ); |
468 | |
469 | BOOST_TEST( p1.get() == 0 ); |
470 | BOOST_TEST( p1.local_use_count() == 0 ); |
471 | } |
472 | |
473 | template<class T> static void null_move_test() |
474 | { |
475 | test_nonempty_move<T>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
476 | test_nonempty_move<T const>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
477 | test_nonempty_move<T volatile>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
478 | test_nonempty_move<T const volatile>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
479 | test_nonempty_move<void>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
480 | test_nonempty_move<void const>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
481 | test_nonempty_move<void volatile>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
482 | test_nonempty_move<void const volatile>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
483 | } |
484 | |
485 | template<class T> static void new_move_test() |
486 | { |
487 | test_nonempty_move<T>( boost::local_shared_ptr<T>( new T() ) ); |
488 | test_nonempty_move<T const>( boost::local_shared_ptr<T>( new T() ) ); |
489 | test_nonempty_move<T volatile>( boost::local_shared_ptr<T>( new T() ) ); |
490 | test_nonempty_move<T const volatile>( boost::local_shared_ptr<T>( new T() ) ); |
491 | test_nonempty_move<void>( boost::local_shared_ptr<T>( new T() ) ); |
492 | test_nonempty_move<void const>( boost::local_shared_ptr<T>( new T() ) ); |
493 | test_nonempty_move<void volatile>( boost::local_shared_ptr<T>( new T() ) ); |
494 | test_nonempty_move<void const volatile>( boost::local_shared_ptr<T>( new T() ) ); |
495 | } |
496 | |
497 | static void move_constructor() |
498 | { |
499 | empty_move_test<int>(); |
500 | empty_move_test<incomplete>(); |
501 | empty_move_test<X>(); |
502 | |
503 | BOOST_TEST( X::instances == 0 ); |
504 | |
505 | null_move_test<int>(); |
506 | null_move_test<X>(); |
507 | |
508 | BOOST_TEST( X::instances == 0 ); |
509 | |
510 | new_move_test<int>(); |
511 | new_move_test<X>(); |
512 | |
513 | BOOST_TEST( X::instances == 0 ); |
514 | } |
515 | |
516 | #else |
517 | |
518 | static void move_constructor() |
519 | { |
520 | } |
521 | |
522 | #endif |
523 | |
524 | // aliasing constructor |
525 | |
526 | template<class T, class U> void test_aliasing_( boost::local_shared_ptr<T> const & p1, U * p2 ) |
527 | { |
528 | boost::local_shared_ptr<U> p3( p1, p2 ); |
529 | |
530 | BOOST_TEST( p3.get() == p2 ); |
531 | BOOST_TEST( p3.local_use_count() == p1.local_use_count() ); |
532 | BOOST_TEST( !p3.owner_before( p1 ) && !p1.owner_before( p3 ) ); |
533 | } |
534 | |
535 | template<class T, class U> void test_01_aliasing_() |
536 | { |
537 | U u; |
538 | boost::local_shared_ptr<T> p1; |
539 | |
540 | test_aliasing_( p1, &u ); |
541 | } |
542 | |
543 | template<class T, class U> void test_01_aliasing() |
544 | { |
545 | test_01_aliasing_<T, U>(); |
546 | test_01_aliasing_<T const, U>(); |
547 | test_01_aliasing_<T volatile, U>(); |
548 | test_01_aliasing_<T const volatile, U>(); |
549 | |
550 | test_01_aliasing_<T, U volatile>(); |
551 | test_01_aliasing_<T const, U volatile>(); |
552 | test_01_aliasing_<T volatile, U volatile>(); |
553 | test_01_aliasing_<T const volatile, U volatile>(); |
554 | } |
555 | |
556 | template<class T, class U> void test_10_aliasing_() |
557 | { |
558 | boost::local_shared_ptr<T> p1( new T() ); |
559 | test_aliasing_( p1, static_cast<U*>(0) ); |
560 | } |
561 | |
562 | template<class T, class U> void test_10_aliasing() |
563 | { |
564 | test_10_aliasing_<T, U>(); |
565 | test_10_aliasing_<T const, U>(); |
566 | test_10_aliasing_<T volatile, U>(); |
567 | test_10_aliasing_<T const volatile, U>(); |
568 | |
569 | test_10_aliasing_<T, U const>(); |
570 | test_10_aliasing_<T const, U const>(); |
571 | test_10_aliasing_<T volatile, U const>(); |
572 | test_10_aliasing_<T const volatile, U const>(); |
573 | |
574 | test_10_aliasing_<T, U volatile>(); |
575 | test_10_aliasing_<T const, U volatile>(); |
576 | test_10_aliasing_<T volatile, U volatile>(); |
577 | test_10_aliasing_<T const volatile, U volatile>(); |
578 | |
579 | test_10_aliasing_<T, U const volatile>(); |
580 | test_10_aliasing_<T const, U const volatile>(); |
581 | test_10_aliasing_<T volatile, U const volatile>(); |
582 | test_10_aliasing_<T const volatile, U const volatile>(); |
583 | } |
584 | |
585 | template<class T, class U> void test_11_aliasing_() |
586 | { |
587 | U u; |
588 | boost::local_shared_ptr<T> p1( new T() ); |
589 | |
590 | test_aliasing_( p1, &u ); |
591 | } |
592 | |
593 | template<class T, class U> void test_11_aliasing() |
594 | { |
595 | test_11_aliasing_<T, U>(); |
596 | test_11_aliasing_<T const, U>(); |
597 | test_11_aliasing_<T volatile, U>(); |
598 | test_11_aliasing_<T const volatile, U>(); |
599 | |
600 | test_11_aliasing_<T, U volatile>(); |
601 | test_11_aliasing_<T const, U volatile>(); |
602 | test_11_aliasing_<T volatile, U volatile>(); |
603 | test_11_aliasing_<T const volatile, U volatile>(); |
604 | } |
605 | |
606 | static void aliasing_constructor() |
607 | { |
608 | test_01_aliasing<int, int>(); |
609 | test_10_aliasing<int, int>(); |
610 | test_11_aliasing<int, int>(); |
611 | |
612 | test_01_aliasing<void, int>(); |
613 | |
614 | test_10_aliasing<int, void>(); |
615 | |
616 | test_10_aliasing<int, incomplete>(); |
617 | |
618 | test_01_aliasing<X, X>(); |
619 | BOOST_TEST( X::instances == 0 ); |
620 | |
621 | test_10_aliasing<X, X>(); |
622 | BOOST_TEST( X::instances == 0 ); |
623 | |
624 | test_11_aliasing<X, X>(); |
625 | BOOST_TEST( X::instances == 0 ); |
626 | |
627 | test_01_aliasing<int, X>(); |
628 | BOOST_TEST( X::instances == 0 ); |
629 | |
630 | test_10_aliasing<int, X>(); |
631 | BOOST_TEST( X::instances == 0 ); |
632 | |
633 | test_11_aliasing<int, X>(); |
634 | BOOST_TEST( X::instances == 0 ); |
635 | |
636 | test_01_aliasing<X, int>(); |
637 | BOOST_TEST( X::instances == 0 ); |
638 | |
639 | test_10_aliasing<X, int>(); |
640 | BOOST_TEST( X::instances == 0 ); |
641 | |
642 | test_11_aliasing<X, int>(); |
643 | BOOST_TEST( X::instances == 0 ); |
644 | |
645 | test_01_aliasing<void, X>(); |
646 | BOOST_TEST( X::instances == 0 ); |
647 | |
648 | test_10_aliasing<X, void>(); |
649 | BOOST_TEST( X::instances == 0 ); |
650 | |
651 | test_10_aliasing<X, incomplete>(); |
652 | BOOST_TEST( X::instances == 0 ); |
653 | } |
654 | |
655 | // shared_ptr copy constructor |
656 | |
657 | template<class T> static void empty_shared_ptr_copy_test() |
658 | { |
659 | boost::shared_ptr<T> p1; |
660 | |
661 | boost::local_shared_ptr<T> p2( p1 ); |
662 | |
663 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
664 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
665 | |
666 | boost::local_shared_ptr<T const> p3( p1 ); |
667 | |
668 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
669 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
670 | |
671 | boost::local_shared_ptr<void> p4( p1 ); |
672 | |
673 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
674 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
675 | |
676 | boost::local_shared_ptr<void const> p5( p3 ); |
677 | |
678 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
679 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
680 | } |
681 | |
682 | template<class T, class U> static void test_nonempty_shared_ptr_copy( boost::shared_ptr<U> const & p1 ) |
683 | { |
684 | long k = p1.use_count(); |
685 | |
686 | { |
687 | boost::local_shared_ptr<T> p2( p1 ); |
688 | |
689 | BOOST_TEST( p2.get() == p1.get() ); |
690 | BOOST_TEST( p2.local_use_count() == 1 ); |
691 | |
692 | BOOST_TEST( p1.use_count() == k + 1 ); |
693 | } |
694 | |
695 | BOOST_TEST( p1.use_count() == k ); |
696 | } |
697 | |
698 | template<class T> static void null_shared_ptr_copy_test() |
699 | { |
700 | boost::shared_ptr<T> p1( static_cast<T*>(0) ); |
701 | |
702 | test_nonempty_shared_ptr_copy<T>( p1 ); |
703 | test_nonempty_shared_ptr_copy<T const>( p1 ); |
704 | test_nonempty_shared_ptr_copy<T volatile>( p1 ); |
705 | test_nonempty_shared_ptr_copy<T const volatile>( p1 ); |
706 | test_nonempty_shared_ptr_copy<void>( p1 ); |
707 | test_nonempty_shared_ptr_copy<void const>( p1 ); |
708 | test_nonempty_shared_ptr_copy<void volatile>( p1 ); |
709 | test_nonempty_shared_ptr_copy<void const volatile>( p1 ); |
710 | } |
711 | |
712 | template<class T> static void new_shared_ptr_copy_test() |
713 | { |
714 | boost::shared_ptr<T> p1( new T() ); |
715 | |
716 | test_nonempty_shared_ptr_copy<T>( p1 ); |
717 | test_nonempty_shared_ptr_copy<T const>( p1 ); |
718 | test_nonempty_shared_ptr_copy<T volatile>( p1 ); |
719 | test_nonempty_shared_ptr_copy<T const volatile>( p1 ); |
720 | test_nonempty_shared_ptr_copy<void>( p1 ); |
721 | test_nonempty_shared_ptr_copy<void const>( p1 ); |
722 | test_nonempty_shared_ptr_copy<void volatile>( p1 ); |
723 | test_nonempty_shared_ptr_copy<void const volatile>( p1 ); |
724 | } |
725 | |
726 | static void shared_ptr_copy_constructor() |
727 | { |
728 | empty_shared_ptr_copy_test<int>(); |
729 | empty_shared_ptr_copy_test<incomplete>(); |
730 | empty_shared_ptr_copy_test<X>(); |
731 | |
732 | BOOST_TEST( X::instances == 0 ); |
733 | |
734 | null_shared_ptr_copy_test<int>(); |
735 | null_shared_ptr_copy_test<X>(); |
736 | |
737 | BOOST_TEST( X::instances == 0 ); |
738 | |
739 | new_shared_ptr_copy_test<int>(); |
740 | new_shared_ptr_copy_test<X>(); |
741 | |
742 | BOOST_TEST( X::instances == 0 ); |
743 | } |
744 | |
745 | // shared_ptr_move constructor |
746 | |
747 | #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) |
748 | |
749 | template<class T> static void empty_shared_ptr_move_test() |
750 | { |
751 | boost::local_shared_ptr<T> p2(( boost::shared_ptr<T>() )); |
752 | |
753 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
754 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
755 | |
756 | boost::local_shared_ptr<T const> p3(( boost::shared_ptr<T>() )); |
757 | |
758 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
759 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
760 | |
761 | boost::local_shared_ptr<void> p4(( boost::shared_ptr<T>() )); |
762 | |
763 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
764 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
765 | |
766 | boost::local_shared_ptr<void const> p5( std::move(p3) ); |
767 | |
768 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
769 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
770 | } |
771 | |
772 | template<class T, class U> static void test_nonempty_shared_ptr_move( boost::shared_ptr<U> && p1 ) |
773 | { |
774 | U* q = p1.get(); |
775 | |
776 | boost::local_shared_ptr<T> p2( std::move(p1) ); |
777 | |
778 | BOOST_TEST( p2.get() == q ); |
779 | BOOST_TEST( p2.local_use_count() == 1 ); |
780 | |
781 | BOOST_TEST( p1.get() == 0 ); |
782 | BOOST_TEST( p1.use_count() == 0 ); |
783 | } |
784 | |
785 | template<class T> static void null_shared_ptr_move_test() |
786 | { |
787 | test_nonempty_shared_ptr_move<T>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
788 | test_nonempty_shared_ptr_move<T const>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
789 | test_nonempty_shared_ptr_move<T volatile>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
790 | test_nonempty_shared_ptr_move<T const volatile>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
791 | test_nonempty_shared_ptr_move<void>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
792 | test_nonempty_shared_ptr_move<void const>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
793 | test_nonempty_shared_ptr_move<void volatile>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
794 | test_nonempty_shared_ptr_move<void const volatile>( boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
795 | } |
796 | |
797 | template<class T> static void new_shared_ptr_move_test() |
798 | { |
799 | test_nonempty_shared_ptr_move<T>( boost::shared_ptr<T>( new T() ) ); |
800 | test_nonempty_shared_ptr_move<T const>( boost::shared_ptr<T>( new T() ) ); |
801 | test_nonempty_shared_ptr_move<T volatile>( boost::shared_ptr<T>( new T() ) ); |
802 | test_nonempty_shared_ptr_move<T const volatile>( boost::shared_ptr<T>( new T() ) ); |
803 | test_nonempty_shared_ptr_move<void>( boost::shared_ptr<T>( new T() ) ); |
804 | test_nonempty_shared_ptr_move<void const>( boost::shared_ptr<T>( new T() ) ); |
805 | test_nonempty_shared_ptr_move<void volatile>( boost::shared_ptr<T>( new T() ) ); |
806 | test_nonempty_shared_ptr_move<void const volatile>( boost::shared_ptr<T>( new T() ) ); |
807 | } |
808 | |
809 | static void shared_ptr_move_constructor() |
810 | { |
811 | empty_shared_ptr_move_test<int>(); |
812 | empty_shared_ptr_move_test<incomplete>(); |
813 | empty_shared_ptr_move_test<X>(); |
814 | |
815 | BOOST_TEST( X::instances == 0 ); |
816 | |
817 | null_shared_ptr_move_test<int>(); |
818 | null_shared_ptr_move_test<X>(); |
819 | |
820 | BOOST_TEST( X::instances == 0 ); |
821 | |
822 | new_shared_ptr_move_test<int>(); |
823 | new_shared_ptr_move_test<X>(); |
824 | |
825 | BOOST_TEST( X::instances == 0 ); |
826 | } |
827 | |
828 | #else |
829 | |
830 | static void shared_ptr_move_constructor() |
831 | { |
832 | } |
833 | |
834 | #endif |
835 | |
836 | // unique_ptr_constructor |
837 | |
838 | #if !defined( BOOST_NO_CXX11_SMART_PTR ) && !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) |
839 | |
840 | template<class T, class U> static void test_null_unique_ptr( std::unique_ptr<U> && p1 ) |
841 | { |
842 | boost::local_shared_ptr<T> p2( std::move( p1 ) ); |
843 | |
844 | BOOST_TEST( p1.get() == 0 ); |
845 | |
846 | BOOST_TEST( p2.get() == 0 ); |
847 | BOOST_TEST( p2.local_use_count() == 0 ); |
848 | } |
849 | |
850 | template<class T> static void null_unique_ptr_test() |
851 | { |
852 | test_null_unique_ptr<T>( std::unique_ptr<T>() ); |
853 | |
854 | test_null_unique_ptr<T const>( std::unique_ptr<T>() ); |
855 | test_null_unique_ptr<T volatile>( std::unique_ptr<T>() ); |
856 | test_null_unique_ptr<T const volatile>( std::unique_ptr<T>() ); |
857 | |
858 | test_null_unique_ptr<T const>( std::unique_ptr<T const>() ); |
859 | test_null_unique_ptr<T volatile>( std::unique_ptr<T volatile>() ); |
860 | test_null_unique_ptr<T const volatile>( std::unique_ptr<T const volatile>() ); |
861 | |
862 | test_null_unique_ptr<void>( std::unique_ptr<T>() ); |
863 | |
864 | test_null_unique_ptr<void const>( std::unique_ptr<T>() ); |
865 | test_null_unique_ptr<void volatile>( std::unique_ptr<T>() ); |
866 | test_null_unique_ptr<void const volatile>( std::unique_ptr<T>() ); |
867 | |
868 | test_null_unique_ptr<void const>( std::unique_ptr<T const>() ); |
869 | test_null_unique_ptr<void volatile>( std::unique_ptr<T volatile>() ); |
870 | test_null_unique_ptr<void const volatile>( std::unique_ptr<T const volatile>() ); |
871 | } |
872 | |
873 | template<class T, class U, class D> static void test_nonempty_unique_ptr( std::unique_ptr<U, D> && p1 ) |
874 | { |
875 | U * q = p1.get(); |
876 | |
877 | boost::local_shared_ptr<T> p2( std::move(p1) ); |
878 | |
879 | BOOST_TEST( p2.get() == q ); |
880 | BOOST_TEST( p2.local_use_count() == 1 ); |
881 | |
882 | BOOST_TEST( p1.get() == 0 ); |
883 | } |
884 | |
885 | template<class T> static void new_unique_ptr_test() |
886 | { |
887 | test_nonempty_unique_ptr<T>( std::unique_ptr<T>( new T() ) ); |
888 | |
889 | test_nonempty_unique_ptr<T const>( std::unique_ptr<T>( new T() ) ); |
890 | test_nonempty_unique_ptr<T volatile>( std::unique_ptr<T>( new T() ) ); |
891 | test_nonempty_unique_ptr<T const volatile>( std::unique_ptr<T>( new T() ) ); |
892 | |
893 | test_nonempty_unique_ptr<T const>( std::unique_ptr<T const>( new T() ) ); |
894 | test_nonempty_unique_ptr<T volatile>( std::unique_ptr<T volatile>( new T() ) ); |
895 | test_nonempty_unique_ptr<T const volatile>( std::unique_ptr<T const volatile>( new T() ) ); |
896 | |
897 | test_nonempty_unique_ptr<void>( std::unique_ptr<T>( new T() ) ); |
898 | |
899 | test_nonempty_unique_ptr<void const>( std::unique_ptr<T>( new T() ) ); |
900 | test_nonempty_unique_ptr<void volatile>( std::unique_ptr<T>( new T() ) ); |
901 | test_nonempty_unique_ptr<void const volatile>( std::unique_ptr<T>( new T() ) ); |
902 | |
903 | test_nonempty_unique_ptr<void const>( std::unique_ptr<T const>( new T() ) ); |
904 | test_nonempty_unique_ptr<void volatile>( std::unique_ptr<T volatile>( new T() ) ); |
905 | test_nonempty_unique_ptr<void const volatile>( std::unique_ptr<T const volatile>( new T() ) ); |
906 | } |
907 | |
908 | template<class T> static void test_deleter_unique_ptr() |
909 | { |
910 | m = 0; |
911 | |
912 | test_nonempty_unique_ptr<T>( std::unique_ptr<int, void(*)(int*)>( &m, deleter2 ) ); |
913 | |
914 | BOOST_TEST( m == 1 ); |
915 | } |
916 | |
917 | template<class T> static void deleter_unique_ptr_test() |
918 | { |
919 | test_deleter_unique_ptr<T>(); |
920 | test_deleter_unique_ptr<T const>(); |
921 | test_deleter_unique_ptr<T volatile>(); |
922 | test_deleter_unique_ptr<T const volatile>(); |
923 | } |
924 | |
925 | static void unique_ptr_constructor() |
926 | { |
927 | null_unique_ptr_test<int>(); |
928 | null_unique_ptr_test<X>(); |
929 | |
930 | BOOST_TEST( X::instances == 0 ); |
931 | |
932 | new_unique_ptr_test<int>(); |
933 | new_unique_ptr_test<X>(); |
934 | |
935 | BOOST_TEST( X::instances == 0 ); |
936 | |
937 | deleter_unique_ptr_test<int>(); |
938 | deleter_unique_ptr_test<void>(); |
939 | } |
940 | |
941 | #else |
942 | |
943 | static void unique_ptr_constructor() |
944 | { |
945 | } |
946 | |
947 | #endif |
948 | |
949 | // copy assignment |
950 | |
951 | template<class T> static void empty_copy_assign_test() |
952 | { |
953 | boost::local_shared_ptr<T> p1; |
954 | |
955 | BOOST_TEST_EQ( p1.get(), static_cast<void*>(0) ); |
956 | BOOST_TEST_EQ( p1.local_use_count(), 0 ); |
957 | |
958 | boost::local_shared_ptr<T> p2; |
959 | |
960 | p2 = p1; |
961 | |
962 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
963 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
964 | |
965 | boost::local_shared_ptr<T const> p3; |
966 | |
967 | p3 = p1; |
968 | |
969 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
970 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
971 | |
972 | boost::local_shared_ptr<void> p4; |
973 | |
974 | p4 = p1; |
975 | |
976 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
977 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
978 | |
979 | boost::local_shared_ptr<void const> p5; |
980 | |
981 | p5 = p3; |
982 | |
983 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
984 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
985 | } |
986 | |
987 | template<class T> static void empty_copy_assign_test_() |
988 | { |
989 | boost::local_shared_ptr<T> p1; |
990 | |
991 | BOOST_TEST_EQ( p1.get(), static_cast<void*>(0) ); |
992 | BOOST_TEST_EQ( p1.local_use_count(), 0 ); |
993 | |
994 | boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); |
995 | |
996 | p2 = p1; |
997 | |
998 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
999 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1000 | |
1001 | boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); |
1002 | |
1003 | p3 = p1; |
1004 | |
1005 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1006 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1007 | |
1008 | boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); |
1009 | |
1010 | p4 = p1; |
1011 | |
1012 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1013 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1014 | |
1015 | boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); |
1016 | |
1017 | p5 = p3; |
1018 | |
1019 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1020 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1021 | } |
1022 | |
1023 | template<class T, class U> static void test_nonempty_copy_assign( boost::local_shared_ptr<T> p2, boost::local_shared_ptr<U> const & p1 ) |
1024 | { |
1025 | long k = p1.local_use_count(); |
1026 | |
1027 | p2 = p1; |
1028 | |
1029 | BOOST_TEST( p2.get() == p1.get() ); |
1030 | BOOST_TEST( p2.local_use_count() == p1.local_use_count() ); |
1031 | BOOST_TEST( p2.local_use_count() == k + 1 ); |
1032 | |
1033 | p2.reset(); |
1034 | |
1035 | BOOST_TEST( p1.local_use_count() == k ); |
1036 | } |
1037 | |
1038 | template<class T> static void null_copy_assign_test() |
1039 | { |
1040 | boost::local_shared_ptr<T> p1( static_cast<T*>(0) ); |
1041 | |
1042 | test_nonempty_copy_assign( boost::local_shared_ptr<T>(), p1 ); |
1043 | test_nonempty_copy_assign( boost::local_shared_ptr<T const>(), p1 ); |
1044 | test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>(), p1 ); |
1045 | test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>(), p1 ); |
1046 | |
1047 | test_nonempty_copy_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), p1 ); |
1048 | test_nonempty_copy_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), p1 ); |
1049 | test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), p1 ); |
1050 | test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), p1 ); |
1051 | |
1052 | test_nonempty_copy_assign( boost::local_shared_ptr<void>(), p1 ); |
1053 | test_nonempty_copy_assign( boost::local_shared_ptr<void const>(), p1 ); |
1054 | test_nonempty_copy_assign( boost::local_shared_ptr<void volatile>(), p1 ); |
1055 | test_nonempty_copy_assign( boost::local_shared_ptr<void const volatile>(), p1 ); |
1056 | } |
1057 | |
1058 | template<class T> static void new_copy_assign_test() |
1059 | { |
1060 | boost::local_shared_ptr<T> p1( new T() ); |
1061 | |
1062 | test_nonempty_copy_assign( boost::local_shared_ptr<T>(), p1 ); |
1063 | test_nonempty_copy_assign( boost::local_shared_ptr<T const>(), p1 ); |
1064 | test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>(), p1 ); |
1065 | test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>(), p1 ); |
1066 | |
1067 | test_nonempty_copy_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), p1 ); |
1068 | test_nonempty_copy_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), p1 ); |
1069 | test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), p1 ); |
1070 | test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), p1 ); |
1071 | |
1072 | test_nonempty_copy_assign( boost::local_shared_ptr<T>( new T() ), p1 ); |
1073 | test_nonempty_copy_assign( boost::local_shared_ptr<T const>( new T const() ), p1 ); |
1074 | test_nonempty_copy_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), p1 ); |
1075 | test_nonempty_copy_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), p1 ); |
1076 | |
1077 | test_nonempty_copy_assign( boost::local_shared_ptr<void>(), p1 ); |
1078 | test_nonempty_copy_assign( boost::local_shared_ptr<void const>(), p1 ); |
1079 | test_nonempty_copy_assign( boost::local_shared_ptr<void volatile>(), p1 ); |
1080 | test_nonempty_copy_assign( boost::local_shared_ptr<void const volatile>(), p1 ); |
1081 | } |
1082 | |
1083 | static void copy_assignment() |
1084 | { |
1085 | empty_copy_assign_test<incomplete>(); |
1086 | empty_copy_assign_test<int>(); |
1087 | empty_copy_assign_test_<int>(); |
1088 | empty_copy_assign_test<X>(); |
1089 | empty_copy_assign_test_<X>(); |
1090 | |
1091 | BOOST_TEST( X::instances == 0 ); |
1092 | |
1093 | null_copy_assign_test<int>(); |
1094 | null_copy_assign_test<X>(); |
1095 | |
1096 | BOOST_TEST( X::instances == 0 ); |
1097 | |
1098 | new_copy_assign_test<int>(); |
1099 | new_copy_assign_test<X>(); |
1100 | |
1101 | BOOST_TEST( X::instances == 0 ); |
1102 | } |
1103 | |
1104 | // move assignment |
1105 | |
1106 | #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) |
1107 | |
1108 | template<class T> static void empty_move_assign_test() |
1109 | { |
1110 | boost::local_shared_ptr<T> p2; |
1111 | |
1112 | p2 = boost::local_shared_ptr<T>(); |
1113 | |
1114 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
1115 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1116 | |
1117 | boost::local_shared_ptr<T const> p3; |
1118 | |
1119 | p3 = boost::local_shared_ptr<T>(); |
1120 | |
1121 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1122 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1123 | |
1124 | boost::local_shared_ptr<void> p4; |
1125 | |
1126 | p4 = boost::local_shared_ptr<T>(); |
1127 | |
1128 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1129 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1130 | |
1131 | boost::local_shared_ptr<void const> p5; |
1132 | |
1133 | p5 = std::move( p3 ); |
1134 | |
1135 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1136 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1137 | } |
1138 | |
1139 | template<class T> static void empty_move_assign_test_() |
1140 | { |
1141 | boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); |
1142 | |
1143 | p2 = boost::local_shared_ptr<T>(); |
1144 | |
1145 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
1146 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1147 | |
1148 | boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); |
1149 | |
1150 | p3 = boost::local_shared_ptr<T>(); |
1151 | |
1152 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1153 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1154 | |
1155 | boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); |
1156 | |
1157 | p4 = boost::local_shared_ptr<T>(); |
1158 | |
1159 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1160 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1161 | |
1162 | boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); |
1163 | |
1164 | p5 = std::move( p3 ); |
1165 | |
1166 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1167 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1168 | } |
1169 | |
1170 | template<class T, class U> static void test_nonempty_move_assign( boost::local_shared_ptr<T> p2, boost::local_shared_ptr<U> && p1 ) |
1171 | { |
1172 | U* q = p1.get(); |
1173 | long k = p1.local_use_count(); |
1174 | |
1175 | p2 = std::move( p1 ); |
1176 | |
1177 | BOOST_TEST( p2.get() == q ); |
1178 | BOOST_TEST( p2.local_use_count() == k ); |
1179 | |
1180 | BOOST_TEST( p1.get() == 0 ); |
1181 | BOOST_TEST( p1.local_use_count() == 0 ); |
1182 | } |
1183 | |
1184 | template<class T> static void null_move_assign_test() |
1185 | { |
1186 | test_nonempty_move_assign( boost::local_shared_ptr<T>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1187 | test_nonempty_move_assign( boost::local_shared_ptr<T const>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1188 | test_nonempty_move_assign( boost::local_shared_ptr<T volatile>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1189 | test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1190 | |
1191 | test_nonempty_move_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1192 | test_nonempty_move_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1193 | test_nonempty_move_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1194 | test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1195 | |
1196 | test_nonempty_move_assign( boost::local_shared_ptr<void>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1197 | test_nonempty_move_assign( boost::local_shared_ptr<void const>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1198 | test_nonempty_move_assign( boost::local_shared_ptr<void volatile>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1199 | test_nonempty_move_assign( boost::local_shared_ptr<void const volatile>(), boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1200 | } |
1201 | |
1202 | template<class T> static void new_move_assign_test() |
1203 | { |
1204 | test_nonempty_move_assign( boost::local_shared_ptr<T>(), boost::local_shared_ptr<T>( new T() ) ); |
1205 | test_nonempty_move_assign( boost::local_shared_ptr<T const>(), boost::local_shared_ptr<T>( new T() ) ); |
1206 | test_nonempty_move_assign( boost::local_shared_ptr<T volatile>(), boost::local_shared_ptr<T>( new T() ) ); |
1207 | test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>(), boost::local_shared_ptr<T>( new T() ) ); |
1208 | |
1209 | test_nonempty_move_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), boost::local_shared_ptr<T>( new T() ) ); |
1210 | test_nonempty_move_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), boost::local_shared_ptr<T>( new T() ) ); |
1211 | test_nonempty_move_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), boost::local_shared_ptr<T>( new T() ) ); |
1212 | test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), boost::local_shared_ptr<T>( new T() ) ); |
1213 | |
1214 | test_nonempty_move_assign( boost::local_shared_ptr<T>( new T() ), boost::local_shared_ptr<T>( new T() ) ); |
1215 | test_nonempty_move_assign( boost::local_shared_ptr<T const>( new T const() ), boost::local_shared_ptr<T>( new T() ) ); |
1216 | test_nonempty_move_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), boost::local_shared_ptr<T>( new T() ) ); |
1217 | test_nonempty_move_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), boost::local_shared_ptr<T>( new T() ) ); |
1218 | |
1219 | test_nonempty_move_assign( boost::local_shared_ptr<void>(), boost::local_shared_ptr<T>( new T() ) ); |
1220 | test_nonempty_move_assign( boost::local_shared_ptr<void const>(), boost::local_shared_ptr<T>( new T() ) ); |
1221 | test_nonempty_move_assign( boost::local_shared_ptr<void volatile>(), boost::local_shared_ptr<T>( new T() ) ); |
1222 | test_nonempty_move_assign( boost::local_shared_ptr<void const volatile>(), boost::local_shared_ptr<T>( new T() ) ); |
1223 | } |
1224 | |
1225 | static void move_assignment() |
1226 | { |
1227 | empty_move_assign_test<incomplete>(); |
1228 | empty_move_assign_test<int>(); |
1229 | empty_move_assign_test_<int>(); |
1230 | empty_move_assign_test<X>(); |
1231 | empty_move_assign_test_<X>(); |
1232 | |
1233 | BOOST_TEST( X::instances == 0 ); |
1234 | |
1235 | null_move_assign_test<int>(); |
1236 | null_move_assign_test<X>(); |
1237 | |
1238 | BOOST_TEST( X::instances == 0 ); |
1239 | |
1240 | new_move_assign_test<int>(); |
1241 | new_move_assign_test<X>(); |
1242 | |
1243 | BOOST_TEST( X::instances == 0 ); |
1244 | } |
1245 | |
1246 | #else |
1247 | |
1248 | static void move_assignment() |
1249 | { |
1250 | } |
1251 | |
1252 | #endif |
1253 | |
1254 | // nullptr assignment |
1255 | |
1256 | #if !defined( BOOST_NO_CXX11_NULLPTR ) |
1257 | |
1258 | template<class T> static void test_nullptr_assign( boost::local_shared_ptr<T> p1 ) |
1259 | { |
1260 | p1 = nullptr; |
1261 | |
1262 | BOOST_TEST( p1.get() == 0 ); |
1263 | BOOST_TEST( p1.local_use_count() == 0 ); |
1264 | } |
1265 | |
1266 | template<class T> static void empty_nullptr_assign_test() |
1267 | { |
1268 | test_nullptr_assign( boost::local_shared_ptr<T>() ); |
1269 | test_nullptr_assign( boost::local_shared_ptr<T const>() ); |
1270 | test_nullptr_assign( boost::local_shared_ptr<T volatile>() ); |
1271 | test_nullptr_assign( boost::local_shared_ptr<T const volatile>() ); |
1272 | } |
1273 | |
1274 | template<class T> static void null_nullptr_assign_test() |
1275 | { |
1276 | test_nullptr_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1277 | test_nullptr_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ) ); |
1278 | test_nullptr_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ) ); |
1279 | test_nullptr_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ) ); |
1280 | } |
1281 | |
1282 | template<class T> static void new_nullptr_assign_test() |
1283 | { |
1284 | test_nullptr_assign( boost::local_shared_ptr<T>( new T() ) ); |
1285 | test_nullptr_assign( boost::local_shared_ptr<T const>( new T const() ) ); |
1286 | test_nullptr_assign( boost::local_shared_ptr<T volatile>( new T volatile() ) ); |
1287 | test_nullptr_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ) ); |
1288 | } |
1289 | |
1290 | static void nullptr_assignment() |
1291 | { |
1292 | empty_nullptr_assign_test<incomplete>(); |
1293 | empty_nullptr_assign_test<void>(); |
1294 | empty_nullptr_assign_test<int>(); |
1295 | empty_nullptr_assign_test<X>(); |
1296 | |
1297 | BOOST_TEST( X::instances == 0 ); |
1298 | |
1299 | null_nullptr_assign_test<int>(); |
1300 | null_nullptr_assign_test<X>(); |
1301 | |
1302 | BOOST_TEST( X::instances == 0 ); |
1303 | |
1304 | new_nullptr_assign_test<int>(); |
1305 | new_nullptr_assign_test<X>(); |
1306 | |
1307 | BOOST_TEST( X::instances == 0 ); |
1308 | } |
1309 | |
1310 | #else |
1311 | |
1312 | static void nullptr_assignment() |
1313 | { |
1314 | } |
1315 | |
1316 | #endif |
1317 | |
1318 | // default_reset |
1319 | |
1320 | template<class T> static void test_default_reset( boost::local_shared_ptr<T> p1 ) |
1321 | { |
1322 | p1.reset(); |
1323 | |
1324 | BOOST_TEST( p1.get() == 0 ); |
1325 | BOOST_TEST( p1.local_use_count() == 0 ); |
1326 | } |
1327 | |
1328 | template<class T> static void empty_default_reset_test() |
1329 | { |
1330 | test_default_reset( boost::local_shared_ptr<T>() ); |
1331 | test_default_reset( boost::local_shared_ptr<T const>() ); |
1332 | test_default_reset( boost::local_shared_ptr<T volatile>() ); |
1333 | test_default_reset( boost::local_shared_ptr<T const volatile>() ); |
1334 | } |
1335 | |
1336 | template<class T> static void null_default_reset_test() |
1337 | { |
1338 | test_default_reset( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1339 | test_default_reset( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ) ); |
1340 | test_default_reset( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ) ); |
1341 | test_default_reset( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ) ); |
1342 | } |
1343 | |
1344 | template<class T> static void new_default_reset_test() |
1345 | { |
1346 | test_default_reset( boost::local_shared_ptr<T>( new T() ) ); |
1347 | test_default_reset( boost::local_shared_ptr<T const>( new T const() ) ); |
1348 | test_default_reset( boost::local_shared_ptr<T volatile>( new T volatile() ) ); |
1349 | test_default_reset( boost::local_shared_ptr<T const volatile>( new T const volatile() ) ); |
1350 | } |
1351 | |
1352 | static void default_reset() |
1353 | { |
1354 | empty_default_reset_test<incomplete>(); |
1355 | empty_default_reset_test<void>(); |
1356 | empty_default_reset_test<int>(); |
1357 | empty_default_reset_test<X>(); |
1358 | |
1359 | BOOST_TEST( X::instances == 0 ); |
1360 | |
1361 | null_default_reset_test<int>(); |
1362 | null_default_reset_test<X>(); |
1363 | |
1364 | BOOST_TEST( X::instances == 0 ); |
1365 | |
1366 | new_default_reset_test<int>(); |
1367 | new_default_reset_test<X>(); |
1368 | |
1369 | BOOST_TEST( X::instances == 0 ); |
1370 | } |
1371 | |
1372 | // shared_ptr copy assignment |
1373 | |
1374 | template<class T> static void empty_shared_ptr_copy_assign_test() |
1375 | { |
1376 | boost::shared_ptr<T> sp1; |
1377 | |
1378 | BOOST_TEST_EQ( sp1.get(), static_cast<void*>(0) ); |
1379 | BOOST_TEST_EQ( sp1.use_count(), 0 ); |
1380 | |
1381 | boost::local_shared_ptr<T> p2; |
1382 | |
1383 | p2 = sp1; |
1384 | |
1385 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
1386 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1387 | |
1388 | boost::local_shared_ptr<T const> p3; |
1389 | |
1390 | p3 = sp1; |
1391 | |
1392 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1393 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1394 | |
1395 | boost::local_shared_ptr<void> p4; |
1396 | |
1397 | p4 = sp1; |
1398 | |
1399 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1400 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1401 | |
1402 | boost::shared_ptr<T const> sp2( sp1 ); |
1403 | boost::local_shared_ptr<void const> p5; |
1404 | |
1405 | p5 = sp2; |
1406 | |
1407 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1408 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1409 | } |
1410 | |
1411 | template<class T> static void empty_shared_ptr_copy_assign_test_() |
1412 | { |
1413 | boost::shared_ptr<T> sp1; |
1414 | |
1415 | BOOST_TEST_EQ( sp1.get(), static_cast<void*>(0) ); |
1416 | BOOST_TEST_EQ( sp1.use_count(), 0 ); |
1417 | |
1418 | boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); |
1419 | |
1420 | p2 = sp1; |
1421 | |
1422 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
1423 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1424 | |
1425 | boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); |
1426 | |
1427 | p3 = sp1; |
1428 | |
1429 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1430 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1431 | |
1432 | boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); |
1433 | |
1434 | p4 = sp1; |
1435 | |
1436 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1437 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1438 | |
1439 | boost::shared_ptr<T const> sp2( sp1 ); |
1440 | boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); |
1441 | |
1442 | p5 = sp2; |
1443 | |
1444 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1445 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1446 | } |
1447 | |
1448 | template<class T, class U> static void test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T> p2, boost::shared_ptr<U> const & p1 ) |
1449 | { |
1450 | long k = p1.use_count(); |
1451 | |
1452 | p2 = p1; |
1453 | |
1454 | BOOST_TEST( p2.get() == p1.get() ); |
1455 | BOOST_TEST( p2.local_use_count() == 1 ); |
1456 | BOOST_TEST( p1.use_count() == k + 1 ); |
1457 | |
1458 | p2.reset(); |
1459 | |
1460 | BOOST_TEST( p1.use_count() == k ); |
1461 | } |
1462 | |
1463 | template<class T> static void null_shared_ptr_copy_assign_test() |
1464 | { |
1465 | boost::shared_ptr<T> p1( static_cast<T*>(0) ); |
1466 | |
1467 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>(), p1 ); |
1468 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>(), p1 ); |
1469 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>(), p1 ); |
1470 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>(), p1 ); |
1471 | |
1472 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), p1 ); |
1473 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), p1 ); |
1474 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), p1 ); |
1475 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), p1 ); |
1476 | |
1477 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void>(), p1 ); |
1478 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void const>(), p1 ); |
1479 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void volatile>(), p1 ); |
1480 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void const volatile>(), p1 ); |
1481 | } |
1482 | |
1483 | template<class T> static void new_shared_ptr_copy_assign_test() |
1484 | { |
1485 | boost::shared_ptr<T> p1( new T() ); |
1486 | |
1487 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>(), p1 ); |
1488 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>(), p1 ); |
1489 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>(), p1 ); |
1490 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>(), p1 ); |
1491 | |
1492 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), p1 ); |
1493 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), p1 ); |
1494 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), p1 ); |
1495 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), p1 ); |
1496 | |
1497 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T>( new T() ), p1 ); |
1498 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const>( new T const() ), p1 ); |
1499 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), p1 ); |
1500 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), p1 ); |
1501 | |
1502 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void>(), p1 ); |
1503 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void const>(), p1 ); |
1504 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void volatile>(), p1 ); |
1505 | test_nonempty_shared_ptr_copy_assign( boost::local_shared_ptr<void const volatile>(), p1 ); |
1506 | } |
1507 | |
1508 | static void shared_ptr_copy_assignment() |
1509 | { |
1510 | empty_shared_ptr_copy_assign_test<incomplete>(); |
1511 | empty_shared_ptr_copy_assign_test<int>(); |
1512 | empty_shared_ptr_copy_assign_test_<int>(); |
1513 | empty_shared_ptr_copy_assign_test<X>(); |
1514 | empty_shared_ptr_copy_assign_test_<X>(); |
1515 | |
1516 | BOOST_TEST( X::instances == 0 ); |
1517 | |
1518 | null_shared_ptr_copy_assign_test<int>(); |
1519 | null_shared_ptr_copy_assign_test<X>(); |
1520 | |
1521 | BOOST_TEST( X::instances == 0 ); |
1522 | |
1523 | new_shared_ptr_copy_assign_test<int>(); |
1524 | new_shared_ptr_copy_assign_test<X>(); |
1525 | |
1526 | BOOST_TEST( X::instances == 0 ); |
1527 | } |
1528 | |
1529 | // shared_ptr_move assignment |
1530 | |
1531 | #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) |
1532 | |
1533 | template<class T> static void empty_shared_ptr_move_assign_test() |
1534 | { |
1535 | boost::local_shared_ptr<T> p2; |
1536 | |
1537 | p2 = boost::shared_ptr<T>(); |
1538 | |
1539 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
1540 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1541 | |
1542 | boost::local_shared_ptr<T const> p3; |
1543 | |
1544 | p3 = boost::shared_ptr<T>(); |
1545 | |
1546 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1547 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1548 | |
1549 | boost::local_shared_ptr<void> p4; |
1550 | |
1551 | p4 = boost::shared_ptr<T>(); |
1552 | |
1553 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1554 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1555 | |
1556 | boost::local_shared_ptr<void const> p5; |
1557 | |
1558 | p5 = boost::shared_ptr<T const>(); |
1559 | |
1560 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1561 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1562 | } |
1563 | |
1564 | template<class T> static void empty_shared_ptr_move_assign_test_() |
1565 | { |
1566 | boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); |
1567 | |
1568 | p2 = boost::shared_ptr<T>(); |
1569 | |
1570 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
1571 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1572 | |
1573 | boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); |
1574 | |
1575 | p3 = boost::shared_ptr<T>(); |
1576 | |
1577 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1578 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1579 | |
1580 | boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); |
1581 | |
1582 | p4 = boost::shared_ptr<T>(); |
1583 | |
1584 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1585 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1586 | |
1587 | boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); |
1588 | |
1589 | p5 = boost::shared_ptr<T const>(); |
1590 | |
1591 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1592 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1593 | } |
1594 | |
1595 | template<class T, class U> static void test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T> p2, boost::shared_ptr<U> && p1 ) |
1596 | { |
1597 | U* q = p1.get(); |
1598 | long k = p1.use_count(); |
1599 | |
1600 | p2 = std::move( p1 ); |
1601 | |
1602 | BOOST_TEST_EQ( p2.get(), q ); |
1603 | BOOST_TEST_EQ( p2.local_use_count(), 1 ); |
1604 | |
1605 | BOOST_TEST( p1.get() == 0 ); |
1606 | BOOST_TEST( p1.use_count() == 0 ); |
1607 | |
1608 | boost::shared_ptr<T> p3( p2 ); |
1609 | |
1610 | BOOST_TEST_EQ( p3.get(), q ); |
1611 | BOOST_TEST_EQ( p3.use_count(), k + 1 ); |
1612 | } |
1613 | |
1614 | template<class T> static void null_shared_ptr_move_assign_test() |
1615 | { |
1616 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1617 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1618 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1619 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1620 | |
1621 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1622 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1623 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1624 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1625 | |
1626 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1627 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void const>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1628 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void volatile>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1629 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void const volatile>(), boost::shared_ptr<T>( static_cast<T*>(0) ) ); |
1630 | } |
1631 | |
1632 | template<class T> static void new_shared_ptr_move_assign_test() |
1633 | { |
1634 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>(), boost::shared_ptr<T>( new T() ) ); |
1635 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>(), boost::shared_ptr<T>( new T() ) ); |
1636 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>(), boost::shared_ptr<T>( new T() ) ); |
1637 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>(), boost::shared_ptr<T>( new T() ) ); |
1638 | |
1639 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), boost::shared_ptr<T>( new T() ) ); |
1640 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), boost::shared_ptr<T>( new T() ) ); |
1641 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), boost::shared_ptr<T>( new T() ) ); |
1642 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), boost::shared_ptr<T>( new T() ) ); |
1643 | |
1644 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T>( new T() ), boost::shared_ptr<T>( new T() ) ); |
1645 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const>( new T const() ), boost::shared_ptr<T>( new T() ) ); |
1646 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), boost::shared_ptr<T>( new T() ) ); |
1647 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), boost::shared_ptr<T>( new T() ) ); |
1648 | |
1649 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void>(), boost::shared_ptr<T>( new T() ) ); |
1650 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void const>(), boost::shared_ptr<T>( new T() ) ); |
1651 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void volatile>(), boost::shared_ptr<T>( new T() ) ); |
1652 | test_nonempty_shared_ptr_move_assign( boost::local_shared_ptr<void const volatile>(), boost::shared_ptr<T>( new T() ) ); |
1653 | } |
1654 | |
1655 | static void shared_ptr_move_assignment() |
1656 | { |
1657 | empty_shared_ptr_move_assign_test<incomplete>(); |
1658 | empty_shared_ptr_move_assign_test<int>(); |
1659 | empty_shared_ptr_move_assign_test_<int>(); |
1660 | empty_shared_ptr_move_assign_test<X>(); |
1661 | empty_shared_ptr_move_assign_test_<X>(); |
1662 | |
1663 | BOOST_TEST( X::instances == 0 ); |
1664 | |
1665 | null_shared_ptr_move_assign_test<int>(); |
1666 | null_shared_ptr_move_assign_test<X>(); |
1667 | |
1668 | BOOST_TEST( X::instances == 0 ); |
1669 | |
1670 | new_shared_ptr_move_assign_test<int>(); |
1671 | new_shared_ptr_move_assign_test<X>(); |
1672 | |
1673 | BOOST_TEST( X::instances == 0 ); |
1674 | } |
1675 | |
1676 | #else |
1677 | |
1678 | static void shared_ptr_move_assignment() |
1679 | { |
1680 | } |
1681 | |
1682 | #endif |
1683 | |
1684 | // unique_ptr assignment |
1685 | |
1686 | #if !defined( BOOST_NO_CXX11_RVALUE_REFERENCES ) && !defined( BOOST_NO_CXX11_SMART_PTR ) |
1687 | |
1688 | template<class T> static void empty_unique_ptr_assign_test() |
1689 | { |
1690 | boost::local_shared_ptr<T> p2; |
1691 | |
1692 | p2 = std::unique_ptr<T>(); |
1693 | |
1694 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
1695 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1696 | |
1697 | boost::local_shared_ptr<T const> p3; |
1698 | |
1699 | p3 = std::unique_ptr<T>(); |
1700 | |
1701 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1702 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1703 | |
1704 | boost::local_shared_ptr<void> p4; |
1705 | |
1706 | p4 = std::unique_ptr<T>(); |
1707 | |
1708 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1709 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1710 | |
1711 | boost::local_shared_ptr<void const> p5; |
1712 | |
1713 | p5 = std::unique_ptr<T const>(); |
1714 | |
1715 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1716 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1717 | } |
1718 | |
1719 | template<class T> static void empty_unique_ptr_assign_test_() |
1720 | { |
1721 | boost::local_shared_ptr<T> p2( static_cast<T*>(0) ); |
1722 | |
1723 | p2 = std::unique_ptr<T>(); |
1724 | |
1725 | BOOST_TEST_EQ( p2.get(), static_cast<void*>(0) ); |
1726 | BOOST_TEST_EQ( p2.local_use_count(), 0 ); |
1727 | |
1728 | boost::local_shared_ptr<T const> p3( static_cast<T const*>(0) ); |
1729 | |
1730 | p3 = std::unique_ptr<T>(); |
1731 | |
1732 | BOOST_TEST_EQ( p3.get(), static_cast<void*>(0) ); |
1733 | BOOST_TEST_EQ( p3.local_use_count(), 0 ); |
1734 | |
1735 | boost::local_shared_ptr<void> p4( static_cast<T*>(0) ); |
1736 | |
1737 | p4 = std::unique_ptr<T>(); |
1738 | |
1739 | BOOST_TEST_EQ( p4.get(), static_cast<void*>(0) ); |
1740 | BOOST_TEST_EQ( p4.local_use_count(), 0 ); |
1741 | |
1742 | boost::local_shared_ptr<void const> p5( static_cast<T const*>(0) ); |
1743 | |
1744 | p5 = std::unique_ptr<T const>(); |
1745 | |
1746 | BOOST_TEST_EQ( p5.get(), static_cast<void*>(0) ); |
1747 | BOOST_TEST_EQ( p5.local_use_count(), 0 ); |
1748 | } |
1749 | |
1750 | template<class T, class U, class D> static void test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T> p2, std::unique_ptr<U, D> && p1 ) |
1751 | { |
1752 | U* q = p1.get(); |
1753 | |
1754 | p2 = std::move( p1 ); |
1755 | |
1756 | BOOST_TEST_EQ( p2.get(), q ); |
1757 | BOOST_TEST_EQ( p2.local_use_count(), 1 ); |
1758 | |
1759 | BOOST_TEST( p1.get() == 0 ); |
1760 | } |
1761 | |
1762 | template<class T> static void new_unique_ptr_assign_test() |
1763 | { |
1764 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>(), std::unique_ptr<T>( new T() ) ); |
1765 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>(), std::unique_ptr<T>( new T() ) ); |
1766 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>(), std::unique_ptr<T>( new T() ) ); |
1767 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>(), std::unique_ptr<T>( new T() ) ); |
1768 | |
1769 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), std::unique_ptr<T>( new T() ) ); |
1770 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), std::unique_ptr<T>( new T() ) ); |
1771 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), std::unique_ptr<T>( new T() ) ); |
1772 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), std::unique_ptr<T>( new T() ) ); |
1773 | |
1774 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>( new T() ), std::unique_ptr<T>( new T() ) ); |
1775 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>( new T const() ), std::unique_ptr<T>( new T() ) ); |
1776 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), std::unique_ptr<T>( new T() ) ); |
1777 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), std::unique_ptr<T>( new T() ) ); |
1778 | |
1779 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void>(), std::unique_ptr<T>( new T() ) ); |
1780 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void const>(), std::unique_ptr<T>( new T() ) ); |
1781 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void volatile>(), std::unique_ptr<T>( new T() ) ); |
1782 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void const volatile>(), std::unique_ptr<T>( new T() ) ); |
1783 | } |
1784 | |
1785 | template<class T> static void del_unique_ptr_assign_test() |
1786 | { |
1787 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1788 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1789 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1790 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1791 | |
1792 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>( static_cast<T*>(0) ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1793 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>( static_cast<T const*>(0) ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1794 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>( static_cast<T volatile*>(0) ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1795 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>( static_cast<T const volatile*>(0) ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1796 | |
1797 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T>( new T() ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1798 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const>( new T const() ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1799 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T volatile>( new T volatile() ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1800 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<T const volatile>( new T const volatile() ), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1801 | |
1802 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1803 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void const>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1804 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void volatile>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1805 | test_nonempty_unique_ptr_assign( boost::local_shared_ptr<void const volatile>(), std::unique_ptr<T, boost::checked_deleter<T>>( new T() ) ); |
1806 | } |
1807 | |
1808 | static void unique_ptr_assignment() |
1809 | { |
1810 | empty_unique_ptr_assign_test<int>(); |
1811 | empty_unique_ptr_assign_test_<int>(); |
1812 | empty_unique_ptr_assign_test<X>(); |
1813 | empty_unique_ptr_assign_test_<X>(); |
1814 | |
1815 | BOOST_TEST( X::instances == 0 ); |
1816 | |
1817 | new_unique_ptr_assign_test<int>(); |
1818 | new_unique_ptr_assign_test<X>(); |
1819 | |
1820 | BOOST_TEST( X::instances == 0 ); |
1821 | |
1822 | del_unique_ptr_assign_test<int>(); |
1823 | del_unique_ptr_assign_test<X>(); |
1824 | |
1825 | BOOST_TEST( X::instances == 0 ); |
1826 | } |
1827 | |
1828 | #else |
1829 | |
1830 | static void unique_ptr_assignment() |
1831 | { |
1832 | } |
1833 | |
1834 | #endif |
1835 | |
1836 | // pointer reset |
1837 | |
1838 | template<class T, class U> static void test_pointer_reset( boost::local_shared_ptr<U> p2 ) |
1839 | { |
1840 | T * q = new T(); |
1841 | |
1842 | p2.reset( q ); |
1843 | |
1844 | BOOST_TEST_EQ( p2.get(), q ); |
1845 | BOOST_TEST_EQ( p2.local_use_count(), 1 ); |
1846 | } |
1847 | |
1848 | template<class T> static void empty_pointer_reset_test() |
1849 | { |
1850 | test_pointer_reset<T>( boost::local_shared_ptr<T>() ); |
1851 | test_pointer_reset<T>( boost::local_shared_ptr<T const>() ); |
1852 | test_pointer_reset<T>( boost::local_shared_ptr<T volatile>() ); |
1853 | test_pointer_reset<T>( boost::local_shared_ptr<T const volatile>() ); |
1854 | |
1855 | test_pointer_reset<T>( boost::local_shared_ptr<void>() ); |
1856 | test_pointer_reset<T>( boost::local_shared_ptr<void const>() ); |
1857 | test_pointer_reset<T>( boost::local_shared_ptr<void volatile>() ); |
1858 | test_pointer_reset<T>( boost::local_shared_ptr<void const volatile>() ); |
1859 | } |
1860 | |
1861 | template<class T> static void null_pointer_reset_test() |
1862 | { |
1863 | test_pointer_reset<T>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1864 | test_pointer_reset<T>( boost::local_shared_ptr<T const>( static_cast<T*>(0) ) ); |
1865 | test_pointer_reset<T>( boost::local_shared_ptr<T volatile>( static_cast<T*>(0) ) ); |
1866 | test_pointer_reset<T>( boost::local_shared_ptr<T const volatile>( static_cast<T*>(0) ) ); |
1867 | |
1868 | test_pointer_reset<T>( boost::local_shared_ptr<void>( static_cast<T*>(0) ) ); |
1869 | test_pointer_reset<T>( boost::local_shared_ptr<void const>( static_cast<T*>(0) ) ); |
1870 | test_pointer_reset<T>( boost::local_shared_ptr<void volatile>( static_cast<T*>(0) ) ); |
1871 | test_pointer_reset<T>( boost::local_shared_ptr<void const volatile>( static_cast<T*>(0) ) ); |
1872 | } |
1873 | |
1874 | template<class T> static void new_pointer_reset_test() |
1875 | { |
1876 | test_pointer_reset<T>( boost::local_shared_ptr<T>( new T() ) ); |
1877 | test_pointer_reset<T>( boost::local_shared_ptr<T const>( new T() ) ); |
1878 | test_pointer_reset<T>( boost::local_shared_ptr<T volatile>( new T() ) ); |
1879 | test_pointer_reset<T>( boost::local_shared_ptr<T const volatile>( new T() ) ); |
1880 | |
1881 | test_pointer_reset<T>( boost::local_shared_ptr<void>( new T() ) ); |
1882 | test_pointer_reset<T>( boost::local_shared_ptr<void const>( new T() ) ); |
1883 | test_pointer_reset<T>( boost::local_shared_ptr<void volatile>( new T() ) ); |
1884 | test_pointer_reset<T>( boost::local_shared_ptr<void const volatile>( new T() ) ); |
1885 | } |
1886 | |
1887 | static void pointer_reset() |
1888 | { |
1889 | empty_pointer_reset_test<int>(); |
1890 | empty_pointer_reset_test<X>(); |
1891 | |
1892 | BOOST_TEST( X::instances == 0 ); |
1893 | |
1894 | null_pointer_reset_test<int>(); |
1895 | null_pointer_reset_test<X>(); |
1896 | |
1897 | BOOST_TEST( X::instances == 0 ); |
1898 | |
1899 | new_pointer_reset_test<int>(); |
1900 | new_pointer_reset_test<X>(); |
1901 | |
1902 | BOOST_TEST( X::instances == 0 ); |
1903 | } |
1904 | |
1905 | // deleter reset |
1906 | |
1907 | template<class T> class deleter |
1908 | { |
1909 | private: |
1910 | |
1911 | bool * called_; |
1912 | |
1913 | public: |
1914 | |
1915 | explicit deleter( bool * called ): called_( called ) {} |
1916 | void operator()( T * p ) { *called_ = true; delete p; } |
1917 | }; |
1918 | |
1919 | template<class T, class U> static void test_deleter_reset( boost::local_shared_ptr<U> p2 ) |
1920 | { |
1921 | T * q = new T(); |
1922 | |
1923 | bool called = false; |
1924 | |
1925 | p2.reset( q, deleter<T>( &called ) ); |
1926 | |
1927 | BOOST_TEST_EQ( p2.get(), q ); |
1928 | BOOST_TEST_EQ( p2.local_use_count(), 1 ); |
1929 | |
1930 | boost::shared_ptr<U> p3( p2 ); |
1931 | |
1932 | BOOST_TEST( boost::get_deleter< deleter<T> >( p3 ) != 0 ); |
1933 | |
1934 | p3.reset(); |
1935 | BOOST_TEST( !called ); |
1936 | |
1937 | p2.reset(); |
1938 | BOOST_TEST( called ); |
1939 | } |
1940 | |
1941 | template<class T> static void empty_deleter_reset_test() |
1942 | { |
1943 | test_deleter_reset<T>( boost::local_shared_ptr<T>() ); |
1944 | test_deleter_reset<T>( boost::local_shared_ptr<T const>() ); |
1945 | test_deleter_reset<T>( boost::local_shared_ptr<T volatile>() ); |
1946 | test_deleter_reset<T>( boost::local_shared_ptr<T const volatile>() ); |
1947 | |
1948 | test_deleter_reset<T>( boost::local_shared_ptr<void>() ); |
1949 | test_deleter_reset<T>( boost::local_shared_ptr<void const>() ); |
1950 | test_deleter_reset<T>( boost::local_shared_ptr<void volatile>() ); |
1951 | test_deleter_reset<T>( boost::local_shared_ptr<void const volatile>() ); |
1952 | } |
1953 | |
1954 | template<class T> static void null_deleter_reset_test() |
1955 | { |
1956 | test_deleter_reset<T>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
1957 | test_deleter_reset<T>( boost::local_shared_ptr<T const>( static_cast<T*>(0) ) ); |
1958 | test_deleter_reset<T>( boost::local_shared_ptr<T volatile>( static_cast<T*>(0) ) ); |
1959 | test_deleter_reset<T>( boost::local_shared_ptr<T const volatile>( static_cast<T*>(0) ) ); |
1960 | |
1961 | test_deleter_reset<T>( boost::local_shared_ptr<void>( static_cast<T*>(0) ) ); |
1962 | test_deleter_reset<T>( boost::local_shared_ptr<void const>( static_cast<T*>(0) ) ); |
1963 | test_deleter_reset<T>( boost::local_shared_ptr<void volatile>( static_cast<T*>(0) ) ); |
1964 | test_deleter_reset<T>( boost::local_shared_ptr<void const volatile>( static_cast<T*>(0) ) ); |
1965 | } |
1966 | |
1967 | template<class T> static void new_deleter_reset_test() |
1968 | { |
1969 | test_deleter_reset<T>( boost::local_shared_ptr<T>( new T() ) ); |
1970 | test_deleter_reset<T>( boost::local_shared_ptr<T const>( new T() ) ); |
1971 | test_deleter_reset<T>( boost::local_shared_ptr<T volatile>( new T() ) ); |
1972 | test_deleter_reset<T>( boost::local_shared_ptr<T const volatile>( new T() ) ); |
1973 | |
1974 | test_deleter_reset<T>( boost::local_shared_ptr<void>( new T() ) ); |
1975 | test_deleter_reset<T>( boost::local_shared_ptr<void const>( new T() ) ); |
1976 | test_deleter_reset<T>( boost::local_shared_ptr<void volatile>( new T() ) ); |
1977 | test_deleter_reset<T>( boost::local_shared_ptr<void const volatile>( new T() ) ); |
1978 | } |
1979 | |
1980 | static void deleter_reset() |
1981 | { |
1982 | empty_deleter_reset_test<int>(); |
1983 | empty_deleter_reset_test<X>(); |
1984 | |
1985 | BOOST_TEST( X::instances == 0 ); |
1986 | |
1987 | null_deleter_reset_test<int>(); |
1988 | null_deleter_reset_test<X>(); |
1989 | |
1990 | BOOST_TEST( X::instances == 0 ); |
1991 | |
1992 | new_deleter_reset_test<int>(); |
1993 | new_deleter_reset_test<X>(); |
1994 | |
1995 | BOOST_TEST( X::instances == 0 ); |
1996 | } |
1997 | |
1998 | // allocator reset |
1999 | |
2000 | template<class T, class U> static void test_allocator_reset( boost::local_shared_ptr<U> p2 ) |
2001 | { |
2002 | T * q = new T(); |
2003 | |
2004 | bool called = false; |
2005 | |
2006 | p2.reset( q, deleter<T>( &called ), std::allocator<T>() ); |
2007 | |
2008 | BOOST_TEST_EQ( p2.get(), q ); |
2009 | BOOST_TEST_EQ( p2.local_use_count(), 1 ); |
2010 | |
2011 | boost::shared_ptr<U> p3( p2 ); |
2012 | |
2013 | BOOST_TEST( boost::get_deleter< deleter<T> >( p3 ) != 0 ); |
2014 | |
2015 | p3.reset(); |
2016 | BOOST_TEST( !called ); |
2017 | |
2018 | p2.reset(); |
2019 | BOOST_TEST( called ); |
2020 | } |
2021 | |
2022 | template<class T> static void empty_allocator_reset_test() |
2023 | { |
2024 | test_allocator_reset<T>( boost::local_shared_ptr<T>() ); |
2025 | test_allocator_reset<T>( boost::local_shared_ptr<T const>() ); |
2026 | test_allocator_reset<T>( boost::local_shared_ptr<T volatile>() ); |
2027 | test_allocator_reset<T>( boost::local_shared_ptr<T const volatile>() ); |
2028 | |
2029 | test_allocator_reset<T>( boost::local_shared_ptr<void>() ); |
2030 | test_allocator_reset<T>( boost::local_shared_ptr<void const>() ); |
2031 | test_allocator_reset<T>( boost::local_shared_ptr<void volatile>() ); |
2032 | test_allocator_reset<T>( boost::local_shared_ptr<void const volatile>() ); |
2033 | } |
2034 | |
2035 | template<class T> static void null_allocator_reset_test() |
2036 | { |
2037 | test_allocator_reset<T>( boost::local_shared_ptr<T>( static_cast<T*>(0) ) ); |
2038 | test_allocator_reset<T>( boost::local_shared_ptr<T const>( static_cast<T*>(0) ) ); |
2039 | test_allocator_reset<T>( boost::local_shared_ptr<T volatile>( static_cast<T*>(0) ) ); |
2040 | test_allocator_reset<T>( boost::local_shared_ptr<T const volatile>( static_cast<T*>(0) ) ); |
2041 | |
2042 | test_allocator_reset<T>( boost::local_shared_ptr<void>( static_cast<T*>(0) ) ); |
2043 | test_allocator_reset<T>( boost::local_shared_ptr<void const>( static_cast<T*>(0) ) ); |
2044 | test_allocator_reset<T>( boost::local_shared_ptr<void volatile>( static_cast<T*>(0) ) ); |
2045 | test_allocator_reset<T>( boost::local_shared_ptr<void const volatile>( static_cast<T*>(0) ) ); |
2046 | } |
2047 | |
2048 | template<class T> static void new_allocator_reset_test() |
2049 | { |
2050 | test_allocator_reset<T>( boost::local_shared_ptr<T>( new T() ) ); |
2051 | test_allocator_reset<T>( boost::local_shared_ptr<T const>( new T() ) ); |
2052 | test_allocator_reset<T>( boost::local_shared_ptr<T volatile>( new T() ) ); |
2053 | test_allocator_reset<T>( boost::local_shared_ptr<T const volatile>( new T() ) ); |
2054 | |
2055 | test_allocator_reset<T>( boost::local_shared_ptr<void>( new T() ) ); |
2056 | test_allocator_reset<T>( boost::local_shared_ptr<void const>( new T() ) ); |
2057 | test_allocator_reset<T>( boost::local_shared_ptr<void volatile>( new T() ) ); |
2058 | test_allocator_reset<T>( boost::local_shared_ptr<void const volatile>( new T() ) ); |
2059 | } |
2060 | |
2061 | static void allocator_reset() |
2062 | { |
2063 | empty_allocator_reset_test<int>(); |
2064 | empty_allocator_reset_test<X>(); |
2065 | |
2066 | BOOST_TEST( X::instances == 0 ); |
2067 | |
2068 | null_allocator_reset_test<int>(); |
2069 | null_allocator_reset_test<X>(); |
2070 | |
2071 | BOOST_TEST( X::instances == 0 ); |
2072 | |
2073 | new_allocator_reset_test<int>(); |
2074 | new_allocator_reset_test<X>(); |
2075 | |
2076 | BOOST_TEST( X::instances == 0 ); |
2077 | } |
2078 | |
2079 | // aliasing reset |
2080 | |
2081 | struct null_deleter |
2082 | { |
2083 | void operator()( void const volatile* ) {} |
2084 | }; |
2085 | |
2086 | template<class T, class U> void test_aliasing_reset_( boost::local_shared_ptr<T> const & p1, U * p2 ) |
2087 | { |
2088 | boost::local_shared_ptr<U> p3( static_cast<U*>(0), null_deleter() ); |
2089 | |
2090 | p3.reset( p1, p2 ); |
2091 | |
2092 | BOOST_TEST( p3.get() == p2 ); |
2093 | BOOST_TEST( p3.local_use_count() == p1.local_use_count() ); |
2094 | BOOST_TEST( !p3.owner_before( p1 ) && !p1.owner_before( p3 ) ); |
2095 | } |
2096 | |
2097 | template<class T, class U> void test_01_aliasing_reset_() |
2098 | { |
2099 | U u; |
2100 | boost::local_shared_ptr<T> p1; |
2101 | |
2102 | test_aliasing_reset_( p1, &u ); |
2103 | } |
2104 | |
2105 | template<class T, class U> void test_01_aliasing_reset() |
2106 | { |
2107 | test_01_aliasing_reset_<T, U>(); |
2108 | test_01_aliasing_reset_<T const, U>(); |
2109 | test_01_aliasing_reset_<T volatile, U>(); |
2110 | test_01_aliasing_reset_<T const volatile, U>(); |
2111 | |
2112 | test_01_aliasing_reset_<T, U volatile>(); |
2113 | test_01_aliasing_reset_<T const, U volatile>(); |
2114 | test_01_aliasing_reset_<T volatile, U volatile>(); |
2115 | test_01_aliasing_reset_<T const volatile, U volatile>(); |
2116 | } |
2117 | |
2118 | template<class T, class U> void test_10_aliasing_reset_() |
2119 | { |
2120 | boost::local_shared_ptr<T> p1( new T() ); |
2121 | test_aliasing_reset_( p1, static_cast<U*>(0) ); |
2122 | } |
2123 | |
2124 | template<class T, class U> void test_10_aliasing_reset() |
2125 | { |
2126 | test_10_aliasing_reset_<T, U>(); |
2127 | test_10_aliasing_reset_<T const, U>(); |
2128 | test_10_aliasing_reset_<T volatile, U>(); |
2129 | test_10_aliasing_reset_<T const volatile, U>(); |
2130 | |
2131 | test_10_aliasing_reset_<T, U const>(); |
2132 | test_10_aliasing_reset_<T const, U const>(); |
2133 | test_10_aliasing_reset_<T volatile, U const>(); |
2134 | test_10_aliasing_reset_<T const volatile, U const>(); |
2135 | |
2136 | test_10_aliasing_reset_<T, U volatile>(); |
2137 | test_10_aliasing_reset_<T const, U volatile>(); |
2138 | test_10_aliasing_reset_<T volatile, U volatile>(); |
2139 | test_10_aliasing_reset_<T const volatile, U volatile>(); |
2140 | |
2141 | test_10_aliasing_reset_<T, U const volatile>(); |
2142 | test_10_aliasing_reset_<T const, U const volatile>(); |
2143 | test_10_aliasing_reset_<T volatile, U const volatile>(); |
2144 | test_10_aliasing_reset_<T const volatile, U const volatile>(); |
2145 | } |
2146 | |
2147 | template<class T, class U> void test_11_aliasing_reset_() |
2148 | { |
2149 | U u; |
2150 | boost::local_shared_ptr<T> p1( new T() ); |
2151 | |
2152 | test_aliasing_reset_( p1, &u ); |
2153 | } |
2154 | |
2155 | template<class T, class U> void test_11_aliasing_reset() |
2156 | { |
2157 | test_11_aliasing_reset_<T, U>(); |
2158 | test_11_aliasing_reset_<T const, U>(); |
2159 | test_11_aliasing_reset_<T volatile, U>(); |
2160 | test_11_aliasing_reset_<T const volatile, U>(); |
2161 | |
2162 | test_11_aliasing_reset_<T, U volatile>(); |
2163 | test_11_aliasing_reset_<T const, U volatile>(); |
2164 | test_11_aliasing_reset_<T volatile, U volatile>(); |
2165 | test_11_aliasing_reset_<T const volatile, U volatile>(); |
2166 | } |
2167 | |
2168 | static void aliasing_reset() |
2169 | { |
2170 | test_01_aliasing_reset<int, int>(); |
2171 | test_10_aliasing_reset<int, int>(); |
2172 | test_11_aliasing_reset<int, int>(); |
2173 | |
2174 | test_01_aliasing_reset<void, int>(); |
2175 | |
2176 | test_10_aliasing_reset<int, void>(); |
2177 | |
2178 | test_10_aliasing_reset<int, incomplete>(); |
2179 | |
2180 | test_01_aliasing_reset<X, X>(); |
2181 | BOOST_TEST( X::instances == 0 ); |
2182 | |
2183 | test_10_aliasing_reset<X, X>(); |
2184 | BOOST_TEST( X::instances == 0 ); |
2185 | |
2186 | test_11_aliasing_reset<X, X>(); |
2187 | BOOST_TEST( X::instances == 0 ); |
2188 | |
2189 | test_01_aliasing_reset<int, X>(); |
2190 | BOOST_TEST( X::instances == 0 ); |
2191 | |
2192 | test_10_aliasing_reset<int, X>(); |
2193 | BOOST_TEST( X::instances == 0 ); |
2194 | |
2195 | test_11_aliasing_reset<int, X>(); |
2196 | BOOST_TEST( X::instances == 0 ); |
2197 | |
2198 | test_01_aliasing_reset<X, int>(); |
2199 | BOOST_TEST( X::instances == 0 ); |
2200 | |
2201 | test_10_aliasing_reset<X, int>(); |
2202 | BOOST_TEST( X::instances == 0 ); |
2203 | |
2204 | test_11_aliasing_reset<X, int>(); |
2205 | BOOST_TEST( X::instances == 0 ); |
2206 | |
2207 | test_01_aliasing_reset<void, X>(); |
2208 | BOOST_TEST( X::instances == 0 ); |
2209 | |
2210 | test_10_aliasing_reset<X, void>(); |
2211 | BOOST_TEST( X::instances == 0 ); |
2212 | |
2213 | test_10_aliasing_reset<X, incomplete>(); |
2214 | BOOST_TEST( X::instances == 0 ); |
2215 | } |
2216 | |
2217 | // element access |
2218 | |
2219 | template<class T> static void empty_element_access_() |
2220 | { |
2221 | boost::local_shared_ptr<T> p1; |
2222 | |
2223 | BOOST_TEST_EQ( p1.operator->(), static_cast<T*>(0) ); |
2224 | BOOST_TEST_EQ( p1.get(), static_cast<T*>(0) ); |
2225 | BOOST_TEST( p1? false: true ); |
2226 | BOOST_TEST( !p1 ); |
2227 | BOOST_TEST_EQ( p1.local_use_count(), 0 ); |
2228 | } |
2229 | |
2230 | template<class T> static void empty_element_access() |
2231 | { |
2232 | empty_element_access_<T>(); |
2233 | empty_element_access_<T const>(); |
2234 | empty_element_access_<T volatile>(); |
2235 | empty_element_access_<T const volatile>(); |
2236 | } |
2237 | |
2238 | template<class T> static void new_element_access_() |
2239 | { |
2240 | { |
2241 | T * p0 = new T(); |
2242 | boost::local_shared_ptr<T> p1( p0 ); |
2243 | |
2244 | BOOST_TEST_EQ( p1.operator->(), p0 ); |
2245 | BOOST_TEST_EQ( p1.get(), p0 ); |
2246 | BOOST_TEST_EQ( &*p1, p0 ); |
2247 | BOOST_TEST( p1? true: false ); |
2248 | BOOST_TEST_NOT( !p1 ); |
2249 | BOOST_TEST_EQ( p1.local_use_count(), 1 ); |
2250 | } |
2251 | |
2252 | { |
2253 | T * p0 = new T[3](); |
2254 | boost::local_shared_ptr<T[]> p1( p0 ); |
2255 | |
2256 | BOOST_TEST_EQ( p1.get(), p0 ); |
2257 | |
2258 | BOOST_TEST_EQ( &p1[0], &p0[0] ); |
2259 | BOOST_TEST_EQ( &p1[1], &p0[1] ); |
2260 | BOOST_TEST_EQ( &p1[2], &p0[2] ); |
2261 | |
2262 | BOOST_TEST( p1? true: false ); |
2263 | BOOST_TEST_NOT( !p1 ); |
2264 | BOOST_TEST_EQ( p1.local_use_count(), 1 ); |
2265 | } |
2266 | |
2267 | { |
2268 | T * p0 = new T[3](); |
2269 | boost::local_shared_ptr<T[3]> p1( p0 ); |
2270 | |
2271 | BOOST_TEST_EQ( p1.get(), p0 ); |
2272 | |
2273 | BOOST_TEST_EQ( &p1[0], &p0[0] ); |
2274 | BOOST_TEST_EQ( &p1[1], &p0[1] ); |
2275 | BOOST_TEST_EQ( &p1[2], &p0[2] ); |
2276 | |
2277 | BOOST_TEST( p1? true: false ); |
2278 | BOOST_TEST_NOT( !p1 ); |
2279 | BOOST_TEST_EQ( p1.local_use_count(), 1 ); |
2280 | } |
2281 | } |
2282 | |
2283 | template<class T> static void new_element_access() |
2284 | { |
2285 | new_element_access_<T>(); |
2286 | new_element_access_<T const>(); |
2287 | new_element_access_<T volatile>(); |
2288 | new_element_access_<T const volatile>(); |
2289 | } |
2290 | |
2291 | static void element_access() |
2292 | { |
2293 | empty_element_access<int>(); |
2294 | empty_element_access<X>(); |
2295 | |
2296 | BOOST_TEST( X::instances == 0 ); |
2297 | |
2298 | empty_element_access<incomplete>(); |
2299 | empty_element_access<void>(); |
2300 | |
2301 | new_element_access<int>(); |
2302 | new_element_access<X>(); |
2303 | |
2304 | BOOST_TEST( X::instances == 0 ); |
2305 | } |
2306 | |
2307 | // shared_ptr conversion |
2308 | |
2309 | template<class T, class U> static void empty_shared_ptr_conversion_() |
2310 | { |
2311 | boost::local_shared_ptr<T> p1; |
2312 | boost::shared_ptr<U> p2( p1 ); |
2313 | |
2314 | BOOST_TEST_EQ( p2.get(), static_cast<U*>(0) ); |
2315 | BOOST_TEST_EQ( p2.use_count(), 0 ); |
2316 | } |
2317 | |
2318 | template<class T> static void empty_shared_ptr_conversion() |
2319 | { |
2320 | empty_shared_ptr_conversion_<T, T>(); |
2321 | empty_shared_ptr_conversion_<T, T const>(); |
2322 | empty_shared_ptr_conversion_<T, T volatile>(); |
2323 | empty_shared_ptr_conversion_<T, T const volatile>(); |
2324 | |
2325 | empty_shared_ptr_conversion_<T const, T const>(); |
2326 | empty_shared_ptr_conversion_<T volatile, T volatile>(); |
2327 | empty_shared_ptr_conversion_<T const volatile, T const volatile>(); |
2328 | |
2329 | empty_shared_ptr_conversion_<T, void>(); |
2330 | empty_shared_ptr_conversion_<T, void const>(); |
2331 | empty_shared_ptr_conversion_<T, void volatile>(); |
2332 | empty_shared_ptr_conversion_<T, void const volatile>(); |
2333 | |
2334 | empty_shared_ptr_conversion_<T const, void const>(); |
2335 | empty_shared_ptr_conversion_<T volatile, void volatile>(); |
2336 | empty_shared_ptr_conversion_<T const volatile, void const volatile>(); |
2337 | } |
2338 | |
2339 | template<class T, class U> static void new_shared_ptr_conversion_() |
2340 | { |
2341 | boost::local_shared_ptr<T> p1( new T() ); |
2342 | boost::shared_ptr<U> p2( p1 ); |
2343 | |
2344 | BOOST_TEST_EQ( p2.get(), p1.get() ); |
2345 | BOOST_TEST_EQ( p2.use_count(), 2 ); |
2346 | |
2347 | boost::shared_ptr<U> p3( p1 ); |
2348 | |
2349 | BOOST_TEST_EQ( p3.get(), p1.get() ); |
2350 | BOOST_TEST_EQ( p3.use_count(), 3 ); |
2351 | BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); |
2352 | |
2353 | BOOST_TEST_EQ( p1.local_use_count(), 1 ); |
2354 | |
2355 | p1.reset(); |
2356 | |
2357 | BOOST_TEST_EQ( p2.use_count(), 2 ); |
2358 | BOOST_TEST_EQ( p3.use_count(), 2 ); |
2359 | } |
2360 | |
2361 | template<class T> static void new_shared_ptr_conversion() |
2362 | { |
2363 | new_shared_ptr_conversion_<T, T>(); |
2364 | new_shared_ptr_conversion_<T, T const>(); |
2365 | new_shared_ptr_conversion_<T, T volatile>(); |
2366 | new_shared_ptr_conversion_<T, T const volatile>(); |
2367 | |
2368 | new_shared_ptr_conversion_<T const, T const>(); |
2369 | new_shared_ptr_conversion_<T volatile, T volatile>(); |
2370 | new_shared_ptr_conversion_<T const volatile, T const volatile>(); |
2371 | |
2372 | new_shared_ptr_conversion_<T, void>(); |
2373 | new_shared_ptr_conversion_<T, void const>(); |
2374 | new_shared_ptr_conversion_<T, void volatile>(); |
2375 | new_shared_ptr_conversion_<T, void const volatile>(); |
2376 | |
2377 | new_shared_ptr_conversion_<T const, void const>(); |
2378 | new_shared_ptr_conversion_<T volatile, void volatile>(); |
2379 | new_shared_ptr_conversion_<T const volatile, void const volatile>(); |
2380 | } |
2381 | |
2382 | static void shared_ptr_conversion() |
2383 | { |
2384 | empty_shared_ptr_conversion<void>(); |
2385 | empty_shared_ptr_conversion<incomplete>(); |
2386 | empty_shared_ptr_conversion<int>(); |
2387 | empty_shared_ptr_conversion<X>(); |
2388 | |
2389 | BOOST_TEST( X::instances == 0 ); |
2390 | |
2391 | new_shared_ptr_conversion<int>(); |
2392 | new_shared_ptr_conversion<X>(); |
2393 | |
2394 | BOOST_TEST( X::instances == 0 ); |
2395 | } |
2396 | |
2397 | // weak_ptr conversion |
2398 | |
2399 | template<class T, class U> static void empty_weak_ptr_conversion_() |
2400 | { |
2401 | boost::local_shared_ptr<T> p1; |
2402 | boost::weak_ptr<U> p2( p1 ); |
2403 | |
2404 | BOOST_TEST_EQ( p2.lock().get(), static_cast<U*>(0) ); |
2405 | BOOST_TEST_EQ( p2.use_count(), 0 ); |
2406 | } |
2407 | |
2408 | template<class T> static void empty_weak_ptr_conversion() |
2409 | { |
2410 | empty_weak_ptr_conversion_<T, T>(); |
2411 | empty_weak_ptr_conversion_<T, T const>(); |
2412 | empty_weak_ptr_conversion_<T, T volatile>(); |
2413 | empty_weak_ptr_conversion_<T, T const volatile>(); |
2414 | |
2415 | empty_weak_ptr_conversion_<T const, T const>(); |
2416 | empty_weak_ptr_conversion_<T volatile, T volatile>(); |
2417 | empty_weak_ptr_conversion_<T const volatile, T const volatile>(); |
2418 | |
2419 | empty_weak_ptr_conversion_<T, void>(); |
2420 | empty_weak_ptr_conversion_<T, void const>(); |
2421 | empty_weak_ptr_conversion_<T, void volatile>(); |
2422 | empty_weak_ptr_conversion_<T, void const volatile>(); |
2423 | |
2424 | empty_weak_ptr_conversion_<T const, void const>(); |
2425 | empty_weak_ptr_conversion_<T volatile, void volatile>(); |
2426 | empty_weak_ptr_conversion_<T const volatile, void const volatile>(); |
2427 | } |
2428 | |
2429 | template<class T, class U> static void new_weak_ptr_conversion_() |
2430 | { |
2431 | boost::local_shared_ptr<T> p1( new T() ); |
2432 | boost::weak_ptr<U> p2( p1 ); |
2433 | |
2434 | BOOST_TEST_EQ( p2.lock().get(), p1.get() ); |
2435 | BOOST_TEST_EQ( p2.use_count(), 1 ); |
2436 | |
2437 | boost::weak_ptr<U> p3( p1 ); |
2438 | |
2439 | BOOST_TEST_EQ( p3.lock().get(), p1.get() ); |
2440 | BOOST_TEST_EQ( p3.use_count(), 1 ); |
2441 | BOOST_TEST( !(p2 < p3) && !(p3 < p2) ); |
2442 | |
2443 | BOOST_TEST_EQ( p1.local_use_count(), 1 ); |
2444 | |
2445 | p1.reset(); |
2446 | |
2447 | BOOST_TEST_EQ( p2.use_count(), 0 ); |
2448 | BOOST_TEST_EQ( p3.use_count(), 0 ); |
2449 | } |
2450 | |
2451 | template<class T> static void new_weak_ptr_conversion() |
2452 | { |
2453 | new_weak_ptr_conversion_<T, T>(); |
2454 | new_weak_ptr_conversion_<T, T const>(); |
2455 | new_weak_ptr_conversion_<T, T volatile>(); |
2456 | new_weak_ptr_conversion_<T, T const volatile>(); |
2457 | |
2458 | new_weak_ptr_conversion_<T const, T const>(); |
2459 | new_weak_ptr_conversion_<T volatile, T volatile>(); |
2460 | new_weak_ptr_conversion_<T const volatile, T const volatile>(); |
2461 | |
2462 | new_weak_ptr_conversion_<T, void>(); |
2463 | new_weak_ptr_conversion_<T, void const>(); |
2464 | new_weak_ptr_conversion_<T, void volatile>(); |
2465 | new_weak_ptr_conversion_<T, void const volatile>(); |
2466 | |
2467 | new_weak_ptr_conversion_<T const, void const>(); |
2468 | new_weak_ptr_conversion_<T volatile, void volatile>(); |
2469 | new_weak_ptr_conversion_<T const volatile, void const volatile>(); |
2470 | } |
2471 | |
2472 | static void weak_ptr_conversion() |
2473 | { |
2474 | empty_weak_ptr_conversion<void>(); |
2475 | empty_weak_ptr_conversion<incomplete>(); |
2476 | empty_weak_ptr_conversion<int>(); |
2477 | empty_weak_ptr_conversion<X>(); |
2478 | |
2479 | BOOST_TEST( X::instances == 0 ); |
2480 | |
2481 | new_weak_ptr_conversion<int>(); |
2482 | new_weak_ptr_conversion<X>(); |
2483 | |
2484 | BOOST_TEST( X::instances == 0 ); |
2485 | } |
2486 | |
2487 | // main |
2488 | |
2489 | int main() |
2490 | { |
2491 | default_constructor(); |
2492 | nullptr_constructor(); |
2493 | pointer_constructor(); |
2494 | deleter_constructor(); |
2495 | copy_constructor(); |
2496 | move_constructor(); |
2497 | aliasing_constructor(); |
2498 | nullptr_deleter_constructor(); |
2499 | allocator_constructor(); |
2500 | nullptr_allocator_constructor(); |
2501 | shared_ptr_copy_constructor(); |
2502 | shared_ptr_move_constructor(); |
2503 | unique_ptr_constructor(); |
2504 | |
2505 | copy_assignment(); |
2506 | move_assignment(); |
2507 | nullptr_assignment(); |
2508 | shared_ptr_copy_assignment(); |
2509 | shared_ptr_move_assignment(); |
2510 | unique_ptr_assignment(); |
2511 | |
2512 | default_reset(); |
2513 | pointer_reset(); |
2514 | deleter_reset(); |
2515 | allocator_reset(); |
2516 | aliasing_reset(); |
2517 | |
2518 | element_access(); |
2519 | shared_ptr_conversion(); |
2520 | weak_ptr_conversion(); |
2521 | // swap_test(); |
2522 | // owner_before_test(); |
2523 | // equal_test(); |
2524 | // operator< ? |
2525 | // casts |
2526 | // get_pointer |
2527 | // operator<< |
2528 | // hash |
2529 | |
2530 | return boost::report_errors(); |
2531 | } |
2532 | |