1// Copyright (C) 2005-2015 Free Software Foundation, Inc.
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 3, 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 COPYING3.  If not see
16// <http://www.gnu.org/licenses/>.
17
18// TR1 2.2.2 Template class shared_ptr [tr.util.smartptr.shared]
19
20#include <tr1/memory>
21#include <testsuite_hooks.h>
22
23struct A { };
24
25// 2.2.3.5 shared_ptr observers [tr.util.smartptr.shared.obs]
26
27// unique
28int
29test01()
30{
31  bool test __attribute__((unused)) = true;
32
33  const std::tr1::shared_ptr<A> p1;
34  VERIFY( !p1.unique() );
35  const std::tr1::shared_ptr<A> p2(p1);
36  VERIFY( !p1.unique() );
37
38  return 0;
39}
40
41int
42test02()
43{
44  bool test __attribute__((unused)) = true;
45
46  std::tr1::shared_ptr<A> p1(new A);
47  VERIFY( p1.unique() );
48  std::tr1::shared_ptr<A> p2(p1);
49  VERIFY( !p1.unique() );
50  p1.reset();
51  VERIFY( !p1.unique() );
52  VERIFY( p2.unique() );
53
54  return 0;
55}
56
57int
58test03()
59{
60  bool test __attribute__((unused)) = true;
61
62  std::tr1::shared_ptr<A> p1(new A);
63  std::tr1::shared_ptr<A> p2(p1);
64  p2.reset(new A);
65  VERIFY( p1.unique() );
66  VERIFY( p2.unique() );
67
68  return 0;
69}
70
71
72int
73main()
74{
75  test01();
76  test02();
77  test03();
78  return 0;
79}
80