< Summary

Class:VisualTestController
Assembly:VisualTests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Tests/VisualTests/VisualTestController.cs
Covered lines:6
Uncovered lines:32
Coverable lines:38
Total lines:108
Line coverage:15.7% (6 of 38)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
VisualTestController()0%110100%
Awake()0%110100%
Start()0%23.628037.5%
InstantiateTestedObjects()0%12300%
TakeSnapshots()0%42600%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Tests/VisualTests/VisualTestController.cs

#LineLine coverage
 1using DCL;
 2using DCL.Helpers;
 3using System.Collections;
 4using DCL.Controllers;
 5using UnityEngine;
 6
 7public class VisualTestController : MonoBehaviour
 8{
 129    public static VisualTestController i { get; private set; }
 10    public new Camera camera;
 11    public bool takeSnapshots = false;
 12    public bool snapshotsAreBaseline = false;
 613    public bool instantiateSceneObjects = true;
 14
 1215    private void Awake() { i = this; }
 16
 17    IEnumerator Start()
 18    {
 619        if (instantiateSceneObjects)
 20        {
 021            yield return InstantiateTestedObjects();
 22        }
 23
 624        if (takeSnapshots)
 25        {
 026            if (snapshotsAreBaseline)
 27            {
 028                yield return VisualTestHelpers.GenerateBaselineForTest(TakeSnapshots());
 029            }
 30            else
 31            {
 032                yield return TakeSnapshots();
 33            }
 34        }
 635    }
 36
 37    IEnumerator InstantiateTestedObjects()
 38    {
 039        var sceneController = Environment.i.world.sceneController;
 040        var scenesToLoad = (Resources.Load("TestJSON/SceneLoadingTest") as TextAsset).text;
 41
 042        sceneController.UnloadAllScenes();
 043        sceneController.LoadParcelScenes(scenesToLoad);
 44
 045        yield return null;
 46
 047        var scene = Environment.i.world.state.loadedScenes["0,0"] as ParcelScene;
 048        string textureUrl = TestAssetsUtils.GetPath() + "/Images/atlas.png";
 49
 050        TestHelpers.InstantiateEntityWithMaterial(scene, "1", new Vector3(-3, 1, 3),
 51            new DCL.Components.BasicMaterial.Model
 52            {
 53                texture = textureUrl,
 54            }, "testBasicMaterial");
 55
 056        TestHelpers.InstantiateEntityWithMaterial(scene, "2", new Vector3(0, 1, 3), new DCL.Components.PBRMaterial.Model
 57        {
 58            albedoTexture = textureUrl,
 59            metallic = 0,
 60            roughness = 1,
 61        }, "testMaterial1");
 62
 063        string materialID = "testMaterial2";
 064        TestHelpers.InstantiateEntityWithMaterial(scene, "3", new Vector3(3, 1, 3), new DCL.Components.PBRMaterial.Model
 65        {
 66            albedoTexture = textureUrl,
 67            metallic = 1,
 68            roughness = 1,
 69            alphaTexture = textureUrl,
 70        }, materialID);
 71
 72        // Re-assign last PBR material to new entity
 073        TestHelpers.InstantiateEntityWithShape(scene, "4", DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(6, 1, 3));
 74
 075        string entityId = "4";
 76
 077        scene.SharedComponentAttach(
 78            entityId,
 79            materialID
 80        );
 81
 082        Color color = new Color(1, 0.7f, 0.7f);
 83
 84        // Update material attached to 2 entities, adding albedoColor
 085        scene.SharedComponentUpdate(materialID, JsonUtility.ToJson(new DCL.Components.PBRMaterial.Model
 86        {
 87            albedoTexture = textureUrl,
 88            metallic = 1,
 89            roughness = 1,
 90            alphaTexture = textureUrl,
 91            albedoColor = color
 92        }));
 93
 094        TestHelpers.InstantiateEntityWithShape(scene, "5", DCL.Models.CLASS_ID.BOX_SHAPE, new Vector3(-6, 1, 6));
 095        TestHelpers.InstantiateEntityWithShape(scene, "6", DCL.Models.CLASS_ID.SPHERE_SHAPE, new Vector3(-3, 1, 6));
 096        TestHelpers.InstantiateEntityWithShape(scene, "7", DCL.Models.CLASS_ID.PLANE_SHAPE, new Vector3(0, 1, 6));
 097        TestHelpers.InstantiateEntityWithShape(scene, "8", DCL.Models.CLASS_ID.CONE_SHAPE, new Vector3(3, 1, 6));
 098        TestHelpers.InstantiateEntityWithShape(scene, "9", DCL.Models.CLASS_ID.CYLINDER_SHAPE, new Vector3(6, 1, 6));
 099    }
 100
 101    IEnumerator TakeSnapshots()
 102    {
 0103        yield return VisualTestHelpers.TakeSnapshotOrTest("snapshot_1.png", new Vector3(10f, 10f, 0f), Vector3.zero);
 0104        yield return VisualTestHelpers.TakeSnapshotOrTest("snapshot_2.png", new Vector3(0f, 10f, 0f), Vector3.zero);
 0105        yield return VisualTestHelpers.TakeSnapshotOrTest("snapshot_3.png", new Vector3(-10f, 10f, 0f), Vector3.zero);
 0106        yield return VisualTestHelpers.TakeSnapshotOrTest("snapshot_4.png", new Vector3(0f, 10f, -10f), Vector3.zero);
 0107    }
 108}