< Summary

Class:DCL.GLTFast.Wrappers.GltfDownloaderWrapper
Assembly:AssetPromiseKeeper
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTFast/Wrappers/GLTFDownloaderWrapper.cs
Covered lines:16
Uncovered lines:2
Coverable lines:18
Total lines:59
Line coverage:88.8% (16 of 18)
Covered branches:0
Total branches:0
Covered methods:7
Total methods:8
Method coverage:87.5% (7 of 8)

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
GltfDownloaderWrapper(...)0%110100%
IsGltfBinary(...)0%2.062075%
Dispose()0%110100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTFast/Wrappers/GLTFDownloaderWrapper.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using GLTFast;
 4using GLTFast.Loading;
 5using UnityEngine;
 6using UnityEngine.Networking;
 7
 8namespace DCL.GLTFast.Wrappers
 9{
 10    public class GltfDownloaderWrapper : IDownload
 11    {
 12        /// <summary>
 13        /// First four bytes of a glTF-Binary file are made up of this signature
 14        /// Represents glTF in ASCII
 15        /// </summary>
 16        private const uint GLB_SIGNATURE = 0x46546c67;
 17
 18        private readonly UnityWebRequest webRequest;
 19        private byte[] cachedData;
 20        private bool isDisposed;
 21
 10022        public GltfDownloaderWrapper(UnityWebRequest webRequest)
 23        {
 10024            this.webRequest = webRequest;
 10025        }
 26
 20027        public bool Success => webRequest.result == UnityWebRequest.Result.Success;
 028        public string Error => webRequest.error;
 29
 30        public byte[] Data
 31        {
 32            get
 33            {
 18234                if (isDisposed) return null;
 18235                if (cachedData != null) return cachedData;
 36
 36437                if (webRequest != null) return webRequest.downloadHandler.data;
 038                return null;
 39            }
 40        }
 41
 1242        public string Text => webRequest.downloadHandler.text;
 9743        public bool? IsBinary => IsGltfBinary(Data);
 44
 45        private static bool IsGltfBinary(byte[] data)
 46        {
 9747            if (data == null) return false;
 9748            var gltfBinarySignature = BitConverter.ToUInt32(data, 0);
 9749            return gltfBinarySignature == GLB_SIGNATURE;
 50        }
 51
 52        public void Dispose()
 53        {
 19454            isDisposed = true;
 19455            cachedData = null;
 19456            webRequest.Dispose();
 19457        }
 58    }
 59}