Make all individual scripts smart pointers.
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -19,9 +19,10 @@ public:
|
||||
};
|
||||
|
||||
TEST_CASE("Script Aggregator properly iterates containing script.", "[Battling, Scripting]") {
|
||||
Script* script = new TestScript("test");
|
||||
auto script = std::make_unique<TestScript>("test");
|
||||
auto ran = 0;
|
||||
auto vec = ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(&script)};
|
||||
auto vec =
|
||||
ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script))};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
@@ -29,16 +30,17 @@ TEST_CASE("Script Aggregator properly iterates containing script.", "[Battling,
|
||||
dynamic_cast<TestScript*>(next)->TestMethod(ran);
|
||||
}
|
||||
CHECK(ran == 1);
|
||||
delete script;
|
||||
}
|
||||
|
||||
TEST_CASE("Script Aggregator properly iterates multiple scripts.", "[Battling, Scripting]") {
|
||||
Script* script = new TestScript("test");
|
||||
Script* script2 = new TestScript("test2");
|
||||
Script* script3 = new TestScript("test3");
|
||||
auto script = std::make_unique<TestScript>("test");
|
||||
auto script2 = std::make_unique<TestScript>("test2");
|
||||
auto script3 = std::make_unique<TestScript>("test3");
|
||||
auto ran = 0;
|
||||
auto vec = ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(&script), ScriptWrapper::FromScript(&script2),
|
||||
ScriptWrapper::FromScript(&script3)};
|
||||
auto vec =
|
||||
ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script)),
|
||||
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script2)),
|
||||
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script3))};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNext();
|
||||
@@ -46,9 +48,6 @@ TEST_CASE("Script Aggregator properly iterates multiple scripts.", "[Battling, S
|
||||
dynamic_cast<TestScript*>(next)->TestMethod(ran);
|
||||
}
|
||||
CHECK(ran == 3);
|
||||
delete script;
|
||||
delete script2;
|
||||
delete script3;
|
||||
}
|
||||
|
||||
TEST_CASE("Script Aggregator properly iterates Script Set.", "[Battling, Scripting]") {
|
||||
@@ -71,14 +70,15 @@ TEST_CASE("Script Aggregator properly iterates Script Set.", "[Battling, Scripti
|
||||
}
|
||||
|
||||
TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.", "[Battling, Scripting]") {
|
||||
Script* script = new TestScript("test");
|
||||
auto script = std::make_unique<TestScript>("test");
|
||||
Script* script2 = new TestScript("test2");
|
||||
Script* script3 = new TestScript("test3");
|
||||
auto ran = 0;
|
||||
auto set = ScriptSet();
|
||||
set.Add(script2);
|
||||
set.Add(script3);
|
||||
auto vec = ArbUt::List<ScriptWrapper>{ScriptWrapper::FromSet(&set), ScriptWrapper::FromScript(&script)};
|
||||
auto vec = ArbUt::List<ScriptWrapper>{
|
||||
ScriptWrapper::FromSet(&set), ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script))};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNextNotNull();
|
||||
@@ -86,18 +86,18 @@ TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.",
|
||||
dynamic_cast<TestScript*>(next)->TestMethod(ran);
|
||||
}
|
||||
CHECK(ran == 3);
|
||||
delete script;
|
||||
}
|
||||
|
||||
TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.", "[Battling, Scripting]") {
|
||||
Script* script = new TestScript("test");
|
||||
auto script = std::make_unique<TestScript>("test");
|
||||
Script* script2 = new TestScript("test2");
|
||||
Script* script3 = new TestScript("test3");
|
||||
auto ran = 0;
|
||||
auto set = ScriptSet();
|
||||
set.Add(script2);
|
||||
set.Add(script3);
|
||||
auto vec = ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(&script), ScriptWrapper::FromSet(&set)};
|
||||
auto vec = ArbUt::List<ScriptWrapper>{
|
||||
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script)), ScriptWrapper::FromSet(&set)};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNextNotNull();
|
||||
@@ -105,20 +105,20 @@ TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.",
|
||||
dynamic_cast<TestScript*>(next)->TestMethod(ran);
|
||||
}
|
||||
CHECK(ran == 3);
|
||||
delete script;
|
||||
}
|
||||
|
||||
TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Script.", "[Battling, Scripting]") {
|
||||
Script* script = new TestScript("test");
|
||||
auto script = std::make_unique<TestScript>("test");
|
||||
Script* script2 = new TestScript("test2");
|
||||
Script* script3 = new TestScript("test3");
|
||||
Script* script4 = new TestScript("test4");
|
||||
auto script4 = std::make_unique<TestScript>("test4");
|
||||
auto ran = 0;
|
||||
auto set = ScriptSet();
|
||||
set.Add(script2);
|
||||
set.Add(script3);
|
||||
auto vec = ArbUt::List<ScriptWrapper>{ScriptWrapper::FromScript(&script), ScriptWrapper::FromSet(&set),
|
||||
ScriptWrapper::FromScript(&script4)};
|
||||
auto vec = ArbUt::List<ScriptWrapper>{
|
||||
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script)), ScriptWrapper::FromSet(&set),
|
||||
ScriptWrapper::FromScript(reinterpret_cast<std::unique_ptr<Script>*>(&script4))};
|
||||
auto aggr = ScriptAggregator(vec);
|
||||
while (aggr.HasNext()) {
|
||||
auto next = aggr.GetNextNotNull();
|
||||
@@ -126,8 +126,6 @@ TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Sc
|
||||
dynamic_cast<TestScript*>(next)->TestMethod(ran);
|
||||
}
|
||||
CHECK(ran == 4);
|
||||
delete script;
|
||||
delete script4;
|
||||
}
|
||||
|
||||
TEST_CASE("Script Aggregator properly iterates when empty.", "[Battling, Scripting]") {
|
||||
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
|
||||
class ScriptSourceWithScriptPtr : public ScriptSource {
|
||||
public:
|
||||
Script* ScriptPtr = nullptr;
|
||||
std::unique_ptr<Script> ScriptPtr = nullptr;
|
||||
|
||||
protected:
|
||||
size_t ScriptCount() const override { return 1; }
|
||||
@@ -50,11 +50,10 @@ TEST_CASE("Script source with unset script ptr.", "[Battling, Scripting]") {
|
||||
|
||||
TEST_CASE("Script source with script ptr being set.", "[Battling, Scripting]") {
|
||||
auto source = ScriptSourceWithScriptPtr();
|
||||
source.ScriptPtr = new TestScript("foobar");
|
||||
source.ScriptPtr = std::make_unique<TestScript>("foobar");
|
||||
auto scripts = source.GetScriptIterator();
|
||||
auto first = scripts.GetNext();
|
||||
CHECK(first != nullptr);
|
||||
delete source.ScriptPtr;
|
||||
}
|
||||
|
||||
TEST_CASE("Script source with script ptr being set after first iteration.", "[Battling, Scripting]") {
|
||||
@@ -62,11 +61,10 @@ TEST_CASE("Script source with script ptr being set after first iteration.", "[Ba
|
||||
auto scripts = source.GetScriptIterator();
|
||||
auto first = scripts.GetNext();
|
||||
CHECK(first == nullptr);
|
||||
source.ScriptPtr = new TestScript("foobar");
|
||||
source.ScriptPtr = std::make_unique<TestScript>("foobar");
|
||||
scripts = source.GetScriptIterator();
|
||||
first = scripts.GetNext();
|
||||
CHECK(first != nullptr);
|
||||
delete source.ScriptPtr;
|
||||
}
|
||||
|
||||
TEST_CASE("Script source with empty script set.", "[Battling, Scripting]") {
|
||||
|
||||
Reference in New Issue
Block a user