This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
- Author
- Jacques-Olivier Lachaud (
jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr
) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
- Date
- 2014/07/22
Functions for testing class CountedConstPtrOrConstPtr.
This file is part of the DGtal library.
Definition in file testCountedConstPtrOrConstPtr.cpp.
bool testCountedConstPtrOrConstPtrMemory |
( |
| ) |
|
Definition at line 72 of file testCountedConstPtrOrConstPtr.cpp.
74 unsigned int nbok = 0;
76 trace.
beginBlock (
"Testing CountedConstPtrOrConstPtr memory managment..." );
78 trace.
beginBlock (
"An invalid CountedConstPtrOrConstPtr does not create any instance." );
82 ++nb; nbok += A::nb == 0 ? 1 : 0;
83 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
86 trace.
beginBlock (
"A CountedConstPtrOrConstPtr can be used as a simple pointer on an object without acquiring it." );
89 ++nb; nbok += A::nb == 1 ? 1 : 0;
90 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
93 ++nb; nbok += A::nb == 1 ? 1 : 0;
94 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
95 ++nb; nbok += cptr.isSimple() ? 1 : 0;
96 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.isSimple()" << std::endl;
98 ++nb; nbok += A::nb == 1 ? 1 : 0;
99 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
101 ++nb; nbok += A::nb == 0 ? 1 : 0;
102 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
105 trace.
beginBlock (
"CountedConstPtrOrConstPtr can be used as a smart pointer with acquisition and automatic deallocation." );
108 ++nb; nbok += A::nb == 1 ? 1 : 0;
109 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
110 ++nb; nbok += cptr.isSmart() ? 1 : 0;
111 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.isSmart()" << std::endl;
113 ++nb; nbok += A::nb == 0 ? 1 : 0;
114 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
117 trace.
beginBlock (
"CountedConstPtrOrConstPtr can be initialized with = CountedConstPtrOrConstPtr<A>( pointer )." );
120 ++nb; nbok += A::nb == 1 ? 1 : 0;
121 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
122 ++nb; nbok += cptr.
isSmart() ? 1 : 0;
123 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.isSmart()" << std::endl;
125 ++nb; nbok += A::nb == 0 ? 1 : 0;
126 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
129 trace.
beginBlock (
"CountedConstPtrOrConstPtr can be initialized with = CountedPtr<A>( pointer )." );
132 ++nb; nbok += A::nb == 1 ? 1 : 0;
133 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
134 ++nb; nbok += cptr.
isSmart() ? 1 : 0;
135 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.isSmart()" << std::endl;
137 ++nb; nbok += A::nb == 0 ? 1 : 0;
138 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
141 trace.
beginBlock (
"CountedConstPtrOrConstPtr allows to share objects." );
145 ++nb; nbok += A::nb == 1 ? 1 : 0;
146 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
147 ++nb; nbok += cptr.
get() == cptr2.
get() ? 1 : 0;
148 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() == cptr2.get()" << std::endl;
149 ++nb; nbok += cptr.
count() == 2 ? 1 : 0;
150 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.count() == 2" << std::endl;
151 ++nb; nbok += cptr2.
count() == 2 ? 1 : 0;
152 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr2.count() == 2" << std::endl;
154 ++nb; nbok += A::nb == 0 ? 1 : 0;
155 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
158 trace.
beginBlock (
"CountedConstPtrOrConstPtr allows to share objects with CountedPtr." );
162 ++nb; nbok += A::nb == 1 ? 1 : 0;
163 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
164 ++nb; nbok += cptr.
get() == cptr2.
get() ? 1 : 0;
165 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() == cptr2.get()" << std::endl;
166 ++nb; nbok += cptr.
count() == 2 ? 1 : 0;
167 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.count() == 2" << std::endl;
168 ++nb; nbok += cptr2.
count() == 2 ? 1 : 0;
169 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr2.count() == 2" << std::endl;
171 ++nb; nbok += A::nb == 0 ? 1 : 0;
172 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
175 trace.
beginBlock (
"CountedConstPtrOrConstPtr allows to share objects with CountedPtrOrPtr." );
179 ++nb; nbok += A::nb == 1 ? 1 : 0;
180 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
181 ++nb; nbok += cptr.
get() == cptr2.
get() ? 1 : 0;
182 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() == cptr2.get()" << std::endl;
183 ++nb; nbok += cptr.
count() == 2 ? 1 : 0;
184 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.count() == 2" << std::endl;
185 ++nb; nbok += cptr2.
count() == 2 ? 1 : 0;
186 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr2.count() == 2" << std::endl;
188 ++nb; nbok += A::nb == 0 ? 1 : 0;
189 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
192 trace.
beginBlock (
"CountedConstPtrOrConstPtr are smart wrt assignment." );
196 ++nb; nbok += A::nb == 2 ? 1 : 0;
197 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 2" << std::endl;
198 ++nb; nbok += cptr.
get() != cptr2.
get() ? 1 : 0;
199 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() != cptr2.get()" << std::endl;
201 ++nb; nbok += A::nb == 1 ? 1 : 0;
202 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
203 ++nb; nbok += cptr.
get()->a == 12 ? 1 : 0;
204 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get()->a == 12" << std::endl;
206 ++nb; nbok += cptr.
get() == cptr2.
get() ? 1 : 0;
207 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() == cptr2.get()" << std::endl;
208 ++nb; nbok += cptr.
count() == 2 ? 1 : 0;
209 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.count() == 2" << std::endl;
210 ++nb; nbok += cptr2.
count() == 2 ? 1 : 0;
211 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr2.count() == 2" << std::endl;
213 ++nb; nbok += A::nb == 0 ? 1 : 0;
214 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
217 trace.
beginBlock (
"CountedConstPtrOrConstPtr and CountedPtr are smart wrt assignment." );
221 ++nb; nbok += A::nb == 2 ? 1 : 0;
222 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 2" << std::endl;
223 ++nb; nbok += cptr.
get() != cptr2.
get() ? 1 : 0;
224 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() != cptr2.get()" << std::endl;
226 ++nb; nbok += A::nb == 1 ? 1 : 0;
227 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
228 ++nb; nbok += cptr.
get()->a == 12 ? 1 : 0;
229 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get()->a == 12" << std::endl;
230 ++nb; nbok += cptr.
get() == cptr2.
get() ? 1 : 0;
231 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() == cptr2.get()" << std::endl;
232 ++nb; nbok += cptr.
count() == 2 ? 1 : 0;
233 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.count() == 2" << std::endl;
234 ++nb; nbok += cptr2.
count() == 2 ? 1 : 0;
235 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr2.count() == 2" << std::endl;
237 ++nb; nbok += A::nb == 0 ? 1 : 0;
238 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
241 trace.
beginBlock (
"CountedConstPtrOrConstPtr and CountedPtrOrPtr are smart wrt assignment." );
245 ++nb; nbok += A::nb == 2 ? 1 : 0;
246 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 2" << std::endl;
247 ++nb; nbok += cptr.
get() != cptr2.
get() ? 1 : 0;
248 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() != cptr2.get()" << std::endl;
250 ++nb; nbok += A::nb == 1 ? 1 : 0;
251 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 1" << std::endl;
252 ++nb; nbok += cptr.
get()->a == 12 ? 1 : 0;
253 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get()->a == 12" << std::endl;
254 ++nb; nbok += cptr.
get() == cptr2.
get() ? 1 : 0;
255 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.get() == cptr2.get()" << std::endl;
256 ++nb; nbok += cptr.
count() == 2 ? 1 : 0;
257 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr.count() == 2" << std::endl;
258 ++nb; nbok += cptr2.
count() == 2 ? 1 : 0;
259 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"cptr2.count() == 2" << std::endl;
261 ++nb; nbok += A::nb == 0 ? 1 : 0;
262 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") " <<
"A::nb == 0" << std::endl;
Aim: Smart or simple const pointer on T. It can be a smart pointer based on reference counts or a sim...
const T * get() const noexcept
unsigned int count() const
Aim: Smart or simple pointer on T. It can be a smart pointer based on reference counts or a simple po...
Aim: Smart pointer based on reference counts.
References DGtal::Trace::beginBlock(), DGtal::CountedConstPtrOrConstPtr< T >::count(), DGtal::CountedPtr< T >::count(), DGtal::CountedPtrOrPtr< T >::count(), DGtal::Trace::endBlock(), DGtal::CountedConstPtrOrConstPtr< T >::get(), DGtal::CountedPtr< T >::get(), DGtal::CountedPtrOrPtr< T >::get(), DGtal::Trace::info(), DGtal::CountedConstPtrOrConstPtr< T >::isSimple(), DGtal::CountedConstPtrOrConstPtr< T >::isSmart(), and DGtal::trace.
Referenced by main().