< Summary

Class:GLTFLoadingTestController
Assembly:TestHelpers
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Tests/GLTFLoadingTestController.cs
Covered lines:0
Uncovered lines:31
Coverable lines:31
Total lines:90
Line coverage:0% (0 of 31)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GLTFLoadingTestController()0%2100%
Start()0%2100%
SendLoadingTimeDataToEndpoint()0%2100%
PostRequest()0%20400%
GLTFLoadingTestTrackingData()0%2100%
TestEvent()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/Tests/GLTFLoadingTestController.cs

#LineLine coverage
 1using DCL;
 2using DCL.Helpers;
 3using System;
 4using System.Collections;
 5using DCL.Controllers;
 6using UnityEngine;
 7using UnityEngine.Networking;
 8using UnityGLTF;
 9using Environment = DCL.Environment;
 10
 11public class GLTFLoadingTestController : MonoBehaviour
 12{
 013    public string dataTrackingURL = "https://tracking.decentraland.org/track";
 14
 15    GLTFComponent[] gltfRenderers;
 16    float loadingStartingTime;
 17
 18    void Start()
 19    {
 20        // ---------
 021        var sceneController = Environment.i.world.sceneController;
 022        var scenesToLoad = (Resources.Load("TestJSON/SceneLoadingTest") as TextAsset).text;
 23
 024        sceneController.UnloadAllScenes();
 025        sceneController.LoadParcelScenes(scenesToLoad);
 26
 027        var scene = Environment.i.world.state.loadedScenes["0,0"] as ParcelScene;
 28
 29        // FULL GLB
 030        TestHelpers.InstantiateEntityWithShape(scene, "1", DCL.Models.CLASS_ID.GLTF_SHAPE, new Vector3(-2.5f, 1, 0),
 31            TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb");
 32
 33        // GLB + Separated Textures
 034        TestHelpers.InstantiateEntityWithShape(scene, "2", DCL.Models.CLASS_ID.GLTF_SHAPE, new Vector3(0f, 1, 0),
 35            TestAssetsUtils.GetPath() + "/GLB/TrunkSeparatedTextures/Trunk.glb");
 36
 37        // GLTF
 038        TestHelpers.InstantiateEntityWithShape(scene, "3", DCL.Models.CLASS_ID.GLTF_SHAPE, new Vector3(2.5f, 1, 0),
 39            TestAssetsUtils.GetPath() + "/GLTF/Trunk/Trunk.gltf");
 40        // ---------
 041    }
 42
 43    void SendLoadingTimeDataToEndpoint()
 44    {
 045        GLTFLoadingTestTrackingData data = new GLTFLoadingTestTrackingData();
 046        data.events[0].TestResultInMilliseconds = (Time.time - loadingStartingTime).ToString();
 47
 048        string parsedJSON = JsonUtility.ToJson(data);
 49
 050        StartCoroutine(PostRequest(dataTrackingURL, parsedJSON));
 051    }
 52
 53    IEnumerator PostRequest(string url, string json)
 54    {
 055        var uwr = new UnityWebRequest(url, "POST");
 056        byte[] jsonToSend = new System.Text.UTF8Encoding().GetBytes(json);
 057        uwr.uploadHandler = (UploadHandler) new UploadHandlerRaw(jsonToSend);
 058        uwr.downloadHandler = (DownloadHandler) new DownloadHandlerBuffer();
 059        uwr.SetRequestHeader("Content-Type", "application/json");
 60
 61        // Send the request then wait here until it returns
 062        yield return uwr.SendWebRequest();
 63
 064        if (uwr.result == UnityWebRequest.Result.ConnectionError)
 65        {
 066            Debug.Log("Error While Sending: " + uwr.error);
 067        }
 68        else
 69        {
 070            Debug.Log("Received: " + uwr.downloadHandler.text);
 71        }
 072    }
 73
 74    [Serializable]
 75    class GLTFLoadingTestTrackingData
 76    {
 077        public string user = "WorldTeam-Unity";
 078        public TestEvent[] events = new TestEvent[1];
 79
 080        public GLTFLoadingTestTrackingData() { events[0] = new TestEvent(); }
 81
 82        [Serializable]
 83        public class TestEvent
 84        {
 085            public string TestRun = "GLTF-LoadingTime";
 86            public string TestResultInMilliseconds;
 087            public string GLTBFileSize = "9.5MB (Lantern)";
 88        }
 89    }
 90}