| | 1 | | using AssetPromiseKeeper_Tests; |
| | 2 | | using DCL; |
| | 3 | | using DCL.Helpers; |
| | 4 | | using System.Collections; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.Assertions; |
| | 7 | | using UnityEngine.TestTools; |
| | 8 | |
|
| | 9 | | namespace AssetPromiseKeeper_Texture_Tests |
| | 10 | | { |
| | 11 | | public class BlockedAndMasterPromisesShould : TestsBase_APK<AssetPromiseKeeper_Texture, |
| | 12 | | AssetPromise_Texture, |
| | 13 | | Asset_Texture, |
| | 14 | | AssetLibrary_Texture> |
| | 15 | | { |
| | 16 | | protected AssetPromise_Texture CreatePromise(string promiseURL, int wrapmode = -1, int filterMode = -1) |
| | 17 | | { |
| | 18 | | AssetPromise_Texture prom; |
| | 19 | |
|
| 6 | 20 | | if (filterMode > -1 && wrapmode > -1) |
| 1 | 21 | | prom = new AssetPromise_Texture(promiseURL, (TextureWrapMode)wrapmode, (FilterMode)filterMode); |
| | 22 | | else |
| 5 | 23 | | prom = new AssetPromise_Texture(promiseURL); |
| | 24 | |
|
| 6 | 25 | | return prom; |
| | 26 | | } |
| | 27 | |
|
| | 28 | | [UnityTest] |
| | 29 | | public IEnumerator FailCorrectlyWhenGivenWrongURL() |
| | 30 | | { |
| 1 | 31 | | var prom = CreatePromise("123325"); |
| 1 | 32 | | Asset_Texture asset = null; |
| 1 | 33 | | bool failEventCalled1 = false; |
| 1 | 34 | | prom.OnSuccessEvent += (x) => { asset = x; }; |
| 3 | 35 | | prom.OnFailEvent += (x) => { failEventCalled1 = true; }; |
| | 36 | |
|
| 1 | 37 | | var prom2 = CreatePromise("43254378"); |
| 1 | 38 | | Asset_Texture asset2 = null; |
| 1 | 39 | | bool failEventCalled2 = false; |
| 1 | 40 | | prom2.OnSuccessEvent += (x) => { asset2 = x; }; |
| 3 | 41 | | prom2.OnFailEvent += (x) => { failEventCalled2 = true; }; |
| | 42 | |
|
| 1 | 43 | | var prom3 = CreatePromise("09898765"); |
| 1 | 44 | | Asset_Texture asset3 = null; |
| 1 | 45 | | bool failEventCalled3 = false; |
| 1 | 46 | | prom3.OnSuccessEvent += (x) => { asset3 = x; }; |
| 3 | 47 | | prom3.OnFailEvent += (x) => { failEventCalled3 = true; }; |
| | 48 | |
|
| 1 | 49 | | keeper.Keep(prom); |
| 1 | 50 | | keeper.Keep(prom2); |
| 1 | 51 | | keeper.Keep(prom3); |
| | 52 | |
|
| 1 | 53 | | Assert.AreEqual(3, keeper.waitingPromisesCount); |
| | 54 | |
|
| 1 | 55 | | yield return prom; |
| 1 | 56 | | yield return prom2; |
| 1 | 57 | | yield return prom3; |
| | 58 | |
|
| 1 | 59 | | Assert.AreNotEqual(AssetPromiseState.FINISHED, prom.state); |
| 1 | 60 | | Assert.AreNotEqual(AssetPromiseState.FINISHED, prom2.state); |
| 1 | 61 | | Assert.AreNotEqual(AssetPromiseState.FINISHED, prom3.state); |
| | 62 | |
|
| 1 | 63 | | Assert.IsTrue(failEventCalled1); |
| 1 | 64 | | Assert.IsTrue(failEventCalled2); |
| 1 | 65 | | Assert.IsTrue(failEventCalled3); |
| | 66 | |
|
| 1 | 67 | | Assert.IsFalse(asset != null); |
| 1 | 68 | | Assert.IsFalse(asset2 != null); |
| 1 | 69 | | Assert.IsFalse(asset3 != null); |
| | 70 | |
|
| 1 | 71 | | Assert.IsFalse(keeper.library.Contains(asset)); |
| 1 | 72 | | Assert.AreNotEqual(1, keeper.library.masterAssets.Count); |
| 1 | 73 | | } |
| | 74 | |
|
| | 75 | | [UnityTest] |
| | 76 | | public IEnumerator WaitForPromisesOfSameTextureWithDifferentSettings() |
| | 77 | | { |
| | 78 | | // default texture (no settings) |
| 1 | 79 | | var prom = CreatePromise(TestAssetsUtils.GetPath() + "/Images/atlas.png"); |
| 1 | 80 | | Asset_Texture asset = null; |
| 1 | 81 | | prom.OnSuccessEvent += (x) => { asset = x; }; |
| 1 | 82 | | keeper.Keep(prom); |
| | 83 | |
|
| | 84 | | // same texture but with settings |
| 1 | 85 | | var prom2 = CreatePromise(TestAssetsUtils.GetPath() + "/Images/atlas.png", (int)TextureWrapMode.Repeat, (int |
| 1 | 86 | | Asset_Texture asset2 = null; |
| 1 | 87 | | prom.OnSuccessEvent += (x) => { asset2 = x; }; |
| 1 | 88 | | keeper.Keep(prom2); |
| | 89 | |
|
| | 90 | | // different texture |
| 1 | 91 | | var prom3 = CreatePromise(TestAssetsUtils.GetPath() + "/Images/avatar.png"); |
| 1 | 92 | | Asset_Texture asset3 = null; |
| 1 | 93 | | prom.OnSuccessEvent += (x) => { asset3 = x; }; |
| 1 | 94 | | keeper.Keep(prom3); |
| | 95 | |
|
| 1 | 96 | | Assert.AreEqual(AssetPromiseState.LOADING, prom.state); |
| 1 | 97 | | Assert.AreEqual(AssetPromiseState.WAITING, prom2.state); |
| 1 | 98 | | Assert.AreEqual(AssetPromiseState.LOADING, prom3.state); |
| | 99 | |
|
| 1 | 100 | | return null; |
| | 101 | | } |
| | 102 | | } |
| | 103 | | } |