1 #include <boost/config.hpp>
3 #if defined(BOOST_MSVC)
5 #pragma warning(disable: 4786) // identifier truncated in debug info
6 #pragma warning(disable: 4710) // function not inlined
7 #pragma warning(disable: 4711) // function selected for automatic inline expansion
8 #pragma warning(disable: 4514) // unreferenced inline removed
9 #pragma warning(disable: 4355) // 'this' : used in base member initializer list
11 #if (BOOST_MSVC >= 1310)
12 #pragma warning(disable: 4675) // resolved overload found with Koenig lookup
20 // Copyright (c) 2002-2005 Peter Dimov
22 // Distributed under the Boost Software License, Version 1.0. (See
23 // accompanying file LICENSE_1_0.txt or copy at
24 // http://www.boost.org/LICENSE_1_0.txt)
27 #include <boost/detail/lightweight_test.hpp>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/weak_ptr.hpp>
37 namespace n_element_type
46 typedef boost::weak_ptr<int>::element_type T;
51 } // namespace n_element_type
55 boost::shared_ptr<incomplete> create_incomplete();
67 struct Z: public X, public virtual Y
71 namespace n_constructors
74 void default_constructor()
77 boost::weak_ptr<int> wp;
78 BOOST_TEST(wp.use_count() == 0);
82 boost::weak_ptr<void> wp;
83 BOOST_TEST(wp.use_count() == 0);
87 boost::weak_ptr<incomplete> wp;
88 BOOST_TEST(wp.use_count() == 0);
92 void shared_ptr_constructor()
95 boost::shared_ptr<int> sp;
97 boost::weak_ptr<int> wp(sp);
98 BOOST_TEST(wp.use_count() == sp.use_count());
100 boost::weak_ptr<void> wp2(sp);
101 BOOST_TEST(wp2.use_count() == sp.use_count());
105 boost::shared_ptr<int> sp(static_cast<int*>(0));
108 boost::weak_ptr<int> wp(sp);
109 BOOST_TEST(wp.use_count() == sp.use_count());
110 BOOST_TEST(wp.use_count() == 1);
111 boost::shared_ptr<int> sp2(wp);
112 BOOST_TEST(wp.use_count() == 2);
113 BOOST_TEST(!(sp < sp2 || sp2 < sp));
117 boost::weak_ptr<void> wp(sp);
118 BOOST_TEST(wp.use_count() == sp.use_count());
119 BOOST_TEST(wp.use_count() == 1);
120 boost::shared_ptr<void> sp2(wp);
121 BOOST_TEST(wp.use_count() == 2);
122 BOOST_TEST(!(sp < sp2 || sp2 < sp));
127 boost::shared_ptr<int> sp(new int);
130 boost::weak_ptr<int> wp(sp);
131 BOOST_TEST(wp.use_count() == sp.use_count());
132 BOOST_TEST(wp.use_count() == 1);
133 boost::shared_ptr<int> sp2(wp);
134 BOOST_TEST(wp.use_count() == 2);
135 BOOST_TEST(!(sp < sp2 || sp2 < sp));
139 boost::weak_ptr<void> wp(sp);
140 BOOST_TEST(wp.use_count() == sp.use_count());
141 BOOST_TEST(wp.use_count() == 1);
142 boost::shared_ptr<void> sp2(wp);
143 BOOST_TEST(wp.use_count() == 2);
144 BOOST_TEST(!(sp < sp2 || sp2 < sp));
149 boost::shared_ptr<void> sp;
151 boost::weak_ptr<void> wp(sp);
152 BOOST_TEST(wp.use_count() == sp.use_count());
156 boost::shared_ptr<void> sp(static_cast<int*>(0));
158 boost::weak_ptr<void> wp(sp);
159 BOOST_TEST(wp.use_count() == sp.use_count());
160 BOOST_TEST(wp.use_count() == 1);
161 boost::shared_ptr<void> sp2(wp);
162 BOOST_TEST(wp.use_count() == 2);
163 BOOST_TEST(!(sp < sp2 || sp2 < sp));
167 boost::shared_ptr<void> sp(new int);
169 boost::weak_ptr<void> wp(sp);
170 BOOST_TEST(wp.use_count() == sp.use_count());
171 BOOST_TEST(wp.use_count() == 1);
172 boost::shared_ptr<void> sp2(wp);
173 BOOST_TEST(wp.use_count() == 2);
174 BOOST_TEST(!(sp < sp2 || sp2 < sp));
178 boost::shared_ptr<incomplete> sp;
180 boost::weak_ptr<incomplete> wp(sp);
181 BOOST_TEST(wp.use_count() == sp.use_count());
183 boost::weak_ptr<void> wp2(sp);
184 BOOST_TEST(wp2.use_count() == sp.use_count());
188 boost::shared_ptr<incomplete> sp = create_incomplete();
191 boost::weak_ptr<incomplete> wp(sp);
192 BOOST_TEST(wp.use_count() == sp.use_count());
193 BOOST_TEST(wp.use_count() == 1);
194 boost::shared_ptr<incomplete> sp2(wp);
195 BOOST_TEST(wp.use_count() == 2);
196 BOOST_TEST(!(sp < sp2 || sp2 < sp));
200 boost::weak_ptr<void> wp(sp);
201 BOOST_TEST(wp.use_count() == sp.use_count());
202 BOOST_TEST(wp.use_count() == 1);
203 boost::shared_ptr<void> sp2(wp);
204 BOOST_TEST(wp.use_count() == 2);
205 BOOST_TEST(!(sp < sp2 || sp2 < sp));
210 boost::shared_ptr<void> sp = create_incomplete();
212 boost::weak_ptr<void> wp(sp);
213 BOOST_TEST(wp.use_count() == sp.use_count());
214 BOOST_TEST(wp.use_count() == 1);
215 boost::shared_ptr<void> sp2(wp);
216 BOOST_TEST(wp.use_count() == 2);
217 BOOST_TEST(!(sp < sp2 || sp2 < sp));
221 void copy_constructor()
224 boost::weak_ptr<int> wp;
225 boost::weak_ptr<int> wp2(wp);
226 BOOST_TEST(wp2.use_count() == wp.use_count());
227 BOOST_TEST(wp2.use_count() == 0);
231 boost::weak_ptr<void> wp;
232 boost::weak_ptr<void> wp2(wp);
233 BOOST_TEST(wp2.use_count() == wp.use_count());
234 BOOST_TEST(wp2.use_count() == 0);
238 boost::weak_ptr<incomplete> wp;
239 boost::weak_ptr<incomplete> wp2(wp);
240 BOOST_TEST(wp2.use_count() == wp.use_count());
241 BOOST_TEST(wp2.use_count() == 0);
245 boost::shared_ptr<int> sp(static_cast<int*>(0));
246 boost::weak_ptr<int> wp(sp);
248 boost::weak_ptr<int> wp2(wp);
249 BOOST_TEST(wp2.use_count() == wp.use_count());
250 BOOST_TEST(wp2.use_count() == 1);
251 BOOST_TEST(!(wp < wp2 || wp2 < wp));
254 BOOST_TEST(!(wp < wp2 || wp2 < wp));
256 boost::weak_ptr<int> wp3(wp);
257 BOOST_TEST(wp3.use_count() == wp.use_count());
258 BOOST_TEST(wp3.use_count() == 0);
259 BOOST_TEST(!(wp < wp3 || wp3 < wp));
263 boost::shared_ptr<int> sp(new int);
264 boost::weak_ptr<int> wp(sp);
266 boost::weak_ptr<int> wp2(wp);
267 BOOST_TEST(wp2.use_count() == wp.use_count());
268 BOOST_TEST(wp2.use_count() == 1);
269 BOOST_TEST(!(wp < wp2 || wp2 < wp));
272 BOOST_TEST(!(wp < wp2 || wp2 < wp));
274 boost::weak_ptr<int> wp3(wp);
275 BOOST_TEST(wp3.use_count() == wp.use_count());
276 BOOST_TEST(wp3.use_count() == 0);
277 BOOST_TEST(!(wp < wp3 || wp3 < wp));
281 boost::shared_ptr<void> sp(static_cast<int*>(0));
282 boost::weak_ptr<void> wp(sp);
284 boost::weak_ptr<void> wp2(wp);
285 BOOST_TEST(wp2.use_count() == wp.use_count());
286 BOOST_TEST(wp2.use_count() == 1);
287 BOOST_TEST(!(wp < wp2 || wp2 < wp));
290 BOOST_TEST(!(wp < wp2 || wp2 < wp));
292 boost::weak_ptr<void> wp3(wp);
293 BOOST_TEST(wp3.use_count() == wp.use_count());
294 BOOST_TEST(wp3.use_count() == 0);
295 BOOST_TEST(!(wp < wp3 || wp3 < wp));
299 boost::shared_ptr<void> sp(new int);
300 boost::weak_ptr<void> wp(sp);
302 boost::weak_ptr<void> wp2(wp);
303 BOOST_TEST(wp2.use_count() == wp.use_count());
304 BOOST_TEST(wp2.use_count() == 1);
305 BOOST_TEST(!(wp < wp2 || wp2 < wp));
308 BOOST_TEST(!(wp < wp2 || wp2 < wp));
310 boost::weak_ptr<void> wp3(wp);
311 BOOST_TEST(wp3.use_count() == wp.use_count());
312 BOOST_TEST(wp3.use_count() == 0);
313 BOOST_TEST(!(wp < wp3 || wp3 < wp));
317 boost::shared_ptr<incomplete> sp = create_incomplete();
318 boost::weak_ptr<incomplete> wp(sp);
320 boost::weak_ptr<incomplete> wp2(wp);
321 BOOST_TEST(wp2.use_count() == wp.use_count());
322 BOOST_TEST(wp2.use_count() == 1);
323 BOOST_TEST(!(wp < wp2 || wp2 < wp));
326 BOOST_TEST(!(wp < wp2 || wp2 < wp));
328 boost::weak_ptr<incomplete> wp3(wp);
329 BOOST_TEST(wp3.use_count() == wp.use_count());
330 BOOST_TEST(wp3.use_count() == 0);
331 BOOST_TEST(!(wp < wp3 || wp3 < wp));
335 void conversion_constructor()
338 boost::weak_ptr<int> wp;
339 boost::weak_ptr<void> wp2(wp);
340 BOOST_TEST(wp2.use_count() == wp.use_count());
341 BOOST_TEST(wp2.use_count() == 0);
345 boost::weak_ptr<incomplete> wp;
346 boost::weak_ptr<void> wp2(wp);
347 BOOST_TEST(wp2.use_count() == wp.use_count());
348 BOOST_TEST(wp2.use_count() == 0);
352 boost::weak_ptr<Z> wp;
354 boost::weak_ptr<X> wp2(wp);
355 BOOST_TEST(wp2.use_count() == wp.use_count());
356 BOOST_TEST(wp2.use_count() == 0);
358 boost::weak_ptr<Y> wp3(wp);
359 BOOST_TEST(wp3.use_count() == wp.use_count());
360 BOOST_TEST(wp3.use_count() == 0);
364 boost::shared_ptr<int> sp(static_cast<int*>(0));
365 boost::weak_ptr<int> wp(sp);
367 boost::weak_ptr<void> wp2(wp);
368 BOOST_TEST(wp2.use_count() == wp.use_count());
369 BOOST_TEST(wp2.use_count() == 1);
370 BOOST_TEST(!(wp < wp2 || wp2 < wp));
373 BOOST_TEST(!(wp < wp2 || wp2 < wp));
375 boost::weak_ptr<void> wp3(wp);
376 BOOST_TEST(wp3.use_count() == wp.use_count());
377 BOOST_TEST(wp3.use_count() == 0);
378 BOOST_TEST(!(wp < wp3 || wp3 < wp));
382 boost::shared_ptr<int> sp(new int);
383 boost::weak_ptr<int> wp(sp);
385 boost::weak_ptr<void> wp2(wp);
386 BOOST_TEST(wp2.use_count() == wp.use_count());
387 BOOST_TEST(wp2.use_count() == 1);
388 BOOST_TEST(!(wp < wp2 || wp2 < wp));
391 BOOST_TEST(!(wp < wp2 || wp2 < wp));
393 boost::weak_ptr<void> wp3(wp);
394 BOOST_TEST(wp3.use_count() == wp.use_count());
395 BOOST_TEST(wp3.use_count() == 0);
396 BOOST_TEST(!(wp < wp3 || wp3 < wp));
400 boost::shared_ptr<incomplete> sp = create_incomplete();
401 boost::weak_ptr<incomplete> wp(sp);
403 boost::weak_ptr<void> wp2(wp);
404 BOOST_TEST(wp2.use_count() == wp.use_count());
405 BOOST_TEST(wp2.use_count() == 1);
406 BOOST_TEST(!(wp < wp2 || wp2 < wp));
409 BOOST_TEST(!(wp < wp2 || wp2 < wp));
411 boost::weak_ptr<void> wp3(wp);
412 BOOST_TEST(wp3.use_count() == wp.use_count());
413 BOOST_TEST(wp3.use_count() == 0);
414 BOOST_TEST(!(wp < wp3 || wp3 < wp));
418 boost::shared_ptr<Z> sp(static_cast<Z*>(0));
419 boost::weak_ptr<Z> wp(sp);
421 boost::weak_ptr<X> wp2(wp);
422 BOOST_TEST(wp2.use_count() == wp.use_count());
423 BOOST_TEST(wp2.use_count() == 1);
424 BOOST_TEST(!(wp < wp2 || wp2 < wp));
427 BOOST_TEST(!(wp < wp2 || wp2 < wp));
429 boost::weak_ptr<X> wp3(wp);
430 BOOST_TEST(wp3.use_count() == wp.use_count());
431 BOOST_TEST(wp3.use_count() == 0);
432 BOOST_TEST(!(wp < wp3 || wp3 < wp));
436 boost::shared_ptr<Z> sp(static_cast<Z*>(0));
437 boost::weak_ptr<Z> wp(sp);
439 boost::weak_ptr<Y> wp2(wp);
440 BOOST_TEST(wp2.use_count() == wp.use_count());
441 BOOST_TEST(wp2.use_count() == 1);
442 BOOST_TEST(!(wp < wp2 || wp2 < wp));
445 BOOST_TEST(!(wp < wp2 || wp2 < wp));
447 boost::weak_ptr<Y> wp3(wp);
448 BOOST_TEST(wp3.use_count() == wp.use_count());
449 BOOST_TEST(wp3.use_count() == 0);
450 BOOST_TEST(!(wp < wp3 || wp3 < wp));
454 boost::shared_ptr<Z> sp(new Z);
455 boost::weak_ptr<Z> wp(sp);
457 boost::weak_ptr<X> wp2(wp);
458 BOOST_TEST(wp2.use_count() == wp.use_count());
459 BOOST_TEST(wp2.use_count() == 1);
460 BOOST_TEST(!(wp < wp2 || wp2 < wp));
463 BOOST_TEST(!(wp < wp2 || wp2 < wp));
465 boost::weak_ptr<X> wp3(wp);
466 BOOST_TEST(wp3.use_count() == wp.use_count());
467 BOOST_TEST(wp3.use_count() == 0);
468 BOOST_TEST(!(wp < wp3 || wp3 < wp));
472 boost::shared_ptr<Z> sp(new Z);
473 boost::weak_ptr<Z> wp(sp);
475 boost::weak_ptr<Y> wp2(wp);
476 BOOST_TEST(wp2.use_count() == wp.use_count());
477 BOOST_TEST(wp2.use_count() == 1);
478 BOOST_TEST(!(wp < wp2 || wp2 < wp));
481 BOOST_TEST(!(wp < wp2 || wp2 < wp));
483 boost::weak_ptr<Y> wp3(wp);
484 BOOST_TEST(wp3.use_count() == wp.use_count());
485 BOOST_TEST(wp3.use_count() == 0);
486 BOOST_TEST(!(wp < wp3 || wp3 < wp));
492 default_constructor();
493 shared_ptr_constructor();
495 conversion_constructor();
498 } // namespace n_constructors
500 namespace n_assignment
503 template<class T> void copy_assignment(boost::shared_ptr<T> & sp)
505 BOOST_TEST(sp.unique());
507 boost::weak_ptr<T> p1;
510 BOOST_TEST(p1.use_count() == 0);
512 boost::weak_ptr<T> p2;
515 BOOST_TEST(p1.use_count() == 0);
517 boost::weak_ptr<T> p3(p1);
520 BOOST_TEST(p1.use_count() == 0);
522 boost::weak_ptr<T> p4(sp);
525 BOOST_TEST(p4.use_count() == 1);
528 BOOST_TEST(p1.use_count() == 1);
531 BOOST_TEST(p4.use_count() == 0);
536 BOOST_TEST(p1.use_count() == 0);
539 BOOST_TEST(p4.use_count() == 0);
542 void conversion_assignment()
545 boost::weak_ptr<void> p1;
547 boost::weak_ptr<incomplete> p2;
550 BOOST_TEST(p1.use_count() == 0);
552 boost::shared_ptr<incomplete> sp = create_incomplete();
553 boost::weak_ptr<incomplete> p3(sp);
556 BOOST_TEST(p1.use_count() == 1);
561 BOOST_TEST(p1.use_count() == 0);
564 BOOST_TEST(p1.use_count() == 0);
568 boost::weak_ptr<X> p1;
570 boost::weak_ptr<Z> p2;
573 BOOST_TEST(p1.use_count() == 0);
575 boost::shared_ptr<Z> sp(new Z);
576 boost::weak_ptr<Z> p3(sp);
579 BOOST_TEST(p1.use_count() == 1);
584 BOOST_TEST(p1.use_count() == 0);
587 BOOST_TEST(p1.use_count() == 0);
591 boost::weak_ptr<Y> p1;
593 boost::weak_ptr<Z> p2;
596 BOOST_TEST(p1.use_count() == 0);
598 boost::shared_ptr<Z> sp(new Z);
599 boost::weak_ptr<Z> p3(sp);
602 BOOST_TEST(p1.use_count() == 1);
607 BOOST_TEST(p1.use_count() == 0);
610 BOOST_TEST(p1.use_count() == 0);
614 template<class T, class U> void shared_ptr_assignment(boost::shared_ptr<U> & sp, T * = 0)
616 BOOST_TEST(sp.unique());
618 boost::weak_ptr<T> p1;
619 boost::weak_ptr<T> p2(p1);
620 boost::weak_ptr<T> p3(sp);
621 boost::weak_ptr<T> p4(p3);
624 BOOST_TEST(p1.use_count() == 1);
627 BOOST_TEST(p2.use_count() == 1);
630 BOOST_TEST(p3.use_count() == 1);
633 BOOST_TEST(p4.use_count() == 1);
637 BOOST_TEST(p1.use_count() == 0);
638 BOOST_TEST(p2.use_count() == 0);
639 BOOST_TEST(p3.use_count() == 0);
640 BOOST_TEST(p4.use_count() == 0);
648 boost::shared_ptr<int> p( new int );
649 copy_assignment( p );
653 boost::shared_ptr<X> p( new X );
654 copy_assignment( p );
658 boost::shared_ptr<void> p( new int );
659 copy_assignment( p );
663 boost::shared_ptr<incomplete> p = create_incomplete();
664 copy_assignment( p );
667 conversion_assignment();
670 boost::shared_ptr<int> p( new int );
671 shared_ptr_assignment<int>( p );
675 boost::shared_ptr<int> p( new int );
676 shared_ptr_assignment<void>( p );
680 boost::shared_ptr<X> p( new X );
681 shared_ptr_assignment<X>( p );
685 boost::shared_ptr<X> p( new X );
686 shared_ptr_assignment<void>( p );
690 boost::shared_ptr<void> p( new int );
691 shared_ptr_assignment<void>( p );
695 boost::shared_ptr<incomplete> p = create_incomplete();
696 shared_ptr_assignment<incomplete>( p );
700 boost::shared_ptr<incomplete> p = create_incomplete();
701 shared_ptr_assignment<void>( p );
705 } // namespace n_assignment
710 template<class T, class U> void test2( boost::shared_ptr<U> & sp, T * = 0 )
712 BOOST_TEST(sp.unique());
714 boost::weak_ptr<T> p1;
715 boost::weak_ptr<T> p2(p1);
716 boost::weak_ptr<T> p3(sp);
717 boost::weak_ptr<T> p4(p3);
718 boost::weak_ptr<T> p5(sp);
719 boost::weak_ptr<T> p6(p5);
722 BOOST_TEST(p1.use_count() == 0);
725 BOOST_TEST(p2.use_count() == 0);
728 BOOST_TEST(p3.use_count() == 0);
731 BOOST_TEST(p4.use_count() == 0);
736 BOOST_TEST(p5.use_count() == 0);
739 BOOST_TEST(p6.use_count() == 0);
745 boost::shared_ptr<int> p( new int );
750 boost::shared_ptr<int> p( new int );
755 boost::shared_ptr<X> p( new X );
760 boost::shared_ptr<X> p( new X );
765 boost::shared_ptr<void> p( new int );
770 boost::shared_ptr<incomplete> p = create_incomplete();
771 test2<incomplete>( p );
775 boost::shared_ptr<incomplete> p = create_incomplete();
780 } // namespace n_reset
782 namespace n_use_count
788 boost::weak_ptr<X> wp;
789 BOOST_TEST(wp.use_count() == 0);
790 BOOST_TEST(wp.expired());
792 boost::weak_ptr<X> wp2;
793 BOOST_TEST(wp.use_count() == 0);
794 BOOST_TEST(wp.expired());
796 boost::weak_ptr<X> wp3(wp);
797 BOOST_TEST(wp.use_count() == 0);
798 BOOST_TEST(wp.expired());
799 BOOST_TEST(wp3.use_count() == 0);
800 BOOST_TEST(wp3.expired());
804 boost::shared_ptr<X> sp(static_cast<X*>(0));
806 boost::weak_ptr<X> wp(sp);
807 BOOST_TEST(wp.use_count() == 1);
808 BOOST_TEST(!wp.expired());
810 boost::weak_ptr<X> wp2(sp);
811 BOOST_TEST(wp.use_count() == 1);
812 BOOST_TEST(!wp.expired());
814 boost::weak_ptr<X> wp3(wp);
815 BOOST_TEST(wp.use_count() == 1);
816 BOOST_TEST(!wp.expired());
817 BOOST_TEST(wp3.use_count() == 1);
818 BOOST_TEST(!wp3.expired());
820 boost::shared_ptr<X> sp2(sp);
822 BOOST_TEST(wp.use_count() == 2);
823 BOOST_TEST(!wp.expired());
824 BOOST_TEST(wp2.use_count() == 2);
825 BOOST_TEST(!wp2.expired());
826 BOOST_TEST(wp3.use_count() == 2);
827 BOOST_TEST(!wp3.expired());
829 boost::shared_ptr<void> sp3(sp);
831 BOOST_TEST(wp.use_count() == 3);
832 BOOST_TEST(!wp.expired());
833 BOOST_TEST(wp2.use_count() == 3);
834 BOOST_TEST(!wp2.expired());
835 BOOST_TEST(wp3.use_count() == 3);
836 BOOST_TEST(!wp3.expired());
840 BOOST_TEST(wp.use_count() == 2);
841 BOOST_TEST(!wp.expired());
842 BOOST_TEST(wp2.use_count() == 2);
843 BOOST_TEST(!wp2.expired());
844 BOOST_TEST(wp3.use_count() == 2);
845 BOOST_TEST(!wp3.expired());
849 BOOST_TEST(wp.use_count() == 1);
850 BOOST_TEST(!wp.expired());
851 BOOST_TEST(wp2.use_count() == 1);
852 BOOST_TEST(!wp2.expired());
853 BOOST_TEST(wp3.use_count() == 1);
854 BOOST_TEST(!wp3.expired());
858 BOOST_TEST(wp.use_count() == 0);
859 BOOST_TEST(wp.expired());
860 BOOST_TEST(wp2.use_count() == 0);
861 BOOST_TEST(wp2.expired());
862 BOOST_TEST(wp3.use_count() == 0);
863 BOOST_TEST(wp3.expired());
867 } // namespace n_use_count
875 boost::weak_ptr<X> wp;
876 boost::weak_ptr<X> wp2;
880 BOOST_TEST(wp.use_count() == 0);
881 BOOST_TEST(wp2.use_count() == 0);
886 BOOST_TEST(wp.use_count() == 0);
887 BOOST_TEST(wp2.use_count() == 0);
891 boost::shared_ptr<X> sp(new X);
892 boost::weak_ptr<X> wp;
893 boost::weak_ptr<X> wp2(sp);
894 boost::weak_ptr<X> wp3(sp);
898 BOOST_TEST(wp.use_count() == 1);
899 BOOST_TEST(wp2.use_count() == 0);
900 BOOST_TEST(!(wp < wp3 || wp3 < wp));
905 BOOST_TEST(wp.use_count() == 0);
906 BOOST_TEST(wp2.use_count() == 1);
907 BOOST_TEST(!(wp2 < wp3 || wp3 < wp2));
913 BOOST_TEST(wp.use_count() == 0);
914 BOOST_TEST(wp2.use_count() == 0);
915 BOOST_TEST(!(wp < wp3 || wp3 < wp));
919 BOOST_TEST(wp.use_count() == 0);
920 BOOST_TEST(wp2.use_count() == 0);
921 BOOST_TEST(!(wp2 < wp3 || wp3 < wp2));
925 boost::shared_ptr<X> sp(new X);
926 boost::shared_ptr<X> sp2(new X);
927 boost::weak_ptr<X> wp(sp);
928 boost::weak_ptr<X> wp2(sp2);
929 boost::weak_ptr<X> wp3(sp2);
933 BOOST_TEST(wp.use_count() == 1);
934 BOOST_TEST(wp2.use_count() == 1);
935 BOOST_TEST(!(wp < wp3 || wp3 < wp));
940 BOOST_TEST(wp.use_count() == 1);
941 BOOST_TEST(wp2.use_count() == 1);
942 BOOST_TEST(!(wp2 < wp3 || wp3 < wp2));
948 BOOST_TEST(wp.use_count() == 1);
949 BOOST_TEST(wp2.use_count() == 0);
950 BOOST_TEST(!(wp < wp3 || wp3 < wp));
954 BOOST_TEST(wp.use_count() == 0);
955 BOOST_TEST(wp2.use_count() == 1);
956 BOOST_TEST(!(wp2 < wp3 || wp3 < wp2));
962 BOOST_TEST(wp.use_count() == 0);
963 BOOST_TEST(wp2.use_count() == 0);
964 BOOST_TEST(!(wp < wp3 || wp3 < wp));
968 BOOST_TEST(wp.use_count() == 0);
969 BOOST_TEST(wp2.use_count() == 0);
970 BOOST_TEST(!(wp2 < wp3 || wp3 < wp2));
974 } // namespace n_swap
976 namespace n_comparison
982 boost::weak_ptr<X> wp;
983 BOOST_TEST(!(wp < wp));
985 boost::weak_ptr<X> wp2;
986 BOOST_TEST(!(wp < wp2 && wp2 < wp));
988 boost::weak_ptr<X> wp3(wp);
989 BOOST_TEST(!(wp3 < wp3));
990 BOOST_TEST(!(wp < wp3 && wp3 < wp));
994 boost::shared_ptr<X> sp(new X);
996 boost::weak_ptr<X> wp(sp);
997 BOOST_TEST(!(wp < wp));
999 boost::weak_ptr<X> wp2;
1000 BOOST_TEST(wp < wp2 || wp2 < wp);
1001 BOOST_TEST(!(wp < wp2 && wp2 < wp));
1007 boost::weak_ptr<X> wp3(wp);
1009 BOOST_TEST(!(wp < wp3 || wp3 < wp));
1010 BOOST_TEST(!(wp < wp3 && wp3 < wp));
1012 BOOST_TEST(wp2 < wp3 || wp3 < wp2);
1013 BOOST_TEST(!(wp2 < wp3 && wp3 < wp2));
1015 boost::weak_ptr<X> wp4(wp2);
1017 BOOST_TEST(wp4 < wp3 || wp3 < wp4);
1018 BOOST_TEST(!(wp4 < wp3 && wp3 < wp4));
1023 BOOST_TEST(b1 == (wp < wp2));
1024 BOOST_TEST(b2 == (wp2 < wp));
1027 boost::weak_ptr<X> wp3(wp);
1029 BOOST_TEST(!(wp < wp3 || wp3 < wp));
1030 BOOST_TEST(!(wp < wp3 && wp3 < wp));
1032 BOOST_TEST(wp2 < wp3 || wp3 < wp2);
1033 BOOST_TEST(!(wp2 < wp3 && wp3 < wp2));
1035 boost::weak_ptr<X> wp4(wp2);
1037 BOOST_TEST(wp4 < wp3 || wp3 < wp4);
1038 BOOST_TEST(!(wp4 < wp3 && wp3 < wp4));
1043 boost::shared_ptr<X> sp(new X);
1044 boost::shared_ptr<X> sp2(new X);
1046 boost::weak_ptr<X> wp(sp);
1047 boost::weak_ptr<X> wp2(sp2);
1049 BOOST_TEST(wp < wp2 || wp2 < wp);
1050 BOOST_TEST(!(wp < wp2 && wp2 < wp));
1056 boost::weak_ptr<X> wp3(wp);
1058 BOOST_TEST(!(wp < wp3 || wp3 < wp));
1059 BOOST_TEST(!(wp < wp3 && wp3 < wp));
1061 BOOST_TEST(wp2 < wp3 || wp3 < wp2);
1062 BOOST_TEST(!(wp2 < wp3 && wp3 < wp2));
1064 boost::weak_ptr<X> wp4(wp2);
1066 BOOST_TEST(wp4 < wp3 || wp3 < wp4);
1067 BOOST_TEST(!(wp4 < wp3 && wp3 < wp4));
1072 BOOST_TEST(b1 == (wp < wp2));
1073 BOOST_TEST(b2 == (wp2 < wp));
1076 boost::weak_ptr<X> wp3(wp);
1078 BOOST_TEST(!(wp < wp3 || wp3 < wp));
1079 BOOST_TEST(!(wp < wp3 && wp3 < wp));
1081 BOOST_TEST(wp2 < wp3 || wp3 < wp2);
1082 BOOST_TEST(!(wp2 < wp3 && wp3 < wp2));
1084 boost::weak_ptr<X> wp4(wp2);
1086 BOOST_TEST(wp4 < wp3 || wp3 < wp4);
1087 BOOST_TEST(!(wp4 < wp3 && wp3 < wp4));
1092 BOOST_TEST(b1 == (wp < wp2));
1093 BOOST_TEST(b2 == (wp2 < wp));
1096 boost::weak_ptr<X> wp3(wp);
1098 BOOST_TEST(!(wp < wp3 || wp3 < wp));
1099 BOOST_TEST(!(wp < wp3 && wp3 < wp));
1101 BOOST_TEST(wp2 < wp3 || wp3 < wp2);
1102 BOOST_TEST(!(wp2 < wp3 && wp3 < wp2));
1104 boost::weak_ptr<X> wp4(wp2);
1106 BOOST_TEST(wp4 < wp3 || wp3 < wp4);
1107 BOOST_TEST(!(wp4 < wp3 && wp3 < wp4));
1112 boost::shared_ptr<X> sp(new X);
1113 boost::shared_ptr<X> sp2(sp);
1115 boost::weak_ptr<X> wp(sp);
1116 boost::weak_ptr<X> wp2(sp2);
1118 BOOST_TEST(!(wp < wp2 || wp2 < wp));
1119 BOOST_TEST(!(wp < wp2 && wp2 < wp));
1125 boost::weak_ptr<X> wp3(wp);
1127 BOOST_TEST(!(wp < wp3 || wp3 < wp));
1128 BOOST_TEST(!(wp < wp3 && wp3 < wp));
1130 BOOST_TEST(!(wp2 < wp3 || wp3 < wp2));
1131 BOOST_TEST(!(wp2 < wp3 && wp3 < wp2));
1133 boost::weak_ptr<X> wp4(wp2);
1135 BOOST_TEST(!(wp4 < wp3 || wp3 < wp4));
1136 BOOST_TEST(!(wp4 < wp3 && wp3 < wp4));
1142 BOOST_TEST(b1 == (wp < wp2));
1143 BOOST_TEST(b2 == (wp2 < wp));
1146 boost::weak_ptr<X> wp3(wp);
1148 BOOST_TEST(!(wp < wp3 || wp3 < wp));
1149 BOOST_TEST(!(wp < wp3 && wp3 < wp));
1151 BOOST_TEST(!(wp2 < wp3 || wp3 < wp2));
1152 BOOST_TEST(!(wp2 < wp3 && wp3 < wp2));
1154 boost::weak_ptr<X> wp4(wp2);
1156 BOOST_TEST(!(wp4 < wp3 || wp3 < wp4));
1157 BOOST_TEST(!(wp4 < wp3 && wp3 < wp4));
1162 boost::shared_ptr<X> spx(new X);
1163 boost::shared_ptr<Y> spy(new Y);
1164 boost::shared_ptr<Z> spz(new Z);
1166 boost::weak_ptr<X> px(spx);
1167 boost::weak_ptr<Y> py(spy);
1168 boost::weak_ptr<Z> pz(spz);
1170 BOOST_TEST(px < py || py < px);
1171 BOOST_TEST(px < pz || pz < px);
1172 BOOST_TEST(py < pz || pz < py);
1174 BOOST_TEST(!(px < py && py < px));
1175 BOOST_TEST(!(px < pz && pz < px));
1176 BOOST_TEST(!(py < pz && pz < py));
1178 boost::weak_ptr<void> pvx(px);
1179 BOOST_TEST(!(pvx < pvx));
1181 boost::weak_ptr<void> pvy(py);
1182 BOOST_TEST(!(pvy < pvy));
1184 boost::weak_ptr<void> pvz(pz);
1185 BOOST_TEST(!(pvz < pvz));
1187 BOOST_TEST(pvx < pvy || pvy < pvx);
1188 BOOST_TEST(pvx < pvz || pvz < pvx);
1189 BOOST_TEST(pvy < pvz || pvz < pvy);
1191 BOOST_TEST(!(pvx < pvy && pvy < pvx));
1192 BOOST_TEST(!(pvx < pvz && pvz < pvx));
1193 BOOST_TEST(!(pvy < pvz && pvz < pvy));
1199 BOOST_TEST(px < py || py < px);
1200 BOOST_TEST(px < pz || pz < px);
1201 BOOST_TEST(py < pz || pz < py);
1203 BOOST_TEST(!(px < py && py < px));
1204 BOOST_TEST(!(px < pz && pz < px));
1205 BOOST_TEST(!(py < pz && pz < py));
1207 BOOST_TEST(!(pvx < pvx));
1208 BOOST_TEST(!(pvy < pvy));
1209 BOOST_TEST(!(pvz < pvz));
1211 BOOST_TEST(pvx < pvy || pvy < pvx);
1212 BOOST_TEST(pvx < pvz || pvz < pvx);
1213 BOOST_TEST(pvy < pvz || pvz < pvy);
1215 BOOST_TEST(!(pvx < pvy && pvy < pvx));
1216 BOOST_TEST(!(pvx < pvz && pvz < pvx));
1217 BOOST_TEST(!(pvy < pvz && pvz < pvy));
1221 boost::shared_ptr<Z> spz(new Z);
1222 boost::shared_ptr<X> spx(spz);
1224 boost::weak_ptr<Z> pz(spz);
1225 boost::weak_ptr<X> px(spx);
1226 boost::weak_ptr<Y> py(spz);
1228 BOOST_TEST(!(px < px));
1229 BOOST_TEST(!(py < py));
1231 BOOST_TEST(!(px < py || py < px));
1232 BOOST_TEST(!(px < pz || pz < px));
1233 BOOST_TEST(!(py < pz || pz < py));
1235 boost::weak_ptr<void> pvx(px);
1236 boost::weak_ptr<void> pvy(py);
1237 boost::weak_ptr<void> pvz(pz);
1239 BOOST_TEST(!(pvx < pvy || pvy < pvx));
1240 BOOST_TEST(!(pvx < pvz || pvz < pvx));
1241 BOOST_TEST(!(pvy < pvz || pvz < pvy));
1246 BOOST_TEST(!(px < px));
1247 BOOST_TEST(!(py < py));
1249 BOOST_TEST(!(px < py || py < px));
1250 BOOST_TEST(!(px < pz || pz < px));
1251 BOOST_TEST(!(py < pz || pz < py));
1253 BOOST_TEST(!(pvx < pvy || pvy < pvx));
1254 BOOST_TEST(!(pvx < pvz || pvz < pvx));
1255 BOOST_TEST(!(pvy < pvz || pvz < pvy));
1259 } // namespace n_comparison
1268 } // namespace n_lock
1275 std::vector< boost::shared_ptr<int> > vi;
1278 boost::shared_ptr<int> pi1(new int);
1279 boost::shared_ptr<int> pi2(new int);
1280 boost::shared_ptr<int> pi3(new int);
1295 std::vector< boost::shared_ptr<X> > vx;
1298 boost::shared_ptr<X> px1(new X);
1299 boost::shared_ptr<X> px2(new X);
1300 boost::shared_ptr<X> px3(new X);
1315 std::map< boost::weak_ptr<void>, long > m;
1318 for(std::vector< boost::shared_ptr<int> >::iterator i = vi.begin(); i != vi.end(); ++i)
1325 for(std::vector< boost::shared_ptr<X> >::iterator i = vx.begin(); i != vx.end(); ++i)
1332 for(std::map< boost::weak_ptr<void>, long >::iterator i = m.begin(); i != m.end(); ++i)
1334 BOOST_TEST(i->first.use_count() == i->second);
1339 } // namespace n_map
1343 n_element_type::test();
1344 n_constructors::test();
1345 n_assignment::test();
1347 n_use_count::test();
1349 n_comparison::test();
1354 return boost::report_errors();
1361 boost::shared_ptr<incomplete> create_incomplete()
1363 boost::shared_ptr<incomplete> px(new incomplete);