@@ -132,6 +132,7 @@ TEST_F(SensingBlocksTest, RegisterBlocks)
132132 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_mousey" , &SensingBlocks::compileMouseY));
133133 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_setdragmode" , &SensingBlocks::compileSetDragMode));
134134 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_loudness" , &SensingBlocks::compileLoudness));
135+ EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_loud" , &SensingBlocks::compileLoud));
135136 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_timer" , &SensingBlocks::compileTimer));
136137 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_resettimer" , &SensingBlocks::compileResetTimer));
137138 EXPECT_CALL (m_engineMock, addCompileFunction (m_section.get (), " sensing_of" , &SensingBlocks::compileOf));
@@ -804,6 +805,84 @@ TEST_F(SensingBlocksTest, LoudnessImpl)
804805 SensingBlocks::audioInput = nullptr ;
805806}
806807
808+ TEST_F (SensingBlocksTest, Loud)
809+ {
810+ Compiler compiler (&m_engineMock);
811+
812+ auto block = std::make_shared<Block>(" a" , " sensing_loud" );
813+
814+ EXPECT_CALL (m_engineMock, functionIndex (&SensingBlocks::loud)).WillOnce (Return (0 ));
815+ compiler.init ();
816+
817+ compiler.setBlock (block);
818+ SensingBlocks::compileLoud (&compiler);
819+
820+ compiler.end ();
821+
822+ ASSERT_EQ (compiler.bytecode (), std::vector<unsigned int >({ vm::OP_START, vm::OP_EXEC, 0 , vm::OP_HALT }));
823+ ASSERT_TRUE (compiler.constValues ().empty ());
824+ }
825+
826+ TEST_F (SensingBlocksTest, LoudImpl)
827+ {
828+ static unsigned int bytecode[] = { vm::OP_START, vm::OP_EXEC, 0 , vm::OP_HALT };
829+ static BlockFunc functions[] = { &SensingBlocks::loud };
830+
831+ VirtualMachine vm (nullptr , &m_engineMock, nullptr );
832+ vm.setFunctions (functions);
833+
834+ vm.setBytecode (bytecode);
835+ vm.run ();
836+
837+ ASSERT_EQ (vm.registerCount (), 1 );
838+
839+ AudioInputMock audioInput;
840+ auto audioLoudness = std::make_shared<AudioLoudnessMock>();
841+ SensingBlocks::audioInput = &audioInput;
842+
843+ EXPECT_CALL (audioInput, audioLoudness ()).WillOnce (Return (audioLoudness));
844+ EXPECT_CALL (*audioLoudness, getLoudness ()).WillOnce (Return (-1 ));
845+ vm.reset ();
846+ vm.run ();
847+
848+ ASSERT_EQ (vm.registerCount (), 1 );
849+ ASSERT_FALSE (vm.getInput (0 , 1 )->toBool ());
850+
851+ EXPECT_CALL (audioInput, audioLoudness ()).WillOnce (Return (audioLoudness));
852+ EXPECT_CALL (*audioLoudness, getLoudness ()).WillOnce (Return (62 ));
853+ vm.reset ();
854+ vm.run ();
855+
856+ ASSERT_EQ (vm.registerCount (), 1 );
857+ ASSERT_TRUE (vm.getInput (0 , 1 )->toBool ());
858+
859+ EXPECT_CALL (audioInput, audioLoudness ()).WillOnce (Return (audioLoudness));
860+ EXPECT_CALL (*audioLoudness, getLoudness ()).WillOnce (Return (9 ));
861+ vm.reset ();
862+ vm.run ();
863+
864+ ASSERT_EQ (vm.registerCount (), 1 );
865+ ASSERT_FALSE (vm.getInput (0 , 1 )->toBool ());
866+
867+ EXPECT_CALL (audioInput, audioLoudness ()).WillOnce (Return (audioLoudness));
868+ EXPECT_CALL (*audioLoudness, getLoudness ()).WillOnce (Return (10 ));
869+ vm.reset ();
870+ vm.run ();
871+
872+ ASSERT_EQ (vm.registerCount (), 1 );
873+ ASSERT_FALSE (vm.getInput (0 , 1 )->toBool ());
874+
875+ EXPECT_CALL (audioInput, audioLoudness ()).WillOnce (Return (audioLoudness));
876+ EXPECT_CALL (*audioLoudness, getLoudness ()).WillOnce (Return (11 ));
877+ vm.reset ();
878+ vm.run ();
879+
880+ ASSERT_EQ (vm.registerCount (), 1 );
881+ ASSERT_TRUE (vm.getInput (0 , 1 )->toBool ());
882+
883+ SensingBlocks::audioInput = nullptr ;
884+ }
885+
807886TEST_F (SensingBlocksTest, Timer)
808887{
809888 Compiler compiler (&m_engineMock);
0 commit comments