mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-15 08:34:40 +00:00
Fix error in DB substitution logic and add regressiontest
This commit is contained in:
parent
d441e2161f
commit
e7d17e5453
2 changed files with 68 additions and 1 deletions
|
|
@ -253,7 +253,7 @@ void SimDataBlock::performSubstitutions(SimDataBlock* dblock, const SimObject* o
|
||||||
b[0] = '\0';
|
b[0] = '\0';
|
||||||
|
|
||||||
Con::EvalResult evalResult = Con::evaluate(avar("return %s;", buffer), false, 0);
|
Con::EvalResult evalResult = Con::evaluate(avar("return %s;", buffer), false, 0);
|
||||||
if (evalResult.valid)
|
if (!evalResult.valid)
|
||||||
{
|
{
|
||||||
Con::errorf("Field Substitution Failed: field=\"%s\" substitution=\"%s\" -- syntax error",
|
Con::errorf("Field Substitution Failed: field=\"%s\" substitution=\"%s\" -- syntax error",
|
||||||
substitutions[i]->mSlot, substitutions[i]->mValue);
|
substitutions[i]->mSlot, substitutions[i]->mValue);
|
||||||
|
|
|
||||||
67
Engine/source/testing/datablockTest.cpp
Normal file
67
Engine/source/testing/datablockTest.cpp
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
#include "console/script.h"
|
||||||
|
#include "T3D/fx/particle.h"
|
||||||
|
#include "T3D/gameBase/gameBase.h"
|
||||||
|
|
||||||
|
TEST(DatablockTest, Datablocks_Can_Be_Overridden)
|
||||||
|
{
|
||||||
|
Con::EvalResult result = Con::evaluatef(R"(
|
||||||
|
datablock SimDataBlock(testDb) {
|
||||||
|
foo = 2;
|
||||||
|
};
|
||||||
|
datablock SimDataBlock(testDb) {
|
||||||
|
foo = 3;
|
||||||
|
};
|
||||||
|
return testDb.foo;
|
||||||
|
)", false, "datablockTest.cpp");
|
||||||
|
|
||||||
|
ASSERT_TRUE(result.valid);
|
||||||
|
// Successfully overrode the datablock
|
||||||
|
EXPECT_STREQ(result.value, "3");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(DatablockTest, Datablocks_Must_Not_Change_Type)
|
||||||
|
{
|
||||||
|
Con::EvalResult result = Con::evaluatef(R"(
|
||||||
|
datablock SimDataBlock(testDb) {
|
||||||
|
foo = 2;
|
||||||
|
};
|
||||||
|
datablock ParticleData(testDb) {
|
||||||
|
foo = 3;
|
||||||
|
};
|
||||||
|
return testDb.foo;
|
||||||
|
)", false, "datablockTest.cpp");
|
||||||
|
|
||||||
|
// Not a syntax error
|
||||||
|
ASSERT_TRUE(result.valid);
|
||||||
|
// Did not override the datablock
|
||||||
|
EXPECT_STREQ(result.value, "2");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(DatablockTest, Datablock_Can_Substitute_String)
|
||||||
|
{
|
||||||
|
Con::EvalResult result = Con::evaluatef(R"(
|
||||||
|
datablock ParticleData(testDb) {
|
||||||
|
lifetimeMS = "$$ %%%%.bar";
|
||||||
|
};
|
||||||
|
|
||||||
|
$simObj = new GameBase(testObj) {
|
||||||
|
bar = 1234;
|
||||||
|
};
|
||||||
|
|
||||||
|
return "done";
|
||||||
|
)", false, "datablockTest.cpp");
|
||||||
|
|
||||||
|
EXPECT_TRUE(result.valid);
|
||||||
|
EXPECT_STREQ(result.value, "done");
|
||||||
|
|
||||||
|
ParticleData* testDb = NULL;
|
||||||
|
Sim::findObject("testDb", testDb);
|
||||||
|
GameBase* testObj = NULL;
|
||||||
|
Sim::findObject("testObj", testObj);
|
||||||
|
|
||||||
|
testDb->performSubstitutions(testDb, testObj);
|
||||||
|
|
||||||
|
EXPECT_EQ(testDb->lifetimeMS, 1234);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue