#if TESTS_BUILD and ANGELSCRIPT #include #include "../../src/Battling/Pokemon/CreatePokemon.hpp" #include "../../src/ScriptResolving/AngelScript/AngelScriptResolver.hpp" #include "../../TestLibrary/TestLibrary.hpp" #define AS_CLASS(name, contents) \ { #name, "namespace Pokemon{ [ItemUse effect=" #name "] class " #name " : ItemUseScript { " contents "}}" } static std::unordered_map _scripts = std::unordered_map{ AS_CLASS(blankClass, R"( )"), AS_CLASS(isItemUsable, R"( bool IsItemUsable() override { return true; } )"), AS_CLASS(isPokemonUseItem, R"( bool IsPokemonUseItem() override { return true; } )"), }; static AngelScriptResolver* _resolverCache = nullptr; static AngelScriptResolver* GetScriptResolver(PkmnLib::Battling::BattleLibrary* mainLib) { if (_resolverCache != nullptr) { delete _resolverCache; } _resolverCache = dynamic_cast(PkmnLib::Battling::BattleLibrary::CreateScriptResolver()); _resolverCache->Initialize(mainLib); for (auto kv : _scripts) { _resolverCache->CreateScript(kv.first, kv.second); } _resolverCache->FinalizeModule(); return _resolverCache; } static AngelScriptItemUseScript* GetScript(PkmnLib::Battling::BattleLibrary* mainLib, const ArbUt::StringView& name) { auto lib = GetScriptResolver(mainLib); auto item = CreatureLib::Library::Item(name, CreatureLib::Library::ItemCategory::MiscItem, CreatureLib::Library::BattleItemCategory::None, 0, new CreatureLib::Library::SecondaryEffect(100, name, {}), nullptr, {}); auto s = lib->LoadItemScript(&item); auto script = s.As(); REQUIRE(script != nullptr); return script.GetValue(); } TEST_CASE("Invoke isItemUsable item use script function on empty class") { auto mainLib = TestLibrary::GetLibrary(); auto script = GetScript(mainLib, "blankClass"_cnc); REQUIRE(script != nullptr); REQUIRE_FALSE(script->IsItemUsable()); } TEST_CASE("Invoke isItemUsable item use script function") { auto mainLib = TestLibrary::GetLibrary(); auto script = GetScript(mainLib, "isItemUsable"_cnc); REQUIRE(script != nullptr); REQUIRE(script->IsItemUsable()); } TEST_CASE("Invoke isPokemonUseItem item use script function on empty class") { auto mainLib = TestLibrary::GetLibrary(); auto script = GetScript(mainLib, "blankClass"_cnc); REQUIRE(script != nullptr); REQUIRE_FALSE(script->IsCreatureUseItem()); } TEST_CASE("Invoke isPokemonUseItem item use script function") { auto mainLib = TestLibrary::GetLibrary(); auto script = GetScript(mainLib, "isPokemonUseItem"_cnc); REQUIRE(script != nullptr); REQUIRE(script->IsCreatureUseItem()); } #endif