< Summary

Class:AssetPromiseKeeper_GLTF_Tests.AnyAssetPromiseShould
Assembly:AssetPromiseKeeper_GLTF_Tests
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTF/Tests/AnyAssetPromiseShould.cs
Covered lines:102
Uncovered lines:4
Coverable lines:106
Total lines:194
Line coverage:96.2% (102 of 106)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
BeSetupCorrectlyAfterLoad()0%330100%
ForceNewInstanceIsOff()0%330100%
ForceNewInstanceIsOffMultipleTimes()0%550100%
ForceNewInstanceIsOn()0%440100%
ForceNewInstanceIsOnMultipleTimes()0%550100%
NotTryToLoadAfterForget()0%660100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/Controllers/AssetManager/GLTF/Tests/AnyAssetPromiseShould.cs

#LineLine coverage
 1using System;
 2using DCL;
 3using DCL.Helpers;
 4using System.Collections;
 5using System.Collections.Generic;
 6using System.Linq;
 7using UnityEngine;
 8using UnityEngine.Assertions;
 9using UnityEngine.TestTools;
 10using Object = UnityEngine.Object;
 11
 12namespace AssetPromiseKeeper_GLTF_Tests
 13{
 14    public class AnyAssetPromiseShould : IntegrationTestSuite_Legacy
 15    {
 16        [UnityTest]
 17        public IEnumerator BeSetupCorrectlyAfterLoad()
 18        {
 119            var keeper = new AssetPromiseKeeper_GLTF();
 20
 121            string url = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 122            AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
 123            Asset_GLTF loadedAsset = null;
 24
 25
 126            prom.OnSuccessEvent +=
 227                (x) => { loadedAsset = x; }
 28                ;
 29
 130            Vector3 initialPos = Vector3.one;
 131            Quaternion initialRot = Quaternion.LookRotation(Vector3.right, Vector3.up);
 132            Vector3 initialScale = Vector3.one * 2;
 33
 134            prom.settings.initialLocalPosition = initialPos;
 135            prom.settings.initialLocalRotation = initialRot;
 136            prom.settings.initialLocalScale = initialScale;
 37
 138            keeper.Keep(prom);
 39
 140            yield return prom;
 41
 142            Assert.IsTrue(PoolManager.i.ContainsPool(loadedAsset.id), "Not in pool after loaded!");
 43
 144            Pool pool = PoolManager.i.GetPool(loadedAsset.id);
 45
 146            Assert.AreEqual(0, pool.unusedObjectsCount, "incorrect inactive objects in pool");
 147            Assert.AreEqual(1, pool.usedObjectsCount, "incorrect active objects in pool");
 148            Assert.IsTrue(pool.original != loadedAsset.container, "In pool, the original gameObject must NOT be the load
 49
 50            //NOTE(Brian): If the following asserts fail, check that ApplySettings_LoadStart() is called from AssetPromi
 151            Assert.AreEqual(initialPos.ToString(), loadedAsset.container.transform.localPosition.ToString(), "initial po
 152            Assert.AreEqual(initialRot.ToString(), loadedAsset.container.transform.localRotation.ToString(), "initial ro
 153            Assert.AreEqual(initialScale.ToString(), loadedAsset.container.transform.localScale.ToString(), "initial sca
 54
 155            Assert.IsTrue(loadedAsset != null);
 156            Assert.IsTrue(keeper.library.Contains(loadedAsset));
 157            Assert.AreEqual(1, keeper.library.masterAssets.Count);
 158            keeper.Cleanup();
 159        }
 60
 61        [UnityTest]
 62        public IEnumerator ForceNewInstanceIsOff()
 63        {
 164            var keeper = new AssetPromiseKeeper_GLTF();
 65
 166            string url = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 167            AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
 168            prom.settings.forceNewInstance = false;
 169            keeper.Keep(prom);
 170            yield return prom;
 71
 172            var poolableObjectComponent = PoolManager.i.GetPoolable(prom.asset.container);
 173            Assert.IsNotNull(poolableObjectComponent);
 174            keeper.Cleanup();
 175        }
 76
 77        [UnityTest]
 78        public IEnumerator ForceNewInstanceIsOffMultipleTimes()
 79        {
 180            var keeper = new AssetPromiseKeeper_GLTF();
 81
 182            var poolableComponents = new List<PoolableObject>();
 83
 184            string url = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 2285            for (int i = 0; i < 10; i++)
 86            {
 1087                AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
 1088                prom.settings.forceNewInstance = false;
 1089                keeper.Keep(prom);
 1090                yield return prom;
 1091                poolableComponents.Add(PoolManager.i.GetPoolable(prom.asset.container));
 1092                keeper.Forget(prom);
 1093            }
 94
 1195            Assert.IsTrue(poolableComponents.TrueForAll(x => x != null));
 196            keeper.Cleanup();
 197        }
 98
 99        [UnityTest]
 100        public IEnumerator ForceNewInstanceIsOn()
 101        {
 1102            var keeper = new AssetPromiseKeeper_GLTF();
 103
 1104            string url = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 1105            AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
 1106            prom.settings.forceNewInstance = true;
 107
 1108            keeper.Keep(prom);
 1109            yield return prom;
 110
 1111            var poolableObjectComponent = PoolManager.i.GetPoolable(prom.asset.container);
 1112            Assert.IsNull(poolableObjectComponent);
 113
 1114            if (prom.asset.container != null)
 1115                Object.Destroy(prom.asset.container);
 116
 1117            keeper.Cleanup();
 1118        }
 119
 120        [UnityTest]
 121        public IEnumerator ForceNewInstanceIsOnMultipleTimes()
 122        {
 1123            var keeper = new AssetPromiseKeeper_GLTF();
 124
 1125            var poolableComponents = new List<PoolableObject>();
 126
 1127            string url = TestAssetsUtils.GetPath() + "/GLB/Lantern/Lantern.glb";
 128
 22129            for (int i = 0; i < 10; i++)
 130            {
 10131                AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
 10132                prom.settings.forceNewInstance = true;
 10133                keeper.Keep(prom);
 10134                yield return prom;
 10135                poolableComponents.Add(PoolManager.i.GetPoolable(prom.asset.container));
 10136                keeper.Forget(prom);
 10137            }
 138
 11139            Assert.IsTrue(poolableComponents.TrueForAll(x => x == null));
 140
 1141            keeper.Cleanup();
 1142        }
 143
 144        [UnityTest]
 145        public IEnumerator NotTryToLoadAfterForget()
 146        {
 1147            var keeper = new AssetPromiseKeeper_GLTF();
 148
 1149            var promises = new List<AssetPromise_GLTF>();
 1150            var forgottenPromises = new Dictionary<int, bool>();
 1151            bool waitMasterPromise = true;
 152
 1153            string url = TestAssetsUtils.GetPath() + "/GLB/Trunk/Trunk.glb";
 154
 1155            AssetPromise_GLTF masterPromise = new AssetPromise_GLTF(scene.contentProvider, url);
 2156            masterPromise.OnPreFinishEvent += promise => waitMasterPromise = false;
 1157            keeper.Keep(masterPromise);
 158
 22159            for (int i = 0; i < 10; i++)
 160            {
 10161                AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url);
 162
 10163                promises.Add(prom);
 164
 10165                int promiseHash = prom.GetHashCode();
 10166                forgottenPromises.Add(promiseHash, false);
 167
 10168                prom.OnSuccessEvent += (asset) =>
 169                {
 0170                    Assert.IsFalse(forgottenPromises[promiseHash], "Success on forgotten promise shouldn't be called");
 0171                };
 10172                prom.OnFailEvent += (asset) =>
 173                {
 0174                    Assert.IsFalse(forgottenPromises[promiseHash], "Fail on forgotten promise shouldn't be called");
 0175                };
 10176                keeper.Keep(prom);
 177            }
 178
 1179            keeper.Forget(masterPromise);
 180
 166181            yield return new WaitWhile(() => waitMasterPromise);
 1182            yield return null;
 183
 22184            for (int i = 0; i < promises.Count; i++)
 185            {
 10186                var prom = promises[i];
 10187                forgottenPromises[prom.GetHashCode()] = true;
 10188                keeper.Forget(prom);
 189            }
 190
 1191            keeper.Cleanup();
 1192        }
 193    }
 194}