Skip to content

Commit

Permalink
test: add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikoga committed Oct 27, 2024
1 parent 17f64ab commit 9b9d7d4
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
71 changes: 71 additions & 0 deletions UnitTests~/AvatarRootTest.cs
Original file line number Diff line number Diff line change
@@ -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

}
}
3 changes: 3 additions & 0 deletions UnitTests~/AvatarRootTest.cs.meta

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

9 changes: 6 additions & 3 deletions UnitTests~/TestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,19 @@ 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<GameObject>(path));
var go = new GameObject();
go.name = name;
go.AddComponent<Animator>();
#if NDMF_VRCSDK3_AVATARS
go.AddComponent<VRCAvatarDescriptor>();
go.AddComponent<PipelineManager>();
if (isVRC)
{
go.AddComponent<VRCAvatarDescriptor>();
go.AddComponent<PipelineManager>();
}
#endif

objects.Add(go);
Expand Down

0 comments on commit 9b9d7d4

Please sign in to comment.