|
3 | 3 | #include <scratchcpp/sprite.h> |
4 | 4 | #include <scratchcpp/rect.h> |
5 | 5 | #include <scratchcpp/virtualmachine.h> |
| 6 | +#include <scratchcpp/script.h> |
6 | 7 | #include <scratch/monitor_p.h> |
7 | 8 | #include <monitorhandlermock.h> |
8 | 9 | #include <randomgeneratormock.h> |
|
12 | 13 | using namespace libscratchcpp; |
13 | 14 |
|
14 | 15 | using ::testing::Return; |
| 16 | +using ::testing::SaveArg; |
| 17 | +using ::testing::_; |
15 | 18 |
|
16 | 19 | static const int PADDING = 5; |
17 | 20 | static const int SCREEN_WIDTH = 400; |
@@ -110,6 +113,32 @@ TEST(MonitorTest, UpdateValue) |
110 | 113 | monitor.updateValue(&vm2); |
111 | 114 | } |
112 | 115 |
|
| 116 | +TEST(MonitorTest, ChangeValue) |
| 117 | +{ |
| 118 | + Monitor monitor("", "test_block"); |
| 119 | + monitor.changeValue(6.2); |
| 120 | + |
| 121 | + MonitorHandlerMock handler; |
| 122 | + EXPECT_CALL(handler, init); |
| 123 | + monitor.setInterface(&handler); |
| 124 | + |
| 125 | + const VirtualMachine *vm = nullptr; |
| 126 | + EXPECT_CALL(handler, onValueChanged(_)).WillOnce(SaveArg<0>(&vm)); |
| 127 | + monitor.changeValue(0.25); |
| 128 | + ASSERT_TRUE(vm); |
| 129 | + ASSERT_EQ(vm->registerCount(), 1); |
| 130 | + ASSERT_EQ(vm->getInput(0, 1)->toDouble(), 0.25); |
| 131 | + |
| 132 | + monitor.setValueChangeFunction([](Block *block, const Value &newValue) { std::cout << block->opcode() + " " + newValue.toString() << std::endl; }); |
| 133 | + EXPECT_CALL(handler, onValueChanged(_)).WillOnce(SaveArg<0>(&vm)); |
| 134 | + testing::internal::CaptureStdout(); |
| 135 | + monitor.changeValue("test"); |
| 136 | + ASSERT_TRUE(vm); |
| 137 | + ASSERT_EQ(vm->registerCount(), 1); |
| 138 | + ASSERT_EQ(vm->getInput(0, 1)->toString(), "test"); |
| 139 | + ASSERT_EQ(testing::internal::GetCapturedStdout(), "test_block test\n"); |
| 140 | +} |
| 141 | + |
113 | 142 | TEST(MonitorTest, Width) |
114 | 143 | { |
115 | 144 | Monitor monitor("", ""); |
|
0 commit comments