@@ -100,6 +100,7 @@ TEST_F(SensingBlocksTest, RegisterBlocks)
100100 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_distanceto" , &SensingBlocks::compileDistanceTo));
101101 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_keypressed" , &SensingBlocks::compileKeyPressed));
102102 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_mousedown" , &SensingBlocks::compileMouseDown));
103+ EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_mousex" , &SensingBlocks::compileMouseX));
103104 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_timer" , &SensingBlocks::compileTimer));
104105 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_resettimer" , &SensingBlocks::compileResetTimer));
105106 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_current" , &SensingBlocks::compileCurrent));
@@ -381,6 +382,47 @@ TEST_F(SensingBlocksTest, MouseDownImpl)
381382 ASSERT_EQ (vm.getInput (0 , 1 )->toBool (), false );
382383}
383384
385+ TEST_F (SensingBlocksTest, MouseX)
386+ {
387+ Compiler compiler (&m_engineMock);
388+
389+ auto block = std::make_shared<Block>(" a" , " sensing_mousex" );
390+
391+ EXPECT_CALL (m_engineMock, functionIndex (&SensingBlocks::mouseX)).WillOnce (Return (0 ));
392+ compiler.init ();
393+
394+ compiler.setBlock (block);
395+ SensingBlocks::compileMouseX (&compiler);
396+
397+ compiler.end ();
398+
399+ ASSERT_EQ (compiler.bytecode (), std::vector<unsigned int >({ vm::OP_START, vm::OP_EXEC, 0 , vm::OP_HALT }));
400+ ASSERT_TRUE (compiler.constValues ().empty ());
401+ }
402+
403+ TEST_F (SensingBlocksTest, MouseXImpl)
404+ {
405+ static unsigned int bytecode[] = { vm::OP_START, vm::OP_EXEC, 0 , vm::OP_HALT };
406+ static BlockFunc functions[] = { &SensingBlocks::mouseX };
407+
408+ VirtualMachine vm (nullptr , &m_engineMock, nullptr );
409+ vm.setFunctions (functions);
410+
411+ EXPECT_CALL (m_engineMock, mouseX ()).WillOnce (Return (48.165 ));
412+ vm.setBytecode (bytecode);
413+ vm.run ();
414+
415+ ASSERT_EQ (vm.registerCount (), 1 );
416+ ASSERT_EQ (vm.getInput (0 , 1 )->toDouble (), 48.165 );
417+
418+ EXPECT_CALL (m_engineMock, mouseX ()).WillOnce (Return (-239.09 ));
419+ vm.reset ();
420+ vm.run ();
421+
422+ ASSERT_EQ (vm.registerCount (), 1 );
423+ ASSERT_EQ (vm.getInput (0 , 1 )->toDouble (), -239.09 );
424+ }
425+
384426TEST_F (SensingBlocksTest, Timer)
385427{
386428 Compiler compiler (&m_engineMock);
0 commit comments