From 67b083b10fa165f5ff27dadab4cb549ad6227117 Mon Sep 17 00:00:00 2001 From: ousttrue Date: Wed, 17 Mar 2021 19:59:45 +0900 Subject: [PATCH] add LoadTests https://github.com/KhronosGroup/glTF-Sample-Models --- Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs | 85 +++++++++++++++++++ .../UniGLTF/Tests/UniGLTF/LoadTests.cs.meta | 11 +++ 2 files changed, 96 insertions(+) create mode 100644 Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs create mode 100644 Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs new file mode 100644 index 000000000..088336b43 --- /dev/null +++ b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.IO; +using NUnit.Framework; +using UnityEngine; + +namespace UniGLTF +{ + public class LoadTests + { + static IEnumerable EnumerateGltfFiles(DirectoryInfo dir) + { + if (dir.Name == ".git") + { + yield break; + } + + foreach (var child in dir.EnumerateDirectories()) + { + foreach (var x in EnumerateGltfFiles(child)) + { + yield return x; + } + } + + foreach (var child in dir.EnumerateFiles()) + { + switch (child.Extension.ToLower()) + { + case ".gltf": + case ".glb": + yield return child; + break; + } + } + } + + static void Load(FileInfo gltf) + { + var parser = new GltfParser(); + try + { + parser.ParsePath(gltf.FullName); + } + catch (Exception) + { + Debug.LogError($"ParseError: {gltf}"); + throw; + } + + try + { + using (var importer = new ImporterContext(parser)) + { + importer.Load(); + } + } + catch (Exception) + { + Debug.LogError($"LoadError: {gltf}"); + throw; + } + } + + [Test] + public void GltfSampleModelsTests() + { + var env = System.Environment.GetEnvironmentVariable("GLTF_SAMPLE_MODELS"); + if (string.IsNullOrEmpty(env)) + { + return; + } + var root = new DirectoryInfo(env); + if (!root.Exists) + { + return; + } + + foreach (var gltf in EnumerateGltfFiles(root)) + { + Load(gltf); + } + } + } +} diff --git a/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta new file mode 100644 index 000000000..956ec4ff5 --- /dev/null +++ b/Assets/UniGLTF/Tests/UniGLTF/LoadTests.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0454ecef7a44cf4280a6f0fcacf3666 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: