|
3 | 3 | #include <scratchcpp/variable.h> |
4 | 4 | #include <scratchcpp/list.h> |
5 | 5 | #include <scratchcpp/compiler.h> |
| 6 | +#include <scratchcpp/monitor.h> |
| 7 | +#include <scratchcpp/block.h> |
6 | 8 | #include <scratchcpp/test/scriptbuilder.h> |
7 | 9 | #include <enginemock.h> |
8 | 10 |
|
@@ -55,6 +57,41 @@ TEST_F(VariableBlocksTest, Variable) |
55 | 57 | ASSERT_EQ(Value(values[1]), "Hello world"); |
56 | 58 | } |
57 | 59 |
|
| 60 | +TEST_F(VariableBlocksTest, VariableMonitor) |
| 61 | +{ |
| 62 | + auto target = std::make_shared<Sprite>(); |
| 63 | + auto var1 = std::make_shared<Variable>("", "var1", 835.21); |
| 64 | + target->addVariable(var1); |
| 65 | + auto var2 = std::make_shared<Variable>("", "var2", "Hello world"); |
| 66 | + target->addVariable(var2); |
| 67 | + |
| 68 | + auto monitor1 = std::make_shared<Monitor>("monitor", "data_variable"); |
| 69 | + auto monitor2 = std::make_shared<Monitor>("monitor", "data_variable"); |
| 70 | + monitor1->block()->setTarget(target.get()); |
| 71 | + monitor2->block()->setTarget(target.get()); |
| 72 | + m_engine->setMonitors({ monitor1, monitor2 }); |
| 73 | + |
| 74 | + ScriptBuilder builder1(m_extension.get(), m_engine, target); |
| 75 | + builder1.addBlock(monitor1->block()); |
| 76 | + builder1.addEntityField("VARIABLE", var1); |
| 77 | + |
| 78 | + ScriptBuilder builder2(m_extension.get(), m_engine, target); |
| 79 | + builder2.addBlock(monitor2->block()); |
| 80 | + builder2.addEntityField("VARIABLE", var2); |
| 81 | + |
| 82 | + m_engine->compile(); |
| 83 | + ASSERT_EQ(monitor1->name(), var1->name()); |
| 84 | + ASSERT_EQ(monitor2->name(), var2->name()); |
| 85 | + |
| 86 | + monitor1->changeValue("test"); |
| 87 | + ASSERT_EQ(var1->value().toString(), "test"); |
| 88 | + ASSERT_EQ(var2->value().toString(), "Hello world"); |
| 89 | + |
| 90 | + monitor2->changeValue(-0.25); |
| 91 | + ASSERT_EQ(var1->value().toString(), "test"); |
| 92 | + ASSERT_EQ(var2->value().toDouble(), -0.25); |
| 93 | +} |
| 94 | + |
58 | 95 | TEST_F(VariableBlocksTest, SetVariableTo) |
59 | 96 | { |
60 | 97 | auto target = std::make_shared<Sprite>(); |
|
0 commit comments