Skip to content

Commit 798ddfe

Browse files
committed
Add PenBlocks class
1 parent e09d28b commit 798ddfe

File tree

6 files changed

+99
-0
lines changed

6 files changed

+99
-0
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ qt_add_qml_module(scratchcpp-render
5555
penlayerpainter.cpp
5656
penlayerpainter.h
5757
penattributes.h
58+
blocks/penblocks.cpp
59+
blocks/penblocks.h
5860
)
5961

6062
list(APPEND QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

src/blocks/penblocks.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// SPDX-License-Identifier: LGPL-3.0-or-later
2+
3+
#include "penblocks.h"
4+
5+
using namespace scratchcpprender;
6+
using namespace libscratchcpp;
7+
8+
std::string PenBlocks::name() const
9+
{
10+
return "Pen";
11+
}
12+
13+
void PenBlocks::registerBlocks(IEngine *engine)
14+
{
15+
}

src/blocks/penblocks.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: LGPL-3.0-or-later
2+
3+
#pragma once
4+
5+
#include <scratchcpp/iblocksection.h>
6+
7+
namespace scratchcpprender
8+
{
9+
10+
class PenBlocks : public libscratchcpp::IBlockSection
11+
{
12+
public:
13+
enum Inputs
14+
{
15+
};
16+
17+
std::string name() const override;
18+
19+
void registerBlocks(libscratchcpp::IEngine *engine) override;
20+
};
21+
22+
} // namespace scratchcpprender

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ add_subdirectory(skins)
3434
add_subdirectory(penattributes)
3535
add_subdirectory(penlayer)
3636
add_subdirectory(penlayerpainter)
37+
add_subdirectory(blocks)

test/blocks/CMakeLists.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# pen_blocks_test
2+
add_executable(
3+
pen_blocks_test
4+
pen_blocks_test.cpp
5+
)
6+
7+
target_link_libraries(
8+
pen_blocks_test
9+
GTest::gtest_main
10+
GTest::gmock_main
11+
scratchcpp-render
12+
scratchcpprender_mocks
13+
${QT_LIBS}
14+
)
15+
16+
add_test(pen_blocks_test)
17+
gtest_discover_tests(pen_blocks_test)

test/blocks/pen_blocks_test.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#include <scratchcpp/compiler.h>
2+
#include <scratchcpp/block.h>
3+
#include <scratchcpp/input.h>
4+
#include <blocks/penblocks.h>
5+
#include <enginemock.h>
6+
7+
#include "../common.h"
8+
9+
using namespace scratchcpprender;
10+
using namespace libscratchcpp;
11+
12+
class PenBlocksTest : public testing::Test
13+
{
14+
public:
15+
void SetUp() override { m_section = std::make_unique<PenBlocks>(); }
16+
17+
void addValueInput(std::shared_ptr<Block> block, const std::string &name, PenBlocks::Inputs id, const Value &value) const
18+
{
19+
auto input = std::make_shared<Input>(name, Input::Type::Shadow);
20+
input->setPrimaryValue(value);
21+
input->setInputId(id);
22+
block->addInput(input);
23+
}
24+
25+
std::unique_ptr<IBlockSection> m_section;
26+
EngineMock m_engineMock;
27+
};
28+
29+
TEST_F(PenBlocksTest, Name)
30+
{
31+
ASSERT_EQ(m_section->name(), "Pen");
32+
}
33+
34+
TEST_F(PenBlocksTest, CategoryVisible)
35+
{
36+
ASSERT_TRUE(m_section->categoryVisible());
37+
}
38+
39+
TEST_F(PenBlocksTest, RegisterBlocks)
40+
{
41+
m_section->registerBlocks(&m_engineMock);
42+
}

0 commit comments

Comments
 (0)