Cleanup of ScriptAggregator class.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2020-04-23 23:23:58 +02:00
parent 3a11bba913
commit dd668f2b1c
11 changed files with 89 additions and 75 deletions

View File

@@ -21,7 +21,7 @@ public:
TEST_CASE("Script Aggregator properly iterates containing script.", "[Battling, Scripting]") {
Script* script = new TestScript("test");
auto ran = 0;
auto vec = Arbutils::Collections::List<ScriptWrapper>{&script};
auto vec = Arbutils::Collections::List<ScriptWrapper>{ScriptWrapper::FromScript(&script)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
@@ -37,7 +37,8 @@ TEST_CASE("Script Aggregator properly iterates multiple scripts.", "[Battling, S
Script* script2 = new TestScript("test2");
Script* script3 = new TestScript("test3");
auto ran = 0;
auto vec = Arbutils::Collections::List<ScriptWrapper>{&script, &script2, &script3};
auto vec = Arbutils::Collections::List<ScriptWrapper>{
ScriptWrapper::FromScript(&script), ScriptWrapper::FromScript(&script2), ScriptWrapper::FromScript(&script3)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
@@ -59,10 +60,10 @@ TEST_CASE("Script Aggregator properly iterates Script Set.", "[Battling, Scripti
set.Add(script);
set.Add(script2);
set.Add(script3);
auto vec = Arbutils::Collections::List<ScriptWrapper>{&set};
auto vec = Arbutils::Collections::List<ScriptWrapper>{ScriptWrapper::FromSet(&set)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
}
@@ -77,10 +78,11 @@ TEST_CASE("Script Aggregator properly iterates data of Script Set and Script.",
auto set = ScriptSet();
set.Add(script2);
set.Add(script3);
auto vec = Arbutils::Collections::List<ScriptWrapper>{&set, &script};
auto vec =
Arbutils::Collections::List<ScriptWrapper>{ScriptWrapper::FromSet(&set), ScriptWrapper::FromScript(&script)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
}
@@ -96,10 +98,11 @@ TEST_CASE("Script Aggregator properly iterates data of Script and Script Set.",
auto set = ScriptSet();
set.Add(script2);
set.Add(script3);
auto vec = Arbutils::Collections::List<ScriptWrapper>{&script, &set};
auto vec =
Arbutils::Collections::List<ScriptWrapper>{ScriptWrapper::FromScript(&script), ScriptWrapper::FromSet(&set)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
}
@@ -116,10 +119,11 @@ TEST_CASE("Script Aggregator properly iterates data of Script, Script Set and Sc
auto set = ScriptSet();
set.Add(script2);
set.Add(script3);
auto vec = Arbutils::Collections::List<ScriptWrapper>{&script, &set, &script4};
auto vec = Arbutils::Collections::List<ScriptWrapper>{
ScriptWrapper::FromScript(&script), ScriptWrapper::FromSet(&set), ScriptWrapper::FromScript(&script4)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();
auto next = aggr.GetNextNotNull();
REQUIRE(next != nullptr);
dynamic_cast<TestScript*>(next)->TestMethod(ran);
}
@@ -141,7 +145,7 @@ TEST_CASE("Script Aggregator properly iterates when empty.", "[Battling, Scripti
TEST_CASE("Script Aggregator properly iterates empty Script Set.", "[Battling, Scripting]") {
auto ran = 0;
auto set = ScriptSet();
auto vec = Arbutils::Collections::List<ScriptWrapper>{&set};
auto vec = Arbutils::Collections::List<ScriptWrapper>{ScriptWrapper::FromSet(&set)};
auto aggr = ScriptAggregator(vec);
while (aggr.HasNext()) {
auto next = aggr.GetNext();

View File

@@ -24,7 +24,9 @@ public:
Script* ScriptPtr = nullptr;
protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override { scripts.Append(&ScriptPtr); }
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
scripts.Append(ScriptWrapper::FromScript(&ScriptPtr));
}
};
class ScriptSourceWithScriptSet : public ScriptSource {
@@ -32,7 +34,9 @@ public:
ScriptSet Set;
protected:
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override { scripts.Append(&Set); }
void GetActiveScripts(Arbutils::Collections::List<ScriptWrapper>& scripts) override {
scripts.Append(ScriptWrapper::FromSet(&Set));
}
};
TEST_CASE("Script source with unset script ptr.", "[Battling, Scripting]") {
@@ -75,7 +79,7 @@ TEST_CASE("Script source with single item script set.", "[Battling, Scripting]")
auto s = new TestScript("foobar");
source.Set.Add(s);
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
auto first = scripts.GetNextNotNull();
CHECK(first != nullptr);
CHECK(first->GetName() == "foobar");
}
@@ -87,11 +91,11 @@ TEST_CASE("Script source with multiple item script set.", "[Battling, Scripting]
source.Set.Add(s);
source.Set.Add(s2);
auto scripts = source.GetScriptIterator();
auto first = scripts.GetNext();
CHECK(first != nullptr);
auto first = scripts.GetNextNotNull();
REQUIRE(first != nullptr);
CHECK(first->GetName() == "foobar");
auto second = scripts.GetNext();
CHECK(second != nullptr);
auto second = scripts.GetNextNotNull();
REQUIRE(second != nullptr);
CHECK(second->GetName() == "foobar2");
}