Skip to content

Commit 235e5df

Browse files
authored
Merge pull request #485 from scratchcpp/monitor_section_and_name_setters
Add monitor block section and name setters
2 parents e5fa752 + 963a0bd commit 235e5df

File tree

6 files changed

+66
-0
lines changed

6 files changed

+66
-0
lines changed

include/scratchcpp/monitor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class LIBSCRATCHCPP_EXPORT Monitor : public Entity
3838
void setInterface(IMonitorHandler *iface);
3939

4040
const std::string &name() const;
41+
void setName(const std::string &name);
4142

4243
Mode mode() const;
4344
void setMode(Mode mode);
@@ -48,6 +49,7 @@ class LIBSCRATCHCPP_EXPORT Monitor : public Entity
4849
void setScript(std::shared_ptr<Script> script);
4950

5051
std::shared_ptr<IBlockSection> blockSection() const;
52+
void setBlockSection(std::shared_ptr<IBlockSection> blockSection);
5153

5254
Sprite *sprite() const;
5355
void setSprite(Sprite *sprite);

src/scratch/monitor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ const std::string &Monitor::name() const
4141
return impl->name;
4242
}
4343

44+
/*! Sets the name of this monitor. */
45+
void Monitor::setName(const std::string &name)
46+
{
47+
impl->name = name;
48+
}
49+
4450
/*! Returns the monitor's mode. */
4551
Monitor::Mode Monitor::mode() const
4652
{
@@ -80,6 +86,12 @@ std::shared_ptr<IBlockSection> Monitor::blockSection() const
8086
return impl->blockSection;
8187
}
8288

89+
/*! Sets the block section of this monitor. */
90+
void Monitor::setBlockSection(std::shared_ptr<IBlockSection> blockSection)
91+
{
92+
impl->blockSection = blockSection;
93+
}
94+
8395
/*! Convenience method which calls block()->target(). */
8496
Sprite *Monitor::sprite() const
8597
{

test/scratch_classes/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ gtest_discover_tests(comment_test)
222222
add_executable(
223223
monitor_test
224224
monitor_test.cpp
225+
testsection.cpp
226+
testsection.h
225227
)
226228

227229
target_link_libraries(

test/scratch_classes/monitor_test.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <randomgeneratormock.h>
1010

1111
#include "../common.h"
12+
#include "testsection.h"
1213

1314
using namespace libscratchcpp;
1415

@@ -47,6 +48,15 @@ TEST(MonitorTest, Interface)
4748
monitor.setInterface(&iface);
4849
}
4950

51+
TEST(MonitorTest, Name)
52+
{
53+
Monitor monitor("", "");
54+
ASSERT_TRUE(monitor.name().empty());
55+
56+
monitor.setName("test");
57+
ASSERT_EQ(monitor.name(), "test");
58+
}
59+
5060
TEST(MonitorTest, Mode)
5161
{
5262
Monitor monitor("", "");
@@ -75,6 +85,16 @@ TEST(MonitorTest, Script)
7585
ASSERT_EQ(monitor.script(), script);
7686
}
7787

88+
TEST(MonitorTest, BlockSection)
89+
{
90+
Monitor monitor("", "");
91+
ASSERT_EQ(monitor.blockSection(), nullptr);
92+
93+
auto section = std::make_shared<TestSection>();
94+
monitor.setBlockSection(section);
95+
ASSERT_EQ(monitor.blockSection(), section);
96+
}
97+
7898
TEST(MonitorTest, Sprite)
7999
{
80100
Monitor monitor("", "");
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include <scratchcpp/iengine.h>
2+
3+
#include "testsection.h"
4+
5+
using namespace libscratchcpp;
6+
7+
std::string TestSection::name() const
8+
{
9+
return "Test";
10+
}
11+
12+
void TestSection::registerBlocks(IEngine *engine)
13+
{
14+
}

test/scratch_classes/testsection.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#pragma once
2+
3+
#include <scratchcpp/iblocksection.h>
4+
5+
namespace libscratchcpp
6+
{
7+
8+
class TestSection : public IBlockSection
9+
{
10+
public:
11+
std::string name() const override;
12+
13+
void registerBlocks(IEngine *engine) override;
14+
};
15+
16+
} // namespace libscratchcpp

0 commit comments

Comments
 (0)