| | 1 | | using DCL.Components; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using System.Collections; |
| | 6 | | using System.Collections.Generic; |
| | 7 | | using DCL; |
| | 8 | | using UnityEngine; |
| | 9 | | using UnityEngine.TestTools; |
| | 10 | |
|
| | 11 | | public class ParametrizedShapesTests : IntegrationTestSuite_Legacy |
| | 12 | | { |
| | 13 | | [UnityTest] |
| | 14 | | public IEnumerator BoxShapeUpdate() |
| | 15 | | { |
| 1 | 16 | | string entityId = "1"; |
| 1 | 17 | | TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE, Vector3.zero); |
| | 18 | |
|
| 1 | 19 | | var meshName = scene.entities[entityId].gameObject.GetComponentInChildren<MeshFilter>().mesh.name; |
| 1 | 20 | | Assert.AreEqual("DCL Box Instance", meshName); |
| 1 | 21 | | yield break; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | [UnityTest] |
| | 25 | | public IEnumerator SphereShapeUpdate() |
| | 26 | | { |
| 1 | 27 | | string entityId = "2"; |
| 1 | 28 | | TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.SPHERE_SHAPE, Vector3.zero); |
| | 29 | |
|
| 1 | 30 | | var meshName = scene.entities[entityId].gameObject.GetComponentInChildren<MeshFilter>().mesh.name; |
| 1 | 31 | | Assert.AreEqual("DCL Sphere Instance", meshName); |
| 1 | 32 | | yield break; |
| | 33 | | } |
| | 34 | |
|
| | 35 | | [UnityTest] |
| | 36 | | public IEnumerator CylinderShapeUpdate() |
| | 37 | | { |
| 1 | 38 | | string entityId = "5"; |
| 1 | 39 | | TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.CYLINDER_SHAPE, Vector3.zero); |
| | 40 | |
|
| 1 | 41 | | var meshName = scene.entities[entityId].gameObject.GetComponentInChildren<MeshFilter>().mesh.name; |
| 1 | 42 | | Assert.AreEqual("DCL Cylinder Instance", meshName); |
| 1 | 43 | | yield break; |
| | 44 | | } |
| | 45 | |
|
| | 46 | | [UnityTest] |
| | 47 | | public IEnumerator ConeShapeUpdate() |
| | 48 | | { |
| 1 | 49 | | string entityId = "4"; |
| 1 | 50 | | TestHelpers.InstantiateEntityWithShape(scene, entityId, DCL.Models.CLASS_ID.CONE_SHAPE, Vector3.zero); |
| | 51 | |
|
| 1 | 52 | | var meshName = scene.entities[entityId].gameObject.GetComponentInChildren<MeshFilter>().mesh.name; |
| | 53 | |
|
| 1 | 54 | | Assert.AreEqual("DCL Cone50v0t1b2l2o Instance", meshName); |
| 1 | 55 | | yield break; |
| | 56 | | } |
| | 57 | |
|
| | 58 | | [UnityTest] |
| | 59 | | public IEnumerator BoxShapeComponentMissingValuesGetDefaultedOnUpdate() |
| | 60 | | { |
| 1 | 61 | | string entityId = "1"; |
| 1 | 62 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| | 63 | |
|
| | 64 | | // 1. Create component with non-default configs |
| 1 | 65 | | string componentJSON = JsonUtility.ToJson(new BoxShape.Model |
| | 66 | | { |
| | 67 | | withCollisions = true |
| | 68 | | }); |
| | 69 | |
|
| 1 | 70 | | string componentId = TestHelpers.CreateAndSetShape(scene, entityId, DCL.Models.CLASS_ID.BOX_SHAPE, |
| | 71 | | componentJSON |
| | 72 | | ); |
| | 73 | |
|
| 1 | 74 | | BoxShape boxShapeComponent = (BoxShape) scene.GetSharedComponent(componentId); |
| | 75 | |
|
| | 76 | | // 2. Check configured values |
| 1 | 77 | | Assert.IsTrue(boxShapeComponent.GetModel().withCollisions); |
| | 78 | |
|
| | 79 | | // 3. Update component with missing values |
| 1 | 80 | | scene.SharedComponentUpdate(componentId, JsonUtility.ToJson(new BoxShape.Model { })); |
| | 81 | |
|
| | 82 | | // 4. Check defaulted values |
| 1 | 83 | | Assert.IsTrue(boxShapeComponent.GetModel().withCollisions); |
| 1 | 84 | | yield break; |
| | 85 | | } |
| | 86 | |
|
| | 87 | | [UnityTest] |
| | 88 | | public IEnumerator BoxShapeAttachedGetsReplacedOnNewAttachment() |
| | 89 | | { |
| 1 | 90 | | yield return TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<BoxShape.Model, BoxShape>(scene, |
| | 91 | | CLASS_ID.BOX_SHAPE); |
| 1 | 92 | | } |
| | 93 | |
|
| | 94 | | [UnityTest] |
| | 95 | | public IEnumerator SphereShapeComponentMissingValuesGetDefaultedOnUpdate() |
| | 96 | | { |
| 1 | 97 | | var component = |
| | 98 | | TestHelpers.SharedComponentCreate<SphereShape, SphereShape.Model>(scene, CLASS_ID.SPHERE_SHAPE); |
| 1 | 99 | | yield return component.routine; |
| | 100 | |
|
| 1 | 101 | | Assert.IsFalse(component == null); |
| | 102 | |
|
| 1 | 103 | | yield return TestHelpers.TestSharedComponentDefaultsOnUpdate<SphereShape.Model, SphereShape>(scene, |
| | 104 | | CLASS_ID.SPHERE_SHAPE); |
| 1 | 105 | | } |
| | 106 | |
|
| | 107 | | [UnityTest] |
| | 108 | | public IEnumerator SphereShapeAttachedGetsReplacedOnNewAttachment() |
| | 109 | | { |
| 1 | 110 | | yield return TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<SphereShape.Model, SphereShape>( |
| | 111 | | scene, CLASS_ID.SPHERE_SHAPE); |
| 1 | 112 | | } |
| | 113 | |
|
| | 114 | | [UnityTest] |
| | 115 | | public IEnumerator ConeShapeComponentMissingValuesGetDefaultedOnUpdate() |
| | 116 | | { |
| 1 | 117 | | var component = TestHelpers.SharedComponentCreate<ConeShape, ConeShape.Model>(scene, CLASS_ID.CONE_SHAPE); |
| 1 | 118 | | yield return component.routine; |
| | 119 | |
|
| 1 | 120 | | Assert.IsFalse(component == null); |
| | 121 | |
|
| 1 | 122 | | yield return TestHelpers.TestSharedComponentDefaultsOnUpdate<ConeShape.Model, ConeShape>(scene, |
| | 123 | | CLASS_ID.CONE_SHAPE); |
| 1 | 124 | | } |
| | 125 | |
|
| | 126 | | [UnityTest] |
| | 127 | | public IEnumerator ConeShapeAttachedGetsReplacedOnNewAttachment() |
| | 128 | | { |
| 1 | 129 | | yield return TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<ConeShape.Model, ConeShape>(scene, |
| | 130 | | CLASS_ID.CONE_SHAPE); |
| 1 | 131 | | } |
| | 132 | |
|
| | 133 | | [UnityTest] |
| | 134 | | public IEnumerator CylinderShapeComponentMissingValuesGetDefaultedOnUpdate() |
| | 135 | | { |
| 1 | 136 | | var component = |
| | 137 | | TestHelpers.SharedComponentCreate<CylinderShape, CylinderShape.Model>(scene, CLASS_ID.CYLINDER_SHAPE); |
| 1 | 138 | | yield return component.routine; |
| | 139 | |
|
| 1 | 140 | | Assert.IsFalse(component == null); |
| | 141 | |
|
| 1 | 142 | | yield return TestHelpers.TestSharedComponentDefaultsOnUpdate<CylinderShape.Model, CylinderShape>(scene, |
| | 143 | | CLASS_ID.CYLINDER_SHAPE); |
| 1 | 144 | | } |
| | 145 | |
|
| | 146 | | [UnityTest] |
| | 147 | | public IEnumerator CylinderShapeAttachedGetsReplacedOnNewAttachment() |
| | 148 | | { |
| 1 | 149 | | yield return |
| | 150 | | TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<CylinderShape.Model, CylinderShape>(scene, |
| | 151 | | CLASS_ID.CYLINDER_SHAPE); |
| 1 | 152 | | } |
| | 153 | |
|
| | 154 | | [UnityTest] |
| | 155 | | public IEnumerator CollisionProperty() |
| | 156 | | { |
| 1 | 157 | | string entityId = "entityId"; |
| 1 | 158 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 1 | 159 | | var entity = scene.entities[entityId]; |
| | 160 | |
|
| 1 | 161 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) }); |
| | 162 | |
|
| 1 | 163 | | yield return null; |
| | 164 | |
|
| | 165 | | // BoxShape |
| 1 | 166 | | BaseShape.Model shapeModel = new BoxShape.Model(); |
| 1 | 167 | | BaseShape shapeComponent = TestHelpers.SharedComponentCreate<BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAP |
| 1 | 168 | | yield return shapeComponent.routine; |
| | 169 | |
|
| 1 | 170 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 171 | |
|
| 1 | 172 | | yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity); |
| | 173 | |
|
| 1 | 174 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 175 | | shapeComponent.Dispose(); |
| 1 | 176 | | yield return null; |
| | 177 | |
|
| | 178 | | // SphereShape |
| 1 | 179 | | shapeModel = new SphereShape.Model(); |
| 1 | 180 | | shapeComponent = TestHelpers.SharedComponentCreate<SphereShape, BaseShape.Model>(scene, CLASS_ID.SPHERE_SHAPE, s |
| 1 | 181 | | yield return shapeComponent.routine; |
| | 182 | |
|
| 1 | 183 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 184 | |
|
| 1 | 185 | | yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity); |
| | 186 | |
|
| 1 | 187 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 188 | | shapeComponent.Dispose(); |
| 1 | 189 | | yield return null; |
| | 190 | |
|
| | 191 | | // ConeShape |
| 1 | 192 | | shapeModel = new ConeShape.Model(); |
| 1 | 193 | | shapeComponent = TestHelpers.SharedComponentCreate<ConeShape, BaseShape.Model>(scene, CLASS_ID.CONE_SHAPE, shape |
| 1 | 194 | | yield return shapeComponent.routine; |
| | 195 | |
|
| 1 | 196 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 197 | |
|
| 1 | 198 | | yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity); |
| | 199 | |
|
| 1 | 200 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 201 | | shapeComponent.Dispose(); |
| 1 | 202 | | yield return null; |
| | 203 | |
|
| | 204 | | // CylinderShape |
| 1 | 205 | | shapeModel = new CylinderShape.Model(); |
| 1 | 206 | | shapeComponent = TestHelpers.SharedComponentCreate<CylinderShape, BaseShape.Model>(scene, CLASS_ID.CYLINDER_SHAP |
| 1 | 207 | | yield return shapeComponent.routine; |
| | 208 | |
|
| 1 | 209 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 210 | |
|
| 1 | 211 | | yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity); |
| | 212 | |
|
| 1 | 213 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 214 | | shapeComponent.Dispose(); |
| 1 | 215 | | yield return null; |
| | 216 | |
|
| | 217 | | // PlaneShape |
| 1 | 218 | | shapeModel = new PlaneShape.Model(); |
| 1 | 219 | | shapeComponent = TestHelpers.SharedComponentCreate<PlaneShape, BaseShape.Model>(scene, CLASS_ID.PLANE_SHAPE, sha |
| 1 | 220 | | yield return shapeComponent.routine; |
| | 221 | |
|
| 1 | 222 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 223 | |
|
| 1 | 224 | | yield return TestHelpers.TestShapeCollision(shapeComponent, shapeModel, entity); |
| | 225 | |
|
| 1 | 226 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 227 | | shapeComponent.Dispose(); |
| 1 | 228 | | yield return null; |
| 1 | 229 | | } |
| | 230 | |
|
| | 231 | | [UnityTest] |
| | 232 | | public IEnumerator VisibleProperty() |
| | 233 | | { |
| 1 | 234 | | string entityId = "entityId"; |
| 1 | 235 | | TestHelpers.CreateSceneEntity(scene, entityId); |
| 1 | 236 | | var entity = scene.entities[entityId]; |
| | 237 | |
|
| 1 | 238 | | TestHelpers.SetEntityTransform(scene, entity, new DCLTransform.Model { position = new Vector3(8, 1, 8) }); |
| | 239 | |
|
| 1 | 240 | | yield return null; |
| | 241 | |
|
| | 242 | | // BoxShape |
| 1 | 243 | | BaseShape.Model shapeModel = new BoxShape.Model(); |
| 1 | 244 | | BaseShape shapeComponent = TestHelpers.SharedComponentCreate<BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAP |
| 1 | 245 | | yield return shapeComponent.routine; |
| | 246 | |
|
| 1 | 247 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 248 | |
|
| 1 | 249 | | yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity); |
| | 250 | |
|
| 1 | 251 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 252 | | shapeComponent.Dispose(); |
| 1 | 253 | | yield return null; |
| | 254 | |
|
| | 255 | | // SphereShape |
| 1 | 256 | | shapeModel = new SphereShape.Model(); |
| 1 | 257 | | shapeComponent = TestHelpers.SharedComponentCreate<SphereShape, BaseShape.Model>(scene, CLASS_ID.SPHERE_SHAPE, s |
| 1 | 258 | | yield return shapeComponent.routine; |
| | 259 | |
|
| 1 | 260 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 261 | |
|
| 1 | 262 | | yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity); |
| | 263 | |
|
| 1 | 264 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 265 | | shapeComponent.Dispose(); |
| 1 | 266 | | yield return null; |
| | 267 | |
|
| | 268 | | // ConeShape |
| 1 | 269 | | shapeModel = new ConeShape.Model(); |
| 1 | 270 | | shapeComponent = TestHelpers.SharedComponentCreate<ConeShape, BaseShape.Model>(scene, CLASS_ID.CONE_SHAPE, shape |
| 1 | 271 | | yield return shapeComponent.routine; |
| | 272 | |
|
| 1 | 273 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 274 | |
|
| 1 | 275 | | yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity); |
| | 276 | |
|
| 1 | 277 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 278 | | shapeComponent.Dispose(); |
| 1 | 279 | | yield return null; |
| | 280 | |
|
| | 281 | | // CylinderShape |
| 1 | 282 | | shapeModel = new CylinderShape.Model(); |
| 1 | 283 | | shapeComponent = TestHelpers.SharedComponentCreate<CylinderShape, BaseShape.Model>(scene, CLASS_ID.CYLINDER_SHAP |
| 1 | 284 | | yield return shapeComponent.routine; |
| | 285 | |
|
| 1 | 286 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 287 | |
|
| 1 | 288 | | yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity); |
| | 289 | |
|
| 1 | 290 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 291 | | shapeComponent.Dispose(); |
| 1 | 292 | | yield return null; |
| | 293 | |
|
| | 294 | | // PlaneShape |
| 1 | 295 | | shapeModel = new PlaneShape.Model(); |
| 1 | 296 | | shapeComponent = TestHelpers.SharedComponentCreate<PlaneShape, BaseShape.Model>(scene, CLASS_ID.PLANE_SHAPE, sha |
| 1 | 297 | | yield return shapeComponent.routine; |
| | 298 | |
|
| 1 | 299 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| | 300 | |
|
| 1 | 301 | | yield return TestHelpers.TestShapeVisibility(shapeComponent, shapeModel, entity); |
| | 302 | |
|
| 1 | 303 | | TestHelpers.DetachSharedComponent(scene, entityId, shapeComponent.id); |
| 1 | 304 | | shapeComponent.Dispose(); |
| 1 | 305 | | yield return null; |
| 1 | 306 | | } |
| | 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 | | { |
| 2 | 314 | | Environment.i.world.sceneBoundsChecker.Stop(); |
| | 315 | |
|
| | 316 | | // Arrange: set inverse of withCollision to trigger is dirty later |
| 2 | 317 | | BaseShape shapeComponent = TestHelpers.SharedComponentCreate<BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAP |
| 2 | 318 | | yield return shapeComponent.routine; |
| 2 | 319 | | List<IDCLEntity> entities = new List<IDCLEntity>(); |
| 24 | 320 | | for (int i = 0; i < entitiesCount; i++) |
| | 321 | | { |
| 10 | 322 | | IDCLEntity entity = TestHelpers.CreateSceneEntity(scene, $"entity{i}"); |
| 10 | 323 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| 10 | 324 | | entities.Add(entity); |
| | 325 | | } |
| | 326 | |
|
| | 327 | | // Act: Update withCollision |
| 2 | 328 | | shapeComponent.UpdateFromModel(new BoxShape.Model { withCollisions = withCollision }); |
| 2 | 329 | | yield return shapeComponent.routine; |
| | 330 | |
|
| | 331 | | // Assert: |
| 24 | 332 | | foreach (IDCLEntity entity in entities) |
| | 333 | | { |
| 40 | 334 | | for (int i = 0; i < entity.meshesInfo.colliders.Count; i++) |
| | 335 | | { |
| 10 | 336 | | Assert.AreEqual(withCollision, entity.meshesInfo.colliders[i].enabled); |
| | 337 | | } |
| | 338 | | } |
| 2 | 339 | | } |
| | 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 | | { |
| 2 | 347 | | Environment.i.world.sceneBoundsChecker.Stop(); |
| | 348 | |
|
| | 349 | | // Arrange: set inverse of visible to trigger is dirty later |
| 2 | 350 | | BaseShape shapeComponent = TestHelpers.SharedComponentCreate<BoxShape, BaseShape.Model>(scene, CLASS_ID.BOX_SHAP |
| 2 | 351 | | yield return shapeComponent.routine; |
| 2 | 352 | | List<IDCLEntity> entities = new List<IDCLEntity>(); |
| 24 | 353 | | for (int i = 0; i < entitiesCount; i++) |
| | 354 | | { |
| 10 | 355 | | IDCLEntity entity = TestHelpers.CreateSceneEntity(scene, $"entity{i}"); |
| 10 | 356 | | TestHelpers.SharedComponentAttach(shapeComponent, entity); |
| 10 | 357 | | entities.Add(entity); |
| | 358 | | } |
| | 359 | |
|
| | 360 | | // Act: Update visible |
| 2 | 361 | | shapeComponent.UpdateFromModel(new BoxShape.Model { visible = visible, withCollisions = true, isPointerBlocker = |
| 2 | 362 | | yield return shapeComponent.routine; |
| | 363 | |
|
| | 364 | | // Assert: |
| 24 | 365 | | foreach (IDCLEntity entity in entities) |
| | 366 | | { |
| 40 | 367 | | for (int i = 0; i < entity.meshesInfo.renderers.Length; i++) |
| | 368 | | { |
| 10 | 369 | | Assert.AreEqual(visible, entity.meshesInfo.renderers[i].enabled); |
| | 370 | | } |
| | 371 | | } |
| 2 | 372 | | } |
| | 373 | | } |