|
| 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/listblocks.h" |
5 | 10 |
|
6 | 11 | using namespace libscratchcpp; |
| 12 | +using namespace libscratchcpp::test; |
7 | 13 |
|
8 | 14 | class ListBlocksTest : public testing::Test |
9 | 15 | { |
10 | 16 | public: |
11 | | - void SetUp() override { m_extension = std::make_unique<ListBlocks>(); } |
| 17 | + void SetUp() override |
| 18 | + { |
| 19 | + m_extension = std::make_unique<ListBlocks>(); |
| 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(ListBlocksTest, AddToList) |
| 31 | +{ |
| 32 | + auto target = std::make_shared<Sprite>(); |
| 33 | + auto list1 = std::make_shared<List>("", ""); |
| 34 | + target->addList(list1); |
| 35 | + auto list2 = std::make_shared<List>("", ""); |
| 36 | + target->addList(list2); |
| 37 | + |
| 38 | + ScriptBuilder builder(m_extension.get(), m_engine, target); |
| 39 | + |
| 40 | + builder.addBlock("data_addtolist"); |
| 41 | + builder.addValueInput("ITEM", "test"); |
| 42 | + builder.addEntityField("LIST", list1); |
| 43 | + |
| 44 | + builder.addBlock("data_addtolist"); |
| 45 | + builder.addValueInput("ITEM", true); |
| 46 | + builder.addEntityField("LIST", list1); |
| 47 | + |
| 48 | + builder.addBlock("data_addtolist"); |
| 49 | + builder.addValueInput("ITEM", 123); |
| 50 | + builder.addEntityField("LIST", list2); |
| 51 | + |
| 52 | + builder.addBlock("data_addtolist"); |
| 53 | + builder.addValueInput("ITEM", "Hello world"); |
| 54 | + builder.addEntityField("LIST", list2); |
| 55 | + |
| 56 | + builder.build(); |
| 57 | + |
| 58 | + builder.run(); |
| 59 | + ASSERT_EQ(list1->toString(), "test true"); |
| 60 | + ASSERT_EQ(list2->toString(), "123 Hello world"); |
| 61 | +} |
0 commit comments