@@ -101,6 +101,7 @@ TEST_F(SensingBlocksTest, RegisterBlocks)
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));
103103 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_mousex" , &SensingBlocks::compileMouseX));
104+ EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_mousey" , &SensingBlocks::compileMouseY));
104105 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_timer" , &SensingBlocks::compileTimer));
105106 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_resettimer" , &SensingBlocks::compileResetTimer));
106107 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_current" , &SensingBlocks::compileCurrent));
@@ -423,6 +424,47 @@ TEST_F(SensingBlocksTest, MouseXImpl)
423424 ASSERT_EQ (vm.getInput (0 , 1 )->toDouble (), -239.09 );
424425}
425426
427+ TEST_F (SensingBlocksTest, MouseY)
428+ {
429+ Compiler compiler (&m_engineMock);
430+
431+ auto block = std::make_shared<Block>(" a" , " sensing_mousey" );
432+
433+ EXPECT_CALL (m_engineMock, functionIndex (&SensingBlocks::mouseY)).WillOnce (Return (0 ));
434+ compiler.init ();
435+
436+ compiler.setBlock (block);
437+ SensingBlocks::compileMouseY (&compiler);
438+
439+ compiler.end ();
440+
441+ ASSERT_EQ (compiler.bytecode (), std::vector<unsigned int >({ vm::OP_START, vm::OP_EXEC, 0 , vm::OP_HALT }));
442+ ASSERT_TRUE (compiler.constValues ().empty ());
443+ }
444+
445+ TEST_F (SensingBlocksTest, MouseYImpl)
446+ {
447+ static unsigned int bytecode[] = { vm::OP_START, vm::OP_EXEC, 0 , vm::OP_HALT };
448+ static BlockFunc functions[] = { &SensingBlocks::mouseY };
449+
450+ VirtualMachine vm (nullptr , &m_engineMock, nullptr );
451+ vm.setFunctions (functions);
452+
453+ EXPECT_CALL (m_engineMock, mouseY ()).WillOnce (Return (159.084 ));
454+ vm.setBytecode (bytecode);
455+ vm.run ();
456+
457+ ASSERT_EQ (vm.registerCount (), 1 );
458+ ASSERT_EQ (vm.getInput (0 , 1 )->toDouble (), 159.084 );
459+
460+ EXPECT_CALL (m_engineMock, mouseY ()).WillOnce (Return (-95.564 ));
461+ vm.reset ();
462+ vm.run ();
463+
464+ ASSERT_EQ (vm.registerCount (), 1 );
465+ ASSERT_EQ (vm.getInput (0 , 1 )->toDouble (), -95.564 );
466+ }
467+
426468TEST_F (SensingBlocksTest, Timer)
427469{
428470 Compiler compiler (&m_engineMock);
0 commit comments