From b8fd22d976dc2c1d4dccc734f6b893dfd42ddddd Mon Sep 17 00:00:00 2001 From: assiduous Date: Wed, 8 Dec 2021 20:48:13 -0800 Subject: [PATCH] Render state notation tests: added static asserts for struct sizes --- Tests/DiligentToolsTest/include/DRSNLoader.hpp | 6 ++++++ .../BlendStateParserTest.cpp | 4 ++++ .../DepthStencilStateParserTest.cpp | 12 +++++++----- .../RasterizerStateParserTest.cpp | 2 ++ .../RenderStateNotationParser/SamplerParserTest.cpp | 2 ++ 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/Tests/DiligentToolsTest/include/DRSNLoader.hpp b/Tests/DiligentToolsTest/include/DRSNLoader.hpp index 3023e982..9269d366 100644 --- a/Tests/DiligentToolsTest/include/DRSNLoader.hpp +++ b/Tests/DiligentToolsTest/include/DRSNLoader.hpp @@ -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 diff --git a/Tests/DiligentToolsTest/src/RenderStateNotationParser/BlendStateParserTest.cpp b/Tests/DiligentToolsTest/src/RenderStateNotationParser/BlendStateParserTest.cpp index 3fa43411..83a56b44 100644 --- a/Tests/DiligentToolsTest/src/RenderStateNotationParser/BlendStateParserTest.cpp +++ b/Tests/DiligentToolsTest/src/RenderStateNotationParser/BlendStateParserTest.cpp @@ -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"); @@ -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"); diff --git a/Tests/DiligentToolsTest/src/RenderStateNotationParser/DepthStencilStateParserTest.cpp b/Tests/DiligentToolsTest/src/RenderStateNotationParser/DepthStencilStateParserTest.cpp index 8d16b3ea..6c7e15f1 100644 --- a/Tests/DiligentToolsTest/src/RenderStateNotationParser/DepthStencilStateParserTest.cpp +++ b/Tests/DiligentToolsTest/src/RenderStateNotationParser/DepthStencilStateParserTest.cpp @@ -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; @@ -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; @@ -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); } diff --git a/Tests/DiligentToolsTest/src/RenderStateNotationParser/RasterizerStateParserTest.cpp b/Tests/DiligentToolsTest/src/RenderStateNotationParser/RasterizerStateParserTest.cpp index 83ffadb0..0c977715 100644 --- a/Tests/DiligentToolsTest/src/RenderStateNotationParser/RasterizerStateParserTest.cpp +++ b/Tests/DiligentToolsTest/src/RenderStateNotationParser/RasterizerStateParserTest.cpp @@ -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"); diff --git a/Tests/DiligentToolsTest/src/RenderStateNotationParser/SamplerParserTest.cpp b/Tests/DiligentToolsTest/src/RenderStateNotationParser/SamplerParserTest.cpp index 68075250..a975ca02 100644 --- a/Tests/DiligentToolsTest/src/RenderStateNotationParser/SamplerParserTest.cpp +++ b/Tests/DiligentToolsTest/src/RenderStateNotationParser/SamplerParserTest.cpp @@ -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");