1// Copyright (C) 2005 Free Software Foundation 2// 3// This file is part of the GNU ISO C++ Library. This library is free 4// software; you can redistribute it and/or modify it under the 5// terms of the GNU General Public License as published by the 6// Free Software Foundation; either version 2, or (at your option) 7// any later version. 8 9// This library is distributed in the hope that it will be useful, 10// but WITHOUT ANY WARRANTY; without even the implied warranty of 11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12// GNU General Public License for more details. 13 14// You should have received a copy of the GNU General Public License along 15// with this library; see the file COPYING. If not, write to the Free 16// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 17// USA. 18 19// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared] 20 21#include <tr1/memory> 22#include <testsuite_hooks.h> 23 24struct A { }; 25struct B : A { }; 26 27 28// 2.2.3.1 shared_ptr constructors [tr.util.smartptr.shared.const] 29 30// Construction from pointer 31 32int 33test01() 34{ 35 bool test __attribute__((unused)) = true; 36 37 A * const a = 0; 38 std::tr1::shared_ptr<A> p(a); 39 VERIFY( p.get() == 0 ); 40 VERIFY( p.use_count() == 1 ); 41 42 return 0; 43} 44 45int 46test02() 47{ 48 bool test __attribute__((unused)) = true; 49 50 A * const a = new A; 51 std::tr1::shared_ptr<A> p(a); 52 VERIFY( p.get() == a ); 53 VERIFY( p.use_count() == 1 ); 54 55 return 0; 56} 57 58 59int 60test03() 61{ 62 bool test __attribute__((unused)) = true; 63 64 B * const b = new B; 65 std::tr1::shared_ptr<A> p(b); 66 VERIFY( p.get() == b ); 67 VERIFY( p.use_count() == 1 ); 68 69 return 0; 70} 71 72int 73main() 74{ 75 test01(); 76 test02(); 77 test02(); 78 return 0; 79} 80