libMesh
Public Member Functions | List of all members
UniquePtrTest Class Reference
Inheritance diagram for UniquePtrTest:
[legend]

Public Member Functions

 CPPUNIT_TEST_SUITE (UniquePtrTest)
 
 CPPUNIT_TEST (testComparison)
 
 CPPUNIT_TEST (testMakeUnique)
 
 CPPUNIT_TEST_SUITE_END ()
 
void setUp ()
 
void tearDown ()
 
void testComparison ()
 
void testMakeUnique ()
 

Detailed Description

Definition at line 22 of file unique_ptr_test.C.

Member Function Documentation

UniquePtrTest::CPPUNIT_TEST ( testComparison  )
UniquePtrTest::CPPUNIT_TEST ( testMakeUnique  )
UniquePtrTest::CPPUNIT_TEST_SUITE ( UniquePtrTest  )
UniquePtrTest::CPPUNIT_TEST_SUITE_END ( )
void UniquePtrTest::setUp ( )

Definition at line 39 of file unique_ptr_test.C.

40  {}
void UniquePtrTest::tearDown ( )

Definition at line 42 of file unique_ptr_test.C.

43  {}
void UniquePtrTest::testComparison ( )

Definition at line 45 of file unique_ptr_test.C.

46  {
47  // Test that if(foo) and if (!foo) compile and do the right thing
48  // for UniquePtr. This tests that the safe_bool thing that our
49  // internal AutoPtr uses is actually working, in cases where users
50  // are configured to use that.
51  {
52  UniquePtr<int> foo(new int(42));
53 
54  bool test1_passed = false;
55  if (foo)
56  test1_passed = true;
57  CPPUNIT_ASSERT(test1_passed);
58 
59  bool test2_passed = true;
60  if (!foo)
61  test2_passed = false;
62  CPPUNIT_ASSERT(test2_passed);
63  }
64 
65  // Test the converse for when foo holds a NULL pointer.
66  {
67  UniquePtr<int> foo;
68 
69  bool test3_passed = true;
70  if (foo)
71  test3_passed = false;
72  CPPUNIT_ASSERT(test3_passed);
73 
74  bool test4_passed = false;
75  if (!foo)
76  test4_passed = true;
77  CPPUNIT_ASSERT(test4_passed);
78  }
79 
80  // Make sure that foo == bar is not allowed. This should not even
81  // compile -- I don't think that's possible to test with CPPUnit
82  // so it's commented out for now, but if you uncomment this test,
83  // you should get a compiler error. This is probably a candidate
84  // for a configure-time test instead.
85  // UniquePtr<int> bar(new int(21));
86  // if (foo == bar)
87  // std::cerr << "This should not compile." << std::endl;
88  }
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
void UniquePtrTest::testMakeUnique ( )

Definition at line 90 of file unique_ptr_test.C.

References CPPUNIT_TEST_SUITE_REGISTRATION().

91  {
92  // If the compiler supports one of the ways of calling
93  // make_unique, test that our macro works for calling it works.
94 #if defined(LIBMESH_HAVE_CXX14_MAKE_UNIQUE) || defined(LIBMESH_HAVE_CXX11_MAKE_UNIQUE_WORKAROUND)
95  std::unique_ptr<int> foo = libmesh_make_unique<int>(42);
96 #endif
97  }

The documentation for this class was generated from the following file: