< Summary

Class:ParametrizedShapesTests
Assembly:ParametrizedShapesTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/ParametrizedShapes/Tests/ParametrizedShapesTests.cs
Covered lines:172
Uncovered lines:0
Coverable lines:172
Total lines:373
Line coverage:100% (172 of 172)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BoxShapeUpdate()0%220100%
SphereShapeUpdate()0%220100%
CylinderShapeUpdate()0%220100%
ConeShapeUpdate()0%220100%
BoxShapeComponentMissingValuesGetDefaultedOnUpdate()0%220100%
BoxShapeAttachedGetsReplacedOnNewAttachment()0%330100%
SphereShapeComponentMissingValuesGetDefaultedOnUpdate()0%440100%
SphereShapeAttachedGetsReplacedOnNewAttachment()0%330100%
ConeShapeComponentMissingValuesGetDefaultedOnUpdate()0%440100%
ConeShapeAttachedGetsReplacedOnNewAttachment()0%330100%
CylinderShapeComponentMissingValuesGetDefaultedOnUpdate()0%440100%
CylinderShapeAttachedGetsReplacedOnNewAttachment()0%330100%
CollisionProperty()0%18180100%
VisibleProperty()0%18180100%
UpdateWithCollisionInMultipleEntities()0%770100%
UpdateVisibilityInMultipleEntities()0%770100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Components/ParametrizedShapes/Tests/ParametrizedShapesTests.cs

