| | 1 | | using DCL; |
| | 2 | | using DCL.Helpers; |
| | 3 | | using DCL.Models; |
| | 4 | | using NUnit.Framework; |
| | 5 | | using System.Collections; |
| | 6 | | using UnityEngine; |
| | 7 | | using UnityEngine.TestTools; |
| | 8 | |
|
| | 9 | | namespace Tests |
| | 10 | | { |
| | 11 | | public class TexturesTests : IntegrationTestSuite_Legacy |
| | 12 | | { |
| | 13 | | // A UnityTest behaves like a coroutine in Play Mode. In Edit Mode you can use |
| | 14 | | // `yield return null;` to skip a frame. |
| | 15 | | [UnityTest] |
| | 16 | | public IEnumerator TextureCreateAndLoadTest() |
| | 17 | | { |
| 1 | 18 | | DCLTexture dclTexture = TestHelpers.CreateDCLTexture(scene, |
| | 19 | | TestAssetsUtils.GetPath() + "/Images/avatar.png", |
| | 20 | | DCLTexture.BabylonWrapMode.CLAMP, |
| | 21 | | FilterMode.Bilinear); |
| | 22 | |
|
| 1 | 23 | | yield return dclTexture.routine; |
| | 24 | |
|
| 1 | 25 | | Assert.IsTrue(dclTexture.texture != null, "Texture didn't load correctly?"); |
| 1 | 26 | | Assert.IsTrue(dclTexture.unityWrap == TextureWrapMode.Clamp, "Bad wrap mode!"); |
| 1 | 27 | | Assert.IsTrue(dclTexture.unitySamplingMode == FilterMode.Bilinear, "Bad sampling mode!"); |
| | 28 | |
|
| 1 | 29 | | dclTexture.Dispose(); |
| | 30 | |
|
| 1 | 31 | | yield return null; |
| 1 | 32 | | Assert.IsTrue(dclTexture.texture == null, "Texture didn't dispose correctly?"); |
| 1 | 33 | | } |
| | 34 | |
|
| | 35 | | [UnityTest] |
| | 36 | | public IEnumerator TextureAttachedGetsReplacedOnNewAttachment() |
| | 37 | | { |
| 1 | 38 | | yield return TestHelpers.TestAttachedSharedComponentOfSameTypeIsReplaced<DCLTexture.Model, DCLTexture>( |
| | 39 | | scene, CLASS_ID.TEXTURE); |
| 1 | 40 | | } |
| | 41 | |
|
| | 42 | | [Test] |
| | 43 | | public void Texture_OnReadyBeforeLoading() |
| | 44 | | { |
| 1 | 45 | | DCLTexture dclTexture = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/avatar.png" |
| 1 | 46 | | bool isOnReady = false; |
| 3 | 47 | | dclTexture.CallWhenReady((x) => { isOnReady = true; }); |
| | 48 | |
|
| 1 | 49 | | Assert.IsTrue(isOnReady); //DCLTexture is ready on creation |
| 1 | 50 | | } |
| | 51 | |
|
| | 52 | | [UnityTest] |
| | 53 | | public IEnumerator Texture_OnReadyWaitLoading() |
| | 54 | | { |
| 1 | 55 | | DCLTexture dclTexture = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/avatar.png" |
| 1 | 56 | | bool isOnReady = false; |
| 3 | 57 | | dclTexture.CallWhenReady((x) => { isOnReady = true; }); |
| 1 | 58 | | yield return dclTexture.routine; |
| | 59 | |
|
| 1 | 60 | | Assert.IsTrue(isOnReady); |
| 1 | 61 | | } |
| | 62 | |
|
| | 63 | | [UnityTest] |
| | 64 | | public IEnumerator Texture_OnReadyAfterLoadingInstantlyCalled() |
| | 65 | | { |
| 1 | 66 | | DCLTexture dclTexture = TestHelpers.CreateDCLTexture(scene, TestAssetsUtils.GetPath() + "/Images/avatar.png" |
| 1 | 67 | | yield return dclTexture.routine; |
| | 68 | |
|
| 1 | 69 | | bool isOnReady = false; |
| 3 | 70 | | dclTexture.CallWhenReady((x) => { isOnReady = true; }); |
| 1 | 71 | | Assert.IsTrue(isOnReady); |
| 1 | 72 | | } |
| | 73 | | } |
| | 74 | | } |