| | 1 | | using AvatarShape_Tests; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using System.Collections; |
| | 6 | | using DCL.Components; |
| | 7 | | using DCL.Interface; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.TestTools; |
| | 10 | |
|
| | 11 | | namespace Tests |
| | 12 | | { |
| | 13 | | public class AvatarShapeTests : IntegrationTestSuite_Legacy |
| | 14 | | { |
| | 15 | |
|
| | 16 | | void AssertMaterialsAreCorrect(Transform root) |
| | 17 | | { |
| 0 | 18 | | Renderer[] renderers = root.GetComponentsInChildren<Renderer>(); |
| | 19 | |
|
| 0 | 20 | | for (int i = 0; i < renderers.Length; i++) |
| | 21 | | { |
| 0 | 22 | | Renderer renderer = renderers[i]; |
| | 23 | |
|
| 0 | 24 | | for (int i1 = 0; i1 < renderer.sharedMaterials.Length; i1++) |
| | 25 | | { |
| 0 | 26 | | Material material = renderer.sharedMaterials[i1]; |
| 0 | 27 | | Assert.IsTrue(!material.shader.name.Contains("Lit"), $"Material must not be LWRP Lit. found {materia |
| | 28 | | } |
| | 29 | | } |
| 0 | 30 | | } |
| | 31 | |
|
| | 32 | | [UnityTest] |
| | 33 | | public IEnumerator DestroyWhileLoading() |
| | 34 | | { |
| 1 | 35 | | AvatarAssetsTestHelpers.CreateTestCatalogLocal(); |
| 1 | 36 | | AvatarShape avatar = AvatarShapeTestHelpers.CreateAvatarShape(scene, "Abortit", "TestAvatar.json"); |
| | 37 | |
|
| 1 | 38 | | GameObject goEntity = avatar.entity.gameObject; |
| | 39 | |
|
| 1 | 40 | | TestHelpers.RemoveSceneEntity(scene, avatar.entity); |
| | 41 | |
|
| 1 | 42 | | yield return null; |
| | 43 | |
|
| 1 | 44 | | bool destroyedOrPooled = goEntity == null || !goEntity.activeSelf; |
| 1 | 45 | | Assert.IsTrue(destroyedOrPooled); |
| 1 | 46 | | } |
| | 47 | |
|
| | 48 | | [UnityTest] |
| | 49 | | [Category("Explicit")] |
| | 50 | | [Explicit("Test too slow")] |
| | 51 | | public IEnumerator InterpolatePosition() |
| | 52 | | { |
| 0 | 53 | | AvatarAssetsTestHelpers.CreateTestCatalogLocal(); |
| 0 | 54 | | AvatarShape avatar = AvatarShapeTestHelpers.CreateAvatarShape(scene, "Abortitus", "TestAvatar.json"); |
| | 55 | |
|
| | 56 | | // We must wait for the AvatarShape to finish or the OnTransformChanged event is not used |
| 0 | 57 | | yield return new DCL.WaitUntil(() => avatar.everythingIsLoaded, 20); |
| | 58 | |
|
| 0 | 59 | | Assert.AreEqual(0f, avatar.entity.gameObject.transform.position.x); |
| 0 | 60 | | Assert.AreEqual(0f, avatar.entity.gameObject.transform.position.z); |
| | 61 | |
|
| | 62 | | // Update position to the other end of the parcel |
| 0 | 63 | | var transformModel = new DCLTransform.Model { position = new Vector3(15, 2, 15) }; |
| | 64 | |
|
| 0 | 65 | | TestHelpers.SetEntityTransform(scene, avatar.entity, transformModel); |
| | 66 | |
|
| 0 | 67 | | yield return null; |
| | 68 | |
|
| 0 | 69 | | Assert.AreNotEqual(15f, avatar.entity.gameObject.transform.position.x); |
| 0 | 70 | | Assert.AreNotEqual(15f, avatar.entity.gameObject.transform.position.z); |
| 0 | 71 | | } |
| | 72 | |
|
| | 73 | | [UnityTest] |
| | 74 | | [Category("Explicit")] |
| | 75 | | [Explicit("Test too slow")] |
| | 76 | | public IEnumerator MaterialsSetCorrectly() |
| | 77 | | { |
| 0 | 78 | | AvatarAssetsTestHelpers.CreateTestCatalogLocal(); |
| 0 | 79 | | AvatarShape avatar = AvatarShapeTestHelpers.CreateAvatarShape(scene, "Joan Darteis", "TestAvatar.json"); |
| 0 | 80 | | yield return new DCL.WaitUntil(() => avatar.everythingIsLoaded, 20); |
| | 81 | |
|
| 0 | 82 | | AssertMaterialsAreCorrect(avatar.transform); |
| 0 | 83 | | } |
| | 84 | |
|
| | 85 | | [UnityTest] |
| | 86 | | [Category("Explicit")] |
| | 87 | | [Explicit("Test too slow")] |
| | 88 | | public IEnumerator NameBackgroundHasCorrectSize() |
| | 89 | | { |
| 0 | 90 | | AvatarAssetsTestHelpers.CreateTestCatalogLocal(); |
| 0 | 91 | | AvatarShape avatar = AvatarShapeTestHelpers.CreateAvatarShape(scene, "Maiqel Yacson", "TestAvatar.json"); |
| 0 | 92 | | yield return new DCL.WaitUntil(() => avatar.everythingIsLoaded, 20); |
| | 93 | |
|
| 0 | 94 | | avatar.transform.position = new Vector3(13, 0, 4); |
| | 95 | |
|
| 0 | 96 | | RectTransform rt = avatar.avatarName.uiContainer.GetComponent<RectTransform>(); |
| | 97 | |
|
| 0 | 98 | | Assert.IsTrue((int)Mathf.Abs(rt.sizeDelta.x) == 190 && (int)Mathf.Abs(rt.sizeDelta.y) == 40, $"Avatar name d |
| 0 | 99 | | } |
| | 100 | |
|
| | 101 | | [UnityTest] |
| | 102 | | [Category("Explicit")] |
| | 103 | | [Explicit("Test too slow")] |
| | 104 | | public IEnumerator WhenTwoAvatarsLoadAtTheSameTimeTheyHaveProperMaterials() |
| | 105 | | { |
| | 106 | | //NOTE(Brian): Avatars must be equal to share their meshes. |
| 0 | 107 | | AvatarAssetsTestHelpers.CreateTestCatalogLocal(); |
| 0 | 108 | | AvatarShape avatar = AvatarShapeTestHelpers.CreateAvatarShape(scene, "Naicholas Keig", "TestAvatar.json"); |
| 0 | 109 | | AvatarShape avatar2 = AvatarShapeTestHelpers.CreateAvatarShape(scene, "Naicholas Keig", "TestAvatar2.json"); |
| | 110 | |
|
| 0 | 111 | | avatar.transform.position = new Vector3(-5, 0, 0); |
| 0 | 112 | | avatar2.transform.position = new Vector3(5, 0, 0); |
| | 113 | |
|
| 0 | 114 | | yield return new DCL.WaitUntil(() => avatar.everythingIsLoaded && avatar2.everythingIsLoaded, 25); |
| | 115 | |
|
| 0 | 116 | | AssertMaterialsAreCorrect(avatar.transform); |
| 0 | 117 | | AssertMaterialsAreCorrect(avatar2.transform); |
| 0 | 118 | | } |
| | 119 | | } |
| | 120 | | } |