File indexing completed on 2024-04-06 12:12:24
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #include "FWCore/Framework/interface/ESProductResolverTemplate.h"
0011 #include "FWCore/Framework/interface/ESProductResolverFactoryProducer.h"
0012 #include "FWCore/Framework/test/ESProductResolverFactoryTemplate.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::ESProductResolverFactoryProducer;
0024 using edm::eventsetup::test::DummyData;
0025
0026 class DummyResolver : public ESProductResolverTemplate<DummyRecord, DummyData> {
0027 public:
0028 DummyResolver() {}
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 ESProductResolverFactoryProducer {
0039 public:
0040 Test1Producer() { registerFactory(std::make_unique<ESProductResolverFactoryTemplate<DummyResolver>>()); }
0041 };
0042
0043 class TestLabelProducer : public ESProductResolverFactoryProducer {
0044 public:
0045 TestLabelProducer() { registerFactory(std::make_unique<ESProductResolverFactoryTemplate<DummyResolver>>(), "fred"); }
0046 };
0047
0048 class testResolverfactor : public CppUnit::TestFixture {
0049 CPPUNIT_TEST_SUITE(testResolverfactor);
0050
0051 CPPUNIT_TEST(registerResolverfactorytemplateTest);
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 registerResolverfactorytemplateTest();
0062 void appendLabelTest();
0063 void labelTest();
0064 };
0065
0066
0067 CPPUNIT_TEST_SUITE_REGISTRATION(testResolverfactor);
0068
0069 void testResolverfactor::registerResolverfactorytemplateTest() {
0070 Test1Producer testProd;
0071 EventSetupRecordKey dummyRecordKey = EventSetupRecordKey::makeKey<DummyRecord>();
0072 testProd.createKeyedResolvers(dummyRecordKey, 1);
0073 CPPUNIT_ASSERT(testProd.isUsingRecord(dummyRecordKey));
0074
0075 ESProductResolverProvider::KeyedResolvers& keyedResolvers = testProd.keyedResolvers(dummyRecordKey);
0076
0077 CPPUNIT_ASSERT(keyedResolvers.size() == 1);
0078 CPPUNIT_ASSERT(nullptr != dynamic_cast<DummyResolver const*>(&(*(keyedResolvers.begin().productResolver()))));
0079 }
0080
0081 void testResolverfactor::labelTest() {
0082 TestLabelProducer testProd;
0083 EventSetupRecordKey dummyRecordKey = EventSetupRecordKey::makeKey<DummyRecord>();
0084 testProd.createKeyedResolvers(dummyRecordKey, 1);
0085 CPPUNIT_ASSERT(testProd.isUsingRecord(dummyRecordKey));
0086
0087 ESProductResolverProvider::KeyedResolvers& keyedResolvers = testProd.keyedResolvers(dummyRecordKey);
0088
0089 CPPUNIT_ASSERT(keyedResolvers.size() == 1);
0090 CPPUNIT_ASSERT(nullptr != dynamic_cast<DummyResolver const*>(&(*(keyedResolvers.begin().productResolver()))));
0091 const std::string kFred("fred");
0092 CPPUNIT_ASSERT(kFred == keyedResolvers.begin().dataKey().name().value());
0093 }
0094
0095 void testResolverfactor::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.createKeyedResolvers(dummyRecordKey, 1);
0105 CPPUNIT_ASSERT(testProd.isUsingRecord(dummyRecordKey));
0106
0107 ESProductResolverProvider::KeyedResolvers& keyedResolvers = testProd.keyedResolvers(dummyRecordKey);
0108
0109 CPPUNIT_ASSERT(keyedResolvers.size() == 1);
0110 CPPUNIT_ASSERT(nullptr != dynamic_cast<DummyResolver const*>(&(*(keyedResolvers.begin().productResolver()))));
0111 const std::string kFredBarney("fredBarney");
0112 CPPUNIT_ASSERT(kFredBarney == keyedResolvers.begin().dataKey().name().value());
0113 }
0114
0115 Test1Producer testProd;
0116 testProd.setAppendToDataLabel(pset);
0117 EventSetupRecordKey dummyRecordKey = EventSetupRecordKey::makeKey<DummyRecord>();
0118 testProd.createKeyedResolvers(dummyRecordKey, 1);
0119 CPPUNIT_ASSERT(testProd.isUsingRecord(dummyRecordKey));
0120
0121 ESProductResolverProvider::KeyedResolvers& keyedResolvers = testProd.keyedResolvers(dummyRecordKey);
0122
0123 CPPUNIT_ASSERT(keyedResolvers.size() == 1);
0124 CPPUNIT_ASSERT(nullptr != dynamic_cast<DummyResolver const*>(&(*(keyedResolvers.begin().productResolver()))));
0125 const std::string kBarney("Barney");
0126 CPPUNIT_ASSERT(kBarney == keyedResolvers.begin().dataKey().name().value());
0127 }