mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
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:
@ -29,6 +29,9 @@ namespace ZoneCodeGenerator.Generating
|
||||
},
|
||||
{
|
||||
"ZoneWrite", new GeneratorPreset("$asset/$asset_write_db", "ZoneWrite.stg")
|
||||
},
|
||||
{
|
||||
"AssetStructTests", new GeneratorPreset("$asset_struct_test", "AssetStructTests.stg")
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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$}$
|
||||
};
|
||||
}
|
||||
>>
|
@ -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" />
|
||||
|
Reference in New Issue
Block a user