Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 /*
0002  *  proxyfactoryproducer_t.cc
0003  *  EDMProto
0004  *
0005  *  Created by Chris Jones on 4/8/05.
0006  *  Changed by Viji Sundararajan on 03-Jul-05.
0007 
0008 */
0009 
0010 #include "FWCore/Framework/interface/DataProxyTemplate.h"
0011 #include "FWCore/Framework/interface/ESProxyFactoryProducer.h"
0012 #include "FWCore/Framework/test/ProxyFactoryTemplate.h"
0013 #include "FWCore/Framework/test/DummyData.h"
0014 #include "FWCore/Framework/test/DummyRecord.h"
0015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0016 
0017 #include "cppunit/extensions/HelperMacros.h"
0018 
0019 #include <memory>
0020 #include <string>
0021 
0022 using namespace edm::eventsetup;
0023 using edm::ESProxyFactoryProducer;
0024 using edm::eventsetup::test::DummyData;
0025 
0026 class DummyProxy : public DataProxyTemplate<DummyRecord, DummyData> {
0027 public:
0028   DummyProxy() {}
0029 
0030 protected:
0031   const value_type* make(const record_type&, const DataKey&) override {
0032     return static_cast<const value_type*>(nullptr);
0033   }
0034   void invalidateCache() override {}
0035   void const* getAfterPrefetchImpl() const override { return nullptr; }
0036 };
0037 
0038 class Test1Producer : public ESProxyFactoryProducer {
0039 public:
0040   Test1Producer() { registerFactory(std::make_unique<ProxyFactoryTemplate<DummyProxy>>()); }
0041 };
0042 
0043 class TestLabelProducer : public ESProxyFactoryProducer {
0044 public:
0045   TestLabelProducer() { registerFactory(std::make_unique<ProxyFactoryTemplate<DummyProxy>>(), "fred"); }
0046 };
0047 
0048 class testProxyfactor : public CppUnit::TestFixture {
0049   CPPUNIT_TEST_SUITE(testProxyfactor);
0050 
0051   CPPUNIT_TEST(registerProxyfactorytemplateTest);
0052   CPPUNIT_TEST(labelTest);
0053   CPPUNIT_TEST(appendLabelTest);
0054 
0055   CPPUNIT_TEST_SUITE_END();
0056 
0057 public:
0058   void setUp() {}
0059   void tearDown() {}
0060 
0061   void registerProxyfactorytemplateTest();
0062   void appendLabelTest();
0063   void labelTest();
0064 };
0065 
0066 ///registration of the test so that the runner can find it
0067 CPPUNIT_TEST_SUITE_REGISTRATION(testProxyfactor);
0068 
0069 void testProxyfactor::registerProxyfactorytemplateTest() {
0070   Test1Producer testProd;
0071   EventSetupRecordKey dummyRecordKey = EventSetupRecordKey::makeKey<DummyRecord>();
0072   testProd.createKeyedProxies(dummyRecordKey, 1);
0073   CPPUNIT_ASSERT(testProd.isUsingRecord(dummyRecordKey));
0074 
0075   DataProxyProvider::KeyedProxies& keyedProxies = testProd.keyedProxies(dummyRecordKey);
0076 
0077   CPPUNIT_ASSERT(keyedProxies.size() == 1);
0078   CPPUNIT_ASSERT(nullptr != dynamic_cast<DummyProxy const*>(&(*(keyedProxies.begin().dataProxy()))));
0079 }
0080 
0081 void testProxyfactor::labelTest() {
0082   TestLabelProducer testProd;
0083   EventSetupRecordKey dummyRecordKey = EventSetupRecordKey::makeKey<DummyRecord>();
0084   testProd.createKeyedProxies(dummyRecordKey, 1);
0085   CPPUNIT_ASSERT(testProd.isUsingRecord(dummyRecordKey));
0086 
0087   DataProxyProvider::KeyedProxies& keyedProxies = testProd.keyedProxies(dummyRecordKey);
0088 
0089   CPPUNIT_ASSERT(keyedProxies.size() == 1);
0090   CPPUNIT_ASSERT(nullptr != dynamic_cast<DummyProxy const*>(&(*(keyedProxies.begin().dataProxy()))));
0091   const std::string kFred("fred");
0092   CPPUNIT_ASSERT(kFred == keyedProxies.begin().dataKey().name().value());
0093 }
0094 
0095 void testProxyfactor::appendLabelTest() {
0096   edm::ParameterSet pset;
0097   std::string kToAppend("Barney");
0098   pset.addParameter("appendToDataLabel", kToAppend);
0099   pset.registerIt();
0100   {
0101     TestLabelProducer testProd;
0102     testProd.setAppendToDataLabel(pset);
0103     EventSetupRecordKey dummyRecordKey = EventSetupRecordKey::makeKey<DummyRecord>();
0104     testProd.createKeyedProxies(dummyRecordKey, 1);
0105     CPPUNIT_ASSERT(testProd.isUsingRecord(dummyRecordKey));
0106 
0107     DataProxyProvider::KeyedProxies& keyedProxies = testProd.keyedProxies(dummyRecordKey);
0108 
0109     CPPUNIT_ASSERT(keyedProxies.size() == 1);
0110     CPPUNIT_ASSERT(nullptr != dynamic_cast<DummyProxy const*>(&(*(keyedProxies.begin().dataProxy()))));
0111     const std::string kFredBarney("fredBarney");
0112     CPPUNIT_ASSERT(kFredBarney == keyedProxies.begin().dataKey().name().value());
0113   }
0114 
0115   Test1Producer testProd;
0116   testProd.setAppendToDataLabel(pset);
0117   EventSetupRecordKey dummyRecordKey = EventSetupRecordKey::makeKey<DummyRecord>();
0118   testProd.createKeyedProxies(dummyRecordKey, 1);
0119   CPPUNIT_ASSERT(testProd.isUsingRecord(dummyRecordKey));
0120 
0121   DataProxyProvider::KeyedProxies& keyedProxies = testProd.keyedProxies(dummyRecordKey);
0122 
0123   CPPUNIT_ASSERT(keyedProxies.size() == 1);
0124   CPPUNIT_ASSERT(nullptr != dynamic_cast<DummyProxy const*>(&(*(keyedProxies.begin().dataProxy()))));
0125   const std::string kBarney("Barney");
0126   CPPUNIT_ASSERT(kBarney == keyedProxies.begin().dataKey().name().value());
0127 }