Teuchos Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GetBaseObjVoidPtr_UnitTests.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Teuchos: Common Tools Package
4 //
5 // Copyright 2004 NTESS and the Teuchos contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
11 #include "Teuchos_RCP.hpp"
12 
13 #include "TestClasses.hpp"
14 
16 
17 
18 namespace Teuchos {
19 
20 
21 TEUCHOS_UNIT_TEST( GetBaseObjVoidPtr, polymorphicClasses )
22 {
23  RCP<C> c_ptr(new C);
24  RCP<B1> b1_ptr = c_ptr;
25  RCP<B2> b2_ptr = c_ptr;
26  RCP<A> a_ptr = c_ptr;
27  TEST_EQUALITY( getBaseObjVoidPtr(&*c_ptr), static_cast<const void*>(&*c_ptr) );
28  TEST_EQUALITY( getBaseObjVoidPtr(&*b1_ptr), static_cast<const void*>(&*c_ptr) );
29  TEST_INEQUALITY( static_cast<const void*>(&*b1_ptr), static_cast<const void*>(&*c_ptr) );
30  TEST_EQUALITY( getBaseObjVoidPtr(&*b2_ptr), static_cast<const void*>(&*c_ptr) );
31  TEST_INEQUALITY( static_cast<const void*>(&*b2_ptr), static_cast<const void*>(&*c_ptr) );
32  TEST_EQUALITY( getBaseObjVoidPtr(&*a_ptr), static_cast<const void*>(&*c_ptr) );
33  TEST_INEQUALITY( static_cast<const void*>(&*a_ptr), static_cast<const void*>(&*c_ptr) );
34 }
35 
36 
37 TEUCHOS_UNIT_TEST( GetBaseObjVoidPtr, nonPolymorphicClasses )
38 {
39  RCP<E> e_ptr(new E);
40  RCP<D> d_ptr = e_ptr;
41  TEST_EQUALITY( getBaseObjVoidPtr(&*e_ptr), static_cast<const void*>(&*e_ptr) );
42  TEST_EQUALITY( getBaseObjVoidPtr(&*d_ptr), static_cast<const void*>(&*e_ptr) );
43 }
44 
45 
46 TEUCHOS_UNIT_TEST( GetBaseObjVoidPtr, nonPolymorphicBuiltInTypes )
47 {
48  RCP<int> i_ptr(new int);
49  TEST_EQUALITY( getBaseObjVoidPtr(&*i_ptr), static_cast<const void*>(&*i_ptr) );
50 }
51 
52 
53 } // namespace Teuchos namespace
#define TEST_INEQUALITY(v1, v2)
Assert the inequality of v1 and v2.
#define TEST_EQUALITY(v1, v2)
Assert the equality of v1 and v2.
TEUCHOS_UNIT_TEST(ConstNonconstObjectContainer, create)
Unit testing support.
Reference-counted pointer class and non-member templated function implementations.