55#include < scratchcpp/stage.h>
66#include < scratchcpp/variable.h>
77#include < scratchcpp/list.h>
8+ #include < scratchcpp/executioncontext.h>
89#include < enginemock.h>
910#include < executablecodemock.h>
1011
@@ -14,6 +15,7 @@ using namespace libscratchcpp;
1415
1516using ::testing::Return;
1617using ::testing::ReturnRef;
18+ using ::testing::Invoke;
1719using ::testing::_;
1820
1921class ScriptTest : public testing ::Test
@@ -51,6 +53,28 @@ TEST_F(ScriptTest, HatPredicateCode)
5153 ASSERT_EQ (script.hatPredicateCode (), code.get ());
5254}
5355
56+ TEST_F (ScriptTest, RunHatPredicate)
57+ {
58+ Script script (nullptr , nullptr , &m_engine);
59+ auto code = std::make_shared<ExecutableCodeMock>();
60+ std::shared_ptr<ExecutionContext> ctx;
61+ script.setHatPredicateCode (code);
62+
63+ EXPECT_CALL (*code, createExecutionContext (_)).WillRepeatedly (Invoke ([&ctx](Thread *thread) {
64+ ctx = std::make_shared<ExecutionContext>(thread);
65+ return ctx;
66+ }));
67+
68+ EXPECT_CALL (*code, runPredicate (_)).WillOnce (Return (true ));
69+ ASSERT_TRUE (script.runHatPredicate (&m_target));
70+
71+ EXPECT_CALL (*code, runPredicate (_)).WillOnce (Return (true ));
72+ ASSERT_TRUE (script.runHatPredicate (&m_target));
73+
74+ EXPECT_CALL (*code, runPredicate (_)).WillOnce (Return (false ));
75+ ASSERT_FALSE (script.runHatPredicate (&m_target));
76+ }
77+
5478TEST_F (ScriptTest, Start)
5579{
5680 Script script1 (nullptr , nullptr , nullptr );
0 commit comments