Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- C++ -*-
0002 //
0003 // Package:     Framework
0004 // Class  :     intersectingiovrecordintervalfinder_t_cppunit
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Chris Jones
0010 //         Created:  Tue Aug 19 14:14:42 EDT 2008
0011 //
0012 
0013 #include "FWCore/Framework/src/IntersectingIOVRecordIntervalFinder.h"
0014 #include "FWCore/Framework/test/DummyRecord.h"
0015 #include "FWCore/Framework/test/DummyFinder.h"
0016 
0017 #include "cppunit/extensions/HelperMacros.h"
0018 using namespace edm::eventsetup;
0019 
0020 class testintersectingiovrecordintervalfinder : public CppUnit::TestFixture {
0021   CPPUNIT_TEST_SUITE(testintersectingiovrecordintervalfinder);
0022 
0023   CPPUNIT_TEST(constructorTest);
0024   CPPUNIT_TEST(intersectionTest);
0025 
0026   CPPUNIT_TEST_SUITE_END();
0027 
0028 public:
0029   void setUp() {}
0030   void tearDown() {}
0031 
0032   void constructorTest();
0033   void intersectionTest();
0034 
0035 };  //Cppunit class declaration over
0036 
0037 ///registration of the test so that the runner can find it
0038 CPPUNIT_TEST_SUITE_REGISTRATION(testintersectingiovrecordintervalfinder);
0039 
0040 void testintersectingiovrecordintervalfinder::constructorTest() {
0041   IntersectingIOVRecordIntervalFinder finder(DummyRecord::keyForClass());
0042   CPPUNIT_ASSERT(finder.findingForRecords().size() == 1);
0043   std::set<EventSetupRecordKey> s = finder.findingForRecords();
0044   CPPUNIT_ASSERT(s.find(DummyRecord::keyForClass()) != s.end());
0045 }
0046 
0047 void testintersectingiovrecordintervalfinder::intersectionTest() {
0048   const EventSetupRecordKey dummyRecordKey = DummyRecord::keyForClass();
0049 
0050   std::vector<edm::propagate_const<std::shared_ptr<edm::EventSetupRecordIntervalFinder>>> finders;
0051   std::shared_ptr<DummyFinder> dummyFinder = std::make_shared<DummyFinder>();
0052   {
0053     IntersectingIOVRecordIntervalFinder intersectingFinder(dummyRecordKey);
0054     const edm::ValidityInterval definedInterval(edm::IOVSyncValue(edm::EventID(1, 1, 1)),
0055                                                 edm::IOVSyncValue(edm::EventID(1, 1, 3)));
0056     finders.push_back(dummyFinder);
0057     dummyFinder->setInterval(definedInterval);
0058     intersectingFinder.swapFinders(finders);
0059 
0060     CPPUNIT_ASSERT(definedInterval ==
0061                    intersectingFinder.findIntervalFor(dummyRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 2))));
0062 
0063     const edm::ValidityInterval unknownedEndInterval(edm::IOVSyncValue(edm::EventID(1, 1, 5)),
0064                                                      edm::IOVSyncValue::invalidIOVSyncValue());
0065     dummyFinder->setInterval(unknownedEndInterval);
0066 
0067     CPPUNIT_ASSERT(unknownedEndInterval ==
0068                    intersectingFinder.findIntervalFor(dummyRecordKey, edm::IOVSyncValue(edm::EventID(1, 1, 5))));
0069   }
0070 
0071   {
0072     finders.clear();
0073 
0074     const edm::IOVSyncValue sync_1(edm::EventID(1, 1, 1));
0075     const edm::IOVSyncValue sync_3(edm::EventID(1, 1, 3));
0076     const edm::IOVSyncValue sync_4(edm::EventID(1, 1, 4));
0077     const edm::IOVSyncValue sync_5(edm::EventID(1, 1, 5));
0078     const edm::ValidityInterval definedInterval(sync_1, sync_4);
0079     dummyFinder->setInterval(definedInterval);
0080     finders.push_back(dummyFinder);
0081 
0082     std::shared_ptr<DummyFinder> dummyFinder2 = std::make_shared<DummyFinder>();
0083     dummyFinder2->setInterval(edm::ValidityInterval(sync_3, sync_5));
0084     finders.push_back(dummyFinder2);
0085     IntersectingIOVRecordIntervalFinder intersectingFinder(dummyRecordKey);
0086     intersectingFinder.swapFinders(finders);
0087 
0088     CPPUNIT_ASSERT(edm::ValidityInterval(sync_3, sync_4) == intersectingFinder.findIntervalFor(dummyRecordKey, sync_3));
0089   }
0090 
0091   {
0092     finders.clear();
0093     const edm::IOVSyncValue sync_1(edm::EventID(1, 1, 1));
0094     const edm::IOVSyncValue sync_3(edm::EventID(1, 1, 3));
0095     const edm::IOVSyncValue sync_4(edm::EventID(1, 1, 4));
0096     const edm::ValidityInterval definedInterval(sync_1, sync_4);
0097     dummyFinder->setInterval(definedInterval);
0098     finders.push_back(dummyFinder);
0099 
0100     std::shared_ptr<DummyFinder> dummyFinder2 = std::make_shared<DummyFinder>();
0101     dummyFinder2->setInterval(edm::ValidityInterval::invalidInterval());
0102     finders.push_back(dummyFinder2);
0103     IntersectingIOVRecordIntervalFinder intersectingFinder(dummyRecordKey);
0104     intersectingFinder.swapFinders(finders);
0105 
0106     CPPUNIT_ASSERT(edm::ValidityInterval::invalidInterval() == dummyFinder2->findIntervalFor(dummyRecordKey, sync_3));
0107 
0108     CPPUNIT_ASSERT(edm::ValidityInterval(sync_1, edm::IOVSyncValue::invalidIOVSyncValue()) ==
0109                    intersectingFinder.findIntervalFor(dummyRecordKey, sync_3));
0110   }
0111 
0112   {
0113     finders.clear();
0114     const edm::IOVSyncValue sync_1(edm::EventID(1, 1, 1));
0115     const edm::IOVSyncValue sync_3(edm::EventID(1, 1, 3));
0116     const edm::IOVSyncValue sync_4(edm::EventID(1, 1, 4));
0117     const edm::ValidityInterval definedInterval(sync_1, sync_4);
0118     dummyFinder->setInterval(definedInterval);
0119     finders.push_back(dummyFinder);
0120 
0121     std::shared_ptr<DummyFinder> dummyFinder2 = std::make_shared<DummyFinder>();
0122     dummyFinder2->setInterval(edm::ValidityInterval(sync_3, edm::IOVSyncValue::invalidIOVSyncValue()));
0123     finders.push_back(dummyFinder2);
0124     IntersectingIOVRecordIntervalFinder intersectingFinder(dummyRecordKey);
0125     intersectingFinder.swapFinders(finders);
0126 
0127     CPPUNIT_ASSERT(edm::ValidityInterval(sync_3, edm::IOVSyncValue::invalidIOVSyncValue()) ==
0128                    dummyFinder2->findIntervalFor(dummyRecordKey, sync_3));
0129 
0130     CPPUNIT_ASSERT(edm::ValidityInterval(sync_3, edm::IOVSyncValue::invalidIOVSyncValue()) ==
0131                    intersectingFinder.findIntervalFor(dummyRecordKey, sync_3));
0132   }
0133 
0134   {
0135     //reverse order so invalid ending is first in list
0136     finders.clear();
0137     const edm::IOVSyncValue sync_1(edm::EventID(1, 1, 1));
0138     const edm::IOVSyncValue sync_3(edm::EventID(1, 1, 3));
0139     const edm::IOVSyncValue sync_4(edm::EventID(1, 1, 4));
0140     const edm::ValidityInterval definedInterval(sync_1, sync_4);
0141 
0142     std::shared_ptr<DummyFinder> dummyFinder2 = std::make_shared<DummyFinder>();
0143     dummyFinder2->setInterval(edm::ValidityInterval(sync_3, edm::IOVSyncValue::invalidIOVSyncValue()));
0144     finders.push_back(dummyFinder2);
0145 
0146     dummyFinder->setInterval(definedInterval);
0147     finders.push_back(dummyFinder);
0148 
0149     IntersectingIOVRecordIntervalFinder intersectingFinder(dummyRecordKey);
0150     intersectingFinder.swapFinders(finders);
0151 
0152     CPPUNIT_ASSERT(edm::ValidityInterval(sync_3, edm::IOVSyncValue::invalidIOVSyncValue()) ==
0153                    dummyFinder2->findIntervalFor(dummyRecordKey, sync_3));
0154 
0155     CPPUNIT_ASSERT(edm::ValidityInterval(sync_3, edm::IOVSyncValue::invalidIOVSyncValue()) ==
0156                    intersectingFinder.findIntervalFor(dummyRecordKey, sync_3));
0157   }
0158 }