Browse Source

Replaced old Trimmed app for a proper AOT ready unit test

vpenades 2 months ago
parent
commit
2736cba9ed

+ 7 - 7
SharpGLTF.sln

@@ -67,8 +67,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Plotly", "example
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.ThirdParty.Tests", "tests\SharpGLTF.ThirdParty.Tests\SharpGLTF.ThirdParty.Tests.csproj", "{38B27C0B-DB22-4CB7-A6DA-4A6C2A8385A8}"
 EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Trimmed.App", "examples\SharpGLTF.Trimmed.App\SharpGLTF.Trimmed.App.csproj", "{A09437F7-403C-44A2-B1FE-15CC535B64CA}"
-EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Runtime", "src\SharpGLTF.Runtime\SharpGLTF.Runtime.csproj", "{E06015B0-8DBC-4DC9-81A2-605DAFE36821}"
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Runtime.Tests", "tests\SharpGLTF.Runtime.Tests\SharpGLTF.Runtime.Tests.csproj", "{3925E45C-E7AA-4396-9567-4D8B1D1EF1C6}"
@@ -87,6 +85,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpGLTF.CodeGen.Extension
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpGLTF.CodeGen.Extensions.Cesium", "build\SharpGLTF.CodeGen.Extensions.Cesium\SharpGLTF.CodeGen.Extensions.Cesium.csproj", "{93100BDB-1DDF-42B9-8C0D-816A0306A5EE}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpGLTF.AOT.Tests", "tests\SharpGLTF.AOT.Tests\SharpGLTF.AOT.Tests.csproj", "{FDC6FFE6-1495-4901-AD43-F3365D7A8F86}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -145,10 +145,6 @@ Global
 		{38B27C0B-DB22-4CB7-A6DA-4A6C2A8385A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{38B27C0B-DB22-4CB7-A6DA-4A6C2A8385A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{38B27C0B-DB22-4CB7-A6DA-4A6C2A8385A8}.Release|Any CPU.Build.0 = Release|Any CPU
-		{A09437F7-403C-44A2-B1FE-15CC535B64CA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
-		{A09437F7-403C-44A2-B1FE-15CC535B64CA}.Debug|Any CPU.Build.0 = Debug|Any CPU
-		{A09437F7-403C-44A2-B1FE-15CC535B64CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
-		{A09437F7-403C-44A2-B1FE-15CC535B64CA}.Release|Any CPU.Build.0 = Release|Any CPU
 		{E06015B0-8DBC-4DC9-81A2-605DAFE36821}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
 		{E06015B0-8DBC-4DC9-81A2-605DAFE36821}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{E06015B0-8DBC-4DC9-81A2-605DAFE36821}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -185,6 +181,10 @@ Global
 		{93100BDB-1DDF-42B9-8C0D-816A0306A5EE}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{93100BDB-1DDF-42B9-8C0D-816A0306A5EE}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{93100BDB-1DDF-42B9-8C0D-816A0306A5EE}.Release|Any CPU.Build.0 = Release|Any CPU
+		{FDC6FFE6-1495-4901-AD43-F3365D7A8F86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{FDC6FFE6-1495-4901-AD43-F3365D7A8F86}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{FDC6FFE6-1495-4901-AD43-F3365D7A8F86}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{FDC6FFE6-1495-4901-AD43-F3365D7A8F86}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE
@@ -203,7 +203,6 @@ Global
 		{7FEFC259-51D6-4409-8724-8DE0EA8D5CD9} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
 		{A63C2A2D-950F-4C76-9299-2B2D325A8653} = {83E7E49D-8A28-45E8-9DBD-1F3AEDEF3E42}
 		{38B27C0B-DB22-4CB7-A6DA-4A6C2A8385A8} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
-		{A09437F7-403C-44A2-B1FE-15CC535B64CA} = {83E7E49D-8A28-45E8-9DBD-1F3AEDEF3E42}
 		{E06015B0-8DBC-4DC9-81A2-605DAFE36821} = {072B725F-773F-4751-9616-E9778897C1D2}
 		{3925E45C-E7AA-4396-9567-4D8B1D1EF1C6} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
 		{F98E7E4B-EF27-48A0-BA56-730F14CEEEE1} = {072B725F-773F-4751-9616-E9778897C1D2}
@@ -213,6 +212,7 @@ Global
 		{688D381F-262F-48CF-B3B7-10EC757C3854} = {D7D51F42-D08C-4DDA-88DA-AF008F10B644}
 		{9F601A55-5AD0-4323-824F-AF7AC4ABEA7F} = {D7D51F42-D08C-4DDA-88DA-AF008F10B644}
 		{93100BDB-1DDF-42B9-8C0D-816A0306A5EE} = {D7D51F42-D08C-4DDA-88DA-AF008F10B644}
+		{FDC6FFE6-1495-4901-AD43-F3365D7A8F86} = {0CBF510D-D836-40BA-95EC-E93FDBB90632}
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 		SolutionGuid = {1D7BBAD9-834C-4981-AC96-0AA5226FC43F}

+ 0 - 15
examples/SharpGLTF.Trimmed.App/Program.cs

@@ -1,15 +0,0 @@
-using System;
-using SharpGLTF.Schema2;
-
-namespace SharpGLTF
-{
-    class Program
-    {
-        public static void Main(string[] args)
-        {
-            ModelRoot
-                .Load(args[0])
-                .Save(args[1]);
-        }
-    }
-}

+ 0 - 18
examples/SharpGLTF.Trimmed.App/Properties/PublishProfiles/FolderProfile.pubxml

@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-https://go.microsoft.com/fwlink/?LinkID=208121.
--->
-<Project>
-  <PropertyGroup>
-    <Configuration>Release</Configuration>
-    <Platform>Any CPU</Platform>
-    <PublishDir>bin\Release\net8.0\publish\win-x64\</PublishDir>
-    <PublishProtocol>FileSystem</PublishProtocol>
-    <_TargetId>Folder</_TargetId>
-    <TargetFramework>net8.0</TargetFramework>
-    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
-    <SelfContained>true</SelfContained>
-    <PublishSingleFile>false</PublishSingleFile>
-    <PublishReadyToRun>false</PublishReadyToRun>
-  </PropertyGroup>
-</Project>

+ 0 - 21
examples/SharpGLTF.Trimmed.App/SharpGLTF.Trimmed.App.csproj

@@ -1,21 +0,0 @@
-<Project Sdk="Microsoft.NET.Sdk">
-
-  <PropertyGroup>
-    <OutputType>Exe</OutputType>
-    <TargetFramework>net8.0</TargetFramework>
-    <PublishAot>true</PublishAot>
-    <RootNamespace>SharpGLTF</RootNamespace>
-  </PropertyGroup>
-
-  <!-- https://docs.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming -->
-
-  <ItemGroup>
-    <ProjectReference Include="..\..\src\SharpGLTF.Core\SharpGLTF.Core.csproj" />
-    <ProjectReference Include="..\..\src\SharpGLTF.Toolkit\SharpGLTF.Toolkit.csproj" />
-
-    <!-- Analyze the whole library, even if attributed with "IsTrimmable" -->
-    <TrimmerRootAssembly Include="SharpGLTF.Core" />
-    <TrimmerRootAssembly Include="SharpGLTF.Toolkit" />
-  </ItemGroup>
-
-</Project>

+ 0 - 1
examples/SharpGLTF.Trimmed.App/publish.cmd

@@ -1 +0,0 @@
-dotnet publish -c Release -r win-x64

+ 8 - 0
tests/SharpGLTF.AOT.Tests/BuildAndRunTests.cmd

@@ -0,0 +1,8 @@
+
+dotnet publish SharpGLTF.AOT.Tests.csproj -c Release -o bin/Publish
+
+cd bin/Publish
+
+SharpGLTF.AOT.Tests.exe
+
+pause

+ 29 - 0
tests/SharpGLTF.AOT.Tests/MainTests.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using NUnit.Framework;
+using NUnit.Framework.Internal;
+
+using SharpGLTF.Schema2;
+
+namespace SharpGLTF
+{
+    internal class MainTests
+    {
+        [TestCase("glTF-Sample-Assets/Models/CesiumMan/glTF/CesiumMan.gltf")]
+        [TestCase("glTF-Sample-Assets/Models/CesiumMan/glTF-Binary/CesiumMan.glb")]
+        public void LoadTest(string modelPath)
+        {
+            var finfo = ResourceInfo.From(modelPath);
+
+            // load Polly model
+            var model = ModelRoot.Load(finfo.FilePath);
+
+            Assert.That(model, Is.Not.Null);
+
+        }
+    }
+}

+ 17 - 0
tests/SharpGLTF.AOT.Tests/Program.cs

@@ -0,0 +1,17 @@
+using System.Diagnostics.CodeAnalysis;
+
+using NUnitLite;
+
+// https://medium.com/@skyake/guidance-for-net-nativeaot-4b9853c80f8a
+
+namespace SharpGLTF
+{
+    internal class Program
+    {
+        [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(MainTests))] // this is confirmed as being required
+        static int Main(string[] args)
+        {
+            return new AutoRun(typeof(Program).Assembly).Execute(args);
+        }
+    }
+}

+ 10 - 0
tests/SharpGLTF.AOT.Tests/Properties/AssemblyInfo.cs

@@ -0,0 +1,10 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+using NUnit.Framework;
+
+[assembly: ResourcePathFormat("{SolutionDirectory}/tests/TestFiles")]
+[assembly: AttachmentPathFormat("*/TestResults/?", true)]

+ 36 - 0
tests/SharpGLTF.AOT.Tests/SharpGLTF.AOT.Tests.csproj

@@ -0,0 +1,36 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+  <PropertyGroup>
+		<RootNamespace>SharpGLTF</RootNamespace>
+		<OutputType>Exe</OutputType>
+		<TargetFramework>net8.0</TargetFramework>		
+		<Nullable>enable</Nullable>
+		<InvariantGlobalization>true</InvariantGlobalization>
+	</PropertyGroup>
+
+	<PropertyGroup>
+		<RuntimeIdentifier>win-x64</RuntimeIdentifier>
+	</PropertyGroup>
+
+	<PropertyGroup>
+		
+		<!-- https://github.com/nunit/nunit/issues/4987 -->
+		<!--
+		<PublishAot>true</PublishAot>
+		-->
+
+		<PublishTrimmed>true</PublishTrimmed>
+		<SelfContained>true</SelfContained>
+
+	</PropertyGroup>
+
+	<ItemGroup>
+		<PackageReference Include="NUnitLite" />
+		<PackageReference Include="TestAttachments.NUnit" />
+	</ItemGroup>
+
+	<ItemGroup>
+	  <ProjectReference Include="..\..\src\SharpGLTF.Toolkit\SharpGLTF.Toolkit.csproj" />
+	</ItemGroup>
+
+</Project>