mirror of
https://github.com/DarkflameUniverse/DarkflameServer.git
synced 2026-11-30 01:41:40 +00:00
test(scripts): which server script an object runs
Custom script over a ported row script, over the empty script and with no row script; empty custom script keeps the row's; an unported custom script still wins (no script); once-per-LOT reporting; IsPorted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
set(DCOMPONENTS_TESTS
|
||||
"DeletionRestrictionTests.cpp"
|
||||
"MovingPlatformComponentTests.cpp"
|
||||
"ScriptComponentTests.cpp"
|
||||
"InventorySaveTests.cpp"
|
||||
"EquipMessagesTests.cpp"
|
||||
"DestroyableLevelConfigTests.cpp"
|
||||
|
||||
101
tests/dGameTests/dComponentsTests/ScriptComponentTests.cpp
Normal file
101
tests/dGameTests/dComponentsTests/ScriptComponentTests.cpp
Normal file
@@ -0,0 +1,101 @@
|
||||
// Which server script an object runs: as the client picks its script, a non-empty custom script in the level config
|
||||
// always wins over the ScriptComponent row's; an empty or missing one leaves the row's.
|
||||
#include "GameDependencies.h"
|
||||
|
||||
#include "GameMessages.h"
|
||||
#include "CDClientManager.h"
|
||||
#include "CDScriptComponentTable.h"
|
||||
#include "Entity.h"
|
||||
#include "ScriptComponent.h"
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace {
|
||||
const std::string cannonScript = "scripts\\ai\\MINIGAME\\SG_GF\\SERVER\\SG_CANNON.lua";
|
||||
const std::string targetScript = "scripts/ai/ACT/SG_TARGET.lua";
|
||||
const std::string emptyScript = "scripts\\empty.lua";
|
||||
}
|
||||
|
||||
class ScriptComponentTests : public GameDependenciesTest {
|
||||
protected:
|
||||
std::unique_ptr<Entity> entity;
|
||||
|
||||
void SetUp() override {
|
||||
SetUpDependencies();
|
||||
auto& scripts = CDClientManager::GetEntriesMutable<CDScriptComponentTable>();
|
||||
scripts[90001] = { 90001, cannonScript, "" };
|
||||
scripts[90002] = { 90002, emptyScript, "" };
|
||||
scripts[90003] = { 90003, "", "" };
|
||||
entity = std::make_unique<Entity>(1, info);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
entity.reset();
|
||||
auto& scripts = CDClientManager::GetEntriesMutable<CDScriptComponentTable>();
|
||||
scripts.erase(90001);
|
||||
scripts.erase(90002);
|
||||
scripts.erase(90003);
|
||||
TearDownDependencies();
|
||||
}
|
||||
|
||||
CppScripts::Script* Load(const int32_t componentID) {
|
||||
ScriptComponent component(entity.get(), componentID);
|
||||
component.LoadDataFromTemplate();
|
||||
component.LoadConfigData();
|
||||
return component.GetScript();
|
||||
}
|
||||
};
|
||||
|
||||
TEST(ScriptComponentChoice, CustomScriptWinsOverTheRowScript) {
|
||||
EXPECT_EQ(ScriptComponent::ChooseServerScript(cannonScript, targetScript), targetScript);
|
||||
EXPECT_EQ(ScriptComponent::ChooseServerScript(emptyScript, targetScript), targetScript);
|
||||
EXPECT_EQ(ScriptComponent::ChooseServerScript("", targetScript), targetScript);
|
||||
}
|
||||
|
||||
TEST(ScriptComponentChoice, EmptyCustomScriptKeepsTheRowScript) {
|
||||
EXPECT_EQ(ScriptComponent::ChooseServerScript(cannonScript, ""), cannonScript);
|
||||
EXPECT_EQ(ScriptComponent::ChooseServerScript("", ""), "");
|
||||
}
|
||||
|
||||
TEST(ScriptComponentChoice, UnportedReplacementIsReportedOncePerLot) {
|
||||
EXPECT_TRUE(ScriptComponent::FirstUnportedReplacement(999901));
|
||||
EXPECT_FALSE(ScriptComponent::FirstUnportedReplacement(999901));
|
||||
EXPECT_TRUE(ScriptComponent::FirstUnportedReplacement(999902));
|
||||
}
|
||||
|
||||
TEST(ScriptComponentChoice, PortedScripts) {
|
||||
EXPECT_TRUE(CppScripts::IsPorted(cannonScript));
|
||||
EXPECT_TRUE(CppScripts::IsPorted(targetScript));
|
||||
EXPECT_TRUE(CppScripts::IsPorted(emptyScript)); // left out on purpose
|
||||
EXPECT_FALSE(CppScripts::IsPorted("scripts\\no\\such\\script.lua"));
|
||||
}
|
||||
|
||||
TEST_F(ScriptComponentTests, RowScriptWithoutCustomScript) {
|
||||
EXPECT_EQ(Load(90001), CppScripts::GetScript(entity.get(), cannonScript));
|
||||
}
|
||||
|
||||
TEST_F(ScriptComponentTests, EmptyCustomScriptKeepsTheRowScript) {
|
||||
entity->SetVar<std::string>(u"custom_script_server", "");
|
||||
EXPECT_EQ(Load(90001), CppScripts::GetScript(entity.get(), cannonScript));
|
||||
}
|
||||
|
||||
TEST_F(ScriptComponentTests, CustomScriptWinsOverAPortedRowScript) {
|
||||
entity->SetVar<std::string>(u"custom_script_server", targetScript);
|
||||
EXPECT_EQ(Load(90001), CppScripts::GetScript(entity.get(), targetScript));
|
||||
}
|
||||
|
||||
TEST_F(ScriptComponentTests, CustomScriptWinsOverTheEmptyScript) {
|
||||
entity->SetVar<std::string>(u"custom_script_server", targetScript);
|
||||
EXPECT_EQ(Load(90002), CppScripts::GetScript(entity.get(), targetScript));
|
||||
}
|
||||
|
||||
TEST_F(ScriptComponentTests, CustomScriptWithoutARowScript) {
|
||||
entity->SetVar<std::string>(u"custom_script_server", targetScript);
|
||||
EXPECT_EQ(Load(90003), CppScripts::GetScript(entity.get(), targetScript));
|
||||
}
|
||||
|
||||
// Not ported: the object runs no script (the row's is lost until the custom one is ported)
|
||||
TEST_F(ScriptComponentTests, UnportedCustomScriptStillWins) {
|
||||
entity->SetVar<std::string>(u"custom_script_server", std::string("scripts\\no\\such\\script.lua"));
|
||||
EXPECT_EQ(Load(90001), CppScripts::GetInvalidScript());
|
||||
}
|
||||
Reference in New Issue
Block a user