< Summary

Class:SceneBoundariesCheckerTests.SBC_Asserts
Assembly:SceneBoundariesCheckerTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneBoundariesController/Tests/SBC_Asserts.cs
Covered lines:132
Uncovered lines:40
Coverable lines:172
Total lines:366
Line coverage:76.7% (132 of 172)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
EntitiesAreBeingCorrectlyRegistered()0%330100%
PShapeIsInvalidatedWhenStartingOutOfBounds()0%330100%
GLTFShapeIsInvalidatedWhenStartingOutOfBounds()0%440100%
NFTShapeIsInvalidatedWhenStartingOutOfBounds()0%42600%
PShapeIsInvalidatedWhenLeavingBounds()0%550100%
GLTFShapeIsInvalidatedWhenLeavingBounds()0%550100%
NFTShapeIsInvalidatedWhenLeavingBounds()0%42600%
HeightIsEvaluated()0%550100%
ChildShapeIsEvaluated()0%660100%
ChildShapeIsEvaluatedOnShapelessParent()0%770100%
PShapeIsResetWhenReenteringBounds()0%550100%
GLTFShapeIsResetWhenReenteringBounds()0%660100%
NFTShapeIsResetWhenReenteringBounds()0%42600%
AssertMeshIsInvalid(...)0%550100%
AssertMeshIsValid(...)0%660100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/SceneBoundariesController/Tests/SBC_Asserts.cs

