added tests
This commit is contained in:
@@ -78,6 +78,53 @@ void TestVectorNormalization()
|
||||
Expect(!NormalizeAndValidateParameterValue(definition, shortInput, value, error), "vec2 parameter rejects wrong component count");
|
||||
}
|
||||
|
||||
void TestColorAndBooleanNormalization()
|
||||
{
|
||||
ShaderParameterDefinition colorDefinition;
|
||||
colorDefinition.id = "tint";
|
||||
colorDefinition.type = ShaderParameterType::Color;
|
||||
colorDefinition.defaultNumbers = { 1.0, 1.0, 1.0, 1.0 };
|
||||
colorDefinition.minNumbers = { 0.0, 0.0, 0.0, 0.0 };
|
||||
colorDefinition.maxNumbers = { 1.0, 1.0, 1.0, 1.0 };
|
||||
|
||||
JsonValue colorInput = JsonValue::MakeArray();
|
||||
colorInput.pushBack(JsonValue(-0.5));
|
||||
colorInput.pushBack(JsonValue(0.25));
|
||||
colorInput.pushBack(JsonValue(1.5));
|
||||
colorInput.pushBack(JsonValue(0.75));
|
||||
|
||||
ShaderParameterValue value;
|
||||
std::string error;
|
||||
Expect(NormalizeAndValidateParameterValue(colorDefinition, colorInput, value, error), "color parameter accepts four-component arrays");
|
||||
Expect(value.numberValues.size() == 4 &&
|
||||
value.numberValues[0] == 0.0 &&
|
||||
value.numberValues[1] == 0.25 &&
|
||||
value.numberValues[2] == 1.0 &&
|
||||
value.numberValues[3] == 0.75, "color parameter clamps each component");
|
||||
|
||||
JsonValue shortColor = JsonValue::MakeArray();
|
||||
shortColor.pushBack(JsonValue(1.0));
|
||||
shortColor.pushBack(JsonValue(1.0));
|
||||
shortColor.pushBack(JsonValue(1.0));
|
||||
error.clear();
|
||||
Expect(!NormalizeAndValidateParameterValue(colorDefinition, shortColor, value, error), "color parameter rejects wrong component count");
|
||||
|
||||
ShaderParameterDefinition boolDefinition;
|
||||
boolDefinition.id = "enabled";
|
||||
boolDefinition.type = ShaderParameterType::Boolean;
|
||||
boolDefinition.defaultBoolean = true;
|
||||
|
||||
ShaderParameterValue defaultValue = DefaultValueForDefinition(boolDefinition);
|
||||
Expect(defaultValue.booleanValue, "boolean default is copied from definition");
|
||||
|
||||
error.clear();
|
||||
Expect(NormalizeAndValidateParameterValue(boolDefinition, JsonValue(false), value, error), "boolean parameter accepts boolean values");
|
||||
Expect(!value.booleanValue, "boolean parameter stores selected value");
|
||||
|
||||
error.clear();
|
||||
Expect(!NormalizeAndValidateParameterValue(boolDefinition, JsonValue("false"), value, error), "boolean parameter rejects string values");
|
||||
}
|
||||
|
||||
void TestEnumAndDefaults()
|
||||
{
|
||||
ShaderParameterDefinition definition;
|
||||
@@ -127,6 +174,7 @@ int main()
|
||||
TestSafePresetFileStems();
|
||||
TestFloatNormalization();
|
||||
TestVectorNormalization();
|
||||
TestColorAndBooleanNormalization();
|
||||
TestEnumAndDefaults();
|
||||
TestTextNormalization();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user