From 9b9d7d47e971a732b4d34c3595fa4767c1a607d5 Mon Sep 17 00:00:00 2001 From: kaikoga Date: Sun, 27 Oct 2024 15:50:07 +0900 Subject: [PATCH] test: add some tests --- UnitTests~/AvatarRootTest.cs | 71 +++++++++++++++++++++++++++++++ UnitTests~/AvatarRootTest.cs.meta | 3 ++ UnitTests~/TestBase.cs | 9 ++-- 3 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 UnitTests~/AvatarRootTest.cs create mode 100644 UnitTests~/AvatarRootTest.cs.meta diff --git a/UnitTests~/AvatarRootTest.cs b/UnitTests~/AvatarRootTest.cs new file mode 100644 index 0000000..458fd1f --- /dev/null +++ b/UnitTests~/AvatarRootTest.cs @@ -0,0 +1,71 @@ +using nadena.dev.ndmf.runtime; +using NUnit.Framework; +using UnityEngine; + +namespace UnitTests.AvatarRootTests +{ + public class AvatarRoot : TestBase + { + private GameObject CreateGenericRoot(string name) => CreateRoot(name, isVRC: false); + private GameObject CreateVRCRoot(string name) => CreateRoot(name, isVRC: true); + + private Transform parentAvatar; + private Transform childAvatar; + + private void ParentIsAvatar() + { + Assert.That(RuntimeUtil.IsAvatarRoot(parentAvatar), Is.True); + Assert.That(RuntimeUtil.IsAvatarRoot(childAvatar), Is.False); + Assert.That(RuntimeUtil.FindAvatarInParents(parentAvatar), Is.EqualTo(parentAvatar)); + Assert.That(RuntimeUtil.FindAvatarInParents(childAvatar), Is.EqualTo(parentAvatar)); + Assert.That(RuntimeUtil.FindAvatarsInScene(parentAvatar.gameObject.scene), Is.EquivalentTo(new [] { parentAvatar })); + } + + [Test] + public void TestGenericContainsGeneric() + { + parentAvatar = CreateGenericRoot("parent").transform; + childAvatar = CreateGenericRoot("child").transform; + + childAvatar.parent = parentAvatar; + + ParentIsAvatar(); + } + +#if NDMF_VRCSDK3_AVATARS + [Test] + public void TestGenericContainsVRC() + { + parentAvatar = CreateGenericRoot("parent").transform; + childAvatar = CreateVRCRoot("child").transform; + + childAvatar.parent = parentAvatar; + + ParentIsAvatar(); + } + + [Test] + public void TestVRCContainsGeneric() + { + parentAvatar = CreateVRCRoot("parent").transform; + childAvatar = CreateGenericRoot("child").transform; + + childAvatar.parent = parentAvatar; + + ParentIsAvatar(); + } + + [Test] + public void TestVRCContainsVRC() + { + parentAvatar = CreateVRCRoot("parent").transform; + childAvatar = CreateVRCRoot("child").transform; + + childAvatar.parent = parentAvatar; + + ParentIsAvatar(); + } +#endif + + } +} \ No newline at end of file diff --git a/UnitTests~/AvatarRootTest.cs.meta b/UnitTests~/AvatarRootTest.cs.meta new file mode 100644 index 0000000..fefec2e --- /dev/null +++ b/UnitTests~/AvatarRootTest.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ed087e64ce72420a9736ceeb2d8bf713 +timeCreated: 1730010598 \ No newline at end of file diff --git a/UnitTests~/TestBase.cs b/UnitTests~/TestBase.cs index a8c923b..d5a9244 100644 --- a/UnitTests~/TestBase.cs +++ b/UnitTests~/TestBase.cs @@ -58,7 +58,7 @@ protected BuildContext CreateContext(GameObject root) return new BuildContext(root, TEMP_ASSET_PATH); // TODO - cleanup } - protected GameObject CreateRoot(string name) + protected GameObject CreateRoot(string name, bool isVRC = true) { //var path = AssetDatabase.GUIDToAssetPath(MinimalAvatarGuid); //var go = GameObject.Instantiate(AssetDatabase.LoadAssetAtPath(path)); @@ -66,8 +66,11 @@ protected GameObject CreateRoot(string name) go.name = name; go.AddComponent(); #if NDMF_VRCSDK3_AVATARS - go.AddComponent(); - go.AddComponent(); + if (isVRC) + { + go.AddComponent(); + go.AddComponent(); + } #endif objects.Add(go);