File tree Expand file tree Collapse file tree 6 files changed +66
-0
lines changed Expand file tree Collapse file tree 6 files changed +66
-0
lines changed Original file line number Diff line number Diff 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);
Original file line number Diff line number Diff 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. */
4551Monitor::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(). */
8496Sprite *Monitor::sprite () const
8597{
Original file line number Diff line number Diff line change @@ -222,6 +222,8 @@ gtest_discover_tests(comment_test)
222222add_executable (
223223 monitor_test
224224 monitor_test.cpp
225+ testsection.cpp
226+ testsection.h
225227)
226228
227229target_link_libraries (
Original file line number Diff line number Diff line change 99#include < randomgeneratormock.h>
1010
1111#include " ../common.h"
12+ #include " testsection.h"
1213
1314using 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+
5060TEST (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+
7898TEST (MonitorTest, Sprite)
7999{
80100 Monitor monitor (" " , " " );
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments