Fix all valgrind leak issues in tests
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
Signed-off-by: Deukhoofd <deukhoofd@gmail.com>
This commit is contained in:
@@ -68,6 +68,7 @@ TEST_CASE( "True or False", "[integration]" ) {
|
||||
script->Evaluate();
|
||||
auto lastValue = script->GetLastValue();
|
||||
REQUIRE(lastValue->EvaluateBool());
|
||||
delete script;
|
||||
}
|
||||
TEST_CASE( "False or True", "[integration]" ) {
|
||||
auto script = Script::Create("false or true");
|
||||
|
||||
@@ -34,6 +34,7 @@ TEST_CASE( "Integer Subtraction", "[integration]" ) {
|
||||
script->Evaluate();
|
||||
auto lastValue = script->GetLastValue();
|
||||
REQUIRE(lastValue->EvaluateInteger() == -4);
|
||||
delete script;
|
||||
}
|
||||
TEST_CASE( "Integer Multiplication", "[integration]" ) {
|
||||
auto script = Script::Create("5 * 8");
|
||||
|
||||
@@ -47,7 +47,7 @@ private:
|
||||
));
|
||||
}
|
||||
|
||||
static GenericFunctionScriptType* AdditionFunctionType;
|
||||
static GenericFunctionScriptType* AdditionFunctionType();
|
||||
|
||||
static EvalValue* GetAdditionFunction(void* obj){
|
||||
return new UserDataFunction(CallAddition, obj);
|
||||
@@ -66,18 +66,19 @@ public:
|
||||
},
|
||||
{
|
||||
HashedString::ConstHash("Addition"),
|
||||
new UserDataField(AdditionFunctionType, GetAdditionFunction, nullptr)
|
||||
new UserDataField(AdditionFunctionType(), GetAdditionFunction, nullptr)
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
GenericFunctionScriptType* UserDataTestObject::AdditionFunctionType =
|
||||
new UserDataFunctionType(make_shared<NumericScriptType>(true, false),
|
||||
vector<shared_ptr<ScriptType>>{
|
||||
make_shared<NumericScriptType>(true, false),
|
||||
make_shared<NumericScriptType>(true, false)
|
||||
});
|
||||
GenericFunctionScriptType* UserDataTestObject::AdditionFunctionType(){
|
||||
return new UserDataFunctionType(make_shared<NumericScriptType>(true, false),
|
||||
vector<shared_ptr<ScriptType>>{
|
||||
make_shared<NumericScriptType>(true, false),
|
||||
make_shared<NumericScriptType>(true, false)
|
||||
});
|
||||
}
|
||||
|
||||
TEST_CASE( "Gets UserData value", "[integration]" ) {
|
||||
UserDataStorage::RegisterType(HashedString::ConstHash("testObject"), UserDataTestObject::CreateData());
|
||||
@@ -88,11 +89,15 @@ end
|
||||
)");
|
||||
REQUIRE(!script->Diagnostics -> HasErrors());
|
||||
script->Evaluate();
|
||||
auto parameter = new UserDataValue(HashedString::ConstHash("testObject"), new UserDataTestObject());
|
||||
auto par = new UserDataTestObject();
|
||||
auto parameter = new UserDataValue(HashedString::ConstHash("testObject"), par);
|
||||
auto variable = script->CallFunction(u"testFunc", {parameter});
|
||||
REQUIRE(variable != nullptr);
|
||||
REQUIRE(variable->EvaluateInteger() == 10);
|
||||
delete par;
|
||||
delete parameter;
|
||||
delete script;
|
||||
UserDataStorage::ClearTypes();
|
||||
}
|
||||
|
||||
TEST_CASE( "Sets UserData value", "[integration]" ) {
|
||||
@@ -111,6 +116,7 @@ end
|
||||
REQUIRE(obj->foo == 5000);
|
||||
delete obj;
|
||||
delete parameter;
|
||||
UserDataStorage::ClearTypes();
|
||||
}
|
||||
|
||||
TEST_CASE( "Calls UserData function", "[integration]" ) {
|
||||
@@ -129,6 +135,7 @@ end
|
||||
delete script;
|
||||
delete obj;
|
||||
delete parameter;
|
||||
UserDataStorage::ClearTypes();
|
||||
}
|
||||
|
||||
TEST_CASE( "Calls UserData function with parameters", "[integration]" ) {
|
||||
@@ -147,6 +154,7 @@ end
|
||||
delete script;
|
||||
delete obj;
|
||||
delete parameter;
|
||||
UserDataStorage::ClearTypes();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user