File indexing completed on 2024-04-06 12:13:15
0001
0002
0003
0004
0005
0006
0007 #include <cassert>
0008 #include <iostream>
0009 #include <string>
0010 #include <cppunit/extensions/HelperMacros.h>
0011 #include "FWCore/Utilities/interface/Signal.h"
0012
0013 class testSignal : public CppUnit::TestFixture {
0014 CPPUNIT_TEST_SUITE(testSignal);
0015
0016 CPPUNIT_TEST(connectTest);
0017 CPPUNIT_TEST(emitTest);
0018
0019 CPPUNIT_TEST_SUITE_END();
0020
0021 public:
0022 void setUp() {}
0023 void tearDown() {}
0024
0025 void connectTest();
0026 void emitTest();
0027 };
0028
0029
0030 CPPUNIT_TEST_SUITE_REGISTRATION(testSignal);
0031
0032 static int s_value = 0;
0033 static void setValueFunct(int iValue) { s_value = iValue; }
0034
0035 void testSignal::connectTest()
0036
0037 {
0038 edm::signalslot::Signal<void(int)> sig;
0039 CPPUNIT_ASSERT(sig.slots().size() == 0);
0040
0041 int value1 = 0;
0042 sig.connect([&](int iValue) -> void { value1 = iValue; });
0043
0044 CPPUNIT_ASSERT(sig.slots().size() == 1);
0045
0046 int value2 = 0;
0047 sig.connect([&](int iValue) { value2 = iValue; });
0048 CPPUNIT_ASSERT(sig.slots().size() == 2);
0049
0050 sig.connect(setValueFunct);
0051
0052 for (auto const& slot : sig.slots()) {
0053 slot(5);
0054 }
0055 CPPUNIT_ASSERT(value1 == 5);
0056 CPPUNIT_ASSERT(value2 == 5);
0057 CPPUNIT_ASSERT(value2 == s_value);
0058 }
0059
0060 void testSignal::emitTest() {
0061 edm::signalslot::Signal<void(int)> sig;
0062
0063 int value1 = 0;
0064 sig.connect([&](int iValue) { value1 = iValue; });
0065
0066 int value2 = 0;
0067 sig.connect([&](int iValue) { value2 = iValue; });
0068
0069 sig.emit(5);
0070 CPPUNIT_ASSERT(value1 == 5);
0071 CPPUNIT_ASSERT(value2 == 5);
0072
0073 sig.emit(1);
0074 CPPUNIT_ASSERT(value1 == 1);
0075 CPPUNIT_ASSERT(value2 == 1);
0076 }