Skip to content
Next Next commit
Add PenBlocks class
  • Loading branch information
adazem009 committed Jan 22, 2024
commit 798ddfe5f2498939693fc3f70c65d3b9d5775389
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ qt_add_qml_module(scratchcpp-render
penlayerpainter.cpp
penlayerpainter.h
penattributes.h
blocks/penblocks.cpp
blocks/penblocks.h
)

list(APPEND QML_IMPORT_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
Expand Down
15 changes: 15 additions & 0 deletions src/blocks/penblocks.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#include "penblocks.h"

using namespace scratchcpprender;
using namespace libscratchcpp;

std::string PenBlocks::name() const
{
return "Pen";
}

void PenBlocks::registerBlocks(IEngine *engine)
{
}
22 changes: 22 additions & 0 deletions src/blocks/penblocks.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: LGPL-3.0-or-later

#pragma once

#include <scratchcpp/iblocksection.h>

namespace scratchcpprender
{

class PenBlocks : public libscratchcpp::IBlockSection
{
public:
enum Inputs
{
};

std::string name() const override;

void registerBlocks(libscratchcpp::IEngine *engine) override;
};

} // namespace scratchcpprender
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ add_subdirectory(skins)
add_subdirectory(penattributes)
add_subdirectory(penlayer)
add_subdirectory(penlayerpainter)
add_subdirectory(blocks)
17 changes: 17 additions & 0 deletions test/blocks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# pen_blocks_test
add_executable(
pen_blocks_test
pen_blocks_test.cpp
)

target_link_libraries(
pen_blocks_test
GTest::gtest_main
GTest::gmock_main
scratchcpp-render
scratchcpprender_mocks
${QT_LIBS}
)

add_test(pen_blocks_test)
gtest_discover_tests(pen_blocks_test)
42 changes: 42 additions & 0 deletions test/blocks/pen_blocks_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <scratchcpp/compiler.h>
#include <scratchcpp/block.h>
#include <scratchcpp/input.h>
#include <blocks/penblocks.h>
#include <enginemock.h>

#include "../common.h"

using namespace scratchcpprender;
using namespace libscratchcpp;

class PenBlocksTest : public testing::Test
{
public:
void SetUp() override { m_section = std::make_unique<PenBlocks>(); }

void addValueInput(std::shared_ptr<Block> block, const std::string &name, PenBlocks::Inputs id, const Value &value) const
{
auto input = std::make_shared<Input>(name, Input::Type::Shadow);
input->setPrimaryValue(value);
input->setInputId(id);
block->addInput(input);
}

std::unique_ptr<IBlockSection> m_section;
EngineMock m_engineMock;
};

TEST_F(PenBlocksTest, Name)
{
ASSERT_EQ(m_section->name(), "Pen");
}

TEST_F(PenBlocksTest, CategoryVisible)
{
ASSERT_TRUE(m_section->categoryVisible());
}

TEST_F(PenBlocksTest, RegisterBlocks)
{
m_section->registerBlocks(&m_engineMock);
}