Updated MaterialPropertyId class in preparation for nested material property sets.

Here the class has been generalized for a list of group names and a final property name, rather than assuming a single group containing the property. This included removing the unused GetPropertyName and GetGroupName functions. All that's really need from this class is conversion to a full property ID string.

Testing:
New unit test.
Reprocessed all core material types and StandardPBR test materials used in Atom Sample Viewer's material screenshot test.
Atom Sample Viewer material screenshot test script.

Signed-off-by: santorac <55155825+santorac@users.noreply.github.com>
This commit is contained in:
santorac
2021-09-18 23:57:52 -07:00
parent 5ed7e91a62
commit 02acf2f65e
10 changed files with 210 additions and 57 deletions
@@ -0,0 +1,131 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#include <AzTest/AzTest.h>
#include <Common/RPITestFixture.h>
#include <Common/ErrorMessageFinder.h>
#include <Atom/RPI.Edit/Material/MaterialPropertyId.h>
namespace UnitTest
{
using namespace AZ;
using namespace RPI;
class MaterialPropertyIdTests
: public RPITestFixture
{
};
TEST_F(MaterialPropertyIdTests, TestConstructWithPropertyName)
{
MaterialPropertyId id{"color"};
EXPECT_TRUE(id.IsValid());
EXPECT_STREQ(id.GetCStr(), "color");
AZ::Name idCastedToName = id;
EXPECT_EQ(idCastedToName, AZ::Name{"color"});
}
TEST_F(MaterialPropertyIdTests, TestConstructWithPropertyName_BadName)
{
ErrorMessageFinder errorMessageFinder;
errorMessageFinder.AddExpectedErrorMessage("not a valid identifier");
MaterialPropertyId id{"color?"};
EXPECT_FALSE(id.IsValid());
errorMessageFinder.CheckExpectedErrorsFound();
}
TEST_F(MaterialPropertyIdTests, TestConstructWithTwoNames)
{
MaterialPropertyId id{"baseColor", "factor"};
EXPECT_TRUE(id.IsValid());
EXPECT_STREQ(id.GetCStr(), "baseColor.factor");
AZ::Name idCastedToName = id;
EXPECT_EQ(idCastedToName, AZ::Name{"baseColor.factor"});
}
TEST_F(MaterialPropertyIdTests, TestConstructWithTwoNames_BadGroupName)
{
ErrorMessageFinder errorMessageFinder;
errorMessageFinder.AddExpectedErrorMessage("not a valid identifier");
MaterialPropertyId id{"layer1.baseColor", "factor"};
EXPECT_FALSE(id.IsValid());
errorMessageFinder.CheckExpectedErrorsFound();
}
TEST_F(MaterialPropertyIdTests, TestConstructWithTwoNames_BadPropertyName)
{
ErrorMessageFinder errorMessageFinder;
errorMessageFinder.AddExpectedErrorMessage("not a valid identifier");
MaterialPropertyId id{"baseColor", ".factor"};
EXPECT_FALSE(id.IsValid());
errorMessageFinder.CheckExpectedErrorsFound();
}
TEST_F(MaterialPropertyIdTests, TestConstructWithMultipleNames)
{
AZStd::vector<AZStd::string> names{"layer1", "clearCoat", "normal", "factor"};
MaterialPropertyId id{names};
EXPECT_TRUE(id.IsValid());
EXPECT_STREQ(id.GetCStr(), "layer1.clearCoat.normal.factor");
AZ::Name idCastedToName = id;
EXPECT_EQ(idCastedToName, AZ::Name{"layer1.clearCoat.normal.factor"});
}
TEST_F(MaterialPropertyIdTests, TestConstructWithMultipleNames_BadName)
{
ErrorMessageFinder errorMessageFinder;
errorMessageFinder.AddExpectedErrorMessage("not a valid identifier");
AZStd::vector<AZStd::string> names{"layer1", "clear-coat", "normal", "factor"};
MaterialPropertyId id{names};
EXPECT_FALSE(id.IsValid());
errorMessageFinder.CheckExpectedErrorsFound();
}
TEST_F(MaterialPropertyIdTests, TestParse)
{
MaterialPropertyId id = MaterialPropertyId::Parse("layer1.clearCoat.normal.factor");
EXPECT_TRUE(id.IsValid());
EXPECT_STREQ(id.GetCStr(), "layer1.clearCoat.normal.factor");
AZ::Name idCastedToName = id;
EXPECT_EQ(idCastedToName, AZ::Name{"layer1.clearCoat.normal.factor"});
}
TEST_F(MaterialPropertyIdTests, TestParse_BadName)
{
ErrorMessageFinder errorMessageFinder;
errorMessageFinder.AddExpectedErrorMessage("not a valid identifier");
MaterialPropertyId id = MaterialPropertyId::Parse("layer1.clearCoat.normal,factor");
EXPECT_FALSE(id.IsValid());
errorMessageFinder.CheckExpectedErrorsFound();
}
TEST_F(MaterialPropertyIdTests, TestNameValidity)
{
EXPECT_TRUE(MaterialPropertyId::IsValidName("a"));
EXPECT_TRUE(MaterialPropertyId::IsValidName("z"));
EXPECT_TRUE(MaterialPropertyId::IsValidName("A"));
EXPECT_TRUE(MaterialPropertyId::IsValidName("Z"));
EXPECT_TRUE(MaterialPropertyId::IsValidName("_"));
EXPECT_TRUE(MaterialPropertyId::IsValidName("m_layer10bazBAZ"));
EXPECT_FALSE(MaterialPropertyId::IsValidName(""));
EXPECT_FALSE(MaterialPropertyId::IsValidName("1layer"));
EXPECT_FALSE(MaterialPropertyId::IsValidName("base-color"));
EXPECT_FALSE(MaterialPropertyId::IsValidName("base.color"));
EXPECT_FALSE(MaterialPropertyId::IsValidName("base/color"));
}
}