Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-18 22:30:24

0001 /*
0002  *  sharedresourcesregistry_t.cppunit.cc
0003  *  CMSSW
0004  *
0005  *  Created by Chris Jones on 8/8/05.
0006  *
0007  */
0008 
0009 #include "cppunit/extensions/HelperMacros.h"
0010 
0011 #define SHAREDRESOURCETESTACCESSORS 1
0012 #include "FWCore/Framework/interface/SharedResourcesRegistry.h"
0013 #include "FWCore/Framework/interface/SharedResourcesAcquirer.h"
0014 
0015 using namespace edm;
0016 
0017 class testSharedResourcesRegistry : public CppUnit::TestFixture {
0018   CPPUNIT_TEST_SUITE(testSharedResourcesRegistry);
0019 
0020   CPPUNIT_TEST(oneTest);
0021   CPPUNIT_TEST(legacyTest);
0022   CPPUNIT_TEST(multipleTest);
0023 
0024   CPPUNIT_TEST_SUITE_END();
0025 
0026 public:
0027   void setUp() {}
0028   void tearDown() {}
0029 
0030   void oneTest();
0031   void legacyTest();
0032   void multipleTest();
0033 };
0034 
0035 ///registration of the test so that the runner can find it
0036 CPPUNIT_TEST_SUITE_REGISTRATION(testSharedResourcesRegistry);
0037 
0038 void testSharedResourcesRegistry::oneTest() {
0039   edm::SharedResourcesRegistry reg;
0040 
0041   CPPUNIT_ASSERT(reg.resourceMap().size() == 0);
0042 
0043   reg.registerSharedResource("foo");
0044   reg.registerSharedResource("bar");
0045   reg.registerSharedResource("zoo");
0046 
0047   {
0048     std::vector<std::string> res{"foo", "bar", "zoo"};
0049     auto tester = reg.createAcquirer(res);
0050 
0051     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0052   }
0053   {
0054     std::vector<std::string> res{"foo"};
0055     auto tester = reg.createAcquirer(res);
0056 
0057     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0058   }
0059 }
0060 
0061 void testSharedResourcesRegistry::legacyTest() {
0062   std::vector<std::string> res{edm::SharedResourcesRegistry::kLegacyModuleResourceName};
0063   {
0064     edm::SharedResourcesRegistry reg;
0065 
0066     reg.registerSharedResource(edm::SharedResourcesRegistry::kLegacyModuleResourceName);
0067     auto tester = reg.createAcquirer(res);
0068 
0069     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0070   }
0071   {
0072     edm::SharedResourcesRegistry reg;
0073 
0074     reg.registerSharedResource(edm::SharedResourcesRegistry::kLegacyModuleResourceName);
0075     reg.registerSharedResource(edm::SharedResourcesRegistry::kLegacyModuleResourceName);
0076 
0077     auto tester = reg.createAcquirer(res);
0078 
0079     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0080   }
0081   {
0082     edm::SharedResourcesRegistry reg;
0083 
0084     reg.registerSharedResource("foo");
0085     reg.registerSharedResource("zoo");
0086 
0087     auto const& resourceMap = reg.resourceMap();
0088     CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).first.get() == nullptr);
0089     CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).first.get() == nullptr);
0090     CPPUNIT_ASSERT(resourceMap.size() == 2);
0091     CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).second == 1);
0092     CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).second == 1);
0093 
0094     reg.registerSharedResource(edm::SharedResourcesRegistry::kLegacyModuleResourceName);
0095     CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).first.get() != nullptr);
0096     CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).first.get() != nullptr);
0097     CPPUNIT_ASSERT(resourceMap.at(edm::SharedResourcesRegistry::kLegacyModuleResourceName).first.get() != nullptr);
0098     CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).second == 2);
0099     CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).second == 2);
0100     CPPUNIT_ASSERT(resourceMap.at(edm::SharedResourcesRegistry::kLegacyModuleResourceName).second == 1);
0101     CPPUNIT_ASSERT(resourceMap.size() == 3);
0102 
0103     reg.registerSharedResource(edm::SharedResourcesRegistry::kLegacyModuleResourceName);
0104     reg.registerSharedResource("bar");
0105     reg.registerSharedResource("zoo");
0106     CPPUNIT_ASSERT(resourceMap.at(std::string("bar")).first.get() != nullptr);
0107     CPPUNIT_ASSERT(resourceMap.at(std::string("bar")).second == 3);
0108     CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).second == 3);
0109     CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).second == 4);
0110     CPPUNIT_ASSERT(resourceMap.at(edm::SharedResourcesRegistry::kLegacyModuleResourceName).second == 2);
0111 
0112     auto tester = reg.createAcquirer(res);
0113 
0114     CPPUNIT_ASSERT(3 == tester.numberOfResources());
0115   }
0116 }
0117 
0118 void testSharedResourcesRegistry::multipleTest() {
0119   edm::SharedResourcesRegistry reg;
0120   auto const& resourceMap = reg.resourceMap();
0121 
0122   reg.registerSharedResource("foo");
0123   reg.registerSharedResource("bar");
0124   reg.registerSharedResource("zoo");
0125   reg.registerSharedResource("zoo");
0126   reg.registerSharedResource("bar");
0127   reg.registerSharedResource("zoo");
0128 
0129   CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).first.get() == nullptr);
0130   CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).first.get() != nullptr);
0131   CPPUNIT_ASSERT(resourceMap.at(std::string("bar")).first.get() != nullptr);
0132   CPPUNIT_ASSERT(resourceMap.at(std::string("bar")).second == 2);
0133   CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).second == 1);
0134   CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).second == 3);
0135   CPPUNIT_ASSERT(resourceMap.size() == 3);
0136 
0137   {
0138     std::vector<std::string> res{"foo", "bar", "zoo"};
0139     auto tester = reg.createAcquirer(res);
0140 
0141     CPPUNIT_ASSERT(2 == tester.numberOfResources());
0142   }
0143   {
0144     std::vector<std::string> res{"foo"};
0145     auto tester = reg.createAcquirer(res);
0146 
0147     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0148   }
0149   {
0150     std::vector<std::string> res{"bar"};
0151     auto tester = reg.createAcquirer(res);
0152 
0153     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0154   }
0155 }