#LineLine coverage
 1using DCL.Components;
 2using DCL.Helpers;
 3using DCL.Models;
 4using NUnit.Framework;
 5using System.Collections;
 6using System.Collections.Generic;
 7using DCL;
 8using UnityEngine;
 9using UnityEngine.TestTools;
 10
 11public class ParametrizedShapesTests : IntegrationTestSuite_Legacy
 12{
 13    [UnityTest]
 14    public IEnumerator BoxShapeUpdate()
 15    {
 116        string entityId = "1";
 117        TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE, Vector3.zero);
 18
 119        var meshName = scene.entities[entityId].gameObject.GetComponentInChildren<MeshFilter>().mesh.name;
 120        Assert.AreEqual("DCL Box Instance", meshName);
 121        yield break;
 22    }
 23
 24    [UnityTest]
 25    public IEnumerator SphereShapeUpdate()
 26    {
 127        string entityId = "2";
 128        TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.SPHERE_SHAPE, Vector3.zero);
 29
 130        var meshName = scene.entities[entityId].gameObject.GetComponentInChildren<MeshFilter>().mesh.name;
 131        Assert.AreEqual("DCL Sphere Instance", meshName);
 132        yield break;
 33    }
 34
 35    [UnityTest]
 36    public IEnumerator CylinderShapeUpdate()
 37    {
 138        string entityId = "5";
 139        TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.CYLINDER_SHAPE, Vector3.zero);
 40
 141        var meshName = scene.entities[entityId].gameObject.GetComponentInChildren<MeshFilter>().mesh.name;
 142        Assert.AreEqual("DCL Cylinder Instance", meshName);
 143        yield break;
 44    }
 45
 46    [UnityTest]
 47    public IEnumerator ConeShapeUpdate()
 48    {
 149        string entityId = "4";
 150        TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.CONE_SHAPE, Vector3.zero);
 51
 152        var meshName = scene.entities[entityId].gameObject.GetComponentInChildren<MeshFilter>().mesh.name;
 53
 154        Assert.AreEqual("DCL Cone50v0t1b2l2o Instance", meshName);
 155        yield break;
 56    }
 57
 58    [UnityTest]
 59    public IEnumerator BoxShapeComponentMissingValuesGetDefaultedOnUpdate()
 60    {
 161        string entityId = "1";
 162        TestHelpers.CreateSceneEntity(scene, entityId);
 63
 64        // 1. Create component with non-default configs
 165        string componentJSON = JsonUtility.ToJson(new BoxShape.Model
 66        {
 67            withCollisions = true
 68        });
 69
 170        string componentId = TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE,
 71            componentJSON
 72        );
 73
 174        BoxShape boxShapeComponent = (BoxShape) scene.GetSharedComponent(componentId);
 75
 76        // 2. Check configured values
 177        Assert.IsTrue(boxShapeComponent.GetModel().withCollisions);
 78
 79        // 3. Update component with missing values
 180        scene.SharedComponentUpdate(componentId, JsonUtility.ToJson(new BoxShape.Model { }));
 81
 82        // 4. Check defaulted values
 183        Assert.IsTrue(boxShapeComponent.GetModel().withCollisions);
 184        yield break;
 85    }
 86
 87    [UnityTest]
 88    public IEnumerator BoxShapeAttachedGetsReplacedOnNewAttachment()
 89    {
 190        yield return TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<BoxShape.Model, BoxShape>(scene,
 91            CLASS_ID.BOX_SHAPE);
 192    }
 93
 94    [UnityTest]
 95    public IEnumerator SphereShapeComponentMissingValuesGetDefaultedOnUpdate()
 96    {
 197        var component =
 98            TestHelpers.SharedComponentCreate<SphereShape, SphereShape.Model>(scene, CLASS_ID.SPHERE_SHAPE);
 199        yield return component.routine;
 100
 1101        Assert.IsFalse(component == null);
 102
 1103        yield return TestHelpers.TestSharedComponentDefaultsOnUpdate<SphereShape.Model, SphereShape>(scene,
 104            CLASS_ID.SPHERE_SHAPE);
 1105    }
 106
 107    [UnityTest]
 108    public IEnumerator SphereShapeAttachedGetsReplacedOnNewAttachment()
 109    {
 1110        yield return TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<SphereShape.Model, SphereShape>(
 111            scene, CLASS_ID.SPHERE_SHAPE);
 1112    }
 113
 114    [UnityTest]
 115    public IEnumerator ConeShapeComponentMissingValuesGetDefaultedOnUpdate()
 116    {
 1117        var component = TestHelpers.SharedComponentCreate<ConeShape, ConeShape.Model>(scene, CLASS_ID.CONE_SHAPE);
 1118        yield return component.routine;
 119
 1120        Assert.IsFalse(component == null);
 121
 1122        yield return TestHelpers.TestSharedComponentDefaultsOnUpdate<ConeShape.Model, ConeShape>(scene,
 123            CLASS_ID.CONE_SHAPE);
 1124    }
 125
 126    [UnityTest]
 127    public IEnumerator ConeShapeAttachedGetsReplacedOnNewAttachment()
 128    {
 1129        yield return TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<ConeShape.Model, ConeShape>(scene,
 130            CLASS_ID.CONE_SHAPE);
 1131    }
 132
 133    [UnityTest]
 134    public IEnumerator CylinderShapeComponentMissingValuesGetDefaultedOnUpdate()
 135    {
 1136        var component =
 137            TestHelpers.SharedComponentCreate<CylinderShape, CylinderShape.Model>(scene, CLASS_ID.CYLINDER_SHAPE);
 1138        yield return component.routine;
 139
 1140        Assert.IsFalse(component == null);
 141
 1142        yield return TestHelpers.TestSharedComponentDefaultsOnUpdate<CylinderShape.Model, CylinderShape>(scene,
 143            CLASS_ID.CYLINDER_SHAPE);
 1144    }
 145
 146    [UnityTest]
 147    public IEnumerator CylinderShapeAttachedGetsReplacedOnNewAttachment()
 148    {
 1149        yield return
 150            TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<CylinderShape.Model, CylinderShape>(scene,
 151                CLASS_ID.CYLINDER_SHAPE);
 1152    }
 153
 154    [UnityTest]
 155    public IEnumerator CollisionProperty()
 156    {
 1157        string entityId = "entityId";
 1158        TestHelpers.CreateSceneEntity(scene, entityId);
 1159        var entity = scene.entities[entityId];
 160
 1161        TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) });
 162
 1163        yield return null;
 164
 165        // BoxShape
 1166        BaseShape.Model shapeModel = new BoxShape.Model();
 1167        BaseShape shapeComponent = TestHelpers.SharedComponentCreate<BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAP
 1168        yield return shapeComponent.routine;
 169
 1170        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 171
 1172        yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity);
 173
 1174        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1175        shapeComponent.Dispose();
 1176        yield return null;
 177
 178        // SphereShape
 1179        shapeModel = new SphereShape.Model();
 1180        shapeComponent = TestHelpers.SharedComponentCreate<SphereShape, BaseShape.Model>(scene, CLASS_ID.SPHERE_SHAPE, s
 1181        yield return shapeComponent.routine;
 182
 1183        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 184
 1185        yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity);
 186
 1187        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1188        shapeComponent.Dispose();
 1189        yield return null;
 190
 191        // ConeShape
 1192        shapeModel = new ConeShape.Model();
 1193        shapeComponent = TestHelpers.SharedComponentCreate<ConeShape, BaseShape.Model>(scene, CLASS_ID.CONE_SHAPE, shape
 1194        yield return shapeComponent.routine;
 195
 1196        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 197
 1198        yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity);
 199
 1200        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1201        shapeComponent.Dispose();
 1202        yield return null;
 203
 204        // CylinderShape
 1205        shapeModel = new CylinderShape.Model();
 1206        shapeComponent = TestHelpers.SharedComponentCreate<CylinderShape, BaseShape.Model>(scene, CLASS_ID.CYLINDER_SHAP
 1207        yield return shapeComponent.routine;
 208
 1209        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 210
 1211        yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity);
 212
 1213        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1214        shapeComponent.Dispose();
 1215        yield return null;
 216
 217        // PlaneShape
 1218        shapeModel = new PlaneShape.Model();
 1219        shapeComponent = TestHelpers.SharedComponentCreate<PlaneShape, BaseShape.Model>(scene, CLASS_ID.PLANE_SHAPE, sha
 1220        yield return shapeComponent.routine;
 221
 1222        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 223
 1224        yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity);
 225
 1226        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1227        shapeComponent.Dispose();
 1228        yield return null;
 1229    }
 230
 231    [UnityTest]
 232    public IEnumerator VisibleProperty()
 233    {
 1234        string entityId = "entityId";
 1235        TestHelpers.CreateSceneEntity(scene, entityId);
 1236        var entity = scene.entities[entityId];
 237
 1238        TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) });
 239
 1240        yield return null;
 241
 242        // BoxShape
 1243        BaseShape.Model shapeModel = new BoxShape.Model();
 1244        BaseShape shapeComponent = TestHelpers.SharedComponentCreate<BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAP
 1245        yield return shapeComponent.routine;
 246
 1247        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 248
 1249        yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity);
 250
 1251        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1252        shapeComponent.Dispose();
 1253        yield return null;
 254
 255        // SphereShape
 1256        shapeModel = new SphereShape.Model();
 1257        shapeComponent = TestHelpers.SharedComponentCreate<SphereShape, BaseShape.Model>(scene, CLASS_ID.SPHERE_SHAPE, s
 1258        yield return shapeComponent.routine;
 259
 1260        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 261
 1262        yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity);
 263
 1264        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1265        shapeComponent.Dispose();
 1266        yield return null;
 267
 268        // ConeShape
 1269        shapeModel = new ConeShape.Model();
 1270        shapeComponent = TestHelpers.SharedComponentCreate<ConeShape, BaseShape.Model>(scene, CLASS_ID.CONE_SHAPE, shape
 1271        yield return shapeComponent.routine;
 272
 1273        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 274
 1275        yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity);
 276
 1277        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1278        shapeComponent.Dispose();
 1279        yield return null;
 280
 281        // CylinderShape
 1282        shapeModel = new CylinderShape.Model();
 1283        shapeComponent = TestHelpers.SharedComponentCreate<CylinderShape, BaseShape.Model>(scene, CLASS_ID.CYLINDER_SHAP
 1284        yield return shapeComponent.routine;
 285
 1286        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 287
 1288        yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity);
 289
 1290        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1291        shapeComponent.Dispose();
 1292        yield return null;
 293
 294        // PlaneShape
 1295        shapeModel = new PlaneShape.Model();
 1296        shapeComponent = TestHelpers.SharedComponentCreate<PlaneShape, BaseShape.Model>(scene, CLASS_ID.PLANE_SHAPE, sha
 1297        yield return shapeComponent.routine;
 298
 1299        TestHelpers.SharedComponentAttach(shapeComponent, entity);
 300
 1301        yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity);
 302
 1303        TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id);
 1304        shapeComponent.Dispose();
 1305        yield return null;
 1306    }
 307
 308    [UnityTest]
 309    [TestCase(5, true, ExpectedResult = null)]
 310    [TestCase(5, false, ExpectedResult = null)]
 311    //TODO: When refactoring these tests to split them by shape, replicate this on them
 312    public IEnumerator UpdateWithCollisionInMultipleEntities(int entitiesCount, bool withCollision)
 313    {
 2314        Environment.i.world.sceneBoundsChecker.Stop();
 315
 316        // Arrange: set inverse of withCollision to trigger is dirty later
 2317        BaseShape shapeComponent = TestHelpers.SharedComponentCreate<BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAP
 2318        yield return shapeComponent.routine;
 2319        List<IDCLEntity> entities = new List<IDCLEntity>();
 24320        for (int i = 0; i < entitiesCount; i++)
 321        {
 10322            IDCLEntity entity = TestHelpers.CreateSceneEntity(scene, $"entity{i}");
 10323            TestHelpers.SharedComponentAttach(shapeComponent, entity);
 10324            entities.Add(entity);
 325        }
 326
 327        // Act: Update withCollision
 2328        shapeComponent.UpdateFromModel(new BoxShape.Model { withCollisions = withCollision });
 2329        yield return shapeComponent.routine;
 330
 331        // Assert:
 24332        foreach (IDCLEntity entity in entities)
 333        {
 40334            for (int i = 0; i < entity.meshesInfo.colliders.Count; i++)
 335            {
 10336                Assert.AreEqual(withCollision, entity.meshesInfo.colliders[i].enabled);
 337            }
 338        }
 2339    }
 340
 341    [UnityTest]
 342    [TestCase(5, true, ExpectedResult = null)]
 343    [TestCase(5, false, ExpectedResult = null)]
 344    //TODO: When refactoring these tests to split them by shape, replicate this on them
 345    public IEnumerator UpdateVisibilityInMultipleEntities(int entitiesCount, bool visible)
 346    {
 2347        Environment.i.world.sceneBoundsChecker.Stop();
 348
 349        // Arrange: set inverse of visible to trigger is dirty later
 2350        BaseShape shapeComponent = TestHelpers.SharedComponentCreate<BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAP
 2351        yield return shapeComponent.routine;
 2352        List<IDCLEntity> entities = new List<IDCLEntity>();
 24353        for (int i = 0; i < entitiesCount; i++)
 354        {
 10355            IDCLEntity entity = TestHelpers.CreateSceneEntity(scene, $"entity{i}");
 10356            TestHelpers.SharedComponentAttach(shapeComponent, entity);
 10357            entities.Add(entity);
 358        }
 359
 360        // Act: Update visible
 2361        shapeComponent.UpdateFromModel(new BoxShape.Model { visible = visible, withCollisions = true, isPointerBlocker =
 2362        yield return shapeComponent.routine;
 363
 364        // Assert:
 24365        foreach (IDCLEntity entity in entities)
 366        {
 40367            for (int i = 0; i < entity.meshesInfo.renderers.Length; i++)
 368            {
 10369                Assert.AreEqual(visible, entity.meshesInfo.renderers[i].enabled);
 370            }
 371        }
 2372    }
 373}