OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [tr1/] [2_general_utilities/] [memory/] [shared_ptr/] [dest/] [dest.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// 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
 
24
struct A
25
{
26
  A() { ++ctor_count; }
27
  ~A() { ++dtor_count; }
28
  static long ctor_count;
29
  static long dtor_count;
30
};
31
long A::ctor_count = 0;
32
long A::dtor_count = 0;
33
 
34
struct B : A
35
{
36
  B() { ++ctor_count; }
37
  ~B() { ++dtor_count; }
38
  static long ctor_count;
39
  static long dtor_count;
40
};
41
long B::ctor_count = 0;
42
long B::dtor_count = 0;
43
 
44
struct D
45
{
46
  void operator()(const B* p) { delete p; ++delete_count; }
47
  static long delete_count;
48
};
49
long D::delete_count = 0;
50
 
51
struct reset_count_struct
52
{
53
  ~reset_count_struct()
54
  {
55
    A::ctor_count = 0;
56
    A::dtor_count = 0;
57
    B::ctor_count = 0;
58
    B::dtor_count = 0;
59
    D::delete_count = 0;
60
  }
61
};
62
 
63
 
64
// 2.2.3.2 shared_ptr destructor [tr.util.smartptr.shared.dest]
65
 
66
// empty shared_ptr
67
int
68
test01()
69
{
70
  reset_count_struct __attribute__((unused)) reset;
71
  bool test __attribute__((unused)) = true;
72
 
73
  {
74
    std::tr1::shared_ptr<A> a;
75
  }
76
  VERIFY( A::ctor_count == 0 );
77
  VERIFY( A::dtor_count == 0 );
78
  VERIFY( B::ctor_count == 0 );
79
  VERIFY( B::dtor_count == 0 );
80
  VERIFY( D::delete_count == 0 );
81
 
82
  return 0;
83
}
84
 
85
// shared ownership
86
int
87
test02()
88
{
89
  reset_count_struct __attribute__((unused)) reset;
90
  bool test __attribute__((unused)) = true;
91
 
92
  std::tr1::shared_ptr<A> a;
93
  {
94
    a = std::tr1::shared_ptr<A>(new B, D());
95
  }
96
  VERIFY( A::ctor_count == 1 );
97
  VERIFY( A::dtor_count == 0 );
98
  VERIFY( B::ctor_count == 1 );
99
  VERIFY( B::dtor_count == 0 );
100
  VERIFY( D::delete_count == 0 );
101
 
102
  return 0;
103
}
104
 
105
// exclusive ownership
106
int
107
test03()
108
{
109
  reset_count_struct __attribute__((unused)) reset;
110
  bool test __attribute__((unused)) = true;
111
 
112
  {
113
    std::tr1::shared_ptr<A> a1(new B);
114
    std::tr1::shared_ptr<A> a2(new B, D());
115
  }
116
  VERIFY( A::ctor_count == 2 );
117
  VERIFY( A::dtor_count == 2 );
118
  VERIFY( B::ctor_count == 2 );
119
  VERIFY( B::dtor_count == 2 );
120
  VERIFY( D::delete_count == 1 );
121
 
122
  return 0;
123
}
124
 
125
 
126
int
127
main()
128
{
129
  test01();
130
  test02();
131
  test03();
132
  return 0;
133
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.