@@ -102,14 +102,6 @@ struct QuestionSpy
102102 MOCK_METHOD (void , asked, (const std::string &), ());
103103};
104104
105- template <typename T, typename ... U>
106- size_t getAddress (std::function<T(U...)> f)
107- {
108- typedef T (fnType)(U...);
109- fnType **fnPointer = f.template target <fnType *>();
110- return (size_t )*fnPointer;
111- }
112-
113105TEST_F (SensingBlocksTest, Name)
114106{
115107 ASSERT_EQ (m_section->name (), " Sensing" );
@@ -181,13 +173,13 @@ TEST_F(SensingBlocksTest, RegisterBlocks)
181173 EXPECT_CALL (m_engineMock, addFieldValue (m_section.get (), " backdrop name" , SensingBlocks::BackdropName));
182174
183175 // Callbacks
184- std::function<void (const std::string &)> questionAnsweredRef = &SensingBlocks::onAnswer;
185- std::function<void (const std::string &)> questionAnswered;
186- EXPECT_CALL (m_engineMock, setQuestionAnswered (_)).WillOnce (SaveArg<0 >(&questionAnswered));
176+ sigslot::signal<const std::string &> questionAnswered;
177+ EXPECT_CALL (m_engineMock, questionAnswered ()).WillOnce (ReturnRef (questionAnswered));
187178
188179 m_section->registerBlocks (&m_engineMock);
189- ASSERT_TRUE (questionAnswered);
190- ASSERT_EQ (getAddress (questionAnsweredRef), getAddress (questionAnswered));
180+
181+ ASSERT_EQ (questionAnswered.slot_count (), 1 );
182+ ASSERT_EQ (questionAnswered.disconnect (&SensingBlocks::onAnswer), 1 );
191183}
192184
193185TEST_F (SensingBlocksTest, DistanceTo)
@@ -381,14 +373,16 @@ TEST_F(SensingBlocksTest, AskAndWaitAndAnswerImpl)
381373 sprite.setBubbleType (Target::BubbleType::Think);
382374 Stage stage;
383375 QuestionSpy spy;
384- std::function<void (const std::string &)> asked = std::bind (&QuestionSpy::asked, &spy, std::placeholders::_1);
376+ auto asked = std::bind (&QuestionSpy::asked, &spy, std::placeholders::_1);
377+ sigslot::signal<const std::string &> askedSignal;
378+ askedSignal.connect (asked);
385379
386380 VirtualMachine vm1 (&sprite, &m_engineMock, nullptr );
387381 vm1.setFunctions (functions);
388382 vm1.setConstValues (constValues);
389383
390384 // Ask 3 questions (2 where the sprite is visible and 1 where it's invisible)
391- EXPECT_CALL (m_engineMock, questionAsked ()).WillOnce (ReturnRef (asked ));
385+ EXPECT_CALL (m_engineMock, questionAsked ()).WillOnce (ReturnRef (askedSignal ));
392386 EXPECT_CALL (spy, asked (" " ));
393387 sprite.setVisible (true );
394388 vm1.setBytecode (bytecode1);
@@ -435,7 +429,7 @@ TEST_F(SensingBlocksTest, AskAndWaitAndAnswerImpl)
435429 ASSERT_EQ (sprite.bubbleText (), " test1" );
436430
437431 // Answer the questions
438- EXPECT_CALL (m_engineMock, questionAsked ()).WillOnce (ReturnRef (asked ));
432+ EXPECT_CALL (m_engineMock, questionAsked ()).WillOnce (ReturnRef (askedSignal ));
439433 EXPECT_CALL (spy, asked (" " ));
440434 SensingBlocks::onAnswer (" hi" );
441435 ASSERT_EQ (sprite.bubbleType (), Target::BubbleType::Say);
@@ -447,7 +441,7 @@ TEST_F(SensingBlocksTest, AskAndWaitAndAnswerImpl)
447441 ASSERT_EQ (vm1.registerCount (), 1 );
448442 ASSERT_EQ (vm1.getInput (0 , 1 )->toString (), " hi" );
449443
450- EXPECT_CALL (m_engineMock, questionAsked ()).WillOnce (ReturnRef (asked ));
444+ EXPECT_CALL (m_engineMock, questionAsked ()).WillOnce (ReturnRef (askedSignal ));
451445 EXPECT_CALL (spy, asked (" test3" ));
452446 SensingBlocks::onAnswer (" hello" );
453447 ASSERT_TRUE (sprite.bubbleText ().empty ());
@@ -457,7 +451,7 @@ TEST_F(SensingBlocksTest, AskAndWaitAndAnswerImpl)
457451 ASSERT_EQ (vm1.registerCount (), 1 );
458452 ASSERT_EQ (vm1.getInput (0 , 1 )->toString (), " hello" );
459453
460- EXPECT_CALL (m_engineMock, questionAsked ()).WillOnce (ReturnRef (asked ));
454+ EXPECT_CALL (m_engineMock, questionAsked ()).WillOnce (ReturnRef (askedSignal ));
461455 EXPECT_CALL (spy, asked (" test2" ));
462456 SensingBlocks::onAnswer (" world" );
463457 ASSERT_TRUE (sprite.bubbleText ().empty ());
0 commit comments