Skip to content

Commit

Permalink
Merge pull request #946 from oocytanb/fix/add_tests_for_validating_nu…
Browse files Browse the repository at this point in the history
…ll_materials

Add test cases for validating null materials
  • Loading branch information
ousttrue authored May 17, 2021
2 parents ef81a65 + c34bb2f commit 361bcd9
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
84 changes: 84 additions & 0 deletions Assets/UniGLTF/Tests/UniGLTF/MeshExportValidatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using NUnit.Framework;
using System.Linq;
using UnityEngine;

namespace UniGLTF
{
public class MeshExportValidatorTests
{
[Test]
public void NoMaterialTest()
{
var validator = ScriptableObject.CreateInstance<MeshExportValidator>();
var root = new GameObject("root");

try
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.SetParent(root.transform);

var renderer = cube.GetComponent<Renderer>();
renderer.sharedMaterials = new Material[0];

validator.SetRoot(root, MeshExportSettings.Default);
var vs = validator.Validate(root);
Assert.False(vs.All(x => x.CanExport));
}
finally
{
GameObject.DestroyImmediate(root);
ScriptableObject.DestroyImmediate(validator);
}
}

[Test]
public void NullMaterialTest()
{
var validator = ScriptableObject.CreateInstance<MeshExportValidator>();
var root = new GameObject("root");

try
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.SetParent(root.transform);

var renderer = cube.GetComponent<Renderer>();
renderer.sharedMaterials = new Material[] { null };

validator.SetRoot(root, MeshExportSettings.Default);
var vs = validator.Validate(root);
Assert.False(vs.All(x => x.CanExport));
}
finally
{
GameObject.DestroyImmediate(root);
ScriptableObject.DestroyImmediate(validator);
}
}

[Test]
public void NullMaterialsTest()
{
var validator = ScriptableObject.CreateInstance<MeshExportValidator>();
var root = new GameObject("root");

try
{
var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
cube.transform.SetParent(root.transform);

var renderer = cube.GetComponent<Renderer>();
renderer.sharedMaterials = new Material[] { null, null };

validator.SetRoot(root, MeshExportSettings.Default);
var vs = validator.Validate(root);
Assert.False(vs.All(x => x.CanExport));
}
finally
{
GameObject.DestroyImmediate(root);
ScriptableObject.DestroyImmediate(validator);
}
}
}
}
11 changes: 11 additions & 0 deletions Assets/UniGLTF/Tests/UniGLTF/MeshExportValidatorTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 361bcd9

Please sign in to comment.