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");
|
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()
|
void TestEnumAndDefaults()
|
||||||
{
|
{
|
||||||
ShaderParameterDefinition definition;
|
ShaderParameterDefinition definition;
|
||||||
@@ -127,6 +174,7 @@ int main()
|
|||||||
TestSafePresetFileStems();
|
TestSafePresetFileStems();
|
||||||
TestFloatNormalization();
|
TestFloatNormalization();
|
||||||
TestVectorNormalization();
|
TestVectorNormalization();
|
||||||
|
TestColorAndBooleanNormalization();
|
||||||
TestEnumAndDefaults();
|
TestEnumAndDefaults();
|
||||||
TestTextNormalization();
|
TestTextNormalization();
|
||||||
|
|
||||||
|
|||||||
@@ -55,12 +55,42 @@ void TestVectorAlignment()
|
|||||||
Expect(ReadFloat(buffer, 16) == 4.0f, "vec4 x value is aligned");
|
Expect(ReadFloat(buffer, 16) == 4.0f, "vec4 x value is aligned");
|
||||||
Expect(ReadFloat(buffer, 28) == 7.0f, "vec4 w value is written");
|
Expect(ReadFloat(buffer, 28) == 7.0f, "vec4 w value is written");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestGlobalParamStylePacking()
|
||||||
|
{
|
||||||
|
std::vector<unsigned char> buffer;
|
||||||
|
AppendStd140Float(buffer, 10.0f); // time
|
||||||
|
AppendStd140Vec2(buffer, 1920.0f, 1080.0f); // input resolution
|
||||||
|
AppendStd140Vec2(buffer, 1280.0f, 720.0f); // output resolution
|
||||||
|
AppendStd140Float(buffer, 42.0f); // frame count
|
||||||
|
AppendStd140Float(buffer, 0.5f); // mix
|
||||||
|
AppendStd140Float(buffer, 1.0f); // bypass
|
||||||
|
AppendStd140Int(buffer, 3); // source history length
|
||||||
|
AppendStd140Int(buffer, 2); // temporal history length
|
||||||
|
AppendStd140Float(buffer, 0.25f); // float parameter
|
||||||
|
AppendStd140Vec2(buffer, 4.0f, 5.0f); // vec2 parameter
|
||||||
|
AppendStd140Vec4(buffer, 0.1f, 0.2f, 0.3f, 1.0f); // color parameter
|
||||||
|
AppendStd140Int(buffer, 1); // boolean parameter
|
||||||
|
AppendStd140Int(buffer, 2); // enum parameter
|
||||||
|
buffer.resize(AlignStd140(buffer.size(), 16), 0);
|
||||||
|
|
||||||
|
Expect(buffer.size() == 96, "global parameter style block is padded to a 16-byte boundary");
|
||||||
|
Expect(ReadFloat(buffer, 0) == 10.0f, "time is at the start of the block");
|
||||||
|
Expect(ReadFloat(buffer, 8) == 1920.0f, "first vec2 aligns after scalar padding");
|
||||||
|
Expect(ReadFloat(buffer, 16) == 1280.0f, "second vec2 follows first vec2");
|
||||||
|
Expect(ReadInt(buffer, 36) == 3, "history length scalar remains tightly packed");
|
||||||
|
Expect(ReadFloat(buffer, 48) == 4.0f, "vec2 shader parameter aligns to 8 bytes");
|
||||||
|
Expect(ReadFloat(buffer, 64) == 0.1f, "color parameter aligns to 16 bytes");
|
||||||
|
Expect(ReadInt(buffer, 80) == 1, "boolean parameter follows vec4");
|
||||||
|
Expect(ReadInt(buffer, 84) == 2, "enum parameter follows boolean");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
TestScalarPacking();
|
TestScalarPacking();
|
||||||
TestVectorAlignment();
|
TestVectorAlignment();
|
||||||
|
TestGlobalParamStylePacking();
|
||||||
|
|
||||||
if (gFailures != 0)
|
if (gFailures != 0)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user