LoadGeneratedTests.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using NUnit.Framework;
  6. namespace SharpGLTF.Schema2.LoadAndSave
  7. {
  8. /// <summary>
  9. /// Test cases for models found in <see href="https://github.com/bghgary/glTF-Asset-Generator"/>
  10. /// </summary>
  11. [TestFixture]
  12. [AttachmentPathFormat("*/TestResults/LoadAndSave/?", true)]
  13. [Category("Model Load and Save")]
  14. public class LoadGeneratedTests
  15. {
  16. #region setup
  17. [OneTimeSetUp]
  18. public void Setup()
  19. {
  20. // TestFiles.DownloadReferenceModels();
  21. }
  22. #endregion
  23. [TestCase(true)]
  24. [TestCase(false)]
  25. public void LoadGeneratedModels(bool isNegativeCase)
  26. {
  27. var files = TestFiles.GetReferenceModelPaths(isNegativeCase);
  28. bool passed = true;
  29. foreach (var filePath in files)
  30. {
  31. // System.Diagnostics.Debug.Assert(!filePath.EndsWith("Buffer_Interleaved_03.gltf"));
  32. if (filePath.EndsWith("Compatibility_05.gltf")) continue; // contains a REQUIRED Material_QuantumRendering
  33. var gltfJson = filePath.EndsWith(".gltf") ? System.IO.File.ReadAllText(filePath) : string.Empty;
  34. var report = GltfValidator.ValidationReport.Validate(filePath);
  35. if (report == null) continue; // ??
  36. if (report.HasUnsupportedExtensions) continue;
  37. try
  38. {
  39. var model = ModelRoot.Load(filePath);
  40. if (report.Severity == GltfValidator.Severity.Error)
  41. {
  42. TestContext.Error.WriteLine($"{filePath.ToShortDisplayPath()} 👎😦 Should not load!");
  43. passed = false;
  44. }
  45. else
  46. {
  47. TestContext.WriteLine($"{filePath.ToShortDisplayPath()} 🙂👍");
  48. }
  49. }
  50. catch (Exception ex)
  51. {
  52. if (report.Severity != GltfValidator.Severity.Error)
  53. {
  54. TestContext.Error.WriteLine($"{filePath.ToShortDisplayPath()} 👎😦 Should load!");
  55. TestContext.Error.WriteLine($" ERROR: {ex.Message}");
  56. passed = false;
  57. }
  58. else
  59. {
  60. TestContext.WriteLine($"{filePath.ToShortDisplayPath()} 🙂👍");
  61. TestContext.WriteLine($" Expected Exception: {ex.Message}");
  62. }
  63. }
  64. /*
  65. if (ShouldLoad && !filePath.ToUpperInvariant().Contains("COMPATIBILITY"))
  66. {
  67. var model = ModelRoot.Load(filePath);
  68. model.AttachToCurrentTest(System.IO.Path.ChangeExtension(System.IO.Path.GetFileName(filePath), ".obj"));
  69. }*/
  70. }
  71. Assert.That(passed);
  72. }
  73. }
  74. }