Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:05:27

0001 #include "Utilities/Testing/interface/CppUnit_testdriver.icpp"
0002 #include "cppunit/extensions/HelperMacros.h"
0003 #include "DetectorDescription/Core/interface/Singleton.h"
0004 #include "DetectorDescription/Core/interface/Singleton.icc"
0005 
0006 class Dummy {
0007 public:
0008   Dummy(void) : value(100.) {}
0009 
0010   double value;
0011 };
0012 
0013 template class DDI::Singleton<Dummy>;
0014 
0015 class testSingleton : public CppUnit::TestFixture {
0016   CPPUNIT_TEST_SUITE(testSingleton);
0017   CPPUNIT_TEST(testEquality);
0018 
0019   CPPUNIT_TEST_SUITE_END();
0020 
0021 public:
0022   void setUp(void) override { m_s = &DDI::Singleton<Dummy>::instance(); }
0023 
0024   void testEquality(void);
0025 
0026 private:
0027   Dummy *m_s;
0028   Dummy *m_copy;
0029 };
0030 
0031 void testSingleton::testEquality(void) {
0032   m_s = &DDI::Singleton<Dummy>::instance();
0033   m_copy = &DDI::Singleton<Dummy>::instance();
0034 
0035   CPPUNIT_ASSERT(m_s != nullptr);
0036   CPPUNIT_ASSERT(m_copy != nullptr);
0037   CPPUNIT_ASSERT(m_s == m_copy);
0038   CPPUNIT_ASSERT(m_s->value == m_copy->value);
0039   m_s->value = 50.0;
0040   CPPUNIT_ASSERT(m_s->value == m_copy->value);
0041 }
0042 
0043 CPPUNIT_TEST_SUITE_REGISTRATION(testSingleton);