Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:12:28

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(multipleTest);
0022 
0023   CPPUNIT_TEST_SUITE_END();
0024 
0025 public:
0026   void setUp() {}
0027   void tearDown() {}
0028 
0029   void oneTest();
0030   void multipleTest();
0031 };
0032 
0033 ///registration of the test so that the runner can find it
0034 CPPUNIT_TEST_SUITE_REGISTRATION(testSharedResourcesRegistry);
0035 
0036 void testSharedResourcesRegistry::oneTest() {
0037   edm::SharedResourcesRegistry reg;
0038 
0039   CPPUNIT_ASSERT(reg.resourceMap().size() == 0);
0040 
0041   reg.registerSharedResource("foo");
0042   reg.registerSharedResource("bar");
0043   reg.registerSharedResource("zoo");
0044 
0045   {
0046     std::vector<std::string> res{"foo", "bar", "zoo"};
0047     auto tester = reg.createAcquirer(res);
0048 
0049     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0050   }
0051   {
0052     std::vector<std::string> res{"foo"};
0053     auto tester = reg.createAcquirer(res);
0054 
0055     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0056   }
0057 }
0058 
0059 void testSharedResourcesRegistry::multipleTest() {
0060   edm::SharedResourcesRegistry reg;
0061   auto const& resourceMap = reg.resourceMap();
0062 
0063   reg.registerSharedResource("foo");
0064   reg.registerSharedResource("bar");
0065   reg.registerSharedResource("zoo");
0066   reg.registerSharedResource("zoo");
0067   reg.registerSharedResource("bar");
0068   reg.registerSharedResource("zoo");
0069 
0070   CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).first.get() == nullptr);
0071   CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).first.get() != nullptr);
0072   CPPUNIT_ASSERT(resourceMap.at(std::string("bar")).first.get() != nullptr);
0073   CPPUNIT_ASSERT(resourceMap.at(std::string("bar")).second == 2);
0074   CPPUNIT_ASSERT(resourceMap.at(std::string("foo")).second == 1);
0075   CPPUNIT_ASSERT(resourceMap.at(std::string("zoo")).second == 3);
0076   CPPUNIT_ASSERT(resourceMap.size() == 3);
0077 
0078   {
0079     std::vector<std::string> res{"foo", "bar", "zoo"};
0080     auto tester = reg.createAcquirer(res);
0081 
0082     CPPUNIT_ASSERT(2 == tester.numberOfResources());
0083   }
0084   {
0085     std::vector<std::string> res{"foo"};
0086     auto tester = reg.createAcquirer(res);
0087 
0088     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0089   }
0090   {
0091     std::vector<std::string> res{"bar"};
0092     auto tester = reg.createAcquirer(res);
0093 
0094     CPPUNIT_ASSERT(1 == tester.numberOfResources());
0095   }
0096 }