Skip to content

Commit ecc4d6d

Browse files
committed
Add tests for AsyncInfo.Run with generic async operations
Introduces tests for IAsyncActionWithProgress<int> and IAsyncOperation<TimeSpan> using AsyncInfo.Run with explicit and transitive type arguments. Ensures correct COM interface querying and memory management for these async operations.
1 parent 682fc7b commit ecc4d6d

File tree

1 file changed

+63
-0
lines changed
  • src/Tests/FunctionalTests/ClassActivation

1 file changed

+63
-0
lines changed

src/Tests/FunctionalTests/ClassActivation/Program.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
using System.Runtime.InteropServices;
66
using System.Runtime.InteropServices.Marshalling;
77
using System.Runtime.Versioning;
8+
using System.Threading.Tasks;
89
using System.Windows.Input;
910
using TestComponent;
1011
using TestComponentCSharp;
12+
using Windows.Foundation;
1113
using Windows.Foundation.Collections;
14+
using Windows.Foundation.Tasks;
1215
using WindowsRuntime.InteropServices;
1316

1417
CustomDisposableTest customDisposableTest = new();
@@ -115,6 +118,46 @@
115118
}
116119
}
117120

121+
IAsyncActionWithProgress<int> asyncActionWithProgress = GenericFactory.MakeAsyncActionWithProgress();
122+
123+
unsafe
124+
{
125+
void* asyncActionWithProgressPtr = WindowsRuntimeMarshal.ConvertToUnmanaged(asyncActionWithProgress);
126+
127+
try
128+
{
129+
ComHelpers.EnsureQueryInterface(
130+
unknownPtr: asyncActionWithProgressPtr,
131+
iids: [
132+
new Guid("0EDE398F-0090-574E-AD30-E152B433BF6A"), // 'IAsyncActionWithProgress<int>'
133+
new Guid("0DB2462F-B6D6-5A6C-8834-B530BAAA45FD")]); // 'IAsyncInfo'
134+
}
135+
finally
136+
{
137+
WindowsRuntimeMarshal.Free(asyncActionWithProgressPtr);
138+
}
139+
}
140+
141+
IAsyncOperation<TimeSpan> asyncOperation = GenericFactory.MakeAsyncOperation();
142+
143+
unsafe
144+
{
145+
void* asyncOperationPtr = WindowsRuntimeMarshal.ConvertToUnmanaged(asyncOperation);
146+
147+
try
148+
{
149+
ComHelpers.EnsureQueryInterface(
150+
unknownPtr: asyncOperationPtr,
151+
iids: [
152+
new Guid("1AE01209-1ACA-51D3-A080-8B1214E0A39E"), // 'IAsyncOperation<TimeSpan>'
153+
new Guid("0DB2462F-B6D6-5A6C-8834-B530BAAA45FD")]); // 'IAsyncInfo'
154+
}
155+
finally
156+
{
157+
WindowsRuntimeMarshal.Free(asyncOperationPtr);
158+
}
159+
}
160+
118161
sealed class TestComposable : Composable
119162
{
120163
}
@@ -209,6 +252,26 @@ class GenericFactory
209252
public static object Make() => Make<bool>();
210253

211254
private static object Make<T>() => new GenericType<T, float>();
255+
256+
// Specific test for 'AsyncInfo.Run' with explicit type arguments
257+
[SupportedOSPlatform("windows10.0.10240.0")]
258+
public static IAsyncActionWithProgress<int> MakeAsyncActionWithProgress()
259+
{
260+
return AsyncInfo.Run<int>((token, progress) => Task.CompletedTask);
261+
}
262+
263+
// Specific test for 'AsyncInfo.Run' with transitive type arguments
264+
[SupportedOSPlatform("windows10.0.10240.0")]
265+
public static IAsyncOperation<TimeSpan> MakeAsyncOperation()
266+
{
267+
return MakeAsyncActionOperation<TimeSpan>();
268+
}
269+
270+
[SupportedOSPlatform("windows10.0.10240.0")]
271+
private static IAsyncOperation<T> MakeAsyncActionOperation<T>()
272+
{
273+
return AsyncInfo.Run(token => Task.FromResult(default(T)));
274+
}
212275
}
213276

214277
[Guid("3C832AA5-5F7E-46EE-B1BF-7FE03AE866AF")]

0 commit comments

Comments
 (0)