|
| 1 | +using System; |
| 2 | +using System.Runtime.InteropServices; |
| 3 | +using System.Diagnostics; |
| 4 | +using RunnerWorld.wit.imports.test.lists; |
| 5 | +using System.Text; |
| 6 | + |
| 7 | + |
| 8 | +public class Program |
| 9 | +{ |
| 10 | + public static void Main(string[] args) |
| 11 | + { |
| 12 | + ToTestInterop.EmptyListParam(new byte[0]); |
| 13 | + ToTestInterop.EmptyStringParam(""); |
| 14 | + |
| 15 | + { |
| 16 | + byte[] result = ToTestInterop.EmptyListResult(); |
| 17 | + Debug.Assert(result.Length == 0); |
| 18 | + } |
| 19 | + |
| 20 | + { |
| 21 | + string result = ToTestInterop.EmptyStringResult(); |
| 22 | + Debug.Assert(result.Length == 0); |
| 23 | + } |
| 24 | + |
| 25 | + ToTestInterop.ListParam(new byte[] { (byte)1, (byte)2, (byte)3, (byte)4 }); |
| 26 | + ToTestInterop.ListParam((new byte[] { (byte)1, (byte)2, (byte)3, (byte)4 }).AsSpan()); |
| 27 | + ToTestInterop.ListParam((new byte[] { (byte)1, (byte)2, (byte)3, (byte)4 }).AsMemory()); |
| 28 | + ToTestInterop.ListParam2("foo"); |
| 29 | + ToTestInterop.ListParam3(new List<String>() { |
| 30 | + "foo", |
| 31 | + "bar", |
| 32 | + "baz" |
| 33 | + }); |
| 34 | + |
| 35 | + ToTestInterop.ListParam4(new List<List<String>>() { |
| 36 | + new List<String>() { |
| 37 | + "foo", |
| 38 | + "bar" |
| 39 | + }, |
| 40 | + new List<String>() { |
| 41 | + "baz" |
| 42 | + } |
| 43 | + }); |
| 44 | + |
| 45 | + List<string> randomStrings = new List<string>(); |
| 46 | + for (int i = 0; i < 1000; i++) |
| 47 | + { |
| 48 | + randomStrings.Add(Guid.NewGuid().ToString()); |
| 49 | + } |
| 50 | + ToTestInterop.ListParamLarge(randomStrings); |
| 51 | + |
| 52 | + { |
| 53 | + byte[] result = ToTestInterop.ListResult(); |
| 54 | + Debug.Assert(result.Length == 5); |
| 55 | + Debug.Assert(result[0] == (byte)1); |
| 56 | + Debug.Assert(result[1] == (byte)2); |
| 57 | + Debug.Assert(result[2] == (byte)3); |
| 58 | + Debug.Assert(result[3] == (byte)4); |
| 59 | + Debug.Assert(result[4] == (byte)5); |
| 60 | + } |
| 61 | + |
| 62 | + { |
| 63 | + string result = ToTestInterop.ListResult2(); |
| 64 | + Console.WriteLine(result); |
| 65 | + Debug.Assert(result == "hello!"); |
| 66 | + } |
| 67 | + |
| 68 | + { |
| 69 | + List<String> result = ToTestInterop.ListResult3(); |
| 70 | + Debug.Assert(result.Count() == 2); |
| 71 | + Console.WriteLine(result[0]); |
| 72 | + Console.WriteLine(result[1]); |
| 73 | + Debug.Assert(result[0] == "hello,"); |
| 74 | + Debug.Assert(result[1] == "world!"); |
| 75 | + } |
| 76 | + |
| 77 | + string[] strings = { "x", "", "hello", "hello ⚑ world" }; |
| 78 | + foreach (string s in strings) |
| 79 | + { |
| 80 | + string result = ToTestInterop.StringRoundtrip(s); |
| 81 | + Debug.Assert(result == s); |
| 82 | + |
| 83 | + byte[] bytes = Encoding.UTF8.GetBytes(s); |
| 84 | + Debug.Assert(bytes.SequenceEqual(ToTestInterop.ListRoundtrip(bytes))); |
| 85 | + } |
| 86 | + |
| 87 | + { |
| 88 | + var (u, s) = ToTestInterop.ListMinmax8( |
| 89 | + new byte[] { byte.MinValue, byte.MaxValue }, |
| 90 | + new sbyte[] { sbyte.MinValue, sbyte.MaxValue } |
| 91 | + ); |
| 92 | + |
| 93 | + Debug.Assert(u.Length == 2 && u[0] == byte.MinValue && u[1] == byte.MaxValue); |
| 94 | + Debug.Assert(s.Length == 2 && s[0] == sbyte.MinValue && s[1] == sbyte.MaxValue); |
| 95 | + } |
| 96 | + |
| 97 | + { |
| 98 | + var (u, s) = ToTestInterop.ListMinmax16( |
| 99 | + new ushort[] { ushort.MinValue, ushort.MaxValue }, |
| 100 | + new short[] { short.MinValue, short.MaxValue } |
| 101 | + ); |
| 102 | + |
| 103 | + Console.WriteLine(u[0]); |
| 104 | + Console.WriteLine(u[1]); |
| 105 | + Debug.Assert(u.Length == 2, $"u.Length {u.Length}"); |
| 106 | + Debug.Assert(u[0] == ushort.MinValue, $"u[0] == {u[0]}"); |
| 107 | + Debug.Assert(u[1] == ushort.MaxValue, $"u[1] == {u[1]}"); |
| 108 | + |
| 109 | + Debug.Assert(s.Length == 2); |
| 110 | + Console.WriteLine(s[0]); |
| 111 | + Console.WriteLine(s[1]); |
| 112 | + Debug.Assert(s.Length == 2 && s[0] == short.MinValue && s[1] == short.MaxValue); |
| 113 | + } |
| 114 | + |
| 115 | + { |
| 116 | + var (u, s) = ToTestInterop.ListMinmax32( |
| 117 | + new uint[] { uint.MinValue, uint.MaxValue }, |
| 118 | + new int[] { int.MinValue, int.MaxValue } |
| 119 | + ); |
| 120 | + |
| 121 | + Debug.Assert(u.Length == 2 && u[0] == uint.MinValue && u[1] == uint.MaxValue); |
| 122 | + Debug.Assert(s.Length == 2 && s[0] == int.MinValue && s[1] == int.MaxValue); |
| 123 | + } |
| 124 | + |
| 125 | + { |
| 126 | + var (u, s) = ToTestInterop.ListMinmax64( |
| 127 | + new ulong[] { ulong.MinValue, ulong.MaxValue }, |
| 128 | + new long[] { long.MinValue, long.MaxValue } |
| 129 | + ); |
| 130 | + |
| 131 | + Debug.Assert(u.Length == 2 && u[0] == ulong.MinValue && u[1] == ulong.MaxValue); |
| 132 | + |
| 133 | + Debug.Assert(s.Length == 2 && s[0] == long.MinValue && s[1] == long.MaxValue); |
| 134 | + } |
| 135 | + |
| 136 | + { |
| 137 | + var (u, s) = ToTestInterop.ListMinmaxFloat( |
| 138 | + new float[] { |
| 139 | + float.MinValue, |
| 140 | + float.MaxValue, |
| 141 | + float.NegativeInfinity, |
| 142 | + float.PositiveInfinity |
| 143 | + }, |
| 144 | + new double[] { |
| 145 | + double.MinValue, |
| 146 | + double.MaxValue, |
| 147 | + double.NegativeInfinity, |
| 148 | + double.PositiveInfinity |
| 149 | + }); |
| 150 | + |
| 151 | + Debug.Assert(u.Length == 4 |
| 152 | + && u[0] == float.MinValue |
| 153 | + && u[1] == float.MaxValue |
| 154 | + && u[2] == float.NegativeInfinity |
| 155 | + && u[3] == float.PositiveInfinity); |
| 156 | + |
| 157 | + Debug.Assert(s.Length == 4 |
| 158 | + && s[0] == double.MinValue |
| 159 | + && s[1] == double.MaxValue |
| 160 | + && s[2] == double.NegativeInfinity |
| 161 | + && s[3] == double.PositiveInfinity); |
| 162 | + } |
| 163 | + } |
| 164 | +} |
0 commit comments