Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:28:15

0001 /*
0002  *  esproducts_t.cc
0003  *  EDMProto
0004  *
0005  *  Created by Chris Jones on 4/18/05.
0006  *  Changed by Viji Sundararajan on 03-Jul-05.
0007  *
0008  */
0009 
0010 #include "cppunit/extensions/HelperMacros.h"
0011 
0012 #include "FWCore/Framework/interface/ESProducts.h"
0013 using edm::ESProducts;
0014 using edm::es::products;
0015 
0016 class testEsproducts : public CppUnit::TestFixture {
0017   CPPUNIT_TEST_SUITE(testEsproducts);
0018   CPPUNIT_TEST(constPtrTest);
0019   CPPUNIT_TEST(uniquePtrTest);
0020   CPPUNIT_TEST(sharedPtrTest);
0021   CPPUNIT_TEST(manyTest);
0022   CPPUNIT_TEST_SUITE_END();
0023 
0024 public:
0025   void setUp() {}
0026   void tearDown() {}
0027   void constPtrTest();
0028   void uniquePtrTest();
0029   void sharedPtrTest();
0030   void manyTest();
0031 };
0032 
0033 ///registration of the test so that the runner can find it
0034 CPPUNIT_TEST_SUITE_REGISTRATION(testEsproducts);
0035 
0036 ESProducts<const int*, const float*> returnPointers(const int* iInt, const float* iFloat) {
0037   return products(iInt, iFloat);
0038 }
0039 
0040 void testEsproducts::constPtrTest() {
0041   int int_ = 0;
0042   float float_ = 0;
0043 
0044   ESProducts<const int*, const float*> product = returnPointers(&int_, &float_);
0045 
0046   const int* readInt = 0;
0047   const float* readFloat = 0;
0048 
0049   product.moveTo(readInt);
0050   product.moveTo(readFloat);
0051 
0052   CPPUNIT_ASSERT(readInt == &int_);
0053   CPPUNIT_ASSERT(readFloat == &float_);
0054 }
0055 
0056 void testEsproducts::uniquePtrTest() {
0057   constexpr int kInt = 5;
0058   auto int_ = std::make_unique<int>(kInt);
0059   constexpr float kFloat = 3.1;
0060   auto float_ = std::make_unique<float>(kFloat);
0061 
0062   ESProducts<std::unique_ptr<int>, std::unique_ptr<float>> product = products(std::move(int_), std::move(float_));
0063 
0064   std::unique_ptr<int> readInt;
0065   std::unique_ptr<float> readFloat;
0066 
0067   product.moveTo(readInt);
0068   product.moveTo(readFloat);
0069 
0070   CPPUNIT_ASSERT(*readInt == kInt);
0071   CPPUNIT_ASSERT(*readFloat == kFloat);
0072 }
0073 
0074 void testEsproducts::sharedPtrTest() {
0075   auto int_ = std::make_shared<int>(5);
0076   auto float_ = std::make_shared<float>(3.1);
0077 
0078   ESProducts<std::shared_ptr<int>, std::shared_ptr<float>> product = products(int_, float_);
0079 
0080   std::shared_ptr<int> readInt;
0081   std::shared_ptr<float> readFloat;
0082 
0083   product.moveTo(readInt);
0084   product.moveTo(readFloat);
0085 
0086   CPPUNIT_ASSERT(readInt.get() == int_.get());
0087   CPPUNIT_ASSERT(readFloat.get() == float_.get());
0088 }
0089 
0090 ESProducts<const int*, const float*, const double*> returnManyPointers(const int* iInt,
0091                                                                        const float* iFloat,
0092                                                                        const double* iDouble) {
0093   return edm::es::products(iInt, iFloat, iDouble);
0094 }
0095 
0096 void testEsproducts::manyTest() {
0097   int int_ = 0;
0098   float float_ = 0;
0099   double double_ = 0;
0100 
0101   ESProducts<const int*, const float*, const double*> product = returnManyPointers(&int_, &float_, &double_);
0102 
0103   const int* readInt = 0;
0104   const float* readFloat = 0;
0105   const double* readDouble = 0;
0106 
0107   product.moveTo(readInt);
0108   product.moveTo(readFloat);
0109   product.moveTo(readDouble);
0110 
0111   CPPUNIT_ASSERT(readInt == &int_);
0112   CPPUNIT_ASSERT(readFloat == &float_);
0113   CPPUNIT_ASSERT(readDouble == &double_);
0114 }