Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:53:32

0001 #include <cassert>
0002 
0003 #include <cppunit/extensions/HelperMacros.h>
0004 
0005 //
0006 
0007 #include "DataFormats/GeometrySurface/interface/ReferenceCounted.h"
0008 
0009 namespace testreferencecounted {
0010 
0011   class Test : public CppUnit::TestFixture {
0012     CPPUNIT_TEST_SUITE(Test);
0013     CPPUNIT_TEST(deleteTest);
0014     CPPUNIT_TEST(multiRefTest);
0015     CPPUNIT_TEST(assignmentTest);
0016     CPPUNIT_TEST(modifyTest);
0017     CPPUNIT_TEST(intrusiveTest);
0018     CPPUNIT_TEST_SUITE_END();
0019 
0020   public:
0021     void setUp() {}
0022     void tearDown() {}
0023     void deleteTest();
0024     void multiRefTest();
0025     void assignmentTest();
0026     void modifyTest();
0027     void intrusiveTest();
0028   };
0029 
0030   static unsigned int s_construct = 0;
0031 
0032   struct RefTest : public ReferenceCounted {
0033     RefTest() { s_construct++; }
0034     ~RefTest() { s_construct--; }
0035   };
0036 
0037   typedef ReferenceCountingPointer<RefTest> RefPtr;
0038 }  // namespace testreferencecounted
0039 ///registration of the test so that the runner can find it
0040 CPPUNIT_TEST_SUITE_REGISTRATION(testreferencecounted::Test);
0041 
0042 namespace testreferencecounted {
0043   void Test::deleteTest() {
0044     { RefPtr pointer(new RefTest); }
0045     assert(0 == s_construct);
0046   }
0047 
0048   void Test::multiRefTest() {
0049     {
0050       RefPtr pointer(new RefTest);
0051       { RefPtr pointer2(pointer); }
0052     }
0053     assert(0 == s_construct);
0054   }
0055 
0056   void Test::assignmentTest() {
0057     {
0058       RefPtr pointer(new RefTest);
0059       {
0060         RefPtr pointer2;
0061         pointer2 = pointer;
0062       }
0063     }
0064     assert(0 == s_construct);
0065   }
0066 
0067   void Test::modifyTest() {
0068     {
0069       RefPtr pointer(new RefTest);
0070       {
0071         RefPtr pointer2;
0072         pointer2 = pointer;
0073         *pointer = RefTest();
0074       }
0075     }
0076     assert(0 == s_construct);
0077   }
0078 
0079   void Test::intrusiveTest() {
0080     {
0081       RefTest* ptr = new RefTest;
0082       RefPtr pointer(ptr);
0083       { RefPtr pointer2(ptr); }
0084     }
0085     assert(0 == s_construct);
0086   }
0087 }  // namespace testreferencecounted
0088 
0089 ///registration of the test so that the runner can find it
0090 CPPUNIT_TEST_SUITE_REGISTRATION(testreferencecounted::Test);
0091 
0092 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"