Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:03:55

0001 #include "cppunit/extensions/HelperMacros.h"
0002 #include "DataFormats/Common/interface/CloningPtr.h"
0003 
0004 #include <vector>
0005 
0006 class testCloningPtr : public CppUnit::TestFixture {
0007   CPPUNIT_TEST_SUITE(testCloningPtr);
0008   CPPUNIT_TEST(check);
0009   CPPUNIT_TEST_SUITE_END();
0010 
0011 public:
0012   void setUp() {}
0013   void tearDown() {}
0014   void check();
0015 };
0016 
0017 CPPUNIT_TEST_SUITE_REGISTRATION(testCloningPtr);
0018 namespace testcloningptr {
0019   struct Base {
0020     virtual ~Base() {}
0021     virtual int val() const = 0;
0022     virtual Base* clone() const = 0;
0023   };
0024 
0025   struct Inherit : public Base {
0026     Inherit(int iValue) : val_(iValue) {}
0027     virtual int val() const { return val_; }
0028     virtual Base* clone() const { return new Inherit(*this); }
0029     int val_;
0030   };
0031 }  // namespace testcloningptr
0032 
0033 using namespace testcloningptr;
0034 
0035 void testCloningPtr::check() {
0036   using namespace edm;
0037 
0038   Inherit one(1);
0039   CloningPtr<Base> cpOne(one);
0040   CPPUNIT_ASSERT(&one != cpOne.get());
0041   CPPUNIT_ASSERT(1 == cpOne->val());
0042   CPPUNIT_ASSERT(1 == (*cpOne).val());
0043 
0044   CloningPtr<Base> cpOtherOne(cpOne);
0045   CPPUNIT_ASSERT(cpOne.get() != cpOtherOne.get());
0046   CPPUNIT_ASSERT(cpOtherOne->val() == 1);
0047 
0048   CloningPtr<Base> eqOne;
0049   eqOne = cpOne;
0050 
0051   CPPUNIT_ASSERT(cpOne.get() != eqOne.get());
0052   CPPUNIT_ASSERT(eqOne->val() == 1);
0053 }