|
4 | 4 | #include <scratchcpp/compiler.h> |
5 | 5 | #include <scratchcpp/script.h> |
6 | 6 | #include <scratchcpp/thread.h> |
| 7 | +#include <scratchcpp/list.h> |
7 | 8 | #include <scratchcpp/test/scriptbuilder.h> |
8 | 9 | #include <scratch/sound_p.h> |
9 | 10 | #include <enginemock.h> |
@@ -1088,3 +1089,41 @@ TEST_F(SoundBlocksTest, SetVolumeTo_Stage) |
1088 | 1089 | builder.run(); |
1089 | 1090 | ASSERT_EQ(stage->volume(), 38.4); |
1090 | 1091 | } |
| 1092 | + |
| 1093 | +TEST_F(SoundBlocksTest, Volume_Sprite) |
| 1094 | +{ |
| 1095 | + auto sprite = std::make_shared<Sprite>(); |
| 1096 | + sprite->setVolume(50); |
| 1097 | + |
| 1098 | + ScriptBuilder builder(m_extension.get(), m_engine, sprite); |
| 1099 | + builder.addBlock("sound_volume"); |
| 1100 | + builder.captureBlockReturnValue(); |
| 1101 | + builder.build(); |
| 1102 | + |
| 1103 | + sprite->setVolume(1.9); |
| 1104 | + builder.run(); |
| 1105 | + ASSERT_EQ(sprite->volume(), 1.9); |
| 1106 | + |
| 1107 | + List *list = builder.capturedValues(); |
| 1108 | + ASSERT_EQ(list->size(), 1); |
| 1109 | + ASSERT_EQ(Value(list->data()[0]).toDouble(), 1.9); |
| 1110 | +} |
| 1111 | + |
| 1112 | +TEST_F(SoundBlocksTest, Volume_Stage) |
| 1113 | +{ |
| 1114 | + auto stage = std::make_shared<Stage>(); |
| 1115 | + stage->setVolume(75); |
| 1116 | + |
| 1117 | + ScriptBuilder builder(m_extension.get(), m_engine, stage); |
| 1118 | + builder.addBlock("sound_volume"); |
| 1119 | + builder.captureBlockReturnValue(); |
| 1120 | + builder.build(); |
| 1121 | + |
| 1122 | + stage->setVolume(43.7); |
| 1123 | + builder.run(); |
| 1124 | + ASSERT_EQ(stage->volume(), 43.7); |
| 1125 | + |
| 1126 | + List *list = builder.capturedValues(); |
| 1127 | + ASSERT_EQ(list->size(), 1); |
| 1128 | + ASSERT_EQ(Value(list->data()[0]).toDouble(), 43.7); |
| 1129 | +} |
0 commit comments