Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 #include <vector>
0002 
0003 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0004 #include "cppunit/extensions/HelperMacros.h"
0005 
0006 #include "DataFormats/Common/interface/Ref.h"
0007 #include "DataFormats/Common/interface/RefVector.h"
0008 
0009 class TestRefVector : public CppUnit::TestFixture {
0010   CPPUNIT_TEST_SUITE(TestRefVector);
0011   CPPUNIT_TEST(testIteration);
0012   CPPUNIT_TEST_SUITE_END();
0013 
0014 public:
0015   TestRefVector() {}
0016   ~TestRefVector() {}
0017   void setUp() {}
0018   void tearDown() {}
0019 
0020   void testIteration();
0021 
0022 private:
0023 };
0024 
0025 CPPUNIT_TEST_SUITE_REGISTRATION(TestRefVector);
0026 
0027 void TestRefVector::testIteration() {
0028   typedef std::vector<double> product_t;
0029   typedef edm::Ref<product_t> ref_t;
0030   typedef edm::RefVector<product_t> refvec_t;
0031 
0032   product_t product;
0033   product.push_back(1.0);
0034   product.push_back(100.0);
0035   product.push_back(0.5);
0036   product.push_back(2.0);
0037 
0038   refvec_t refvec;
0039   CPPUNIT_ASSERT(refvec.size() == 0);
0040   CPPUNIT_ASSERT(refvec.empty());
0041 
0042   ref_t ref0(edm::ProductID(1, 1), &product[0], 0);
0043   refvec.push_back(ref0);
0044 
0045   ref_t ref1(edm::ProductID(1, 1), &product[2], 2);
0046   refvec.push_back(ref1);
0047 
0048   ref_t ref2(edm::ProductID(1, 1), &product[3], 3);
0049   refvec.push_back(ref2);
0050 
0051   auto iter = refvec.begin();
0052 
0053   CPPUNIT_ASSERT(iter->id() == edm::ProductID(1, 1) && iter->key() == 0 && *(iter->get()) == 1.0);
0054   ++iter;
0055 
0056   CPPUNIT_ASSERT(iter->id() == edm::ProductID(1, 1) && iter->key() == 2 && *(iter->get()) == 0.5);
0057   ++iter;
0058 
0059   CPPUNIT_ASSERT(iter->id() == edm::ProductID(1, 1) && iter->key() == 3 && *(iter->get()) == 2.0);
0060   ++iter;
0061 
0062   CPPUNIT_ASSERT(iter == refvec.end());
0063 }