Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0002 #include "cppunit/extensions/HelperMacros.h"
0003 
0004 #include "DataFormats/Common/interface/RefCore.h"
0005 #include "DataFormats/Common/interface/RefCoreWithIndex.h"
0006 #include "DataFormats/Common/interface/EDProductGetter.h"
0007 
0008 #include "SimpleEDProductGetter.h"
0009 
0010 class TestRefCore : public CppUnit::TestFixture {
0011   CPPUNIT_TEST_SUITE(TestRefCore);
0012   CPPUNIT_TEST(default_ctor);
0013   CPPUNIT_TEST(default_ctor_withindex);
0014 
0015   CPPUNIT_TEST(nondefault_ctor);
0016   CPPUNIT_TEST(nondefault_ctor_withindex);
0017   CPPUNIT_TEST_SUITE_END();
0018 
0019 public:
0020   TestRefCore() {}
0021   ~TestRefCore() {}
0022   void setUp() {}
0023   void tearDown() {}
0024 
0025   void default_ctor();
0026   void nondefault_ctor();
0027   void default_ctor_withindex();
0028   void nondefault_ctor_withindex();
0029 
0030 private:
0031 };
0032 
0033 CPPUNIT_TEST_SUITE_REGISTRATION(TestRefCore);
0034 
0035 void TestRefCore::default_ctor() {
0036   edm::RefCore default_refcore;
0037   CPPUNIT_ASSERT(default_refcore.isNull());
0038   CPPUNIT_ASSERT(default_refcore.isNonnull() == false);
0039   CPPUNIT_ASSERT(!default_refcore);
0040   CPPUNIT_ASSERT(default_refcore.productGetter() == 0);
0041   CPPUNIT_ASSERT(default_refcore.id().isValid() == false);
0042 }
0043 
0044 void TestRefCore::nondefault_ctor() {
0045   SimpleEDProductGetter getter;
0046   edm::ProductID id(1, 201U);
0047   CPPUNIT_ASSERT(id.isValid());
0048 
0049   edm::RefCore refcore(id, 0, &getter, false);
0050   CPPUNIT_ASSERT(refcore.isNull() == false);
0051   CPPUNIT_ASSERT(refcore.isNonnull());
0052   CPPUNIT_ASSERT(!!refcore);
0053   CPPUNIT_ASSERT(refcore.productGetter() == &getter);
0054   CPPUNIT_ASSERT(refcore.id().isValid());
0055 }
0056 
0057 void TestRefCore::default_ctor_withindex() {
0058   edm::RefCoreWithIndex default_refcore;
0059   CPPUNIT_ASSERT(default_refcore.isNull());
0060   CPPUNIT_ASSERT(default_refcore.isNonnull() == false);
0061   CPPUNIT_ASSERT(!default_refcore);
0062   CPPUNIT_ASSERT(default_refcore.productGetter() == 0);
0063   CPPUNIT_ASSERT(default_refcore.id().isValid() == false);
0064   CPPUNIT_ASSERT(default_refcore.index() == edm::key_traits<unsigned int>::value);
0065   edm::RefCore compareTo;
0066   edm::RefCore const& converted = default_refcore.toRefCore();
0067   CPPUNIT_ASSERT(compareTo.productGetter() == converted.productGetter());
0068   CPPUNIT_ASSERT(compareTo.id() == converted.id());
0069 }
0070 
0071 void TestRefCore::nondefault_ctor_withindex() {
0072   SimpleEDProductGetter getter;
0073   edm::ProductID id(1, 201U);
0074   CPPUNIT_ASSERT(id.isValid());
0075 
0076   edm::RefCoreWithIndex refcore(id, 0, &getter, false, 1);
0077   CPPUNIT_ASSERT(refcore.isNull() == false);
0078   CPPUNIT_ASSERT(refcore.isNonnull());
0079   CPPUNIT_ASSERT(!!refcore);
0080   CPPUNIT_ASSERT(refcore.productGetter() == &getter);
0081   CPPUNIT_ASSERT(refcore.id().isValid());
0082   CPPUNIT_ASSERT(refcore.index() == 1);
0083 
0084   edm::RefCore compareTo(id, 0, &getter, false);
0085   edm::RefCore const& converted = refcore.toRefCore();
0086   CPPUNIT_ASSERT(compareTo.productGetter() == converted.productGetter());
0087   CPPUNIT_ASSERT(compareTo.id() == converted.id());
0088 }