Skip to content

Commit

Permalink
Render state notation tests: added static asserts for struct sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Dec 9, 2021
1 parent f6cc086 commit b8fd22d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions Tests/DiligentToolsTest/include/DRSNLoader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ bool TestBitwiseEnum(DynamicLinearAllocator& Allocator, Type MaxBit)
return true;
}

#if defined(_MSC_VER) && defined(_WIN64)
# define CHECK_STRUCT_SIZE(Struct, Size) static_assert(sizeof(Struct) == Size, "Did you add new members to " # Struct " struct? You may need to update this test.")
#else
# define CHECK_STRUCT_SIZE(Struct, Size)
#endif

} // namespace Diligent
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ TEST(Tools_RenderStateNotationParser, ParseBlendStateEnums)

TEST(Tools_RenderStateNotationParser, ParseRenderTargetBlendDesc)
{
CHECK_STRUCT_SIZE(RenderTargetBlendDesc, 10);

DynamicLinearAllocator Allocator{DefaultRawMemoryAllocator::GetAllocator()};

nlohmann::json JsonReference = LoadDRSNFromFile("RenderStates/BlendState/RenderTargetBlendDesc.json");
Expand All @@ -62,6 +64,8 @@ TEST(Tools_RenderStateNotationParser, ParseRenderTargetBlendDesc)

TEST(Tools_RenderStateNotationParser, ParseBlendStateDesc)
{
CHECK_STRUCT_SIZE(BlendStateDesc, 82);

DynamicLinearAllocator Allocator{DefaultRawMemoryAllocator::GetAllocator()};

nlohmann::json JsonReference = LoadDRSNFromFile("RenderStates/BlendState/BlendStateDesc.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ TEST(Tools_RenderStateNotationParser, ParseDepthStencilStateEnums)

TEST(Tools_RenderStateNotationParser, ParserStencilOpDesc)
{
CHECK_STRUCT_SIZE(StencilOpDesc, 4);

DynamicLinearAllocator Allocator{DefaultRawMemoryAllocator::GetAllocator()};

nlohmann::json JsonReference = LoadDRSNFromFile("RenderStates/DepthStencilState/StencilOpDesc.json");

StencilOpDesc DescReference = {};

StencilOpDesc DescReference{};
DescReference.StencilFailOp = STENCIL_OP_ZERO;
DescReference.StencilDepthFailOp = STENCIL_OP_DECR_WRAP;
DescReference.StencilPassOp = STENCIL_OP_INCR_SAT;
Expand All @@ -59,12 +60,13 @@ TEST(Tools_RenderStateNotationParser, ParserStencilOpDesc)

TEST(Tools_RenderStateNotationParser, ParseDepthStencilStateDesc)
{
CHECK_STRUCT_SIZE(DepthStencilStateDesc, 14);

DynamicLinearAllocator Allocator{DefaultRawMemoryAllocator::GetAllocator()};

nlohmann::json JsonReference = LoadDRSNFromFile("RenderStates/DepthStencilState/DepthStencilStateDesc.json");

DepthStencilStateDesc DescReference = {};

DepthStencilStateDesc DescReference{};
DescReference.DepthEnable = false;
DescReference.DepthWriteEnable = false;
DescReference.DepthFunc = COMPARISON_FUNC_GREATER;
Expand All @@ -74,7 +76,7 @@ TEST(Tools_RenderStateNotationParser, ParseDepthStencilStateDesc)
DescReference.FrontFace.StencilFunc = COMPARISON_FUNC_NEVER;
DescReference.BackFace.StencilFunc = COMPARISON_FUNC_NOT_EQUAL;

DepthStencilStateDesc Desc = {};
DepthStencilStateDesc Desc{};
Deserialize(JsonReference, Desc, Allocator);
ASSERT_EQ(Desc, DescReference);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ TEST(Tools_RenderStateNotationParser, ParseRasterizerStateEnums)

TEST(Tools_RenderStateNotationParser, ParseRasterizerStateDesc)
{
CHECK_STRUCT_SIZE(RasterizerStateDesc, 20);

DynamicLinearAllocator Allocator{DefaultRawMemoryAllocator::GetAllocator()};

nlohmann::json JsonReference = LoadDRSNFromFile("RenderStates/RasterizerState/RasterizerStateDesc.json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ TEST(Tools_RenderStateNotationParser, ParseSamplerEnums)

TEST(Tools_RenderStateNotationParser, ParseSamplerDesc)
{
CHECK_STRUCT_SIZE(SamplerDesc, 56);

DynamicLinearAllocator Allocator{DefaultRawMemoryAllocator::GetAllocator()};

nlohmann::json JsonReference = LoadDRSNFromFile("RenderStates/Sampler/SamplerDesc.json");
Expand Down

0 comments on commit b8fd22d

Please sign in to comment.