Updated unit tests to work with the new convention for property name vs property ID.

This revealed that the approach of reflecting both the old "id" and the new "name" would not work, because whenn saving it would write out both fields. So I decied to just give up on backward compatibility. This will be much cleaner than trying to continue supporting "id" as a field name, it is uncommon for users to make their own material types at this point, and if they have made some it is very easy to search and replace "id" with "name" update their files.

All .materialtype files have been updated. RPI unit tests now pass. ASV still passes.

Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
santorac
2021-09-17 23:12:24 -07:00
parent c2abd2d74f
commit 71c7fc0217
10 changed files with 231 additions and 238 deletions
@@ -46,7 +46,7 @@ namespace JsonSerializationTests
AZStd::shared_ptr<AZ::RPI::MaterialTypeSourceData::PropertyDefinition> CreatePartialDefaultInstance() override
{
auto result = AZStd::make_shared<AZ::RPI::MaterialTypeSourceData::PropertyDefinition>();
result->m_nameId = "testProperty";
result->m_name = "testProperty";
result->m_dataType = AZ::RPI::MaterialPropertyDataType::Float;
result->m_step = 1.0f;
result->m_value = 0.0f;
@@ -57,7 +57,7 @@ namespace JsonSerializationTests
{
return R"(
{
"id": "testProperty",
"name": "testProperty",
"type": "Float",
"step": 1.0
})";
@@ -66,7 +66,7 @@ namespace JsonSerializationTests
AZStd::shared_ptr<AZ::RPI::MaterialTypeSourceData::PropertyDefinition> CreateFullySetInstance() override
{
auto result = AZStd::make_shared<AZ::RPI::MaterialTypeSourceData::PropertyDefinition>();
result->m_nameId = "testProperty";
result->m_name = "testProperty";
result->m_description = "description";
result->m_displayName = "display_name";
result->m_dataType = AZ::RPI::MaterialPropertyDataType::Float;
@@ -87,7 +87,7 @@ namespace JsonSerializationTests
{
return R"(
{
"id": "testProperty",
"name": "testProperty",
"displayName": "display_name",
"description": "description",
"type": "Float",
@@ -101,7 +101,7 @@ namespace JsonSerializationTests
"connection":
{
"type": "ShaderOption",
"id": "o_foo",
"name": "o_foo",
"shaderIndex": 2
},
"enumIsUv": true
@@ -135,7 +135,7 @@ namespace JsonSerializationTests
const AZ::RPI::MaterialTypeSourceData::PropertyDefinition& lhs,
const AZ::RPI::MaterialTypeSourceData::PropertyDefinition& rhs) override
{
if (lhs.m_nameId != rhs.m_nameId) { return false; }
if (lhs.m_name != rhs.m_name) { return false; }
if (lhs.m_description != rhs.m_description) { return false; }
if (lhs.m_displayName != rhs.m_displayName) { return false; }
if (lhs.m_dataType != rhs.m_dataType) { return false; }
@@ -153,7 +153,7 @@ namespace JsonSerializationTests
auto& leftConnection = lhs.m_outputConnections[i];
auto& rightConnection = rhs.m_outputConnections[i];
if (leftConnection.m_type != rightConnection.m_type) { return false; }
if (leftConnection.m_nameId != rightConnection.m_nameId) { return false; }
if (leftConnection.m_fieldName != rightConnection.m_fieldName) { return false; }
if (leftConnection.m_shaderIndex != rightConnection.m_shaderIndex) { return false; }
}
return true;
@@ -202,7 +202,7 @@ namespace UnitTest
{
const AZStd::string inputJson = R"(
{
"id": "testProperty",
"name": "testProperty",
"displayName": "Test Property",
"description": "This is a property description",
"type": "Float"
@@ -216,12 +216,12 @@ namespace UnitTest
EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, loadResult.m_jsonResultCode.GetProcessing());
EXPECT_EQ(AZ::JsonSerializationResult::Outcomes::PartialDefaults, loadResult.m_jsonResultCode.GetOutcome());
EXPECT_EQ("testProperty", propertyData.m_nameId);
EXPECT_EQ("testProperty", propertyData.m_name);
EXPECT_EQ("Test Property", propertyData.m_displayName);
EXPECT_EQ("This is a property description", propertyData.m_description);
EXPECT_EQ(MaterialPropertyDataType::Float, propertyData.m_dataType);
EXPECT_TRUE(loadResult.ContainsMessage("/id", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/name", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/displayName", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/description", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/type", "Success"));
@@ -237,7 +237,7 @@ namespace UnitTest
// Note we are keeping id and type because they are required fields
const AZStd::string inputJson = R"(
{
"id": "testProperty",
"name": "testProperty",
"type": "Float"
}
)";
@@ -252,7 +252,7 @@ namespace UnitTest
EXPECT_TRUE(propertyData.m_displayName.empty());
EXPECT_TRUE(propertyData.m_description.empty());
EXPECT_TRUE(loadResult.ContainsMessage("/id", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/name", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/type", "Success"));
EXPECT_FALSE(loadResult.ContainsOutcome(JsonSerializationResult::Outcomes::Skipped));
@@ -280,7 +280,7 @@ namespace UnitTest
{
const AZStd::string inputJson = R"(
{
"id": "testProperty",
"name": "testProperty",
"type": "foo"
}
)";
@@ -294,7 +294,7 @@ namespace UnitTest
EXPECT_EQ(AZ::RPI::MaterialPropertyDataType::Invalid, propertyData.m_dataType);
EXPECT_TRUE(loadResult.ContainsMessage("/id", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/name", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/type", "Enum value could not read"));
}
@@ -303,7 +303,7 @@ namespace UnitTest
const AZStd::string inputJson = R"(
[
{
"id": "testProperty1",
"name": "testProperty1",
"type": "Float",
"defaultValue": 0.5,
"min": 0.1,
@@ -313,7 +313,7 @@ namespace UnitTest
"step": 0.05
},
{
"id": "testProperty2",
"name": "testProperty2",
"type": "Int",
"defaultValue": -1,
"min": -5,
@@ -323,7 +323,7 @@ namespace UnitTest
"step": 1
},
{
"id": "testProperty3",
"name": "testProperty3",
"type": "UInt",
"defaultValue": 4294901761,
"min": 4294901760,
@@ -368,7 +368,7 @@ namespace UnitTest
for (int i = 0; i < propertyData.size(); ++i)
{
AZStd::string prefix = AZStd::string::format("/%d", i);
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/id", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/name", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/type", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/defaultValue", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/min", "Success"));
@@ -388,19 +388,19 @@ namespace UnitTest
const AZStd::string inputJson = R"(
[
{
"id": "testProperty1",
"name": "testProperty1",
"displayName": "Test Property 1",
"description": "Test",
"type": "Float"
},
{
"id": "testProperty2",
"name": "testProperty2",
"displayName": "Test Property 2",
"description": "Test",
"type": "Int"
},
{
"id": "testProperty3",
"name": "testProperty3",
"displayName": "Test Property 3",
"description": "Test",
"type": "UInt"
@@ -443,13 +443,13 @@ namespace UnitTest
const AZStd::string inputJson = R"(
[
{
"id": "testProperty1",
"name": "testProperty1",
"type": "Vector2",
"vectorLabels": ["U", "V"],
"defaultValue": [0.6, 0.5]
},
{
"id": "testProperty2",
"name": "testProperty2",
"type": "Vector4",
"vectorLabels": ["A", "B", "C", "D"],
"defaultValue": [0.3, 0.4, 0.5, 0.6]
@@ -485,21 +485,21 @@ namespace UnitTest
const AZStd::string inputJson = R"(
[
{
"id": "visibilityIsDefault",
"name": "visibilityIsDefault",
"type": "Float"
},
{
"id": "visibilityIsEditable",
"name": "visibilityIsEditable",
"type": "Float",
"visibility": "Enabled"
},
{
"id": "visibilityIsDisabled",
"name": "visibilityIsDisabled",
"type": "Float",
"visibility": "Disabled"
},
{
"id": "visibilityIsHidden",
"name": "visibilityIsHidden",
"type": "Float",
"visibility": "Hidden"
}
@@ -509,20 +509,20 @@ namespace UnitTest
const AZStd::string expectedOutputJson = R"(
[
{
"id": "visibilityIsDefault",
"name": "visibilityIsDefault",
"type": "Float"
},
{
"id": "visibilityIsEditable",
"name": "visibilityIsEditable",
"type": "Float"
},
{
"id": "visibilityIsDisabled",
"name": "visibilityIsDisabled",
"type": "Float",
"visibility": "Disabled"
},
{
"id": "visibilityIsHidden",
"name": "visibilityIsHidden",
"type": "Float",
"visibility": "Hidden"
}
@@ -552,7 +552,7 @@ namespace UnitTest
const AZStd::string inputJson = R"(
[
{
"id": "testProperty1",
"name": "testProperty1",
"type": "Float",
"defaultValue": true,
"min": -1,
@@ -560,7 +560,7 @@ namespace UnitTest
"step": "1"
},
{
"id": "testProperty2",
"name": "testProperty2",
"type": "Int",
"defaultValue": true,
"min": -1.5,
@@ -568,7 +568,7 @@ namespace UnitTest
"step": "1"
},
{
"id": "testProperty3",
"name": "testProperty3",
"type": "UInt",
"defaultValue": "4294963200",
"min": true,
@@ -610,32 +610,32 @@ namespace UnitTest
const AZStd::string inputJson = R"(
[
{
"id": "testProperty1",
"name": "testProperty1",
"type": "Bool",
"defaultValue": true
},
{
"id": "testProperty2",
"name": "testProperty2",
"type": "Vector2",
"defaultValue": [0.1, 0.2]
},
{
"id": "testProperty3",
"name": "testProperty3",
"type": "Vector3",
"defaultValue": [0.3, 0.4, 0.5]
},
{
"id": "testProperty4",
"name": "testProperty4",
"type": "Vector4",
"defaultValue": [0.6, 0.5, 0.8, 0.4]
},
{
"id": "testProperty5",
"name": "testProperty5",
"type": "Color",
"defaultValue": [0.1, 0.2, 0.3]
},
{
"id": "testProperty6",
"name": "testProperty6",
"type": "Image",
"defaultValue": "Default.png"
}
@@ -669,7 +669,7 @@ namespace UnitTest
for (int i = 0; i < propertyData.size(); ++i)
{
AZStd::string prefix = AZStd::string::format("/%d", i);
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/id", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/name", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/type", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage(prefix + "/defaultValue", "Success"));
}
@@ -684,27 +684,27 @@ namespace UnitTest
const AZStd::string inputJson = R"(
[
{
"id": "testProperty1",
"name": "testProperty1",
"type": "Bool"
},
{
"id": "testProperty2",
"name": "testProperty2",
"type": "Vector2"
},
{
"id": "testProperty3",
"name": "testProperty3",
"type": "Vector3"
},
{
"id": "testProperty4",
"name": "testProperty4",
"type": "Vector4"
},
{
"id": "testProperty5",
"name": "testProperty5",
"type": "Color"
},
{
"id": "testProperty6",
"name": "testProperty6",
"type": "Image"
}
]
@@ -745,27 +745,27 @@ namespace UnitTest
const AZStd::string inputJson = R"(
[
{
"id": "testProperty1",
"name": "testProperty1",
"type": "Bool",
"defaultValue": 1
},
{
"id": "testProperty2",
"name": "testProperty2",
"type": "Vector2",
"defaultValue": { "x": 0.4, "y": 0.1 }
},
{
"id": "testProperty3",
"name": "testProperty3",
"type": "Vector3",
"defaultValue": { "x": 0.4, "y": 0.1, "z": 0.5 }
},
{
"id": "testProperty4",
"name": "testProperty4",
"type": "Vector4",
"defaultValue": { "x": 0.4, "y": 0.1, "z": 0.5, "w": 0.6 }
},
{
"id": "testProperty5",
"name": "testProperty5",
"type": "Color",
"defaultValue": { "hex": "FF00FF" }
}
@@ -800,11 +800,11 @@ namespace UnitTest
{
const AZStd::string inputJson = R"(
{
"id": "testProperty",
"name": "testProperty",
"type": "Float",
"connection": {
"type": "ShaderOption",
"id": "o_foo",
"name": "o_foo",
"shaderIndex": 2
}
}
@@ -818,11 +818,11 @@ namespace UnitTest
EXPECT_EQ(1, propertyData.m_outputConnections.size());
EXPECT_EQ(MaterialPropertyOutputType::ShaderOption, propertyData.m_outputConnections[0].m_type);
EXPECT_EQ("o_foo", propertyData.m_outputConnections[0].m_nameId);
EXPECT_EQ("o_foo", propertyData.m_outputConnections[0].m_fieldName);
EXPECT_EQ(2, propertyData.m_outputConnections[0].m_shaderIndex);
EXPECT_TRUE(loadResult.ContainsMessage("/connection/type", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/id", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/name", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/shaderIndex", "Success"));
EXPECT_FALSE(loadResult.ContainsOutcome(JsonSerializationResult::Outcomes::Skipped));
@@ -833,17 +833,17 @@ namespace UnitTest
{
const AZStd::string inputJson = R"(
{
"id": "testProperty",
"name": "testProperty",
"type": "Float",
"connection": [
{
"type": "ShaderInput",
"id": "o_foo",
"name": "o_foo",
"shaderIndex": 2
},
{
"type": "ShaderOption",
"id": "o_bar",
"name": "o_bar",
"shaderIndex": 1
}
]
@@ -858,18 +858,18 @@ namespace UnitTest
EXPECT_EQ(2, propertyData.m_outputConnections.size());
EXPECT_EQ(MaterialPropertyOutputType::ShaderInput, propertyData.m_outputConnections[0].m_type);
EXPECT_EQ("o_foo", propertyData.m_outputConnections[0].m_nameId);
EXPECT_EQ("o_foo", propertyData.m_outputConnections[0].m_fieldName);
EXPECT_EQ(2, propertyData.m_outputConnections[0].m_shaderIndex);
EXPECT_EQ(MaterialPropertyOutputType::ShaderOption, propertyData.m_outputConnections[1].m_type);
EXPECT_EQ("o_bar", propertyData.m_outputConnections[1].m_nameId);
EXPECT_EQ("o_bar", propertyData.m_outputConnections[1].m_fieldName);
EXPECT_EQ(1, propertyData.m_outputConnections[1].m_shaderIndex);
EXPECT_TRUE(loadResult.ContainsMessage("/connection/0/type", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/0/id", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/0/name", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/0/shaderIndex", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/1/type", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/1/id", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/1/name", "Success"));
EXPECT_TRUE(loadResult.ContainsMessage("/connection/1/shaderIndex", "Success"));
EXPECT_FALSE(loadResult.ContainsOutcome(JsonSerializationResult::Outcomes::Skipped));
@@ -881,12 +881,12 @@ namespace UnitTest
// "conection" is misspelled
const AZStd::string inputJson = R"(
{
"id": "testProperty",
"name": "testProperty",
"type": "Float",
"conection": [
{
"type": "ShaderInput",
"id": "o_foo",
"name": "o_foo",
"shaderIndex": 2
}
]
@@ -899,7 +899,7 @@ namespace UnitTest
EXPECT_EQ(AZ::JsonSerializationResult::Tasks::ReadField, loadResult.m_jsonResultCode.GetTask());
EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, loadResult.m_jsonResultCode.GetProcessing());
EXPECT_EQ(propertyData.m_nameId, "testProperty");
EXPECT_EQ(propertyData.m_name, "testProperty");
EXPECT_EQ(propertyData.m_dataType, MaterialPropertyDataType::Float);
EXPECT_EQ(propertyData.m_outputConnections.size(), 0);
@@ -911,13 +911,13 @@ namespace UnitTest
// "shadrIndex" is misspelled
const AZStd::string inputJson = R"(
{
"id": "testProperty",
"name": "testProperty",
"type": "Float",
"connection": [
{
"type": "ShaderInput",
"shadrIndex": 2,
"id": "o_foo"
"name": "o_foo"
}
]
}
@@ -929,10 +929,10 @@ namespace UnitTest
EXPECT_EQ(AZ::JsonSerializationResult::Tasks::ReadField, loadResult.m_jsonResultCode.GetTask());
EXPECT_EQ(AZ::JsonSerializationResult::Processing::Completed, loadResult.m_jsonResultCode.GetProcessing());
EXPECT_EQ(propertyData.m_nameId, "testProperty");
EXPECT_EQ(propertyData.m_name, "testProperty");
EXPECT_EQ(propertyData.m_dataType, MaterialPropertyDataType::Float);
EXPECT_EQ(propertyData.m_outputConnections.size(), 1);
EXPECT_EQ(propertyData.m_outputConnections[0].m_nameId, "o_foo");
EXPECT_EQ(propertyData.m_outputConnections[0].m_fieldName, "o_foo");
EXPECT_EQ(propertyData.m_outputConnections[0].m_type, MaterialPropertyOutputType::ShaderInput);
EXPECT_EQ(propertyData.m_outputConnections[0].m_shaderIndex, -1);