public IEnumerator FailCorrectlyWhenGivenWrongURL() { var keeper = new AssetPromiseKeeper_GLTF(); //NOTE(Brian): Expect the 404 error LogAssert.Expect(LogType.Error, new Regex("^*.?404")); string url = TestAssetsUtils.GetPath() + "/non_existing_url.glb"; AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url); Asset_GLTF asset = null; bool failEventCalled1 = false; prom.OnSuccessEvent += (x) => { asset = x; }; prom.OnFailEvent += (x) => { failEventCalled1 = true; }; AssetPromise_GLTF prom2 = new AssetPromise_GLTF(scene.contentProvider, url); Asset_GLTF asset2 = null; bool failEventCalled2 = false; prom2.OnSuccessEvent += (x) => { asset2 = x; }; prom2.OnFailEvent += (x) => { failEventCalled2 = true; }; AssetPromise_GLTF prom3 = new AssetPromise_GLTF(scene.contentProvider, url); Asset_GLTF asset3 = null; bool failEventCalled3 = false; prom3.OnSuccessEvent += (x) => { asset3 = x; }; prom3.OnFailEvent += (x) => { failEventCalled3 = true; }; keeper.Keep(prom); keeper.Keep(prom2); keeper.Keep(prom3); Assert.AreEqual(3, keeper.waitingPromisesCount); yield return(prom); yield return(prom2); yield return(prom3); Assert.AreNotEqual(AssetPromiseState.FINISHED, prom.state); Assert.AreNotEqual(AssetPromiseState.FINISHED, prom2.state); Assert.AreNotEqual(AssetPromiseState.FINISHED, prom3.state); Assert.IsTrue(failEventCalled1); Assert.IsTrue(failEventCalled2); Assert.IsTrue(failEventCalled3); Assert.IsFalse(asset != null); Assert.IsFalse(asset2 != null); Assert.IsFalse(asset3 != null); Assert.IsFalse(keeper.library.Contains(asset)); Assert.AreNotEqual(1, keeper.library.masterAssets.Count); }
public IEnumerator BeSetupCorrectlyAfterLoad() { var keeper = new AssetPromiseKeeper_GLTF(); string url = Utils.GetTestsAssetsPath() + "/GLB/Lantern/Lantern.glb"; AssetPromise_GLTF prom = new AssetPromise_GLTF(scene.contentProvider, url); Asset_GLTF loadedAsset = null; prom.OnSuccessEvent += (x) => { loadedAsset = x; } ; Vector3 initialPos = Vector3.one; Quaternion initialRot = Quaternion.LookRotation(Vector3.right, Vector3.up); Vector3 initialScale = Vector3.one * 2; prom.settings.initialLocalPosition = initialPos; prom.settings.initialLocalRotation = initialRot; prom.settings.initialLocalScale = initialScale; keeper.Keep(prom); yield return(prom); Assert.IsTrue(PoolManager.i.ContainsPool(loadedAsset.id), "Not in pool after loaded!"); Pool pool = PoolManager.i.GetPool(loadedAsset.id); Assert.AreEqual(0, pool.unusedObjectsCount, "incorrect inactive objects in pool"); Assert.AreEqual(1, pool.usedObjectsCount, "incorrect active objects in pool"); Assert.IsTrue(pool.original != loadedAsset.container, "In pool, the original gameObject must NOT be the loaded asset!"); //NOTE(Brian): If the following asserts fail, check that ApplySettings_LoadStart() is called from AssetPromise_GLTF.AddToLibrary() when the clone is made. Assert.AreEqual(initialPos.ToString(), loadedAsset.container.transform.localPosition.ToString(), "initial position not set correctly!"); Assert.AreEqual(initialRot.ToString(), loadedAsset.container.transform.localRotation.ToString(), "initial rotation not set correctly!"); Assert.AreEqual(initialScale.ToString(), loadedAsset.container.transform.localScale.ToString(), "initial scale not set correctly!"); Assert.IsTrue(loadedAsset != null); Assert.IsTrue(keeper.library.Contains(loadedAsset)); Assert.AreEqual(1, keeper.library.masterAssets.Count); }