|
| 1 | +#include <scratchcpp/project.h> |
| 2 | +#include <scratchcpp/sprite.h> |
| 3 | +#include <scratchcpp/list.h> |
| 4 | +#include <scratchcpp/dev/compiler.h> |
| 5 | +#include <scratchcpp/dev/test/scriptbuilder.h> |
1 | 6 | #include <enginemock.h> |
2 | 7 |
|
3 | 8 | #include "../common.h" |
4 | 9 | #include "dev/blocks/operatorblocks.h" |
5 | 10 |
|
6 | 11 | using namespace libscratchcpp; |
| 12 | +using namespace libscratchcpp::test; |
7 | 13 |
|
8 | 14 | class OperatorBlocksTest : public testing::Test |
9 | 15 | { |
10 | 16 | public: |
11 | | - void SetUp() override { m_extension = std::make_unique<OperatorBlocks>(); } |
| 17 | + void SetUp() override |
| 18 | + { |
| 19 | + m_extension = std::make_unique<OperatorBlocks>(); |
| 20 | + m_engine = m_project.engine().get(); |
| 21 | + m_extension->registerBlocks(m_engine); |
| 22 | + } |
12 | 23 |
|
13 | 24 | std::unique_ptr<IExtension> m_extension; |
| 25 | + Project m_project; |
| 26 | + IEngine *m_engine = nullptr; |
14 | 27 | EngineMock m_engineMock; |
15 | 28 | }; |
| 29 | + |
| 30 | +TEST_F(OperatorBlocksTest, Add) |
| 31 | +{ |
| 32 | + auto target = std::make_shared<Sprite>(); |
| 33 | + ScriptBuilder builder(m_extension.get(), m_engine, target); |
| 34 | + |
| 35 | + builder.addBlock("operator_add"); |
| 36 | + builder.addValueInput("NUM1", 5.7); |
| 37 | + builder.addValueInput("NUM2", 2.5); |
| 38 | + builder.captureBlockReturnValue(); |
| 39 | + |
| 40 | + builder.build(); |
| 41 | + builder.run(); |
| 42 | + |
| 43 | + List *valueList = builder.capturedValues(); |
| 44 | + ValueData *values = valueList->data(); |
| 45 | + ASSERT_EQ(valueList->size(), 1); |
| 46 | + ASSERT_EQ(Value(values[0]), 8.2); |
| 47 | +} |
0 commit comments