Skip to content

Commit 332dbaa

Browse files
committed
Use VirtualMachine instead of Value to update monitor values
1 parent 491dfff commit 332dbaa

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

include/scratchcpp/imonitorhandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class LIBSCRATCHCPP_EXPORT IMonitorHandler
1717

1818
virtual void init(Monitor *) = 0;
1919

20-
virtual void onValueChanged(const Value &value) = 0;
20+
virtual void onValueChanged(const VirtualMachine *vm) = 0;
2121
virtual void onVisibleChanged(bool visible) = 0;
2222
};
2323

include/scratchcpp/monitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class LIBSCRATCHCPP_EXPORT Monitor : public Entity
4949

5050
const std::string &opcode() const;
5151

52-
void updateValue(const Value &value);
52+
void updateValue(const VirtualMachine *vm);
5353

5454
unsigned int width() const;
5555
void setWidth(unsigned int width);

src/scratch/monitor.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,14 @@ const std::string &Monitor::opcode() const
8080
return impl->block->opcode();
8181
}
8282

83-
/*! Updates the monitor's value and notifies its interface about it (if there's any). */
84-
void Monitor::updateValue(const Value &value)
83+
/*!
84+
* Notifies the monitor's interface about value change.
85+
* The interaface is supposed to read it from the VirtualMachine.
86+
*/
87+
void Monitor::updateValue(const VirtualMachine *vm)
8588
{
8689
if (impl->iface)
87-
impl->iface->onValueChanged(value);
90+
impl->iface->onValueChanged(vm);
8891
}
8992

9093
/*! Returns the monitor's width. */

test/mocks/monitorhandlermock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@ class MonitorHandlerMock : public IMonitorHandler
1010
public:
1111
MOCK_METHOD(void, init, (Monitor *), (override));
1212

13-
MOCK_METHOD(void, onValueChanged, (const Value &), (override));
13+
MOCK_METHOD(void, onValueChanged, (const VirtualMachine *), (override));
1414
MOCK_METHOD(void, onVisibleChanged, (bool), (override));
1515
};

test/scratch_classes/monitor_test.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <scratchcpp/block.h>
33
#include <scratchcpp/sprite.h>
44
#include <scratchcpp/rect.h>
5+
#include <scratchcpp/virtualmachine.h>
56
#include <scratch/monitor_p.h>
67
#include <monitorhandlermock.h>
78
#include <randomgeneratormock.h>
@@ -91,17 +92,22 @@ TEST(MonitorTest, Sprite)
9192
TEST(MonitorTest, UpdateValue)
9293
{
9394
Monitor monitor("", "");
94-
monitor.updateValue(5);
95+
VirtualMachine vm1, vm2;
96+
monitor.updateValue(nullptr);
97+
monitor.updateValue(&vm1);
9598

9699
MonitorHandlerMock handler;
97100
EXPECT_CALL(handler, init);
98101
monitor.setInterface(&handler);
99102

100-
EXPECT_CALL(handler, onValueChanged(Value(6.5)));
101-
monitor.updateValue(6.5);
103+
EXPECT_CALL(handler, onValueChanged(&vm1));
104+
monitor.updateValue(&vm1);
102105

103-
EXPECT_CALL(handler, onValueChanged(Value("test")));
104-
monitor.updateValue("test");
106+
EXPECT_CALL(handler, onValueChanged(nullptr));
107+
monitor.updateValue(nullptr);
108+
109+
EXPECT_CALL(handler, onValueChanged(&vm2));
110+
monitor.updateValue(&vm2);
105111
}
106112

107113
TEST(MonitorTest, Width)

0 commit comments

Comments
 (0)