|
| 1 | +#include <scratchcpp/project.h> |
| 2 | +#include <scratchcpp/test/scriptbuilder.h> |
| 3 | +#include <scratchcpp/sprite.h> |
| 4 | +#include <scratchcpp/stage.h> |
| 5 | +#include <scratchcpp/textbubble.h> |
1 | 6 | #include <enginemock.h> |
| 7 | +#include <graphicseffectmock.h> |
2 | 8 |
|
3 | 9 | #include "../common.h" |
4 | 10 | #include "blocks/looksblocks.h" |
5 | 11 |
|
6 | 12 | using namespace libscratchcpp; |
7 | 13 |
|
| 14 | +using ::testing::Return; |
| 15 | + |
8 | 16 | class LooksBlocksTest : public testing::Test |
9 | 17 | { |
10 | 18 | public: |
11 | | - void SetUp() override { m_extension = std::make_unique<LooksBlocks>(); } |
| 19 | + void SetUp() override |
| 20 | + { |
| 21 | + m_extension = std::make_unique<LooksBlocks>(); |
| 22 | + m_engine = m_project.engine().get(); |
| 23 | + m_extension->registerBlocks(m_engine); |
| 24 | + m_extension->onInit(m_engine); |
| 25 | + } |
12 | 26 |
|
13 | 27 | std::unique_ptr<IExtension> m_extension; |
| 28 | + Project m_project; |
| 29 | + IEngine *m_engine = nullptr; |
14 | 30 | EngineMock m_engineMock; |
15 | 31 | }; |
| 32 | + |
| 33 | +TEST_F(LooksBlocksTest, StopProject) |
| 34 | +{ |
| 35 | + auto stage = std::make_shared<Stage>(); |
| 36 | + auto sprite = std::make_shared<Sprite>(); |
| 37 | + GraphicsEffectMock effect; |
| 38 | + m_engine->setTargets({ stage, sprite }); |
| 39 | + |
| 40 | + stage->bubble()->setText("abc"); |
| 41 | + sprite->bubble()->setText("def"); |
| 42 | + EXPECT_CALL(effect, clamp(10)).WillOnce(Return(10)); |
| 43 | + sprite->setGraphicsEffectValue(&effect, 10); |
| 44 | + EXPECT_CALL(effect, clamp(2.5)).WillOnce(Return(2.5)); |
| 45 | + stage->setGraphicsEffectValue(&effect, 2.5); |
| 46 | + |
| 47 | + m_engine->stop(); |
| 48 | + ASSERT_TRUE(stage->bubble()->text().empty()); |
| 49 | + ASSERT_TRUE(sprite->bubble()->text().empty()); |
| 50 | + ASSERT_EQ(stage->graphicsEffectValue(&effect), 0); |
| 51 | + ASSERT_EQ(sprite->graphicsEffectValue(&effect), 0); |
| 52 | +} |
0 commit comments