// Copyright (c) ZeroC, Inc. All rights reserved. using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; using ZeroC.Test; namespace ZeroC.Ice.Test.Operations { public sealed class AsyncMyDerivedClass : IAsyncMyDerivedClass { private readonly object _mutex = new(); private int _opByteSOnewayCallCount; private Thread_opVoid? _opVoidThread; internal class Thread_opVoid : TaskCompletionSource { private readonly object _mutex = new(); public void Start() { lock (_mutex) { _thread = new Thread(new ThreadStart(Run)); _thread.Start(); } } public void Run() => SetResult(null); public void Join() { lock (_mutex) { _thread!.Join(); } } private Thread? _thread; } // Override the Object "pseudo" operations to verify the operation mode. public ValueTask IceIsAAsync(string id, Current current, CancellationToken cancel) { TestHelper.Assert(current.IsIdempotent); return new(typeof(IMyDerivedClass).GetAllIceTypeIds().Contains(id)); } public ValueTask IcePingAsync(Current current, CancellationToken cancel) { TestHelper.Assert(current.IsIdempotent); return default; } public ValueTask> IceIdsAsync(Current current, CancellationToken cancel) { TestHelper.Assert(current.IsIdempotent); return new(typeof(IMyDerivedClass).GetAllIceTypeIds()); } public ValueTask IceIdAsync(Current current, CancellationToken cancel) { TestHelper.Assert(current.IsIdempotent); return new(typeof(IMyDerivedClass).GetIceTypeId()!); } public ValueTask ShutdownAsync(Current current, CancellationToken cancel) { while (_opVoidThread != null) { _opVoidThread.Join(); _opVoidThread = null; } current.Communicator.ShutdownAsync(); return default; } public ValueTask SupportsCompressAsync(Current current, CancellationToken cancel) => new(true); public ValueTask OpVoidAsync(Current current, CancellationToken cancel) { TestHelper.Assert(!current.IsIdempotent); while (_opVoidThread != null) { _opVoidThread.Join(); _opVoidThread = null; } _opVoidThread = new Thread_opVoid(); _opVoidThread.Start(); return new(_opVoidThread.Task); } public ValueTask<(bool, bool)> OpBoolAsync(bool p1, bool p2, Current current, CancellationToken cancel) => new((p2, p1)); public ValueTask<(ReadOnlyMemory, ReadOnlyMemory)> OpBoolSAsync( bool[] p1, bool[] p2, Current current, CancellationToken cancel) { bool[] p3 = new bool[p1.Length + p2.Length]; Array.Copy(p1, p3, p1.Length); Array.Copy(p2, 0, p3, p1.Length, p2.Length); bool[] r = new bool[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpBoolSSAsync( bool[][] p1, bool[][] p2, Current current, CancellationToken cancel) { bool[][] p3 = new bool[p1.Length + p2.Length][]; Array.Copy(p1, p3, p1.Length); Array.Copy(p2, 0, p3, p1.Length, p2.Length); bool[][] r = new bool[p1.Length][]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(byte, byte)> OpByteAsync(byte p1, byte p2, Current current, CancellationToken cancel) => new((p1, (byte)(p1 ^ p2))); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpByteBoolDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(ReadOnlyMemory, ReadOnlyMemory)> OpByteSAsync( byte[] p1, byte[] p2, Current current, CancellationToken cancel) { byte[] p3 = new byte[p1.Length]; for (int i = 0; i < p1.Length; i++) { p3[i] = p1[^(i + 1)]; } byte[] r = new byte[p1.Length + p2.Length]; Array.Copy(p1, r, p1.Length); Array.Copy(p2, 0, r, p1.Length, p2.Length); return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpByteSSAsync( byte[][] p1, byte[][] p2, Current current, CancellationToken cancel) { byte[][] p3 = new byte[p1.Length][]; for (int i = 0; i < p1.Length; i++) { p3[i] = p1[^(i + 1)]; } byte[][] r = new byte[p1.Length + p2.Length][]; Array.Copy(p1, r, p1.Length); Array.Copy(p2, 0, r, p1.Length, p2.Length); return new((r, p3)); } public ValueTask<(double, float, double)> OpFloatDoubleAsync( float p1, double p2, Current current, CancellationToken cancel) => new((p2, p1, p2)); public ValueTask<(ReadOnlyMemory, ReadOnlyMemory, ReadOnlyMemory)> OpFloatDoubleSAsync( float[] p1, double[] p2, Current current, CancellationToken cancel) { float[] p3 = p1; double[] p4 = new double[p2.Length]; for (int i = 0; i < p2.Length; i++) { p4[i] = p2[^(i + 1)]; } double[] r = new double[p2.Length + p1.Length]; Array.Copy(p2, r, p2.Length); for (int i = 0; i < p1.Length; i++) { r[p2.Length + i] = p1[i]; } return new((r, p3, p4)); } public ValueTask<(IEnumerable>, IEnumerable>, IEnumerable>)> OpFloatDoubleSSAsync( float[][] p1, double[][] p2, Current current, CancellationToken cancel) { float[][] p3 = p1; double[][] p4 = new double[p2.Length][]; for (int i = 0; i < p2.Length; i++) { p4[i] = p2[^(i + 1)]; } double[][] r = new double[p2.Length + p2.Length][]; Array.Copy(p2, r, p2.Length); for (int i = 0; i < p2.Length; i++) { r[p2.Length + i] = new double[p2[i].Length]; for (int j = 0; j < p2[i].Length; j++) { r[p2.Length + i][j] = p2[i][j]; } } return new((r, p3, p4)); } public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpLongFloatDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpULongFloatDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(IMyClassPrx?, IMyClassPrx?, IMyClassPrx?)> OpMyClassAsync( IMyClassPrx? p1, Current current, CancellationToken cancel) => new(( current.Adapter.CreateProxy(current.Identity, IMyClassPrx.Factory), p1, current.Adapter.CreateProxy("noSuchIdentity", IMyClassPrx.Factory))); public ValueTask<(MyEnum, MyEnum)> OpMyEnumAsync(MyEnum p1, Current current, CancellationToken cancel) => new((MyEnum.enum3, p1)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpShortIntDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpUShortUIntDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(long, short, int, long)> OpShortIntLongAsync( short p1, int p2, long p3, Current current, CancellationToken cancel) => new((p3, p1, p2, p3)); public ValueTask<(ulong, ushort, uint, ulong)> OpUShortUIntULongAsync( ushort p1, uint p2, ulong p3, Current current, CancellationToken cancel) => new((p3, p1, p2, p3)); public ValueTask OpVarIntAsync(int v, Current current, CancellationToken cancel) => new(v); public ValueTask OpVarUIntAsync(uint v, Current current, CancellationToken cancel) => new(v); public ValueTask OpVarLongAsync(long v, Current current, CancellationToken cancel) => new(v); public ValueTask OpVarULongAsync(ulong v, Current current, CancellationToken cancel) => new(v); public ValueTask<(ReadOnlyMemory, ReadOnlyMemory, ReadOnlyMemory, ReadOnlyMemory)> OpShortIntLongSAsync( short[] p1, int[] p2, long[] p3, Current current, CancellationToken cancel) { short[] p4 = p1; int[] p5 = new int[p2.Length]; for (int i = 0; i < p2.Length; i++) { p5[i] = p2[^(i + 1)]; } long[]? p6 = new long[p3.Length + p3.Length]; Array.Copy(p3, p6, p3.Length); Array.Copy(p3, 0, p6, p3.Length, p3.Length); return new((p3, p4, p5, p6)); } public ValueTask<(ReadOnlyMemory, ReadOnlyMemory, ReadOnlyMemory, ReadOnlyMemory)> OpUShortUIntULongSAsync(ushort[] p1, uint[] p2, ulong[] p3, Current current, CancellationToken cancel) { ushort[]? p4 = p1; uint[] p5 = new uint[p2.Length]; for (int i = 0; i < p2.Length; i++) { p5[i] = p2[^(i + 1)]; } ulong[] p6 = new ulong[p3.Length + p3.Length]; Array.Copy(p3, p6, p3.Length); Array.Copy(p3, 0, p6, p3.Length, p3.Length); return new((p3, p4, p5, p6)); } public ValueTask<(IEnumerable, IEnumerable, IEnumerable)> OpVarIntVarLongSAsync(int[] p1, long[] p2, Current current, CancellationToken cancel) { int[] p4 = new int[p1.Length]; for (int i = 0; i < p1.Length; i++) { p4[i] = p1[^(i + 1)]; } long[] p5 = new long[p2.Length + p2.Length]; Array.Copy(p2, p5, p2.Length); Array.Copy(p2, 0, p5, p2.Length, p2.Length); return new((p2, p4, p5)); } public ValueTask<(IEnumerable, IEnumerable, IEnumerable)> OpVarUIntVarULongSAsync(uint[] p1, ulong[] p2, Current current, CancellationToken cancel) { uint[] p4 = new uint[p1.Length]; for (int i = 0; i < p1.Length; i++) { p4[i] = p1[^(i + 1)]; } ulong[] p5 = new ulong[p2.Length + p2.Length]; Array.Copy(p2, p5, p2.Length); Array.Copy(p2, 0, p5, p2.Length, p2.Length); return new((p2, p4, p5)); } public ValueTask<(IEnumerable>, IEnumerable>, IEnumerable>, IEnumerable>)> OpShortIntLongSSAsync(short[][] p1, int[][] p2, long[][] p3, Current current, CancellationToken cancel) { short[][] p4 = p1; int[][] p5 = new int[p2.Length][]; for (int i = 0; i < p2.Length; i++) { p5[i] = p2[^(i + 1)]; } long[][] p6 = new long[p3.Length + p3.Length][]; Array.Copy(p3, p6, p3.Length); Array.Copy(p3, 0, p6, p3.Length, p3.Length); return new((p3, p4, p5, p6)); } public ValueTask<(IEnumerable>, IEnumerable>, IEnumerable>, IEnumerable>)> OpUShortUIntULongSSAsync(ushort[][] p1, uint[][] p2, ulong[][] p3, Current current, CancellationToken cancel) { ushort[][] p4 = p1; uint[][] p5 = new uint[p2.Length][]; for (int i = 0; i < p2.Length; i++) { p5[i] = p2[^(i + 1)]; } ulong[][]? p6 = new ulong[p3.Length + p3.Length][]; Array.Copy(p3, p6, p3.Length); Array.Copy(p3, 0, p6, p3.Length, p3.Length); return new((p3, p4, p5, p6)); } public ValueTask<(string, string)> OpStringAsync(string p1, string p2, Current current, CancellationToken cancel) => new(($"{p1} {p2}", $"{p2} {p1}")); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpStringMyEnumDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpMyEnumStringDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpMyStructMyEnumDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(IEnumerable>, IEnumerable>)> OpByteBoolDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpShortIntDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpUShortUIntDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpLongFloatDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpULongFloatDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpStringStringDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpStringMyEnumDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpMyEnumStringDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpMyStructMyEnumDSAsync( Dictionary[] p1, Dictionary[] p2, Current current, CancellationToken cancel) { var p3 = new Dictionary[p1.Length + p2.Length]; Array.Copy(p2, p3, p2.Length); Array.Copy(p1, 0, p3, p2.Length, p1.Length); var r = new Dictionary[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpByteByteSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpBoolBoolSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpShortShortSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpUShortUShortSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpIntIntSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpUIntUIntSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpLongLongSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpULongULongSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpStringFloatSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpStringDoubleSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpStringStringSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpMyEnumMyEnumSDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p2)); public ValueTask> OpIntSAsync(int[] s, Current current, CancellationToken cancel) { int[] r = new int[s.Length]; for (int i = 0; i < s.Length; ++i) { r[i] = -s[i]; } return new(r); } public ValueTask> OpContextAsync( Current current, CancellationToken cancel) => new(current.Context); public ValueTask OpByteSOnewayAsync(byte[] s, Current current, CancellationToken cancel) { lock (_mutex) { ++_opByteSOnewayCallCount; } return default; } public ValueTask OpByteSOnewayCallCountAsync(Current current, CancellationToken cancel) { lock (_mutex) { int count = _opByteSOnewayCallCount; _opByteSOnewayCallCount = 0; return new(count); } } public ValueTask OpDoubleMarshalingAsync(double p1, double[] p2, Current current, CancellationToken cancel) { double d = 1278312346.0 / 13.0; TestHelper.Assert(p1 == d); for (int i = 0; i < p2.Length; ++i) { TestHelper.Assert(p2[i] == d); } return default; } public ValueTask<(IEnumerable, IEnumerable)> OpStringSAsync( string[] p1, string[] p2, Current current, CancellationToken cancel) { string[] p3 = new string[p1.Length + p2.Length]; Array.Copy(p1, p3, p1.Length); Array.Copy(p2, 0, p3, p1.Length, p2.Length); string[] r = new string[p1.Length]; for (int i = 0; i < p1.Length; i++) { r[i] = p1[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>, IEnumerable>)> OpStringSSAsync( string[][] p1, string[][] p2, Current current, CancellationToken cancel) { string[][] p3 = new string[p1.Length + p2.Length][]; Array.Copy(p1, p3, p1.Length); Array.Copy(p2, 0, p3, p1.Length, p2.Length); string[][] r = new string[p2.Length][]; for (int i = 0; i < p2.Length; i++) { r[i] = p2[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IEnumerable>>, IEnumerable>>)> OpStringSSSAsync(string[][][] p1, string[][][] p2, Current current, CancellationToken cancel) { string[][][] p3 = new string[p1.Length + p2.Length][][]; Array.Copy(p1, p3, p1.Length); Array.Copy(p2, 0, p3, p1.Length, p2.Length); string[][][] r = new string[p2.Length][][]; for (int i = 0; i < p2.Length; i++) { r[i] = p2[^(i + 1)]; } return new((r, p3)); } public ValueTask<(IReadOnlyDictionary, IReadOnlyDictionary)> OpStringStringDAsync( Dictionary p1, Dictionary p2, Current current, CancellationToken cancel) => new((MergeDictionaries(p1, p2), p1)); public ValueTask<(Structure, Structure)> OpStructAsync( Structure p1, Structure p2, Current current, CancellationToken cancel) { Structure p3 = p1; p3.S.S = "a new string"; return new((p2, p3)); } public ValueTask OpIdempotentAsync(Current current, CancellationToken cancel) { TestHelper.Assert(current.IsIdempotent); return default; } // "return" exception when called two-way, otherwise succeeds. public ValueTask OpOnewayAsync(Current current, CancellationToken cancel) => throw new SomeException(); // "return" exception when called two-way, otherwise succeeds. public ValueTask OpOnewayMetadataAsync(Current current, CancellationToken cancel) => throw new SomeException(); public ValueTask OpDerivedAsync(Current current, CancellationToken cancel) => default; public ValueTask OpByte1Async(byte value, Current current, CancellationToken cancel) => new(value); public ValueTask OpShort1Async(short value, Current current, CancellationToken cancel) => new(value); public ValueTask OpInt1Async(int value, Current current, CancellationToken cancel) => new(value); public ValueTask OpLong1Async(long value, Current current, CancellationToken cancel) => new(value); public ValueTask OpUShort1Async(ushort value, Current current, CancellationToken cancel) => new(value); public ValueTask OpUInt1Async(uint value, Current current, CancellationToken cancel) => new(value); public ValueTask OpULong1Async(ulong value, Current current, CancellationToken cancel) => new(value); public ValueTask OpFloat1Async(float value, Current current, CancellationToken cancel) => new(value); public ValueTask OpDouble1Async(double value, Current current, CancellationToken cancel) => new(value); public ValueTask OpString1Async(string value, Current current, CancellationToken cancel) => new(value); public ValueTask> OpStringS1Async( string[] value, Current current, CancellationToken cancel) => new(value); public ValueTask> OpByteBoolD1Async( Dictionary value, Current current, CancellationToken cancel) => new(value); public ValueTask> OpStringS2Async( string[] value, Current current, CancellationToken cancel) => new(value); public ValueTask> OpByteBoolD2Async( Dictionary value, Current current, CancellationToken cancel) => new(value); public ValueTask OpMyClass1Async(MyClass1? value, Current current, CancellationToken cancel) => new(value); public ValueTask OpMyStruct1Async(MyStruct1 value, Current current, CancellationToken cancel) => new(value); public ValueTask> OpStringLiteralsAsync(Current current, CancellationToken cancel) { return new(new string[] { Constants.s0, Constants.s1, Constants.s2, Constants.s3, Constants.s4, Constants.s5, Constants.s6, Constants.s7, Constants.s8, Constants.s9, Constants.s10, Constants.sw0, Constants.sw1, Constants.sw2, Constants.sw3, Constants.sw4, Constants.sw5, Constants.sw6, Constants.sw7, Constants.sw8, Constants.sw9, Constants.sw10, Constants.ss0, Constants.ss1, Constants.ss2, Constants.ss3, Constants.ss4, Constants.ss5, Constants.su0, Constants.su1, Constants.su2 }); } public ValueTask> OpWStringLiteralsAsync(Current current, CancellationToken cancel) { return new(new string[] { Constants.s0, Constants.s1, Constants.s2, Constants.s3, Constants.s4, Constants.s5, Constants.s6, Constants.s7, Constants.s8, Constants.s9, Constants.s10, Constants.sw0, Constants.sw1, Constants.sw2, Constants.sw3, Constants.sw4, Constants.sw5, Constants.sw6, Constants.sw7, Constants.sw8, Constants.sw9, Constants.sw10, Constants.ss0, Constants.ss1, Constants.ss2, Constants.ss3, Constants.ss4, Constants.ss5, Constants.su0, Constants.su1, Constants.su2 }); } public async ValueTask OpMStruct1Async(Current current, CancellationToken cancel) { await Task.Delay(0, cancel); return new IMyClass.OpMStruct1MarshaledReturnValue( new Structure(null, MyEnum.enum1, new AnotherStruct("")), current); } public async ValueTask OpMStruct2Async( Structure p1, Current current, CancellationToken cancel) { await Task.Delay(0, cancel); return new IMyClass.OpMStruct2MarshaledReturnValue(p1, p1, current); } public async ValueTask OpMSeq1Async( Current current, CancellationToken cancel) { await Task.Delay(0, cancel); return new IMyClass.OpMSeq1MarshaledReturnValue(Array.Empty(), current); } public async ValueTask OpMSeq2Async( string[] p1, Current current, CancellationToken cancel) { await Task.Delay(0, cancel); return new IMyClass.OpMSeq2MarshaledReturnValue(p1, p1, current); } public async ValueTask OpMDict1Async( Current current, CancellationToken cancel) { await Task.Delay(0, cancel); return new IMyClass.OpMDict1MarshaledReturnValue(new Dictionary(), current); } public async ValueTask OpMDict2Async( Dictionary p1, Current current, CancellationToken cancel) { await Task.Delay(0, cancel); return new IMyClass.OpMDict2MarshaledReturnValue(p1, p1, current); } public ValueTask OpSendStream1Async(Stream p1, Current current, CancellationToken cancel) { CompareStreams(File.OpenRead("AllTests.cs"), p1); return default; } /// The Current object for the dispatch. /// A cancellation token that receives the cancellation requests. public ValueTask OpSendStream2Async(string p1, Stream p2, Current current, CancellationToken cancel) { CompareStreams(File.OpenRead(p1), p2); return default; } /// The Current object for the dispatch. /// A cancellation token that receives the cancellation requests. public ValueTask OpGetStream1Async(Current current, CancellationToken cancel) => new(File.OpenRead("AllTests.cs")); /// The Current object for the dispatch. /// A cancellation token that receives the cancellation requests. /// Named tuple with the following fields: public ValueTask<(string R1, Stream R2)> OpGetStream2Async(Current current, CancellationToken cancel) => new(("AllTests.cs", File.OpenRead("AllTests.cs"))); /// The Current object for the dispatch. /// A cancellation token that receives the cancellation requests. public ValueTask OpSendAndGetStream1Async(Stream p1, Current current, CancellationToken cancel) => new(p1); /// The Current object for the dispatch. /// A cancellation token that receives the cancellation requests. /// Named tuple with the following fields: public ValueTask<(string R1, Stream R2)> OpSendAndGetStream2Async( string p1, Stream p2, Current current, CancellationToken cancel) => new((p1, p2)); private static void CompareStreams(Stream s1, Stream s2) { int v1, v2; do { v1 = s1.ReadByte(); v2 = s2.ReadByte(); TestHelper.Assert(v1 == v2); } while (v1 != -1 && v2 != -1); s1.Dispose(); s2.Dispose(); } private static IReadOnlyDictionary MergeDictionaries( IReadOnlyDictionary first, IReadOnlyDictionary second) where TKey : notnull { var result = new Dictionary(first); foreach ((TKey key, TValue value) in second) { result[key] = value; } return result; } } }