|
2 | 2 | #include <scratchcpp/block.h> |
3 | 3 | #include <scratchcpp/input.h> |
4 | 4 | #include <scratchcpp/field.h> |
| 5 | +#include <scratchcpp/sprite.h> |
5 | 6 | #include <enginemock.h> |
6 | 7 |
|
7 | 8 | #include "../common.h" |
@@ -90,5 +91,48 @@ TEST_F(LooksBlocksTest, CategoryVisible) |
90 | 91 |
|
91 | 92 | TEST_F(LooksBlocksTest, RegisterBlocks) |
92 | 93 | { |
| 94 | + // Blocks |
| 95 | + EXPECT_CALL(m_engineMock, addCompileFunction(m_section.get(), "looks_show", &LooksBlocks::compileShow)); |
| 96 | + |
93 | 97 | m_section->registerBlocks(&m_engineMock); |
94 | 98 | } |
| 99 | + |
| 100 | +TEST_F(LooksBlocksTest, Show) |
| 101 | +{ |
| 102 | + Compiler compiler(&m_engineMock); |
| 103 | + |
| 104 | + auto block = std::make_shared<Block>("a", "looks_show"); |
| 105 | + |
| 106 | + EXPECT_CALL(m_engineMock, functionIndex(&LooksBlocks::show)).WillOnce(Return(0)); |
| 107 | + |
| 108 | + compiler.init(); |
| 109 | + compiler.setBlock(block); |
| 110 | + LooksBlocks::compileShow(&compiler); |
| 111 | + compiler.end(); |
| 112 | + |
| 113 | + ASSERT_EQ(compiler.bytecode(), std::vector<unsigned int>({ vm::OP_START, vm::OP_EXEC, 0, vm::OP_HALT })); |
| 114 | + ASSERT_TRUE(compiler.constValues().empty()); |
| 115 | +} |
| 116 | + |
| 117 | +TEST_F(LooksBlocksTest, ShowImpl) |
| 118 | +{ |
| 119 | + static unsigned int bytecode[] = { vm::OP_START, vm::OP_EXEC, 0, vm::OP_HALT }; |
| 120 | + static BlockFunc functions[] = { &LooksBlocks::show }; |
| 121 | + |
| 122 | + Sprite sprite; |
| 123 | + sprite.setVisible(false); |
| 124 | + |
| 125 | + VirtualMachine vm(&sprite, nullptr, nullptr); |
| 126 | + vm.setBytecode(bytecode); |
| 127 | + vm.setFunctions(functions); |
| 128 | + vm.run(); |
| 129 | + |
| 130 | + ASSERT_EQ(vm.registerCount(), 0); |
| 131 | + ASSERT_TRUE(sprite.visible()); |
| 132 | + |
| 133 | + vm.reset(); |
| 134 | + vm.run(); |
| 135 | + |
| 136 | + ASSERT_EQ(vm.registerCount(), 0); |
| 137 | + ASSERT_TRUE(sprite.visible()); |
| 138 | +} |
0 commit comments