Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RCP_UnitTests.cpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Teuchos: Common Tools Package
6 // Copyright (2004) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Michael A. Heroux (maherou@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
45 #include "Teuchos_RCP.hpp"
46 #include "Teuchos_getConst.hpp"
48 #ifdef HAVE_TEUCHOS_BOOST
50 #endif
51 #ifdef HAVE_TEUCHOSCORE_CXX11
53 #endif
54 
55 #include "TestClasses.hpp"
56 
58 
59 
60 namespace {
61 
62 
63 using Teuchos::as;
64 using Teuchos::null;
65 using Teuchos::Ptr;
66 using Teuchos::RCP;
67 using Teuchos::rcp;
68 using Teuchos::rcpFromRef;
69 using Teuchos::rcpFromUndefRef;
70 using Teuchos::outArg;
71 using Teuchos::rcpWithEmbeddedObj;
72 using Teuchos::getEmbeddedObj;
73 using Teuchos::getOptionalEmbeddedObj;
74 using Teuchos::getOptionalNonconstEmbeddedObj;
75 using Teuchos::set_extra_data;
76 using Teuchos::get_optional_nonconst_extra_data;
77 using Teuchos::getConst;
82 using Teuchos::RCP_WEAK;
84 
85 
86 TEUCHOS_UNIT_TEST( DeallocNull, free )
87 {
89  d.free(0);
90 }
91 
92 
93 TEUCHOS_UNIT_TEST( RCP, assignSelf_null )
94 {
95  RCP<A> a_rcp;
96  a_rcp = a_rcp;
97  TEST_ASSERT(is_null(a_rcp));
98 }
99 
100 
101 TEUCHOS_UNIT_TEST( RCP, assignSelf_nonnull )
102 {
103  RCP<A> a_rcp(new A);
104  A *a_raw_ptr = a_rcp.getRawPtr();
105  a_rcp = a_rcp;
106  TEST_ASSERT(nonnull(a_rcp));
107  TEST_EQUALITY(a_rcp.getRawPtr(), a_raw_ptr);
108 }
109 
110 
112 {
113  RCP<A> a_rcp(new A);
114  RCP<const A> ca_rcp = a_rcp.getConst();
115  TEST_EQUALITY(a_rcp.getRawPtr(), ca_rcp.getRawPtr());
116 }
117 
118 
119 TEUCHOS_UNIT_TEST( RCP, explicit_null )
120 {
121  RCP<A> a_rcp(0);
122  TEST_ASSERT(is_null(a_rcp));
123 }
124 
125 
126 TEUCHOS_UNIT_TEST( RCP, explicit_dealloc_null )
127 {
128  RCP<A> a_rcp = rcpWithDealloc(static_cast<A*>(0), Teuchos::DeallocNull<A>(), false);
129  TEST_ASSERT(is_null(a_rcp));
130 }
131 
132 
133 TEUCHOS_UNIT_TEST( RCP, explicit_null_null )
134 {
135  RCP<A> a_rcp(0, null);
136  TEST_ASSERT(is_null(a_rcp));
137 }
138 
139 
140 TEUCHOS_UNIT_TEST( RCP, explicit_null_nonnull )
141 {
142  A *a = new A;
143  RCP<A> a_rcp(a, null);
144  TEST_ASSERT(nonnull(a_rcp));
145  delete a;
146 }
147 
148 
149 TEUCHOS_UNIT_TEST( RCP, rcpFromRef_raw_ref )
150 {
151  A a;
152  RCP<A> a_rcp = rcpFromRef(a);
153  TEST_EQUALITY(a_rcp.getRawPtr(), &a);
154  TEST_ASSERT(nonnull(a_rcp));
155 }
156 
157 
158 TEUCHOS_UNIT_TEST( RCP, rcpFromRef_from_rcp )
159 {
160  RCP<A> a_rcp1 = rcp<A>(new A);
161  RCP<A> a_rcp2 = rcpFromRef(*a_rcp1);
162  TEST_EQUALITY(a_rcp2.getRawPtr(), a_rcp1.getRawPtr());
163  if (RCPNodeTracer::isTracingActiveRCPNodes())
164  {
165  TEST_EQUALITY_CONST(a_rcp2.strong_count(), 1);
166  TEST_EQUALITY_CONST(a_rcp2.weak_count(), 1);
167  TEST_EQUALITY_CONST(a_rcp2.has_ownership(), true);
168  }
169  else {
170  TEST_EQUALITY_CONST(a_rcp2.strong_count(), 1);
171  TEST_EQUALITY_CONST(a_rcp2.weak_count(), 0);
172  TEST_EQUALITY_CONST(a_rcp2.has_ownership(), false);
173  }
174 }
175 
176 
178 {
179  A a;
180  RCP<A> a_rcp = rcpFromUndefRef(a);
181  TEST_ASSERT(nonnull(a_rcp));
182 }
183 
184 
185 //
186 // Test rcpCloneNode(...)
187 //
188 
189 
190 TEUCHOS_UNIT_TEST( RCP, rcpCloneNode_null )
191 {
192  ECHO(RCP<RCP<int> > rcp1 = null);
193  ECHO(RCP<RCP<int> > rcp2 = rcpCloneNode(rcp1));
194  TEST_EQUALITY(rcp2, null);
195 }
196 
197 
198 TEUCHOS_UNIT_TEST( RCP, rcpCloneNode_basic )
199 {
200 
201  ECHO(RCP<int> rcp1 = rcp(new int(0)));
202 
203  ECHO(RCP<int> rcp2 = rcpCloneNode(rcp1));
204  TEST_ASSERT(nonnull(rcp2));
205  TEST_EQUALITY(rcp1.strong_count(), 2);
206  TEST_EQUALITY(rcp2.strong_count(), 1);
207 
208  ECHO(RCP<int> rcp3 = rcp2);
209  TEST_EQUALITY(rcp1.strong_count(), 2);
210  TEST_EQUALITY(rcp2.strong_count(), 2);
211  TEST_EQUALITY(rcp3.strong_count(), 2);
212 
213  ECHO(RCP <int> rcp4 = rcp1);
214  TEST_EQUALITY(rcp1.strong_count(), 3);
215  TEST_EQUALITY(rcp2.strong_count(), 2);
216  TEST_EQUALITY(rcp3.strong_count(), 2);
217 
218  ECHO(rcp4 = null);
219  TEST_EQUALITY(rcp1.strong_count(), 2);
220  TEST_EQUALITY(rcp2.strong_count(), 2);
221  TEST_EQUALITY(rcp3.strong_count(), 2);
222  TEST_EQUALITY(rcp4.strong_count(), 0);
223 
224  ECHO(rcp1 = null);
225  TEST_EQUALITY(rcp1.strong_count(), 0);
226  TEST_EQUALITY(rcp2.strong_count(), 2);
227  TEST_EQUALITY(rcp3.strong_count(), 2);
228  TEST_EQUALITY(rcp4.strong_count(), 0);
229 
230  ECHO(rcp2 = null);
231  TEST_EQUALITY(rcp2.strong_count(), 0);
232  TEST_EQUALITY(rcp3.strong_count(), 1);
233 
234  ECHO(rcp3 = null);
235  TEST_EQUALITY(rcp3.strong_count(), 0);
236 
237 }
238 
239 
240 //
241 // Test duplicate owning RCP objects
242 //
243 
244 
245 // Test that shows that we can detect trying to create two owning RCPs
246 // pointing to the same polymorphic object but having different interfaces
247 // with different addresses. This happens due to virtual base classes. Only
248 // works when we have a working getBaseObjVoidPtr(...) function.
249 TEUCHOS_UNIT_TEST( RCP, duplicate_rcp_owning_polymorphic )
250 {
252  ECHO(C *c_ptr = new C);
253  ECHO(A *a_ptr = c_ptr);
254  ECHO(RCP<C> c_rcp = rcp(c_ptr)); // Okay
255 #if defined(TEUCHOS_DEBUG) && defined(HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR)
256  // With determine they are pointed to the same object!
257  TEST_THROW(RCP<A> a_rcp = rcp(a_ptr), DuplicateOwningRCPError);
258 #else
259  // Will not determine they are point to the same object!
260  ECHO(RCP<A> a_rcp = rcp(a_ptr));
261  TEST_EQUALITY(a_rcp.getRawPtr(), a_ptr);
262  ECHO(a_rcp.release()); // Better or we will get a segfault!
263 #endif
264 }
265 
266 
267 // Test that shows that we can detect trying to create two owning RCPs
268 // pointing to the same polymorphic object with the same type and therefore
269 // the same address. This works even if these use virtual base classes. This
270 // works even without a working getBaseObjVoidPtr(...) function.
271 TEUCHOS_UNIT_TEST( RCP, duplicate_rcp_owning_polymorphic_different_addr )
272 {
274  ECHO(A *a_ptr1 = new C);
275  ECHO(A *a_ptr2 = a_ptr1);
276  ECHO(RCP<A> a_rcp1 = rcp(a_ptr1)); // Okay
277 #if defined(TEUCHOS_DEBUG)
278  // With determine they are pointed to the same object!
279  TEST_THROW(RCP<A> a_rcp2 = rcp(a_ptr2), DuplicateOwningRCPError);
280 #else
281  // Will not determine they are point to the same object!
282  ECHO(RCP<A> a_rcp2 = rcp(a_ptr2));
283  TEST_EQUALITY(a_rcp2.getRawPtr(), a_ptr2);
284  ECHO(a_rcp2.release()); // Better or we will get a segfault!
285 #endif
286 }
287 
288 
289 // Test that shows that we can always detect trying to create two owning RCPs
290 // pointing to the same nonpolymorphic object having different interfaces but
291 // the same address (single non-virtual inheritance). Works just fine without
292 // a working getBaseObjVoidPtr(...) function.
293 TEUCHOS_UNIT_TEST( RCP, duplicate_rcp_owning_nonpolymorphic_same_addr )
294 {
296  ECHO(E *e_ptr = new E);
297  ECHO(E *d_ptr = e_ptr);
298  ECHO(RCP<E> e_rcp = rcp(e_ptr)); // Okay
299 #if defined(TEUCHOS_DEBUG)
300  // With determine they are pointed to the same object even without support
301  // for getBaseObjVoidPtr(...) because no dynamic_cast is needed.
302  TEST_THROW(RCP<D> d_rcp = rcp(d_ptr), DuplicateOwningRCPError);
303 #else
304  // Will not determine they are point to the same object!
305  ECHO(RCP<D> d_rcp = rcp(d_ptr));
306  TEST_EQUALITY(d_rcp.getRawPtr(), d_ptr);
307  ECHO(d_rcp.release()); // Better or we will get a segfault!
308 #endif
309 }
310 
311 
312 //
313 // These next tests shows that we can detect when two RCPs are create to the same
314 // object, one owning and the other non-owning. When we have a working
315 // getBaseObjVoidPtr(...) function, the new non-owning RCP will actually be a
316 // weak RCP that can be used to detect circular dependencies.
317 //
318 
319 
320 // rcp
321 
322 
323 TEUCHOS_UNIT_TEST( RCP, rcp_duplicate_rcp_nonowning_polymorphic_different_addr )
324 {
326  ECHO(RCP<C> c_rcp(new C));
327  ECHO(A &a_ref = *c_rcp);
328  ECHO(RCP<A> a_rcp = rcp(&a_ref, false));
329  ECHO(c_rcp = null);
330 #if defined(TEUCHOS_DEBUG) && defined(HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR)
331  TEST_THROW(a_rcp->A_g(), DanglingReferenceError);
332 #else
333  TEST_NOTHROW(a_rcp.getRawPtr());
334 #endif
335 }
336 
337 
338 TEUCHOS_UNIT_TEST( RCP, rcp_duplicate_rcp_nonowning_polymorphic_same_addr )
339 {
341  ECHO(RCP<A> a_rcp1(new C));
342  ECHO(A &a_ref = *a_rcp1);
343  ECHO(RCP<A> a_rcp2 = rcp(&a_ref, false));
344  ECHO(a_rcp1 = null);
345 #if defined(TEUCHOS_DEBUG)
346  TEST_THROW(a_rcp2->A_g(), DanglingReferenceError);
347 #else
348  TEST_NOTHROW(a_rcp2.getRawPtr());
349 #endif
350 }
351 
352 
353 TEUCHOS_UNIT_TEST( RCP, rcp_duplicate_rcp_nonowning_nonpolymorphic )
354 {
356  ECHO(RCP<E> e_rcp(new E));
357  ECHO(D &d_ref = *e_rcp);
358  ECHO(RCP<D> d_rcp = rcp(&d_ref, false));
359  ECHO(e_rcp = null);
360 #if defined(TEUCHOS_DEBUG)
361  TEST_THROW(d_rcp->D_g(), DanglingReferenceError);
362 #else
363  TEST_NOTHROW(d_rcp.getRawPtr());
364 #endif
365 }
366 
367 
368 // rcpFromRef
369 
370 
371 TEUCHOS_UNIT_TEST( RCP, rcpFromRef_duplicate_rcp_nonowning_polymorphic_different_addr )
372 {
374  ECHO(RCP<C> c_rcp(new C));
375  ECHO(A &a_ref = *c_rcp);
376  ECHO(RCP<A> a_rcp = rcpFromRef(a_ref));
377  ECHO(c_rcp = null);
378 #if defined(TEUCHOS_DEBUG) && defined(HAS_TEUCHOS_GET_BASE_OBJ_VOID_PTR)
379  TEST_THROW(a_rcp->A_g(), DanglingReferenceError);
380 #else
381  TEST_NOTHROW(a_rcp.getRawPtr());
382 #endif
383 }
384 
385 
386 TEUCHOS_UNIT_TEST( RCP, rcpFromRef_duplicate_rcp_nonowning_polymorphic_same_addr )
387 {
389  ECHO(RCP<A> a_rcp1(new C));
390  ECHO(A &a_ref = *a_rcp1);
391  ECHO(RCP<A> a_rcp2 = rcpFromRef(a_ref));
392  ECHO(a_rcp1 = null);
393 #if defined(TEUCHOS_DEBUG)
394  TEST_THROW(a_rcp2->A_g(), DanglingReferenceError);
395 #else
396  TEST_NOTHROW(a_rcp2.getRawPtr());
397 #endif
398 }
399 
400 
401 TEUCHOS_UNIT_TEST( RCP, rcpFromRef_duplicate_rcp_nonowning_nonpolymorphic )
402 {
404  ECHO(RCP<E> e_rcp(new E));
405  ECHO(D &d_ref = *e_rcp);
406  ECHO(RCP<D> d_rcp = rcpFromRef(d_ref));
407  ECHO(e_rcp = null);
408 #if defined(TEUCHOS_DEBUG)
409  TEST_THROW(d_rcp->D_g(), DanglingReferenceError);
410 #else
411  TEST_NOTHROW(d_rcp.getRawPtr());
412 #endif
413 }
414 
415 
416 // rcpFromUndefRef (Can never detect dangling references)
417 
418 
419 TEUCHOS_UNIT_TEST( RCP, rcpFromUndefRef_duplicate_rcp_nonowning_polymorphic_same_addr )
420 {
422  ECHO(RCP<A> a_rcp1(new C));
423  ECHO(A &a_ref = *a_rcp1);
424  ECHO(RCP<A> a_rcp2 = rcpFromUndefRef(a_ref));
425  ECHO(a_rcp1 = null);
426  TEST_NOTHROW(a_rcp2.getRawPtr());
427 }
428 
429 
430 //
431 // extra data and embedded objects tests
432 //
433 
434 
436 {
437  RCP<A> a_rcp = rcp(new A);
438  set_extra_data( as<int>(1), "blob", outArg(a_rcp) );
439  TEST_EQUALITY_CONST(*get_optional_nonconst_extra_data<int>(a_rcp, "blob"), as<int>(1));
440 }
441 
442 
443 TEUCHOS_UNIT_TEST( RCP, getOptionalEmbeddedObj_null )
444 {
445  ECHO(RCP<A> a_rcp = rcp(new A));
446  const Ptr<const RCP<C> > c_ptr_rcp_1 =
447  getOptionalEmbeddedObj<A, RCP<C> >(a_rcp);
448  TEST_EQUALITY_CONST( c_ptr_rcp_1, null );
449  const Ptr<RCP<C> > c_ptr_rcp_2 =
450  getOptionalNonconstEmbeddedObj<A, RCP<C> >(a_rcp);
451  TEST_EQUALITY_CONST( c_ptr_rcp_2, null );
452 }
453 
454 
455 TEUCHOS_UNIT_TEST( RCP, getOptionalEmbeddedObj_default )
456 {
457 
458  ECHO(RCP<C> c_rcp = rcp(new C));
459  ECHO(RCP<A> a_rcp = rcpWithEmbeddedObj(new A, c_rcp));
460 
461  Ptr<const RCP<C> > c_ptr_rcp_1 =
462  getOptionalEmbeddedObj<A, RCP<C> >(a_rcp);
463  TEST_EQUALITY_CONST( is_null(c_ptr_rcp_1), false );
464  TEST_EQUALITY( (*c_ptr_rcp_1).getRawPtr(), c_rcp.getRawPtr() );
465  TEST_EQUALITY( (*c_ptr_rcp_1)->C_g(), C_g_return );
466 
467  Ptr<RCP<C> > c_ptr_rcp_2 =
468  getOptionalNonconstEmbeddedObj<A, RCP<C> >(a_rcp);
469  TEST_EQUALITY_CONST( is_null(c_ptr_rcp_2), false );
470  TEST_EQUALITY( (*c_ptr_rcp_2).getRawPtr(), c_rcp.getRawPtr() );
471  TEST_EQUALITY( (*c_ptr_rcp_2)->C_f(), C_f_return );
472 
473 }
474 
475 
476 TEUCHOS_UNIT_TEST( RCP, reset_null )
477 {
478  RCP<A> a_rcp = rcp(new A);
479  a_rcp.reset();
480  TEST_ASSERT(is_null(a_rcp));
481 }
482 
483 
484 TEUCHOS_UNIT_TEST( RCP, reset_nonnull )
485 {
486  RCP<A> a_rcp = rcp(new A);
487  C* c_rawp = new C;
488  a_rcp.reset(c_rawp);
489  A* a_rawp = c_rawp;
490  TEST_EQUALITY( a_rcp.getRawPtr(), a_rawp );
491 }
492 
493 
495 {
496  ECHO(RCP<A> a_rcp = rcp(new A));
497  TEST_EQUALITY_CONST(is_null(a_rcp), false);
498  TEST_EQUALITY_CONST(nonnull(a_rcp), true);
499  ECHO(a_rcp = null);
500  TEST_EQUALITY_CONST(is_null(a_rcp), true);
501  TEST_EQUALITY_CONST(nonnull(a_rcp), false);
502 }
503 
504 
505 TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL( RCP, weakDelete, T )
506 {
507 
508  ECHO(RCP<T> rcp_strong = rcp(new T));
509 
510  TEST_EQUALITY_CONST( rcp_strong.strength(), RCP_STRONG );
511  TEST_EQUALITY_CONST( rcp_strong.is_null(), false );
512  TEST_EQUALITY_CONST( rcp_strong.strong_count(), 1 );
513  TEST_EQUALITY_CONST( rcp_strong.weak_count(), 0 );
514  TEST_EQUALITY_CONST( rcp_strong.total_count(), 1 );
515 
516  ECHO(RCP<T> rcp_weak1 = rcp_strong.create_weak());
517 
518  TEST_EQUALITY_CONST( rcp_weak1.strength(), RCP_WEAK );
519  TEST_EQUALITY_CONST( rcp_weak1.is_null(), false );
520  TEST_EQUALITY_CONST( rcp_weak1.strong_count(), 1 );
521  TEST_EQUALITY_CONST( rcp_weak1.weak_count(), 1 );
522  TEST_EQUALITY_CONST( rcp_weak1.total_count(), 2 );
523 
524  TEST_EQUALITY_CONST( rcp_strong.strong_count(), 1 );
525  TEST_EQUALITY_CONST( rcp_strong.is_null(), false );
526  TEST_EQUALITY_CONST( rcp_strong.weak_count(), 1 );
527  TEST_EQUALITY_CONST( rcp_strong.total_count(), 2 );
528 
529  TEST_EQUALITY_CONST( rcp_weak1.shares_resource(rcp_strong), true );
530 
531  TEST_EQUALITY( rcp_weak1.get(), rcp_weak1.getRawPtr() );
532  TEST_EQUALITY( rcp_weak1.get(), rcp_strong.get() );
533  TEST_EQUALITY( rcp_weak1.getRawPtr(), rcp_strong.getRawPtr() );
534 
535  ECHO(RCP<T> rcp_weak2 = rcp_weak1);
536 
537  TEST_EQUALITY_CONST( rcp_weak2.strength(), RCP_WEAK );
538  TEST_EQUALITY_CONST( rcp_weak2.is_null(), false );
539  TEST_EQUALITY_CONST( rcp_weak2.strong_count(), 1 );
540  TEST_EQUALITY_CONST( rcp_weak2.weak_count(), 2 );
541  TEST_EQUALITY_CONST( rcp_weak2.total_count(), 3 );
542 
543  TEST_EQUALITY_CONST( rcp_strong.strong_count(), 1 );
544  TEST_EQUALITY_CONST( rcp_strong.is_null(), false );
545  TEST_EQUALITY_CONST( rcp_strong.weak_count(), 2 );
546  TEST_EQUALITY_CONST( rcp_strong.total_count(), 3 );
547 
548  TEST_EQUALITY_CONST( rcp_weak1.shares_resource(rcp_strong), true );
549  TEST_EQUALITY_CONST( rcp_weak1.shares_resource(rcp_weak2), true );
550  TEST_EQUALITY_CONST( rcp_weak2.shares_resource(rcp_strong), true );
551 
552  TEST_EQUALITY( rcp_weak2.get(), rcp_strong.get() );
553  TEST_EQUALITY( rcp_weak2.getRawPtr(), rcp_strong.getRawPtr() );
554 
555  ECHO(rcp_strong = null); // This deletes the underlying object of type T!
556 
557  TEST_EQUALITY_CONST( rcp_strong.strength(), RCP_STRONG );
558  TEST_EQUALITY_CONST( rcp_strong.is_null(), true );
559  TEST_EQUALITY_CONST( rcp_strong.strong_count(), 0 );
560  TEST_EQUALITY_CONST( rcp_strong.strong_count(), 0 );
561  TEST_EQUALITY_CONST( rcp_strong.weak_count(), 0 );
562  TEST_EQUALITY_CONST( rcp_strong.total_count(), 0 );
563  TEST_EQUALITY_CONST( rcp_strong.is_valid_ptr(), true );
564 
565  TEST_EQUALITY_CONST( rcp_strong.shares_resource(rcp_weak1), false );
566  TEST_EQUALITY_CONST( rcp_strong.shares_resource(rcp_weak2), false );
567 
568  TEST_EQUALITY_CONST( rcp_weak1.has_ownership(), true );
569  TEST_EQUALITY_CONST( rcp_weak1.strong_count(), 0 );
570  TEST_EQUALITY_CONST( rcp_weak1.strong_count(), 0 );
571  TEST_EQUALITY_CONST( rcp_weak1.weak_count(), 2 );
572  TEST_EQUALITY_CONST( rcp_weak1.total_count(), 2 );
573  TEST_EQUALITY_CONST( rcp_weak1.is_valid_ptr(), false );
574 
575  TEST_EQUALITY_CONST( rcp_weak2.has_ownership(), true );
576  TEST_EQUALITY_CONST( rcp_weak2.strong_count(), 0 );
577  TEST_EQUALITY_CONST( rcp_weak2.strong_count(), 0 );
578  TEST_EQUALITY_CONST( rcp_weak2.weak_count(), 2 );
579  TEST_EQUALITY_CONST( rcp_weak2.total_count(), 2 );
580  TEST_EQUALITY_CONST( rcp_weak2.is_valid_ptr(), false );
581 
582  TEST_EQUALITY_CONST( rcp_weak1.shares_resource(rcp_weak2), true );
583 
584  ECHO(rcp_weak1.assert_not_null()); // Does not throw!
585  ECHO(rcp_weak2.assert_not_null()); // Does not throw!
586 
587  TEST_THROW( rcp_weak1.assert_valid_ptr(), DanglingReferenceError );
588 #ifdef TEUCHOS_DEBUG
589  TEST_THROW( rcp_weak1.operator->(), DanglingReferenceError );
590  TEST_THROW( *rcp_weak1, DanglingReferenceError );
591  TEST_THROW( rcp_weak1.create_weak(), DanglingReferenceError );
592  TEST_THROW( rcp_weak1.get(), DanglingReferenceError );
593  TEST_THROW( rcp_weak1.getRawPtr(), DanglingReferenceError );
594  TEST_THROW( rcp_weak1(), DanglingReferenceError );
595  TEST_THROW( rcp_weak1.release(), DanglingReferenceError );
596 #endif // TEUCHOS_DEBUG
597 
598  ECHO(rcp_weak1 = null); // Just deicrements weak count!
599 
600  TEST_EQUALITY_CONST( rcp_weak1.strength(), RCP_STRONG );
601  TEST_EQUALITY_CONST( rcp_weak1.is_null(), true );
602  TEST_EQUALITY_CONST( rcp_weak1.strong_count(), 0 );
603  TEST_EQUALITY_CONST( rcp_weak1.strong_count(), 0 );
604  TEST_EQUALITY_CONST( rcp_weak1.weak_count(), 0 );
605  TEST_EQUALITY_CONST( rcp_weak1.total_count(), 0 );
606  TEST_EQUALITY_CONST( rcp_weak1.is_valid_ptr(), true );
607 
608  TEST_EQUALITY_CONST( rcp_weak2.has_ownership(), true );
609  TEST_EQUALITY_CONST( rcp_weak2.strong_count(), 0 );
610  TEST_EQUALITY_CONST( rcp_weak2.strong_count(), 0 );
611  TEST_EQUALITY_CONST( rcp_weak2.weak_count(), 1 );
612  TEST_EQUALITY_CONST( rcp_weak2.total_count(), 1 );
613  TEST_EQUALITY_CONST( rcp_weak2.is_valid_ptr(), false );
614 
615  TEST_EQUALITY_CONST( rcp_weak1.shares_resource(rcp_weak2), false );
616 
617  TEST_THROW( rcp_weak2.assert_valid_ptr(), DanglingReferenceError );
618 #ifdef TEUCHOS_DEBUG
619  TEST_THROW( rcp_weak2.operator->(), DanglingReferenceError );
620  TEST_THROW( *rcp_weak2, DanglingReferenceError );
621  TEST_THROW( rcp_weak2.create_weak(), DanglingReferenceError );
622  TEST_THROW( rcp_weak2.get(), DanglingReferenceError );
623  TEST_THROW( rcp_weak2.getRawPtr(), DanglingReferenceError );
624  TEST_THROW( rcp_weak2(), DanglingReferenceError );
625  TEST_THROW( rcp_weak2.release(), DanglingReferenceError );
626 #endif // TEUCHOS_DEBUG
627 
628 }
629 
630 
631 TEUCHOS_UNIT_TEST( RCP, weak_strong )
632 {
633 
634  ECHO(RCP<A> rcp1(rcp(new A)));
635  TEST_EQUALITY_CONST( rcp1.strength(), RCP_STRONG );
636 
637  ECHO(RCP<A> rcp2 = rcp1.create_weak());
638 
639  TEST_EQUALITY_CONST( rcp2.strength(), RCP_WEAK );
640  TEST_EQUALITY_CONST( rcp1.strong_count(), 1 );
641  TEST_EQUALITY_CONST( rcp1.weak_count(), 1 );
642  TEST_EQUALITY_CONST( rcp2.strong_count(), 1 );
643  TEST_EQUALITY_CONST( rcp2.weak_count(), 1 );
644 
645  ECHO(RCP<A> rcp3 = rcp2.create_strong());
646 
647  TEST_EQUALITY_CONST( rcp3.strength(), RCP_STRONG );
648  TEST_EQUALITY_CONST( rcp1.strong_count(), 2 );
649  TEST_EQUALITY_CONST( rcp1.weak_count(), 1 );
650  TEST_EQUALITY_CONST( rcp2.strong_count(), 2 );
651  TEST_EQUALITY_CONST( rcp2.weak_count(), 1 );
652 
653  // This will make the underlying object A gets deleted!
654  ECHO(rcp1 = null);
655  ECHO(rcp3 = null);
656 
657  ECHO(rcp2 = null); // Should make the underlying node go away
658 
659 }
660 
661 
662 //
663 // circularReference
664 //
665 
666 
667 TEUCHOS_UNIT_TEST( RCP, circularReference_a_then_c )
668 {
669  {
670  // Create objects a and c
671  ECHO(RCP<A> a = rcp(new A));
672  ECHO(RCP<C> c = rcp(new C));
673 
674  // Create a circular reference where 'a' owns 'c' strongly but 'c' only
675  // owns 'a' weakly.
676  ECHO(a->set_C(c));
677  ECHO(c->set_A(a.create_weak()));
678 
680  TEST_EQUALITY( c->call_A_g(), A_g_return );
681 
682  // Remove 'a' first and then remove 'c'. Since 'a' is only weakly held by
683  // 'c', this will result in 'a' being deleted right away. In this case,
684  // if anyone tries to access 'a' after this debug mode will throw.
685 
686  ECHO(a = null);
687 
688  // c is now dead!
689 #ifdef TEUCHOS_DEBUG
690  TEST_THROW(c->call_A_g(), DanglingReferenceError);
691 #endif
692 
693  // Finally, when 'c' goes away implicitly, it will do nothing because it
694  // only had weak ownership of a. So it will clean up with any trouble.
695  }
696 }
697 
698 
699 TEUCHOS_UNIT_TEST( RCP, circularReference_c_then_a )
700 {
701  {
702  // Create objects a and c
703  ECHO(RCP<A> a = rcp(new A));
704  ECHO(RCP<C> c = rcp(new C));
705 
706  // Create a circular reference where 'a' owns 'c' strongly but 'c' only
707  // owns 'a' weakly.
708  ECHO(a->set_C(c));
709  ECHO(c->set_A(a.create_weak()));
710 
712  TEST_EQUALITY( c->call_A_g(), A_g_return );
713 
714  // Remove 'c' first and then remove 'a' implicitly at the end of the
715  // block. Since 'c' is held strongly by 'a' and since we are keeping the
716  // strong pointer for 'a' alive, we can call functions on 'a' all we want
717  // with no fear of accessing dead memory.
718 
719  ECHO(c = null);
720 
721  TEST_EQUALITY( a->call_C_f(), C_f_return ); // a is still alive!
722 
723  // Finally, when 'a' goes away implicitly, it will take 'c' with it. In
724  // the complex set of nested calls that take place due to the circular
725  // reference, everything will get cleaned up correctly. Also, if any
726  // client code where to try to access an object as it is being deleted, an
727  // exception will get thrown and no memory error will occur (unless an
728  // abort(...) is called when an exception gets thrown from a destructor
729  // when an exception is already active).
730  }
731 }
732 
733 
734 TEUCHOS_UNIT_TEST( RCP, circularReference_self )
735 {
736  {
737  // Create one 'c' object
738  ECHO(RCP<C> c = rcp(new C));
739  // Create a weak circular reference where 'c' points back to itself
740  ECHO(c->set_A(c.create_weak()));
741  // Now, try to set 'c' to null.
742  ECHO(c = null); // All memory should be cleaned up here!
743  }
744 }
745 
746 
747 TEUCHOS_UNIT_TEST( RCP, danglingPtr1 )
748 {
749  ECHO(RCP<A> a_rcp = rcp(new A));
750  ECHO(Ptr<A> a_ptr = a_rcp());
751  ECHO(A *badPtr = a_rcp.getRawPtr());
752  ECHO(a_rcp = null);
753 #ifdef TEUCHOS_DEBUG
754  TEST_THROW( *a_ptr, DanglingReferenceError );
755  (void)badPtr;
756 #else
757  TEST_EQUALITY( a_ptr.getRawPtr(), badPtr );
758 #endif
759 }
760 
761 
762 TEUCHOS_UNIT_TEST( RCP, danglingPtr2 )
763 {
764  ECHO(Ptr<A> a_ptr);
765  ECHO(A *badPtr = 0);
766  {
767  ECHO(RCP<A> a_rcp = rcp(new A));
768  ECHO(badPtr = a_rcp.getRawPtr());
769  ECHO(a_ptr = a_rcp.ptr());
770  TEST_EQUALITY( a_ptr.getRawPtr(), badPtr );
771  }
772 #ifdef TEUCHOS_DEBUG
773  TEST_THROW( *a_ptr, DanglingReferenceError );
774  (void)badPtr;
775 #else
776  TEST_EQUALITY( a_ptr.getRawPtr(), badPtr );
777 #endif
778 }
779 
780 
781 TEUCHOS_UNIT_TEST( RCP, danglingPtr3 )
782 {
783  ECHO(Ptr<A> a_ptr);
784  ECHO(A *badPtr = 0);
785  {
786  ECHO(RCP<A> a_rcp = rcp(new A));
787  ECHO(badPtr = a_rcp.getRawPtr());
788  ECHO(Ptr<A> a_ptr2(a_rcp.ptr()));
789  ECHO(Ptr<A> a_ptr3(a_ptr2));
790  ECHO(a_ptr = a_ptr3);
791  TEST_EQUALITY( a_ptr.getRawPtr(), badPtr );
792  }
793 #ifdef TEUCHOS_DEBUG
794  TEST_THROW( *a_ptr, DanglingReferenceError );
795  (void)badPtr;
796 #else
797  TEST_EQUALITY( a_ptr.getRawPtr(), badPtr );
798 #endif
799 }
800 
801 
802 TEUCHOS_UNIT_TEST( RCP, danglingPtr4 )
803 {
804  ECHO(Ptr<A> a_ptr);
805  ECHO(A *badPtr = 0);
806  {
807  ECHO(RCP<C> c_rcp = rcp(new C));
808  ECHO(badPtr = c_rcp.getRawPtr());
809  ECHO(Ptr<A> a_ptr2(c_rcp.ptr()));
810  ECHO(a_ptr = a_ptr2);
811  TEST_EQUALITY( a_ptr.getRawPtr(), badPtr );
812  }
813 #ifdef TEUCHOS_DEBUG
814  TEST_THROW( *a_ptr, DanglingReferenceError );
815  (void)badPtr;
816 #else
817  TEST_EQUALITY( a_ptr.getRawPtr(), badPtr );
818 #endif
819 }
820 
821 
822 #ifdef TEUCHOS_DEBUG
823 
824 /* ToDo: Comment this back in once I have everything working
825 
826 // Test that the RCPNode tracing machinary can detect if an owning RCPNode is
827 // being created that would result in a double delete.
828 TEUCHOS_UNIT_TEST( RCP, multiRcpCreateError )
829 {
830  C *c_ptr = new C;
831 #if !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING)
832  Teuchos::setTracingActiveRCPNodes(true);
833 #endif
834  RCP<C> c_rcp = rcp(c_ptr); // Okay
835  RCP<C> c_rcp2;
836  TEST_THROW(c_rcp2 = rcp(c_ptr), DuplicateOwningRCPError);
837 #if !defined(HAVE_TEUCHOS_DEBUG_RCP_NODE_TRACING)
838  Teuchos::setTracingActiveRCPNodes(false);
839 #endif
840  // Clean up memory so no leaks and not double deletes no matter what.
841  c_rcp.release();
842  c_rcp2.release();
843  delete c_ptr;
844 }
845 
846 */
847 
848 #endif // TEUCHOS_DEBUG
849 
850 
851 //
852 // invertObjectOwnership
853 //
854 
855 
856 RCP<C> createCAFactory()
857 {
858  RCP<C> c = rcp(new C);
859  c->set_A(rcp(new A));
860  return c;
861 }
862 
863 
864 RCP<A> createACFactory()
865 {
866  RCP<C> c = createCAFactory();
867  return Teuchos::rcpWithInvertedObjOwnership(c->get_A(), c);
868 }
869 
870 
871 RCP<C> extractCFromA(const RCP<A> &a)
872 {
873  return Teuchos::getInvertedObjOwnershipParent<C>(a);
874 }
875 
876 
877 TEUCHOS_UNIT_TEST( RCP, invertObjectOwnership_basic )
878 {
879  RCP<A> a = createACFactory();
880  RCP<C> c = extractCFromA(a);
881  TEST_EQUALITY_CONST( a.strong_count(), 1 );
882  TEST_EQUALITY_CONST( c->get_A().strong_count(), 3 );
883  TEST_ASSERT( !a.shares_resource(c->get_A()) );
884  TEST_EQUALITY( a.getRawPtr(), c->get_A().getRawPtr() );
885  TEST_EQUALITY( a->A_g(), A_g_return );
886  TEST_EQUALITY( c->C_g(), C_g_return );
887 }
888 
889 
890 // This unit test shows that you can remove the RCP in the C object
891 // and the A object will still live on.
892 TEUCHOS_UNIT_TEST( RCP, invertObjectOwnership_remove_A )
893 {
894  RCP<A> a = createACFactory();
895  extractCFromA(a)->set_A(null);
896  RCP<C> c = extractCFromA(a);
897  TEST_EQUALITY_CONST( a.strong_count(), 1 );
898  TEST_EQUALITY_CONST( c->get_A(), null );
899  TEST_EQUALITY( a->A_g(), A_g_return );
900  TEST_EQUALITY( c->C_g(), C_g_return );
901 }
902 
903 
904 //
905 // createRCPWithBadDealloc
906 //
907 
908 
909 RCP<A> createRCPWithBadDealloc()
910 {
911  return rcp(new A[1]); // Will use delete but should use delete []!
912 }
913 
914 
915 template<typename T>
916 class DeallocArrayDeleteExtraData {
917 public:
918  static RCP<DeallocArrayDeleteExtraData<T> > create(T *ptr)
919  { return rcp(new DeallocArrayDeleteExtraData(ptr)); }
920  ~DeallocArrayDeleteExtraData() { delete [] ptr_; }
921 private:
922  T *ptr_;
923  DeallocArrayDeleteExtraData(T *ptr) : ptr_(ptr) {}
924  // Not defined!
925  DeallocArrayDeleteExtraData();
926  DeallocArrayDeleteExtraData(const DeallocArrayDeleteExtraData&);
927  DeallocArrayDeleteExtraData& operator=(const DeallocArrayDeleteExtraData&);
928 };
929 
930 
931 // This unit test shows how you can use extra data to fix a bad deallocation
932 // policy
933 TEUCHOS_UNIT_TEST( RCP, Fix_createRCPWithBadDealloc )
934 {
935  using Teuchos::inOutArg;
936  using Teuchos::set_extra_data;
937  // Create object with bad deallocator
938  RCP<A> a = createRCPWithBadDealloc();
939  TEST_ASSERT(nonnull(a));
940  // Disable default (incorrect) dealloc and set a new deallocation policy as extra data!
941  a.release();
942  set_extra_data( DeallocArrayDeleteExtraData<A>::create(a.getRawPtr()), "dealloc",
943  inOutArg(a));
944 }
945 
946 
947 //
948 // Test RCP/boost::shared_ptr covnersions
949 //
950 
951 
952 #ifdef HAVE_TEUCHOS_BOOST
953 
954 
955 TEUCHOS_UNIT_TEST( boost_shared_ptr, nonnull_is_null )
956 {
957  using boost::shared_ptr;
958  ECHO(shared_ptr<A> a_sptr(new A));
959  TEST_EQUALITY_CONST(is_null(a_sptr), false);
960  TEST_EQUALITY_CONST(nonnull(a_sptr), true);
961  ECHO(a_sptr = shared_ptr<A>());
962  TEST_EQUALITY_CONST(is_null(a_sptr), true);
963  TEST_EQUALITY_CONST(nonnull(a_sptr), false);
964 }
965 
966 
967 #endif // HAVE_TEUCHOS_BOOST
968 
969 
970 //
971 // Test RCP/std::shared_ptr covnersions
972 //
973 
974 
975 #ifdef HAVE_TEUCHOSCORE_CXX11
976 
977 
978 TEUCHOS_UNIT_TEST( std_shared_ptr, nonnull_is_null )
979 {
980  using std::shared_ptr;
981  ECHO(shared_ptr<A> a_sptr(new A));
982  TEST_EQUALITY_CONST(Teuchos::is_null(a_sptr), false);
983  TEST_EQUALITY_CONST(Teuchos::nonnull(a_sptr), true);
984  ECHO(a_sptr = shared_ptr<A>());
985  TEST_EQUALITY_CONST(Teuchos::is_null(a_sptr), true);
986  TEST_EQUALITY_CONST(Teuchos::nonnull(a_sptr), false);
987 }
988 
989 
990 TEUCHOS_UNIT_TEST( std_shared_ptr, convert_to_RCP_null )
991 {
992  const std::shared_ptr<A> a_sptr1;
993  const RCP<A> a_rsptr1 = rcp(a_sptr1);
994  TEST_EQUALITY( a_rsptr1.get(), a_sptr1.get() );
995  TEST_ASSERT(is_null(a_rsptr1));
996 
997  const std::shared_ptr<A> a_sptr2 = get_shared_ptr(a_rsptr1);
998  TEST_EQUALITY( a_sptr1.get(), a_sptr1.get() );
999  TEST_ASSERT(Teuchos::is_null(a_sptr2));
1000 }
1001 
1002 
1003 TEUCHOS_UNIT_TEST( std_shared_ptr, convert_to_RCP )
1004 {
1005  const std::shared_ptr<A> a_sptr1(new C());
1006  const RCP<A> a_rsptr1 = rcp(a_sptr1);
1007  TEST_EQUALITY( a_rsptr1.get(), a_sptr1.get() );
1008  TEST_EQUALITY( a_rsptr1.getRawPtr(), a_sptr1.get() );
1009  TEST_EQUALITY( a_rsptr1.get(), a_rsptr1.getRawPtr() );
1010 
1011  const std::shared_ptr<A> a_sptr2 = get_shared_ptr(a_rsptr1);
1012  TEST_EQUALITY( a_sptr1.get(), a_sptr1.get() );
1013  // NOTE: There is no portable way to check that two std::shared_ptr objects
1014  // share the same underlying shared node :-(
1015 }
1016 
1017 
1018 TEUCHOS_UNIT_TEST( std_shared_ptr, convert_from_RCP_null )
1019 {
1020  const RCP<A> a_rcp1;
1021  const std::shared_ptr<A> a_sptr1(get_shared_ptr(a_rcp1));
1022  TEST_EQUALITY( a_rcp1.get(), a_sptr1.get() );
1023  TEST_ASSERT(Teuchos::is_null(a_sptr1));
1024 
1025  const RCP<A> a_rcp2 = rcp(a_sptr1);
1026  TEST_EQUALITY(a_rcp2.get(), a_sptr1.get());
1027  TEST_ASSERT(is_null(a_rcp2));
1028 }
1029 
1030 
1031 TEUCHOS_UNIT_TEST( std_shared_ptr, convert_from_RCP )
1032 {
1033  const RCP<A> a_rcp1(new C());
1034  const std::shared_ptr<A> a_sptr1(get_shared_ptr(a_rcp1));
1035  TEST_EQUALITY( a_rcp1.get(), a_sptr1.get() );
1036  TEST_EQUALITY( a_rcp1.getRawPtr(), a_sptr1.get() );
1037  TEST_EQUALITY( a_sptr1.get(), a_rcp1.getRawPtr() );
1038 
1039  const RCP<A> a_rcp2 = rcp(a_sptr1);
1040  TEST_EQUALITY( a_rcp2.get(), a_sptr1.get() );
1041  TEST_EQUALITY( a_rcp2.get(), a_rcp1.get() );
1042  TEST_ASSERT( a_rcp1.shares_resource(a_rcp2) );
1043 }
1044 
1045 
1046 #ifdef TEUCHOS_DEBUG
1047 
1048 
1049 TEUCHOS_UNIT_TEST( std_shared_ptr, convert_from_RCP_lookup_node )
1050 {
1051  const RCP<A> a_rcp1(new C());
1052  const std::shared_ptr<A> a_sptr1(get_shared_ptr(a_rcp1));
1053  TEST_EQUALITY( a_sptr1.get(), a_rcp1.get() );
1054 
1055  const RCP<C> c_rcp1 = rcp(std::dynamic_pointer_cast<C>(a_sptr1));
1056  TEST_EQUALITY( c_rcp1.get(), a_rcp1.get() );
1057  TEST_ASSERT( c_rcp1.shares_resource(a_rcp1) );
1058  // NOTE: The above test shows how Teuchos::RCP machinery will automatically
1059  // look up the underlying RCPNode object and use it!
1060 }
1061 
1062 
1063 #endif // TEUCHOS_DEBUG
1064 
1065 
1066 #endif // HAVE_TEUCHOSCORE_CXX11
1067 
1068 
1069 
1070 //
1071 // Template Instantiations
1072 //
1073 
1074 
1075 #ifdef TEUCHOS_DEBUG
1076 
1077 # define DEBUG_UNIT_TEST_GROUP( T ) \
1078 
1079 #else
1080 
1081 # define DEBUG_UNIT_TEST_GROUP( T )
1082 
1083 #endif
1084 
1085 
1086 #define UNIT_TEST_GROUP( T ) \
1087  TEUCHOS_UNIT_TEST_TEMPLATE_1_INSTANT( RCP, weakDelete, T ) \
1088  DEBUG_UNIT_TEST_GROUP(T)
1089 
1090 
1095 
1096 
1097 } // namespace
Dangling reference error exception class.
Null reference error exception class.
RCP< T > rcp(const boost::shared_ptr< T > &sptr)
Conversion function that takes in a boost::shared_ptr object and spits out a Teuchos::RCP object...
void set_extra_data(const T1 &extra_data, const std::string &name, const Ptr< ArrayRCP< T2 > > &p, EPrePostDestruction destroy_when=POST_DESTROY, bool force_unique=true)
Set extra data associated with a ArrayRCP object.
void set_C(const Teuchos::RCP< C > &c)
#define TEST_ASSERT(v1)
Assert the given statement is true.
Ptr< T > inOutArg(T &arg)
create a non-persisting (required or optional) input/output argument for a function call...
Ptr< T1 > get_optional_nonconst_extra_data(RCP< T2 > &p, const std::string &name)
Get a pointer to non-const extra data (if it exists) associated with a RCP object.
#define TEST_NOTHROW(code)
Asserr that the statement &#39;code&#39; does not thrown any excpetions.
int call_C_f()
#define ECHO(statement)
Echo the given statement before it is executed.
bool nonnull(const std::shared_ptr< T > &p)
Returns true if p.get()!=NULL.
bool is_null(const std::shared_ptr< T > &p)
Returns true if p.get()==NULL.
#define TEUCHOS_UNIT_TEST_TEMPLATE_1_DECL(TEST_GROUP, TEST_NAME, TYPE)
Macro for defining a templated unit test with one template parameter.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
#define TEST_THROW(code, ExceptType)
Assert that the statement &#39;code&#39; throws the exception &#39;ExceptType&#39; (otherwise the test fails)...
const T & getConst(T &t)
Return a constant reference to an object given a non-const reference.
const int C_g_return
Definition: TestClasses.hpp:56
const int C_f_return
Definition: TestClasses.hpp:57
#define TEUCHOS_UNIT_TEST(TEST_GROUP, TEST_NAME)
Macro for defining a (non-templated) unit test.
bool is_null(const ArrayRCP< T > &p)
Returns true if p.get()==NULL.
RCP< T > rcpWithEmbeddedObj(T *p, const Embedded &embedded, bool owns_mem=true)
Create an RCP with and also put in an embedded object.
void free(T *ptr)
Deallocates a pointer ptr using delete ptr (required).
Debug-mode RCPNode tracing class.
RCP< T > rcpCloneNode(const RCP< T > &p)
Allocate a new RCP object with a new RCPNode with memory pointing to the initial node.
#define SET_RCPNODE_TRACING()
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Deprecated.
Unit testing support.
#define TEST_EQUALITY_CONST(v1, v2)
Assert the equality of v1 and constant v2.
TypeTo as(const TypeFrom &t)
Convert from one value type to another.
RCP< T > rcpFromUndefRef(T &r)
Return a non-owning weak RCP object from a raw object reference for an undefined type.
std::shared_ptr< T > get_shared_ptr(const RCP< T > &rcp)
Conversion function that takes in a Teuchos::RCP object and spits out a std::shared_ptr object...
RCP< T > rcpFromRef(T &r)
Return a non-owning weak RCP object from a raw object reference for a defined type.
Policy class for deallocator for non-owned RCPs.
Smart reference counting pointer class for automatic garbage collection.
RCP< T > rcpWithDealloc(T *p, Dealloc_T dealloc, bool owns_mem=true)
Initialize from a raw pointer with a deallocation policy.
Ptr< T > outArg(T &arg)
create a non-persisting (required or optional) output argument for a function call.
Thrown if a duplicate owning RCP is creatd the the same object.
Reference-counted pointer class and non-member templated function implementations.
const int A_g_return
Definition: TestClasses.hpp:50
Simple wrapper class for raw pointers to single objects where no persisting relationship exists...
bool nonnull(const ArrayRCP< T > &p)
Returns true if p.get()!=NULL.
#define UNIT_TEST_GROUP(T)