@@ -14,6 +14,7 @@ using namespace scratchcpprender;
1414using namespace libscratchcpp ;
1515
1616using ::testing::Return;
17+ using ::testing::ReturnRef;
1718
1819class ProjectLoaderTest : public testing ::Test
1920{
@@ -59,6 +60,11 @@ class ProjectLoaderTest : public testing::Test
5960 }
6061};
6162
63+ struct AnswerQuestionMock
64+ {
65+ MOCK_METHOD (void , answer, (const std::string &), ());
66+ };
67+
6268TEST_F (ProjectLoaderTest, Constructors)
6369{
6470 ProjectLoader loader1;
@@ -162,6 +168,38 @@ TEST_F(ProjectLoaderTest, TimerEvent)
162168 QCoreApplication::sendEvent (&loader, &event);
163169}
164170
171+ TEST_F (ProjectLoaderTest, QuestionAsked)
172+ {
173+ ProjectLoader loader;
174+ QSignalSpy spy (&loader, &ProjectLoader::questionAsked);
175+
176+ load (&loader, " load_test.sb3" );
177+
178+ auto engine = loader.engine ();
179+ auto f = engine->questionAsked ();
180+ ASSERT_TRUE (f);
181+ ASSERT_TRUE (spy.isEmpty ());
182+ f (" test" );
183+ ASSERT_EQ (spy.count (), 1 );
184+
185+ auto args = spy.takeFirst ();
186+ ASSERT_EQ (args.size (), 1 );
187+ ASSERT_EQ (args.first ().toString (), " test" );
188+ }
189+
190+ TEST_F (ProjectLoaderTest, AnswerQuestion)
191+ {
192+ ProjectLoader loader;
193+ EngineMock engine;
194+ loader.setEngine (&engine);
195+
196+ AnswerQuestionMock mock;
197+ std::function<void (const std::string &)> f = std::bind (&AnswerQuestionMock::answer, &mock, std::placeholders::_1);
198+ EXPECT_CALL (engine, questionAnswered ()).WillOnce (ReturnRef (f));
199+ EXPECT_CALL (mock, answer (" hello" ));
200+ loader.answerQuestion (" hello" );
201+ }
202+
165203TEST_F (ProjectLoaderTest, Fps)
166204{
167205 ProjectLoader loader;
0 commit comments