Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:29:09

0001 /*
0002  *  serviceregistry_t.cppunit.cc
0003  *  CMSSW
0004  *
0005  *  Created by Chris Jones on 9/7/05.
0006  *
0007  */
0008 #include <iostream>
0009 
0010 #include "FWCore/ServiceRegistry/interface/connect_but_block_self.h"
0011 
0012 #include <cppunit/extensions/HelperMacros.h>
0013 
0014 class testConnectButBlockSelf : public CppUnit::TestFixture {
0015   CPPUNIT_TEST_SUITE(testConnectButBlockSelf);
0016 
0017   CPPUNIT_TEST(test);
0018 
0019   CPPUNIT_TEST_SUITE_END();
0020 
0021 public:
0022   void setUp() {}
0023   void tearDown() {}
0024 
0025   void test();
0026 };
0027 
0028 ///registration of the test so that the runner can find it
0029 CPPUNIT_TEST_SUITE_REGISTRATION(testConnectButBlockSelf);
0030 
0031 namespace {
0032   struct ReSignaller {
0033     edm::signalslot::Signal<void()>* signal_;
0034     int& seen_;
0035 
0036     ReSignaller(edm::signalslot::Signal<void()>& iSig, int& iSee) : signal_(&iSig), seen_(iSee) {}
0037 
0038     void operator()() {
0039       //std::cout <<"see signal"<<std::endl;
0040       ++seen_;
0041       (*signal_)();
0042     }
0043   };
0044 }  // namespace
0045 
0046 void testConnectButBlockSelf::test() {
0047   using namespace edm::serviceregistry;
0048   edm::signalslot::Signal<void()> theSignal;
0049 
0050   int iOne(0);
0051   ReSignaller one(theSignal, iOne);
0052   connect_but_block_self(theSignal, one);
0053 
0054   int iTwo(0);
0055   ReSignaller two(theSignal, iTwo);
0056   connect_but_block_self(theSignal, two);
0057 
0058   theSignal();
0059 
0060   //std::cout <<"one "<<iOne <<std::endl;
0061   //std::cout <<"two "<<iTwo <<std::endl;
0062 
0063   //Both see two changes, but they never see their 'own' change
0064   CPPUNIT_ASSERT(iOne == 2);
0065   CPPUNIT_ASSERT(iTwo == 2);
0066 }