Firstborn/Library/PackageCache/com.unity.addressables@1.19.19/Tests/Runtime/AsyncTaskTests.cs
Schaken-Mods 7502018d20 Adding Mod Support
There is an asset in the store I grabbed. the coding is WAY above my head, I got about half of it and integrated and adapted what I can to it. im going as far as I can with it and ill come back in a few month when I understand t better.
2023-05-13 22:01:48 -05:00

54 lines
2.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.Util;
using UnityEngine.TestTools;
namespace AddressableTests.AsyncTask
{
public abstract class AsyncTaskTests : AddressablesTestFixture
{
[UnityTest]
public IEnumerator AsyncTask_MaintainsCorrectRefCountAfterCompletion()
{
AddressablesImpl impl = new AddressablesImpl(new DefaultAllocationStrategy());
var op = impl.InitializeAsync(m_RuntimeSettingsPath);
var task = op.Task;
while (!task.IsCompleted)
yield return null;
yield return null; //need deferred callbacks to get called
Assert.IsFalse(op.IsValid());
}
[UnityTest]
[Ignore("Ignoring until task refactor is complete.")]
public IEnumerator AsyncTask_DoesNotReturnNull_StressTest()
{
for (int i = 0; i < 100; i++)
{
AddressablesImpl impl = new AddressablesImpl(new DefaultAllocationStrategy());
var op = impl.InitializeAsync(m_RuntimeSettingsPath);
var task = op.Task;
while (!task.IsCompleted)
yield return null;
var result = op.Task.Result;
yield return null; //need deferred callbacks to get called
Assert.IsNotNull(op.Task.Result, $"task.Result is null! For task number [{i}]");
op.Release();
}
}
}
#if UNITY_EDITOR
class AsyncTaskTests_FastMode : AsyncTaskTests { protected override TestBuildScriptMode BuildScriptMode { get { return TestBuildScriptMode.Fast; } } }
class AsyncTaskTests_VirtualMode : AsyncTaskTests { protected override TestBuildScriptMode BuildScriptMode { get { return TestBuildScriptMode.Virtual; } } }
class AsyncTaskTests_PackedPlaymodeMode : AsyncTaskTests { protected override TestBuildScriptMode BuildScriptMode { get { return TestBuildScriptMode.PackedPlaymode; } } }
#endif
[UnityPlatform(exclude = new[] { RuntimePlatform.WindowsEditor, RuntimePlatform.OSXEditor, RuntimePlatform.LinuxEditor })]
class AsyncTaskTests_PackedMode : AsyncTaskTests { protected override TestBuildScriptMode BuildScriptMode { get { return TestBuildScriptMode.Packed; } } }
}