diff --git a/src/UniTask/Assets/Tests/AsyncOperationTest.cs b/src/UniTask/Assets/Tests/AsyncOperationTest.cs new file mode 100644 index 0000000..fb29218 --- /dev/null +++ b/src/UniTask/Assets/Tests/AsyncOperationTest.cs @@ -0,0 +1,42 @@ +using System.Collections; +using System.Threading; +using Cysharp.Threading.Tasks; +using FluentAssertions; +using NUnit.Framework; +using UnityEngine; +using UnityEngine.TestTools; + +#if CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6)) +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + +namespace Cysharp.Threading.TasksTests +{ + public class AsyncOperationTest + { + [UnityTest] + public IEnumerator ResourcesLoad_CancelOnPlayerLoop() => UniTask.ToCoroutine(async () => + { + var cts = new CancellationTokenSource(); + var task = Resources.LoadAsync("sample_texture").ToUniTask(cancellationToken: cts.Token, handleImmediately: false); + + cts.Cancel(); + task.Status.Should().Be(UniTaskStatus.Pending); + + await UniTask.NextFrame(); + task.Status.Should().Be(UniTaskStatus.Canceled); + }); + + [Test] + public void ResourcesLoad_CancelImmediately() + { + { + var cts = new CancellationTokenSource(); + var task = Resources.LoadAsync("sample_texture").ToUniTask(cancellationToken: cts.Token, handleImmediately: true); + + cts.Cancel(); + task.Status.Should().Be(UniTaskStatus.Canceled); + } + } + } +} +#endif diff --git a/src/UniTask/Assets/Tests/AsyncOperationTest.cs.meta b/src/UniTask/Assets/Tests/AsyncOperationTest.cs.meta new file mode 100644 index 0000000..fed3f0d --- /dev/null +++ b/src/UniTask/Assets/Tests/AsyncOperationTest.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 295d574a16494d6aa4d02fcb32179e39 +timeCreated: 1698887128 \ No newline at end of file diff --git a/src/UniTask/Assets/Tests/Resources.meta b/src/UniTask/Assets/Tests/Resources.meta new file mode 100644 index 0000000..d568559 --- /dev/null +++ b/src/UniTask/Assets/Tests/Resources.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 8d82913edf6ac48aca30f66ae9ba42d6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/src/UniTask/Assets/Tests/Resources/sample_texture.png b/src/UniTask/Assets/Tests/Resources/sample_texture.png new file mode 100644 index 0000000..2da8909 Binary files /dev/null and b/src/UniTask/Assets/Tests/Resources/sample_texture.png differ diff --git a/src/UniTask/Assets/Tests/Resources/sample_texture.png.meta b/src/UniTask/Assets/Tests/Resources/sample_texture.png.meta new file mode 100644 index 0000000..15a1de5 --- /dev/null +++ b/src/UniTask/Assets/Tests/Resources/sample_texture.png.meta @@ -0,0 +1,208 @@ +fileFormatVersion: 2 +guid: 535006a83baed4ebda99d24a909a2efe +TextureImporter: + internalIDToNameTable: + - first: + 213: -2664112245596591751 + second: sample_texture_0 + - first: + 213: -4606777057269188692 + second: sample_texture_1 + - first: + 213: 1950921086533113773 + second: sample_texture_2 + externalObjects: {} + serializedVersion: 12 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + sRGBTexture: 1 + linearTexture: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapsPreserveCoverage: 0 + alphaTestReferenceValue: 0.5 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + flipGreenChannel: 0 + isReadable: 0 + streamingMipmaps: 0 + streamingMipmapsPriority: 0 + vTOnly: 0 + ignoreMipmapLimit: 0 + grayScaleToAlpha: 0 + generateCubemap: 6 + cubemapConvolution: 0 + seamlessCubemap: 0 + textureFormat: 1 + maxTextureSize: 2048 + textureSettings: + serializedVersion: 2 + filterMode: 1 + aniso: 1 + mipBias: 0 + wrapU: 1 + wrapV: 1 + wrapW: 1 + nPOTScale: 0 + lightmap: 0 + compressionQuality: 50 + spriteMode: 2 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spritePixelsToUnits: 100 + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spriteGenerateFallbackPhysicsShape: 1 + alphaUsage: 1 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 8 + textureShape: 1 + singleChannelComponent: 0 + flipbookRows: 1 + flipbookColumns: 1 + maxTextureSizeSet: 0 + compressionQualitySet: 0 + textureFormatSet: 0 + ignorePngGamma: 0 + applyGammaDecoding: 0 + swizzle: 50462976 + cookieLightType: 0 + platformSettings: + - serializedVersion: 3 + buildTarget: DefaultTexturePlatform + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: WebGL + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: Standalone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + - serializedVersion: 3 + buildTarget: iPhone + maxTextureSize: 2048 + resizeAlgorithm: 0 + textureFormat: -1 + textureCompression: 1 + compressionQuality: 50 + crunchedCompression: 0 + allowsAlphaSplitting: 0 + overridden: 0 + androidETC2FallbackOverride: 0 + forceMaximumCompressionQuality_BC6H_BC7: 0 + spriteSheet: + serializedVersion: 2 + sprites: + - serializedVersion: 2 + name: sample_texture_0 + rect: + serializedVersion: 2 + x: 0 + y: 76 + width: 243 + height: 251 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: -1 + bones: [] + spriteID: 9796277170c270bd0800000000000000 + internalID: -2664112245596591751 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: sample_texture_1 + rect: + serializedVersion: 2 + x: 227 + y: 0 + width: 190 + height: 231 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: -1 + bones: [] + spriteID: ca7fc069ca07110c0800000000000000 + internalID: -4606777057269188692 + vertices: [] + indices: + edges: [] + weights: [] + - serializedVersion: 2 + name: sample_texture_2 + rect: + serializedVersion: 2 + x: 398 + y: 87 + width: 202 + height: 188 + alignment: 0 + pivot: {x: 0, y: 0} + border: {x: 0, y: 0, z: 0, w: 0} + outline: [] + physicsShape: [] + tessellationDetail: -1 + bones: [] + spriteID: da710ab4460131b10800000000000000 + internalID: 1950921086533113773 + vertices: [] + indices: + edges: [] + weights: [] + outline: [] + physicsShape: [] + bones: [] + spriteID: + internalID: 0 + vertices: [] + indices: + edges: [] + weights: [] + secondaryTextures: [] + nameFileIdTable: {} + mipmapLimitGroupName: + pSDRemoveMatte: 0 + userData: + assetBundleName: + assetBundleVariant: