From a89cf168ae1ebb5301e073154cc9fddb5e498c34 Mon Sep 17 00:00:00 2001 From: izrik Date: Mon, 13 May 2024 23:04:49 -0500 Subject: [PATCH 001/151] Add basic test cases for the importer class. --- FbxCppTests/FbxImporterTest.cpp | 33 ++++++++++++++++++++++++++++++++ FbxCppTests/Makefile | 2 +- FbxCppTests/TestRunner.cpp | 1 + FbxCppTests/Tests.h | 1 + FbxSharp/FbxImporter.cs | 20 ++++++++++--------- FbxSharpTests/FbxImporterTest.cs | 32 +++++++++++++++++++++++++++++++ test-cases/FbxImporterTest.tc | 16 ++++++++++++++++ 7 files changed, 95 insertions(+), 10 deletions(-) create mode 100644 FbxCppTests/FbxImporterTest.cpp create mode 100644 FbxSharpTests/FbxImporterTest.cs create mode 100644 test-cases/FbxImporterTest.tc diff --git a/FbxCppTests/FbxImporterTest.cpp b/FbxCppTests/FbxImporterTest.cpp new file mode 100644 index 0000000..ae3f519 --- /dev/null +++ b/FbxCppTests/FbxImporterTest.cpp @@ -0,0 +1,33 @@ + +#include "Tests.h" + +using namespace std; + +void FbxImporter_Create_AllZero() +{ + // given: + FbxManager* manager = FbxManager::Create(); + FbxImporter* importer = FbxImporter::Create(manager, ""); + + // then: + AssertEqual(0, CountProperties(importer)); + AssertEqual(0, importer->GetSrcPropertyCount()); + AssertEqual(0, importer->GetDstPropertyCount()); +} + +void FbxImporter_IsFBX_UnitializedYieldsError() +{ + // given: + FbxManager* manager = FbxManager::Create(); + FbxImporter* importer = FbxImporter::Create(manager, ""); + + // then: + AssertTrue(true); +} + +void FbxImporterTest::RegisterTestCases() +{ + AddTestCase(FbxImporter_Create_AllZero); + AddTestCase(FbxImporter_IsFBX_UnitializedYieldsError); +} + diff --git a/FbxCppTests/Makefile b/FbxCppTests/Makefile index 9ac38cd..83a4348 100644 --- a/FbxCppTests/Makefile +++ b/FbxCppTests/Makefile @@ -30,7 +30,7 @@ ifeq ($(UNAME_S),Darwin) LDFLAGS=-framework Cocoa $(COMMON_LDFLAGS) endif -TC_SOURCES=AnimCurveKeyTest.tc AnimCurveNodeTest.tc AnimCurveTest.tc AnimLayerTest.tc AnimStackTest.tc Assertions.tc CameraTest.tc ClusterTest.tc DeformerTest.tc FbxObjectTest.tc FbxTimeTest.tc GeometryBaseTest.tc GeometryTest.tc LayerContainerTest.tc LightTest.tc MatrixTest.tc MeshTest.tc NodeTest.tc NodeTransformsTest.tc PropertyTest.tc SceneTest.tc SkinTest.tc SubDeformerTest.tc SurfacePhongTest.tc TestFixture.tc TestRunner.tc main.tc LayerTest.tc +TC_SOURCES=AnimCurveKeyTest.tc AnimCurveNodeTest.tc AnimCurveTest.tc AnimLayerTest.tc AnimStackTest.tc Assertions.tc CameraTest.tc ClusterTest.tc DeformerTest.tc FbxObjectTest.tc FbxTimeTest.tc GeometryBaseTest.tc GeometryTest.tc LayerContainerTest.tc LightTest.tc MatrixTest.tc MeshTest.tc NodeTest.tc NodeTransformsTest.tc PropertyTest.tc SceneTest.tc SkinTest.tc SubDeformerTest.tc SurfacePhongTest.tc TestFixture.tc TestRunner.tc main.tc LayerTest.tc FbxImporterTest.tc SOURCES=$(TC_SOURCES:%.tc=%.cpp) HEADERS=Assertions.h OutputDebugStringBuf.h Tests.h OBJECTS=$(SOURCES:%.cpp=obj/%.o) diff --git a/FbxCppTests/TestRunner.cpp b/FbxCppTests/TestRunner.cpp index 82fdbe0..071e72e 100644 --- a/FbxCppTests/TestRunner.cpp +++ b/FbxCppTests/TestRunner.cpp @@ -134,6 +134,7 @@ void RunTests() tests.push_back(new LightTest()); tests.push_back(new CameraTest()); tests.push_back(new LayerTest()); + tests.push_back(new FbxImporterTest()); cout << "Running tests..." << endl; diff --git a/FbxCppTests/Tests.h b/FbxCppTests/Tests.h index cfc87a8..f291339 100644 --- a/FbxCppTests/Tests.h +++ b/FbxCppTests/Tests.h @@ -75,5 +75,6 @@ TestClass(AnimCurveKeyTest); TestClass(LightTest); TestClass(CameraTest); TestClass(LayerTest); +TestClass(FbxImporterTest); #endif // __FBXCPPTESTS_TESTS_H diff --git a/FbxSharp/FbxImporter.cs b/FbxSharp/FbxImporter.cs index bf63b00..b1e9290 100644 --- a/FbxSharp/FbxImporter.cs +++ b/FbxSharp/FbxImporter.cs @@ -12,15 +12,17 @@ public FbxImporter(string name = null) public string Name; - //public bool Initialize(string pFileName /*, int pFileFormat = -1, FbxIOSettings*pIOSettings = null*/) - //{ - // throw new NotImplementedException(); - //} - - //public bool Import(Document pDocument /*, bool pNonBlocking=false*/) - //{ - // throw new NotImplementedException(); - //} + private string initializedFilename = null; + + public bool Initialize(string pFileName /*, int pFileFormat = -1, FbxIOSettings*pIOSettings = null*/) + { + throw new NotImplementedException(); + } + + public bool Import(FbxDocument pDocument /*, bool pNonBlocking=false*/) + { + throw new NotImplementedException(); + } public FbxScene Import(string filename) { diff --git a/FbxSharpTests/FbxImporterTest.cs b/FbxSharpTests/FbxImporterTest.cs new file mode 100644 index 0000000..27cf5c2 --- /dev/null +++ b/FbxSharpTests/FbxImporterTest.cs @@ -0,0 +1,32 @@ +using System; +using NUnit.Framework; +using FbxSharp; + +namespace FbxSharpTests +{ + [TestFixture] + public class FbxImporterTest : TestBase + { + [Test] + public void FbxImporter_Create_AllZero() + { + // given: + var importer = new FbxImporter(""); + + // then: + Assert.AreEqual(0, CountProperties(importer)); + Assert.AreEqual(0, importer.GetSrcPropertyCount()); + Assert.AreEqual(0, importer.GetDstPropertyCount()); + } + + [Test] + public void FbxImporter_IsFBX_UnitializedYieldsError() + { + // given: + var importer = new FbxImporter(""); + + // then: + Assert.True(true); + } + } +} diff --git a/test-cases/FbxImporterTest.tc b/test-cases/FbxImporterTest.tc new file mode 100644 index 0000000..31ec99d --- /dev/null +++ b/test-cases/FbxImporterTest.tc @@ -0,0 +1,16 @@ +fixture FbxImporterTest +test FbxImporter_Create_AllZero + given + FbxImporter importer = new("") + + then + AssertEqual(0, CountProperties(importer)) + AssertEqual(0, importer.GetSrcPropertyCount()) + AssertEqual(0, importer.GetDstPropertyCount()) + +test FbxImporter_IsFBX_UnitializedYieldsError + given + FbxImporter importer = new("") + + then + AssertTrue(true) From 617632fe7e53100eba568777e9d93785e1b93c72 Mon Sep 17 00:00:00 2001 From: izrik Date: Tue, 14 May 2024 11:13:06 -0500 Subject: [PATCH 002/151] Make the gen scripts PWD-invariant. --- FbxCppTests/gen_tests.sh | 7 +++++-- FbxSharpTests/gen_tests.sh | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/FbxCppTests/gen_tests.sh b/FbxCppTests/gen_tests.sh index 6cb4f68..99eaebe 100755 --- a/FbxCppTests/gen_tests.sh +++ b/FbxCppTests/gen_tests.sh @@ -1,16 +1,19 @@ #!/bin/bash +__DIR__="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +__ROOT_DIR__="$(dirname "$(realpath "$__DIR__")")" + DEBUG= if [[ "$1" == "--debug" ]]; then DEBUG=1 fi -for f in ../test-cases/*.tc +for f in "$__ROOT_DIR__"/test-cases/*.tc do g=`basename $f .tc` if [[ -n "$DEBUG" ]]; then echo "Generating $g in C++" fi - dotnet ../TestCaseGenerator/bin/Debug/net8.0/TestCaseGenerator.dll cpp $f $g.cpp + dotnet "$__ROOT_DIR__/TestCaseGenerator/bin/Debug/net8.0/TestCaseGenerator.dll" cpp $f "$__DIR__/$g.cpp" done diff --git a/FbxSharpTests/gen_tests.sh b/FbxSharpTests/gen_tests.sh index 0db9daa..62932a4 100755 --- a/FbxSharpTests/gen_tests.sh +++ b/FbxSharpTests/gen_tests.sh @@ -1,16 +1,19 @@ #!/bin/bash +__DIR__="$(dirname "$(realpath "${BASH_SOURCE[0]}")")" +__ROOT_DIR__="$(dirname "$(realpath "$__DIR__")")" + DEBUG= if [[ "$1" == "--debug" ]]; then DEBUG=1 fi -for f in ../test-cases/*.tc +for f in "$__ROOT_DIR__"/test-cases/*.tc do g=`basename $f .tc` if [[ -n "$DEBUG" ]]; then echo "Generating $g in C#" fi - dotnet ../TestCaseGenerator/bin/Debug/net8.0/TestCaseGenerator.dll cs $f $g.cs + dotnet "$__ROOT_DIR__/TestCaseGenerator/bin/Debug/net8.0/TestCaseGenerator.dll" cs $f "$__DIR__/$g.cs" done From c60d6a98f22e4259878003ee7b4bfa9c4f2dd5d5 Mon Sep 17 00:00:00 2001 From: izrik Date: Tue, 14 May 2024 11:13:21 -0500 Subject: [PATCH 003/151] Adjust the test case. --- FbxCppTests/FbxImporterTest.cpp | 6 +++--- FbxSharpTests/FbxImporterTest.cs | 4 ++-- test-cases/FbxImporterTest.tc | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/FbxCppTests/FbxImporterTest.cpp b/FbxCppTests/FbxImporterTest.cpp index ae3f519..9a0f103 100644 --- a/FbxCppTests/FbxImporterTest.cpp +++ b/FbxCppTests/FbxImporterTest.cpp @@ -15,19 +15,19 @@ void FbxImporter_Create_AllZero() AssertEqual(0, importer->GetDstPropertyCount()); } -void FbxImporter_IsFBX_UnitializedYieldsError() +void FbxImporter_IsFBX_UnitializedYieldsFalse() { // given: FbxManager* manager = FbxManager::Create(); FbxImporter* importer = FbxImporter::Create(manager, ""); // then: - AssertTrue(true); + AssertFalse(importer->IsFBX()); } void FbxImporterTest::RegisterTestCases() { AddTestCase(FbxImporter_Create_AllZero); - AddTestCase(FbxImporter_IsFBX_UnitializedYieldsError); + AddTestCase(FbxImporter_IsFBX_UnitializedYieldsFalse); } diff --git a/FbxSharpTests/FbxImporterTest.cs b/FbxSharpTests/FbxImporterTest.cs index 27cf5c2..28030eb 100644 --- a/FbxSharpTests/FbxImporterTest.cs +++ b/FbxSharpTests/FbxImporterTest.cs @@ -20,13 +20,13 @@ public void FbxImporter_Create_AllZero() } [Test] - public void FbxImporter_IsFBX_UnitializedYieldsError() + public void FbxImporter_IsFBX_UnitializedYieldsFalse() { // given: var importer = new FbxImporter(""); // then: - Assert.True(true); + Assert.False(importer.IsFBX()); } } } diff --git a/test-cases/FbxImporterTest.tc b/test-cases/FbxImporterTest.tc index 31ec99d..9bf9550 100644 --- a/test-cases/FbxImporterTest.tc +++ b/test-cases/FbxImporterTest.tc @@ -8,9 +8,9 @@ test FbxImporter_Create_AllZero AssertEqual(0, importer.GetSrcPropertyCount()) AssertEqual(0, importer.GetDstPropertyCount()) -test FbxImporter_IsFBX_UnitializedYieldsError +test FbxImporter_IsFBX_UnitializedYieldsFalse given FbxImporter importer = new("") then - AssertTrue(true) + AssertFalse(importer.IsFBX()) From 9df159d2abf0091b4b33c4fb8e028ed6dbdaf874 Mon Sep 17 00:00:00 2001 From: izrik Date: Tue, 14 May 2024 11:53:47 -0500 Subject: [PATCH 004/151] Don't overwrite output files that are newer than the input files. Add a flag to force overwriting. --- TestCaseGenerator/Program.cs | 128 ++++++++++++++++++++++++----------- 1 file changed, 90 insertions(+), 38 deletions(-) diff --git a/TestCaseGenerator/Program.cs b/TestCaseGenerator/Program.cs index 50acb38..61e19a6 100644 --- a/TestCaseGenerator/Program.cs +++ b/TestCaseGenerator/Program.cs @@ -13,8 +13,25 @@ class MainClass public static void Main(string [] args) { var commander = new Commander("TestCaseGenerator", GetVersionStringFromAssembly()); - commander.Commands.Add("cs", CreateCommand("cs", "Generate C# tests", GenerateCs)); - commander.Commands.Add("cpp", CreateCommand("cpp", "Generate C++ tests", GenerateCpp)); + + var forceOption = new Option() + { + Name = "force", + Description = + "Generate a test file even if it already exists and is " + + "newer than the source .tc file", + Type = ParameterType.Flag, + }; + + var csCmd = CreateCommand( + "cs", "Generate C# tests", GenerateCs, + options: new[] { forceOption }); + commander.Commands.Add("cs", csCmd); + + var cppCmd = CreateCommand( + "cpp", "Generate C++ tests", GenerateCpp, + options: new[] { forceOption }); + commander.Commands.Add("cpp", cppCmd); try { @@ -59,23 +76,33 @@ public static string GetVersionStringFromAssembly() return version.ToString(version.Major == 0 ? 2 : 3); } - static Command CreateCommand(string name, string description, Action, TextWriter> generator) + static Command CreateCommand(string name, string description, + Action, TextWriter> generator, + IEnumerable extraParams = null, + IEnumerable