ZoneCodeGenerator/ZoneCommon: Automatically generate unit tests for struct sizes and alignments to make sure they match the expected values for fastfiles

This commit is contained in:
Jan
2019-09-28 12:31:19 +02:00
parent e7e65127e2
commit c150350fc0
7 changed files with 298 additions and 1 deletions

View File

@ -29,6 +29,9 @@ namespace ZoneCodeGenerator.Generating
},
{
"ZoneWrite", new GeneratorPreset("$asset/$asset_write_db", "ZoneWrite.stg")
},
{
"AssetStructTests", new GeneratorPreset("$asset_struct_test", "AssetStructTests.stg")
}
};

View File

@ -0,0 +1,41 @@
delimiters "$", "$"
import "Common.stg"
TestMethod(structure) ::= <<
$if(structure.NonEmbeddedReferenceExists)$
TEST_METHOD(Test_$structure.Type.Name$)
{
Assert::AreEqual($structure.Type.Size$u, sizeof($structure.Type.FullName$));
Assert::AreEqual($structure.Type.Alignment$u, alignof($structure.Type.FullName$));
}
$endif$
>>
// =======================
// Source file entry point
// =======================
source(context) ::= <<
// ====================================================================
// This file has been generated by ZoneCodeGenerator.
// Do not modify.
// Any changes will be discarded when regenerating.
// ====================================================================
#include "CppUnitTest.h"
#include "Game/$context.Game$/$context.Game$.h"
using namespace Microsoft::VisualStudio::CppUnitTestFramework;
using namespace $context.Game$;
namespace ZoneCommonTests
{
TEST_CLASS(AssetStructTest_$context.Asset.Type.Name$)
{
public:
$TestMethod(context.Asset)$
$context.Structures:{structure | $if(!structure.IsAsset)$$TestMethod(structure)$
$endif$}$
};
}
>>

View File

@ -165,6 +165,7 @@
<EmbeddedResource Include="Generating\Templates\Common.stg" />
<EmbeddedResource Include="Generating\Templates\ZoneLoad.stg" />
<EmbeddedResource Include="Generating\Templates\ZoneWrite.stg" />
<EmbeddedResource Include="Generating\Templates\AssetStructTests.stg" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />