1163849Spjd// Copyright (C) 2005-2015 Free Software Foundation, Inc.
2163849Spjd//
3163849Spjd// This file is part of the GNU ISO C++ Library.  This library is free
4163849Spjd// software; you can redistribute it and/or modify it under the
5163849Spjd// terms of the GNU General Public License as published by the
6163849Spjd// Free Software Foundation; either version 3, or (at your option)
7163849Spjd// any later version.
8163849Spjd
9163849Spjd// This library is distributed in the hope that it will be useful,
10163849Spjd// but WITHOUT ANY WARRANTY; without even the implied warranty of
11163849Spjd// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12163849Spjd// GNU General Public License for more details.
13163849Spjd
14163849Spjd// You should have received a copy of the GNU General Public License along
15163849Spjd// with this library; see the file COPYING3.  If not see
16163849Spjd// <http://www.gnu.org/licenses/>.
17163849Spjd
18163849Spjd// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
19163849Spjd
20163849Spjd#include <tr1/memory>
21163849Spjd#include <testsuite_hooks.h>
22163849Spjd
23163849Spjdstruct A { };
24163849Spjd
25163849Spjd// 2.2.3.5 shared_ptr observers [tr.util.smartptr.shared.obs]
26163849Spjd
27163849Spjd// unique
28163849Spjdint
29163849Spjdtest01()
30163849Spjd{
31163849Spjd  bool test __attribute__((unused)) = true;
32163849Spjd
33163849Spjd  const std::tr1::shared_ptr<A> p1;
34163849Spjd  VERIFY( !p1.unique() );
35163849Spjd  const std::tr1::shared_ptr<A> p2(p1);
36163849Spjd  VERIFY( !p1.unique() );
37163849Spjd
38163849Spjd  return 0;
39163849Spjd}
40163849Spjd
41163849Spjdint
42163849Spjdtest02()
43163849Spjd{
44163849Spjd  bool test __attribute__((unused)) = true;
45163849Spjd
46163849Spjd  std::tr1::shared_ptr<A> p1(new A);
47163849Spjd  VERIFY( p1.unique() );
48163849Spjd  std::tr1::shared_ptr<A> p2(p1);
49163849Spjd  VERIFY( !p1.unique() );
50163849Spjd  p1.reset();
51163849Spjd  VERIFY( !p1.unique() );
52163849Spjd  VERIFY( p2.unique() );
53163849Spjd
54163849Spjd  return 0;
55163849Spjd}
56163849Spjd
57163849Spjdint
58163849Spjdtest03()
59163849Spjd{
60163849Spjd  bool test __attribute__((unused)) = true;
61163849Spjd
62163849Spjd  std::tr1::shared_ptr<A> p1(new A);
63163849Spjd  std::tr1::shared_ptr<A> p2(p1);
64163849Spjd  p2.reset(new A);
65163849Spjd  VERIFY( p1.unique() );
66163849Spjd  VERIFY( p2.unique() );
67163849Spjd
68163849Spjd  return 0;
69163849Spjd}
70163849Spjd
71163849Spjd
72163849Spjdint
73163849Spjdmain()
74163849Spjd{
75163849Spjd  test01();
76163849Spjd  test02();
77163849Spjd  test03();
78163849Spjd  return 0;
79163849Spjd}
80163849Spjd