mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-05-13 14:04:29 -05:00
glb の parse を厳格に
This commit is contained in:
parent
95fb2eba1d
commit
79cad1342d
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace UniGLTF
|
||||
|
|
@ -37,5 +39,40 @@ namespace UniGLTF
|
|||
// NOTE: 大文字小文字が違うだけの名前は、同一としてみなされ、Suffix が付く。
|
||||
Assert.AreEqual("foobar__UNIGLTF__DUPLICATED__2", parsed.GLTF.textures[1].name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ヘッダが正しいが、後ろが切れている場合に throw する
|
||||
/// </summary>
|
||||
[Test]
|
||||
public void GlbLengthTest()
|
||||
{
|
||||
var env = System.Environment.GetEnvironmentVariable("GLTF_SAMPLE_MODELS");
|
||||
if (string.IsNullOrEmpty(env))
|
||||
{
|
||||
return;
|
||||
}
|
||||
var root = new DirectoryInfo($"{env}/2.0");
|
||||
if (!root.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var path = Path.Combine(root.ToString(), "DamagedHelmet\\glTF-Binary\\DamagedHelmet.glb");
|
||||
Assert.True(File.Exists(path));
|
||||
|
||||
var bytes = File.ReadAllBytes(path);
|
||||
var data = new GlbBinaryParser(bytes, Path.GetFileNameWithoutExtension(path)).Parse();
|
||||
|
||||
// 2個目のチャンクを削る
|
||||
var mod = bytes.Take(12 + 8 + data.Chunks[0].Bytes.Count).ToArray();
|
||||
// 再パース
|
||||
|
||||
Assert.Throws<IOException>(() =>
|
||||
{
|
||||
var data2 = new GlbBinaryParser(mod, Path.GetFileNameWithoutExtension(path)).Parse();
|
||||
});
|
||||
|
||||
var a = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user