#LineLine coverage
 1using DCL;
 2using DCL.Components;
 3using DCL.Controllers;
 4using DCL.Helpers;
 5using DCL.Models;
 6using Newtonsoft.Json;
 7using NUnit.Framework;
 8using System.Collections;
 9using System.Linq;
 10using UnityEngine;
 11
 12namespace SceneBoundariesCheckerTests
 13{
 14    public static class SBC_Asserts
 15    {
 16        public static IEnumerator EntitiesAreBeingCorrectlyRegistered(ParcelScene scene)
 17        {
 118            var boxShape1 = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(20, 2, 20));
 119            var boxShape2 = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(20, 2, 20));
 20
 121            var entity1 = boxShape1.attachedEntities.First();
 122            var entity2 = boxShape2.attachedEntities.First();
 23
 124            TestHelpers.SetEntityParent(scene, entity1, entity2);
 25
 126            Assert.AreEqual(2, scene.entities.Count, "scene entities count can't be zero!");
 127            Assert.AreEqual(2, Environment.i.world.sceneBoundsChecker.entitiesToCheckCount, "entities to check can't be 
 28
 129            yield return null;
 30
 131            TestHelpers.RemoveSceneEntity(scene, entity2.entityId);
 32
 133            Environment.i.platform.parcelScenesCleaner.ForceCleanup();
 34
 135            Assert.AreEqual(0, scene.entities.Count, "entity count should be zero");
 136            Assert.AreEqual(0, Environment.i.world.sceneBoundsChecker.entitiesToCheckCount, "entities to check should be
 137        }
 38
 39        public static IEnumerator PShapeIsInvalidatedWhenStartingOutOfBounds(ParcelScene scene)
 40        {
 241            var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(20, 2, 20));
 242            yield return null;
 43
 244            AssertMeshIsInvalid(boxShape.attachedEntities.First().meshesInfo);
 245        }
 46
 47        public static IEnumerator GLTFShapeIsInvalidatedWhenStartingOutOfBounds(ParcelScene scene)
 48        {
 249            var entity = TestHelpers.CreateSceneEntity(scene);
 50
 251            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) });
 52
 253            TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeO
 54                new
 55                {
 56                    src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb"
 57                }));
 258            LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity);
 1459            yield return new UnityEngine.WaitUntil(() => gltfShape.alreadyLoaded);
 260            yield return null;
 61
 262            AssertMeshIsInvalid(entity.meshesInfo);
 263        }
 64
 65        public static IEnumerator NFTShapeIsInvalidatedWhenStartingOutOfBounds(ParcelScene scene)
 66        {
 067            var entity = TestHelpers.CreateSceneEntity(scene);
 68
 069            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) });
 70
 071            var componentModel = new NFTShape.Model()
 72            {
 73                src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536"
 74            };
 075            NFTShape component = TestHelpers.SharedComponentCreate<NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, 
 076            yield return component.routine;
 77
 078            TestHelpers.SharedComponentAttach(component, entity);
 79
 080            yield return null;
 81
 082            LoadWrapper shapeLoader = NFTShape.GetLoaderForEntity(entity);
 083            yield return new UnityEngine.WaitUntil(() => shapeLoader.alreadyLoaded);
 84
 085            yield return null;
 86
 087            AssertMeshIsInvalid(entity.meshesInfo);
 088        }
 89
 90        public static IEnumerator PShapeIsInvalidatedWhenLeavingBounds(ParcelScene scene)
 91        {
 292            var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(8, 1, 8));
 293            yield return null;
 94
 295            var entity = boxShape.attachedEntities.First();
 96
 297            AssertMeshIsValid(entity.meshesInfo);
 98
 99            // Move object to surpass the scene boundaries
 2100            var transformModel = new DCLTransform.Model { position = new Vector3(18, 1, 18) };
 2101            TestHelpers.SetEntityTransform(scene, entity, transformModel);
 102
 2103            yield return null;
 2104            yield return null;
 105
 2106            AssertMeshIsInvalid(entity.meshesInfo);
 2107        }
 108
 109        public static IEnumerator GLTFShapeIsInvalidatedWhenLeavingBounds(ParcelScene scene)
 110        {
 2111            var entity = TestHelpers.CreateSceneEntity(scene);
 112
 2113            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) });
 114
 2115            TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeO
 116                new
 117                {
 118                    src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb"
 119                }));
 2120            LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity);
 14121            yield return new UnityEngine.WaitUntil(() => gltfShape.alreadyLoaded);
 122
 2123            AssertMeshIsValid(entity.meshesInfo);
 124
 125            // Move object to surpass the scene boundaries
 2126            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) });
 127
 2128            yield return null;
 2129            yield return null;
 130
 2131            AssertMeshIsInvalid(entity.meshesInfo);
 2132        }
 133
 134        public static IEnumerator NFTShapeIsInvalidatedWhenLeavingBounds(ParcelScene scene)
 135        {
 0136            var entity = TestHelpers.CreateSceneEntity(scene);
 137
 0138            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) });
 139
 0140            var componentModel = new NFTShape.Model()
 141            {
 142                src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536"
 143            };
 0144            NFTShape component = TestHelpers.SharedComponentCreate<NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, 
 0145            yield return component.routine;
 146
 0147            TestHelpers.SharedComponentAttach(component, entity);
 148
 0149            yield return null;
 150
 0151            LoadWrapper shapeLoader = NFTShape.GetLoaderForEntity(entity);
 0152            yield return new UnityEngine.WaitUntil(() => shapeLoader.alreadyLoaded);
 153
 0154            AssertMeshIsValid(entity.meshesInfo);
 155
 156            // Move object to surpass the scene boundaries
 0157            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) });
 158
 0159            yield return null;
 160
 0161            AssertMeshIsInvalid(entity.meshesInfo);
 0162        }
 163
 164        public static IEnumerator HeightIsEvaluated(ParcelScene scene)
 165        {
 2166            var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(8, 5, 8));
 2167            var entity = boxShape.attachedEntities.First();
 2168            yield return null;
 169
 2170            AssertMeshIsValid(entity.meshesInfo);
 171
 172            // Move object to surpass the scene height boundaries
 2173            var transformModel = new DCLTransform.Model { position = new Vector3(8, 30, 8) };
 2174            TestHelpers.SetEntityTransform(scene, entity, transformModel);
 175
 2176            yield return null;
 2177            yield return null;
 178
 2179            AssertMeshIsInvalid(entity.meshesInfo);
 2180        }
 181
 182        public static IEnumerator ChildShapeIsEvaluated(ParcelScene scene)
 183        {
 2184            string entityId = "1";
 2185            TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(8, 1, 8))
 2186            yield return null;
 187
 2188            AssertMeshIsValid(scene.entities[entityId].meshesInfo);
 189
 190            // Attach child
 2191            string childEntityId = "2";
 2192            TestHelpers.InstantiateEntityWithShape(scene, childEntityId, DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(8, 1
 2193            yield return null;
 194
 2195            AssertMeshIsValid(scene.entities[childEntityId].meshesInfo);
 196
 2197            TestHelpers.SetEntityParent(scene, childEntityId, entityId);
 198
 199            // Move parent object to surpass the scene boundaries
 2200            var transformModel = new DCLTransform.Model { position = new Vector3(18, 1, 18) };
 2201            TestHelpers.SetEntityTransform(scene, scene.entities[entityId], transformModel);
 202
 2203            yield return null;
 2204            yield return null;
 205
 2206            AssertMeshIsInvalid(scene.entities[childEntityId].meshesInfo);
 2207        }
 208
 209        public static IEnumerator ChildShapeIsEvaluatedOnShapelessParent(ParcelScene scene)
 210        {
 211            // create shapeless parent entity
 2212            string entityId = "1";
 2213            TestHelpers.CreateSceneEntity(scene, entityId);
 2214            TestHelpers.SetEntityTransform(scene, scene.entities[entityId], new Vector3(18, 1, 18), Quaternion.identity,
 2215            yield return null;
 216
 2217            AssertMeshIsValid(scene.entities[entityId].meshesInfo);
 218
 219            // Attach child
 2220            string childEntityId = "2";
 2221            TestHelpers.InstantiateEntityWithShape(scene, childEntityId, DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(0, 0
 2222            yield return null;
 223
 2224            TestHelpers.SetEntityParent(scene, childEntityId, entityId);
 2225            yield return null;
 226
 2227            AssertMeshIsInvalid(scene.entities[childEntityId].meshesInfo);
 228
 229            // Move parent object to re-enter the scene boundaries
 2230            TestHelpers.SetEntityTransform(scene, scene.entities[entityId], new Vector3(8, 1, 8), Quaternion.identity, V
 231
 2232            yield return null;
 2233            yield return null;
 234
 2235            AssertMeshIsValid(scene.entities[childEntityId].meshesInfo);
 2236        }
 237
 238        public static IEnumerator PShapeIsResetWhenReenteringBounds(ParcelScene scene)
 239        {
 2240            var boxShape = TestHelpers.CreateEntityWithBoxShape(scene, new Vector3(18, 1, 18));
 2241            yield return null;
 242
 2243            var entity = boxShape.attachedEntities.First();
 2244            yield return null;
 245
 2246            AssertMeshIsInvalid(entity.meshesInfo);
 247
 248            // Move object to re-enter the scene boundaries
 2249            var transformModel = new DCLTransform.Model { position = new Vector3(8, 1, 8) };
 2250            TestHelpers.SetEntityTransform(scene, entity, transformModel);
 251
 2252            yield return null;
 253
 2254            AssertMeshIsValid(entity.meshesInfo);
 2255        }
 256
 257        public static IEnumerator GLTFShapeIsResetWhenReenteringBounds(ParcelScene scene)
 258        {
 1259            var entity = TestHelpers.CreateSceneEntity(scene);
 260
 1261            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) });
 262
 1263            TestHelpers.CreateAndSetShape(scene, entity.entityId, DCL.Models.CLASS_ID.GLTF_SHAPE, JsonConvert.SerializeO
 264                new
 265                {
 266                    src = TestAssetsUtils.GetPath() + "/GLB/PalmTree_01.glb"
 267                }));
 1268            LoadWrapper gltfShape = GLTFShape.GetLoaderForEntity(entity);
 7269            yield return new UnityEngine.WaitUntil(() => gltfShape.alreadyLoaded);
 1270            yield return null;
 271
 1272            AssertMeshIsInvalid(entity.meshesInfo);
 273
 274            // Move object to surpass the scene boundaries
 1275            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) });
 276
 1277            yield return null;
 1278            yield return null;
 279
 1280            AssertMeshIsValid(entity.meshesInfo);
 1281        }
 282
 283        public static IEnumerator NFTShapeIsResetWhenReenteringBounds(ParcelScene scene)
 284        {
 0285            var entity = TestHelpers.CreateSceneEntity(scene);
 286
 0287            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(18, 1, 18) });
 288
 0289            var componentModel = new NFTShape.Model()
 290            {
 291                src = "ethereum://0x06012c8cf97BEaD5deAe237070F9587f8E7A266d/558536"
 292            };
 0293            NFTShape component = TestHelpers.SharedComponentCreate<NFTShape, NFTShape.Model>(scene, CLASS_ID.NFT_SHAPE, 
 0294            yield return component.routine;
 295
 0296            TestHelpers.SharedComponentAttach(component, entity);
 297
 0298            yield return null;
 299
 0300            LoadWrapper shapeLoader = NFTShape.GetLoaderForEntity(entity);
 0301            yield return new UnityEngine.WaitUntil(() => shapeLoader.alreadyLoaded);
 302
 0303            AssertMeshIsInvalid(entity.meshesInfo);
 304
 305            // Move object to surpass the scene boundaries
 0306            TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) });
 307
 0308            yield return null;
 309
 0310            AssertMeshIsValid(entity.meshesInfo);
 0311        }
 312
 313        public static void AssertMeshIsInvalid(MeshesInfo meshesInfo)
 314        {
 18315            Assert.IsTrue(meshesInfo.meshRootGameObject != null, "MeshRootGameObject is null. The object is valid when i
 316
 18317            if (Environment.i.world.sceneBoundsChecker.GetFeedbackStyle() is SceneBoundsFeedbackStyle_RedFlicker)
 318            {
 40319                for (int i = 0; i < meshesInfo.renderers.Length; i++)
 320                {
 10321                    string matName = meshesInfo.renderers[i].sharedMaterial.name;
 10322                    Assert.IsTrue(matName.Contains("Invalid"), $"Material should be Invalid. Material is: {matName}");
 323                }
 10324            }
 325            else
 326            {
 32327                for (int i = 0; i < meshesInfo.renderers.Length; i++)
 328                {
 8329                    Assert.IsFalse(meshesInfo.renderers[i].enabled, $"Renderer {meshesInfo.renderers[i].gameObject.name}
 330                }
 331
 32332                for (int i = 0; i < meshesInfo.colliders.Count; i++)
 333                {
 8334                    Assert.IsFalse(meshesInfo.colliders[i].enabled, $"Collider {meshesInfo.renderers[i].gameObject.name}
 335                }
 336            }
 8337        }
 338
 339        public static void AssertMeshIsValid(MeshesInfo meshesInfo)
 340        {
 19341            if (meshesInfo.meshRootGameObject == null)
 2342                return; // It's valid if there's no mesh
 343
 17344            if (Environment.i.world.sceneBoundsChecker.GetFeedbackStyle() is SceneBoundsFeedbackStyle_RedFlicker)
 345            {
 40346                for (int i = 0; i < meshesInfo.renderers.Length; i++)
 347                {
 10348                    string matName = meshesInfo.renderers[i].sharedMaterial.name;
 10349                    Assert.IsFalse(matName.Contains("Invalid"), $"Material shouldn't be invalid. Material is: {matName}"
 350                }
 10351            }
 352            else
 353            {
 28354                for (int i = 0; i < meshesInfo.renderers.Length; i++)
 355                {
 7356                    Assert.IsTrue(meshesInfo.renderers[i].enabled, $"Renderer {meshesInfo.renderers[i].gameObject.name} 
 357                }
 358
 28359                for (int i = 0; i < meshesInfo.colliders.Count; i++)
 360                {
 7361                    Assert.IsTrue(meshesInfo.colliders[i].enabled, $"Collider {meshesInfo.renderers[i].gameObject.name} 
 362                }
 363            }
 7364        }
 365    }
 366}