2019-11-17 09:27:18 +00:00
|
|
|
#ifdef TESTS_BUILD
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include "../../../extern/catch.hpp"
|
|
|
|
#include "../../../src/Battling/ScriptHandling/ScriptSet.hpp"
|
|
|
|
|
|
|
|
using namespace CreatureLib;
|
|
|
|
using namespace CreatureLib::Battling;
|
|
|
|
|
2020-02-23 11:58:13 +00:00
|
|
|
class TestScript : public Script {
|
|
|
|
private:
|
2020-05-26 16:31:06 +00:00
|
|
|
ArbUt::CaseInsensitiveConstString _name;
|
2020-02-23 11:58:13 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TestScript(std::string name) : _name(std::move(name)){};
|
2020-05-26 16:31:06 +00:00
|
|
|
const ArbUt::CaseInsensitiveConstString& GetName() const noexcept override { return _name; }
|
2020-02-23 11:58:13 +00:00
|
|
|
};
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Empty script set count == 0", "[Battling, Scripting]") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
|
|
|
REQUIRE(set.Count() == 0);
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Add script to script set", "[Battling, Scripting]") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
REQUIRE(set.Count() == 1);
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Add script to script set, then retrieve it", "[Battling, Scripting]") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
REQUIRE(set.Count() == 1);
|
2020-06-02 13:03:31 +00:00
|
|
|
auto get = set.GetIterator().At(0);
|
2019-11-17 09:27:18 +00:00
|
|
|
REQUIRE(get->GetName() == "foobar");
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Add two scripts to script set", "[Battling, Scripting]") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
|
|
|
auto s2 = new TestScript("foobar2");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
set.Add(s2);
|
|
|
|
REQUIRE(set.Count() == 2);
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Add two scripts to script set, then retrieve them", "[Battling, Scripting]") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
|
|
|
auto s2 = new TestScript("foobar2");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
set.Add(s2);
|
|
|
|
REQUIRE(set.Count() == 2);
|
2020-06-02 13:03:31 +00:00
|
|
|
auto get1 = set.GetIterator().At(0);
|
|
|
|
auto get2 = set.GetIterator().At(1);
|
2019-11-17 09:27:18 +00:00
|
|
|
REQUIRE(get1->GetName() == "foobar");
|
|
|
|
REQUIRE(get2->GetName() == "foobar2");
|
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Add script to script set, then remove it", "[Battling, Scripting]") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
REQUIRE(set.Count() == 1);
|
2020-04-09 16:19:21 +00:00
|
|
|
set.Remove("foobar"_cnc.GetHash());
|
2019-11-17 09:27:18 +00:00
|
|
|
REQUIRE(set.Count() == 0);
|
2020-06-02 13:03:31 +00:00
|
|
|
auto& it = set.GetIterator();
|
|
|
|
REQUIRE(it.Count() == 0);
|
2019-11-17 09:27:18 +00:00
|
|
|
}
|
|
|
|
|
2019-11-28 11:55:22 +00:00
|
|
|
TEST_CASE("Add two scripts to script set, then remove them", "[Battling, Scripting]") {
|
2019-11-17 09:27:18 +00:00
|
|
|
auto set = ScriptSet();
|
2020-02-23 11:58:13 +00:00
|
|
|
auto s = new TestScript("foobar");
|
|
|
|
auto s2 = new TestScript("foobar2");
|
2019-11-17 09:27:18 +00:00
|
|
|
set.Add(s);
|
|
|
|
set.Add(s2);
|
|
|
|
REQUIRE(set.Count() == 2);
|
2020-04-09 16:19:21 +00:00
|
|
|
set.Remove("foobar"_cnc.GetHash());
|
2019-11-17 09:27:18 +00:00
|
|
|
REQUIRE(set.Count() == 1);
|
2020-06-02 13:03:31 +00:00
|
|
|
auto& it = set.GetIterator();
|
|
|
|
REQUIRE(it.At(0)->GetName() == "foobar2");
|
2019-11-17 09:27:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|