2 using System
.Collections
.Generic
;
4 using System
.Threading
.Tasks
;
6 using System
.Reflection
;
11 public class TestClass
{
12 public static int i32_res
;
13 public static void InvokeI32 (int a
, int b
) {
17 public static float f32_res
;
18 public static void InvokeFloat (float f
) {
22 public static double f64_res
;
23 public static void InvokeDouble (double d
) {
27 public static long i64_res
;
28 public static void InvokeLong (long l
) {
32 public static string string_res
;
33 public static void InvokeString (string s
) {
37 public static string mkstr
;
38 public static string InvokeMkString() {
43 public static int int_val
;
44 public static void InvokeInt (int i
) {
48 public static object obj1
;
49 public static object InvokeObj1(object obj
)
55 public static object obj2
;
56 public static object InvokeObj2(object obj
)
62 public static object mkobj
;
63 public static object InvokeMkobj()
65 mkobj
= new object ();
69 public static int first_val
, second_val
;
70 public static void PlayWithObj(JSObject obj
) {
71 first_val
= (int)obj
.Invoke ("inc");;
72 second_val
= (int)obj
.Invoke("add", 20);
75 public static object[] js_objs
;
76 public static void PlayWithObjTypes (JSObject obj
) {
77 js_objs
= new object[4];
78 js_objs
[0] = obj
.Invoke ("return_int");
79 js_objs
[1] = obj
.Invoke ("return_double");
80 js_objs
[2] = obj
.Invoke ("return_string");
81 js_objs
[3] = obj
.Invoke ("return_bool");
84 public static int do_add
;
85 public static void UseFunction (JSObject obj
) {
86 do_add
= (int)obj
.Invoke("call", null, 10, 20);
89 public static int dele_res
;
90 public static Func
<int, int, int> MkDelegate () {
97 public static TaskCompletionSource
<int> tcs
;
98 public static Task
<int> task
;
99 public static object MkTask () {
100 tcs
= new TaskCompletionSource
<int> ();
105 public static TaskCompletionSource
<object> tcs3
;
106 public static Task task3
;
107 public static object MkTaskNull () {
108 tcs3
= new TaskCompletionSource
<object> ();
113 public static Task
<object> taskString
;
114 public static object MkTaskString () {
115 tcs3
= new TaskCompletionSource
<object> ();
116 taskString
= tcs3
.Task
;
120 public static Task
<object> the_promise
;
121 public static void InvokePromise (object obj
) {
122 the_promise
= (Task
<object>)obj
;
123 the_promise
.ContinueWith((t
,o
) => {
124 Console
.WriteLine ("Promise result is {0}", t
.Result
);
125 }, null, TaskContinuationOptions
.ExecuteSynchronously
); //must be sync cuz the mainloop pump is gone
128 public static List
<JSObject
> js_objs_to_dispose
= new List
<JSObject
>();
129 public static void DisposeObject(JSObject obj
)
131 js_objs_to_dispose
.Add(obj
);
135 public static object[] js_props
;
136 public static void RetrieveObjectProperties (JSObject obj
) {
137 js_props
= new object[4];
138 js_props
[0] = obj
.GetObjectProperty ("myInt");
139 js_props
[1] = obj
.GetObjectProperty ("myDouble");
140 js_props
[2] = obj
.GetObjectProperty ("myString");
141 js_props
[3] = obj
.GetObjectProperty ("myBoolean");
144 public static void PopulateObjectProperties (JSObject obj
, bool createIfNotExist
) {
145 js_props
= new object[4];
146 obj
.SetObjectProperty ("myInt", 100, createIfNotExist
);
147 obj
.SetObjectProperty ("myDouble", 4.5, createIfNotExist
);
148 obj
.SetObjectProperty ("myString", "qwerty", createIfNotExist
);
149 obj
.SetObjectProperty ("myBoolean", true, createIfNotExist
);
152 public static byte[] byteBuffer
;
153 public static void MarshalByteBuffer (byte[] buffer
) {
157 public static int[] intBuffer
;
158 public static void MarshalInt32Array (int[] buffer
) {
162 public static void MarshalByteBufferToInts (byte[] buffer
) {
163 intBuffer
= new int[buffer
.Length
/ sizeof(int)];
164 for (int i
= 0; i
< buffer
.Length
; i
+= sizeof(int))
165 intBuffer
[i
/ sizeof(int)] = BitConverter
.ToInt32(buffer
, i
);
168 public static float[] floatBuffer
;
169 public static void MarshalFloat32Array (float[] buffer
) {
170 floatBuffer
= buffer
;
173 public static void MarshalByteBufferToFloats (byte[] buffer
) {
174 floatBuffer
= new float[buffer
.Length
/ sizeof(float)];
175 for (int i
= 0; i
< buffer
.Length
; i
+= sizeof(float))
176 floatBuffer
[i
/ sizeof(float)] = BitConverter
.ToSingle(buffer
, i
);
180 public static double[] doubleBuffer
;
181 public static void MarshalFloat64Array (double[] buffer
) {
182 doubleBuffer
= buffer
;
185 public static void MarshalByteBufferToDoubles (byte[] buffer
) {
186 doubleBuffer
= new double[buffer
.Length
/ sizeof(double)];
187 for (int i
= 0; i
< buffer
.Length
; i
+= sizeof(double))
188 doubleBuffer
[i
/ sizeof(double)] = BitConverter
.ToDouble(buffer
, i
);
191 public static void SetTypedArraySByte (JSObject obj
) {
192 sbyte[] buffer
= Enumerable
.Repeat((sbyte)0x20, 11).ToArray();
193 obj
.SetObjectProperty ("typedArray", buffer
);
196 public static sbyte[] taSByte
;
197 public static void GetTypedArraySByte (JSObject obj
) {
198 taSByte
= (sbyte[])obj
.GetObjectProperty ("typedArray");
201 public static void SetTypedArrayByte (JSObject obj
) {
202 var dragons
= "hic sunt dracones";
203 byte[] buffer
= System
.Text
.Encoding
.ASCII
.GetBytes(dragons
);
204 obj
.SetObjectProperty ("dracones", buffer
);
207 public static byte[] taByte
;
208 public static void GetTypedArrayByte (JSObject obj
) {
209 taByte
= (byte[])obj
.GetObjectProperty ("dracones");
212 public static void SetTypedArrayShort (JSObject obj
) {
213 short[] buffer
= Enumerable
.Repeat((short)0x20, 13).ToArray();
214 obj
.SetObjectProperty ("typedArray", buffer
);
217 public static short[] taShort
;
218 public static void GetTypedArrayShort (JSObject obj
) {
219 taShort
= (short[])obj
.GetObjectProperty ("typedArray");
222 public static void SetTypedArrayUShort (JSObject obj
) {
223 ushort[] buffer
= Enumerable
.Repeat((ushort)0x20, 14).ToArray();
224 obj
.SetObjectProperty ("typedArray", buffer
);
227 public static ushort[] taUShort
;
228 public static void GetTypedArrayUShort (JSObject obj
) {
229 taUShort
= (ushort[])obj
.GetObjectProperty ("typedArray");
233 public static void SetTypedArrayInt (JSObject obj
) {
234 int[] buffer
= Enumerable
.Repeat((int)0x20, 15).ToArray();
235 obj
.SetObjectProperty ("typedArray", buffer
);
238 public static int[] taInt
;
239 public static void GetTypedArrayInt (JSObject obj
) {
240 taInt
= (int[])obj
.GetObjectProperty ("typedArray");
243 public static void SetTypedArrayUInt (JSObject obj
) {
244 uint[] buffer
= Enumerable
.Repeat((uint)0x20, 16).ToArray();
245 obj
.SetObjectProperty ("typedArray", buffer
);
248 public static uint[] taUInt
;
249 public static void GetTypedArrayUInt (JSObject obj
) {
250 taUInt
= (uint[])obj
.GetObjectProperty ("typedArray");
253 public static void SetTypedArrayFloat (JSObject obj
) {
254 float[] buffer
= Enumerable
.Repeat(3.14f
, 17).ToArray();
255 obj
.SetObjectProperty ("typedArray", buffer
);
258 public static float[] taFloat
;
259 public static void GetTypedArrayFloat (JSObject obj
) {
260 taFloat
= (float[])obj
.GetObjectProperty ("typedArray");
264 public static void SetTypedArrayDouble (JSObject obj
) {
265 double[] buffer
= Enumerable
.Repeat(3.14d
, 18).ToArray();
266 obj
.SetObjectProperty ("typedArray", buffer
);
269 public static double[] taDouble
;
270 public static void GetTypedArrayDouble (JSObject obj
) {
271 taDouble
= (double[])obj
.GetObjectProperty ("typedArray");
274 public static HttpClient client
;
275 public static string fakeClientHandlerString
;
276 public static HttpClientHandler fakeClientHandler
;
277 public static void SetMessageHandler () {
279 var httpMessageHandler
= typeof(HttpClient
).GetField("GetHttpMessageHandler",
280 BindingFlags
.Static
|
281 BindingFlags
.NonPublic
);
283 httpMessageHandler
.SetValue(null, (Func
<HttpClientHandler
>) (() => {
284 return new FakeHttpClientHandler ();
287 client
= new HttpClient();
293 public class FakeHttpClientHandler
: HttpClientHandler
295 public FakeHttpClientHandler () : base()
297 TestClass
.fakeClientHandlerString
= "Fake HttpClientHandler";
298 TestClass
.fakeClientHandler
= this;
303 public class BindingTests
{
305 public static void MarshalPrimitivesToCS ()
307 TestClass
.i32_res
= 0;
308 Runtime
.InvokeJS ("call_test_method(\"InvokeI32\", \"ii\", [10, 20])");
309 Assert
.AreEqual (TestClass
.i32_res
, 30);
311 TestClass
.f32_res
= 0;
312 Runtime
.InvokeJS ("call_test_method(\"InvokeFloat\", \"f\", [1.5])");
313 Assert
.AreEqual (TestClass
.f32_res
, 1.5f
);
315 TestClass
.f64_res
= 0;
316 Runtime
.InvokeJS ("call_test_method(\"InvokeDouble\", \"d\", [4.5])");
317 Assert
.AreEqual (TestClass
.f64_res
, 4.5);
319 TestClass
.i64_res
= 0;
320 Runtime
.InvokeJS ("call_test_method(\"InvokeLong\", \"l\", [99])");
321 Assert
.AreEqual (TestClass
.i64_res
, 99);
325 public static void MarshalStringToCS ()
327 TestClass
.string_res
= null;
328 Runtime
.InvokeJS ("call_test_method(\"InvokeString\", \"s\", [\"hello\"])");
329 Assert
.AreEqual (TestClass
.string_res
, "hello");
333 public static void MarshalStringToJS ()
335 TestClass
.mkstr
= TestClass
.string_res
= null;
337 var str = call_test_method (""InvokeMkString"", ""o"", [ ]);
338 call_test_method (""InvokeString"", ""s"", [ str ]);
340 Assert
.IsNotNull(TestClass
.mkstr
);
342 Assert
.AreEqual (TestClass
.mkstr
, TestClass
.string_res
);
346 public static void JSObjectKeepIdentityAcrossCalls ()
348 TestClass
.obj1
= TestClass
.obj2
= null;
350 var obj = { foo: 10 };
351 var res = call_test_method (""InvokeObj1"", ""o"", [ obj ]);
352 call_test_method (""InvokeObj2"", ""o"", [ res ]);
355 Assert
.IsNotNull(TestClass
.obj1
);
356 Assert
.AreSame(TestClass
.obj1
, TestClass
.obj2
);
360 public static void CSObjectKeepIdentityAcrossCalls ()
362 TestClass
.mkobj
= TestClass
.obj1
= TestClass
.obj2
= null;
364 var obj = call_test_method (""InvokeMkobj"", """", [ ]);
365 var res = call_test_method (""InvokeObj1"", ""o"", [ obj ]);
366 call_test_method (""InvokeObj2"", ""o"", [ res ]);
369 Assert
.IsNotNull(TestClass
.obj1
);
370 Assert
.AreSame(TestClass
.mkobj
, TestClass
.obj1
);
371 Assert
.AreSame(TestClass
.obj1
, TestClass
.obj2
);
375 public static void JSInvokeInt() {
385 return this.foo + val;
388 call_test_method (""PlayWithObj"", ""o"", [ obj ]);
391 Assert
.AreEqual (TestClass
.first_val
, 10);
392 Assert
.AreEqual (TestClass
.second_val
, 31);
396 public static void JSInvokeTypes() {
399 return_int: function() { return 100; },
400 return_double: function() { return 4.5; },
401 return_string: function() { return 'qwerty'; },
402 return_bool: function() { return true; },
404 call_test_method (""PlayWithObjTypes"", ""o"", [ obj ]);
407 Assert
.AreEqual (TestClass
.js_objs
[0], 100);
408 Assert
.AreEqual (TestClass
.js_objs
[1], 4.5);
409 Assert
.AreEqual (TestClass
.js_objs
[2], "qwerty");
410 Assert
.AreEqual (TestClass
.js_objs
[3], true);
414 public static void JSObjectApply() {
416 var do_add = function(a, b) { return a + b};
417 call_test_method (""UseFunction"", ""o"", [ do_add ]);
419 Assert
.AreEqual (TestClass
.do_add
, 30);
423 public static void MarshalDelegate() {
424 TestClass
.obj1
= null;
426 var dele = call_test_method (""MkDelegate"", """", [ ]);
427 var res = dele (10, 20);
428 call_test_method (""InvokeI32"", ""ii"", [ res, res ]);
431 Assert
.AreEqual (TestClass
.dele_res
, 30);
432 Assert
.AreEqual (TestClass
.i32_res
, 60);
436 public static void PassTaskToJS () {
437 TestClass
.int_val
= 0;
439 var tsk = call_test_method (""MkTask"", """", [ ]);
440 tsk.then (function (value) {
441 Module.print ('PassTaskToJS cont with value ' + value);
444 Assert
.AreEqual (0, TestClass
.int_val
);
445 TestClass
.tcs
.SetResult (99);
446 //FIXME our test harness doesn't suppport async tests.
447 // So manually verify it for now by checking stdout for `PassTaskToJS cont with value 99`
448 //Assert.AreEqual (99, TestClass.int_val);
453 public static void PassTaskToJS2 () {
454 TestClass
.int_val
= 0;
456 var tsk = call_test_method (""MkTask"", """", [ ]);
457 tsk.then (function (value) {},
459 Module.print ('PassTaskToJS2 cont failed due to ' + reason);
462 Assert
.AreEqual (0, TestClass
.int_val
);
463 TestClass
.tcs
.SetException (new Exception ("it failed"));
464 //FIXME our test harness doesn't suppport async tests.
465 // So manually verify it for now by checking stdout for `PassTaskToJS2 cont failed due to System.AggregateException...
466 // Assert.AreEqual (99, TestClass.int_val);
470 public static void PassTaskToJS3 () {
471 TestClass
.int_val
= 0;
473 var tsk = call_test_method (""MkTaskNull"", """", [ ]);
475 Module.print('PassTaskToJS3 cont without value '); // Success!
477 Module.print('PassTaskToJS3 cont failed due to ' + reason); // Error!
480 Assert
.AreEqual (0, TestClass
.int_val
);
481 TestClass
.tcs3
.SetResult (null);
485 public static void PassTaskToJS4 () {
486 TestClass
.int_val
= 0;
488 var tsk = call_test_method (""MkTaskNull"", """", [ ]);
490 Module.print(value); // Success!
492 Module.print('PassTaskToJS4 cont failed due to ' + reason); // Error!
495 Assert
.AreEqual (0, TestClass
.int_val
);
496 TestClass
.tcs3
.SetException (new Exception ("it failed"));
500 public static void PassTaskToJS5 () {
501 TestClass
.int_val
= 0;
503 var tsk = call_test_method (""MkTaskString"", """", [ ]);
504 tsk.then( success => {
505 Module.print('PassTaskToJS5 cont with value ' + success); // Success!
507 Module.print('PassTaskToJS5 cont failed due to ' + reason); // Error!
510 Assert
.AreEqual (0, TestClass
.int_val
);
511 TestClass
.tcs3
.SetResult ("Success");
515 public static void PassTaskToJS6 () {
516 TestClass
.int_val
= 0;
518 var tsk = call_test_method (""MkTaskString"", """", [ ]);
519 tsk.then( success => {
520 Module.print('PassTaskToJS6 cont with value ' + success); // Success!
522 Module.print('PassTaskToJS6 cont failed due to ' + reason); // Error!
525 Assert
.AreEqual (0, TestClass
.int_val
);
526 TestClass
.tcs3
.SetException (new Exception ("it failed"));
530 public static void PassPromiseToCS () {
531 TestClass
.int_val
= 0;
533 var resolve_func = null;
534 var promise = new Promise(function (resolve, reject) {
535 resolve_func = resolve;
537 call_test_method (""InvokePromise"", ""o"", [ promise ]);
540 //FIXME our test harness doesn't suppport async tests.
541 // So manually verify it for now by checking stdout for `Promise result is 111`
542 // Assert.AreEqual (99, TestClass.int_val);
546 public static void BindStaticMethod () {
547 TestClass
.int_val
= 0;
549 var invoke_int = Module.mono_bind_static_method (""[binding_tests]TestClass:InvokeInt"");
553 Assert
.AreEqual (200, TestClass
.int_val
);
557 public static void InvokeStaticMethod () {
558 TestClass
.int_val
= 0;
560 Module.mono_call_static_method (""[binding_tests]TestClass:InvokeInt"", [ 300 ]);
563 Assert
.AreEqual (300, TestClass
.int_val
);
567 public static void ResolveMethod () {
568 TestClass
.int_val
= 0;
570 var invoke_int = Module.mono_method_resolve (""[binding_tests]TestClass:InvokeInt"");
571 call_test_method (""InvokeInt"", ""i"", [ invoke_int ]);
574 Assert
.AreNotEqual (0, TestClass
.int_val
);
578 public static void DisposeObject () {
586 call_test_method (""DisposeObject"", ""o"", [ obj3 ]);
587 call_test_method (""DisposeObject"", ""o"", [ obj2 ]);
588 call_test_method (""DisposeObject"", ""o"", [ obj1 ]);
591 Assert
.AreEqual (-1, TestClass
.js_objs_to_dispose
[0].JSHandle
);
592 Assert
.AreEqual (-1, TestClass
.js_objs_to_dispose
[1].JSHandle
);
593 Assert
.AreEqual (-1, TestClass
.js_objs_to_dispose
[2].JSHandle
);
597 public static void GetObjectProperties () {
599 var obj = {myInt: 100, myDouble: 4.5, myString: ""qwerty"", myBoolean: true};
600 call_test_method (""RetrieveObjectProperties"", ""o"", [ obj ]);
603 Assert
.AreEqual (100, TestClass
.js_props
[0]);
604 Assert
.AreEqual (4.5, TestClass
.js_props
[1]);
605 Assert
.AreEqual ("qwerty", TestClass
.js_props
[2]);
606 Assert
.AreEqual (true, TestClass
.js_props
[3]);
610 public static void SetObjectProperties () {
612 var obj = {myInt: 200, myDouble: 0, myString: ""foo"", myBoolean: false};
613 call_test_method (""PopulateObjectProperties"", ""oi"", [ obj, false ]);
614 call_test_method (""RetrieveObjectProperties"", ""o"", [ obj ]);
617 Assert
.AreEqual (100, TestClass
.js_props
[0]);
618 Assert
.AreEqual (4.5, TestClass
.js_props
[1]);
619 Assert
.AreEqual ("qwerty", TestClass
.js_props
[2]);
620 Assert
.AreEqual (true, TestClass
.js_props
[3]);
624 public static void SetObjectPropertiesIfNotExistsFalse () {
625 // This test will not create the properties if they do not already exist
627 var obj = {myInt: 200};
628 call_test_method (""PopulateObjectProperties"", ""oi"", [ obj, false ]);
629 call_test_method (""RetrieveObjectProperties"", ""o"", [ obj ]);
632 Assert
.AreEqual (100, TestClass
.js_props
[0]);
633 Assert
.AreEqual (null, TestClass
.js_props
[1]);
634 Assert
.AreEqual (null, TestClass
.js_props
[2]);
635 Assert
.AreEqual (null, TestClass
.js_props
[3]);
639 public static void SetObjectPropertiesIfNotExistsTrue () {
640 // This test will set the value of the property if it exists and will create and
641 // set the value if it does not exists
643 var obj = {myInt: 200};
644 call_test_method (""PopulateObjectProperties"", ""oi"", [ obj, true ]);
645 call_test_method (""RetrieveObjectProperties"", ""o"", [ obj ]);
648 Assert
.AreEqual (100, TestClass
.js_props
[0]);
649 Assert
.AreEqual (4.5, TestClass
.js_props
[1]);
650 Assert
.AreEqual ("qwerty", TestClass
.js_props
[2]);
651 Assert
.AreEqual (true, TestClass
.js_props
[3]);
656 public static void MarshalArrayBuffer () {
658 var buffer = new ArrayBuffer(16);
659 call_test_method (""MarshalByteBuffer"", ""o"", [ buffer ]);
662 Assert
.AreEqual (16, TestClass
.byteBuffer
.Length
);
666 public static void MarshalArrayBuffer2Int () {
667 // This really does not work to be honest
668 // The length of the marshalled array is 16 ints but
669 // the first 4 ints will be correct and the rest will
670 // probably be trash from memory
672 var buffer = new ArrayBuffer(16);
673 var int32View = new Int32Array(buffer);
674 for (var i = 0; i < int32View.length; i++) {
675 int32View[i] = i * 2;
677 call_test_method (""MarshalInt32Array"", ""o"", [ buffer ]);
680 Assert
.AreEqual (16, TestClass
.intBuffer
.Length
);
681 Assert
.AreEqual (0, TestClass
.intBuffer
[0]);
682 Assert
.AreEqual (2, TestClass
.intBuffer
[1]);
683 Assert
.AreEqual (4, TestClass
.intBuffer
[2]);
684 Assert
.AreEqual (6, TestClass
.intBuffer
[3]);
688 public static void MarshalArrayBuffer2Int2 () {
691 var buffer = new ArrayBuffer(16);
692 var int32View = new Int32Array(buffer);
693 for (var i = 0; i < int32View.length; i++) {
694 int32View[i] = i * 2;
696 call_test_method (""MarshalByteBufferToInts"", ""o"", [ buffer ]);
699 Assert
.AreEqual (4, TestClass
.intBuffer
.Length
);
700 Assert
.AreEqual (0, TestClass
.intBuffer
[0]);
701 Assert
.AreEqual (2, TestClass
.intBuffer
[1]);
702 Assert
.AreEqual (4, TestClass
.intBuffer
[2]);
703 Assert
.AreEqual (6, TestClass
.intBuffer
[3]);
708 public static void MarshalTypedArray () {
710 var buffer = new ArrayBuffer(16);
711 var uint8View = new Uint8Array(buffer);
712 call_test_method (""MarshalByteBuffer"", ""o"", [ uint8View ]);
715 Assert
.AreEqual (16, TestClass
.byteBuffer
.Length
);
719 public static void MarshalTypedArray2Int () {
721 var buffer = new ArrayBuffer(16);
722 var int32View = new Int32Array(buffer);
723 for (var i = 0; i < int32View.length; i++) {
724 int32View[i] = i * 2;
726 call_test_method (""MarshalInt32Array"", ""o"", [ int32View ]);
729 Assert
.AreEqual (4, TestClass
.intBuffer
.Length
);
730 Assert
.AreEqual (0, TestClass
.intBuffer
[0]);
731 Assert
.AreEqual (2, TestClass
.intBuffer
[1]);
732 Assert
.AreEqual (4, TestClass
.intBuffer
[2]);
733 Assert
.AreEqual (6, TestClass
.intBuffer
[3]);
737 public static void MarshalTypedArray2Float () {
739 var typedArray = new Float32Array([1, 2.1334, 3, 4.2, 5]);
740 call_test_method (""MarshalFloat32Array"", ""o"", [ typedArray ]);
743 Assert
.AreEqual (1, TestClass
.floatBuffer
[0]);
744 Assert
.AreEqual (2.1334f
, TestClass
.floatBuffer
[1]);
745 Assert
.AreEqual (3, TestClass
.floatBuffer
[2]);
746 Assert
.AreEqual (4.2f
, TestClass
.floatBuffer
[3]);
747 Assert
.AreEqual (5, TestClass
.floatBuffer
[4]);
751 public static void MarshalArrayBuffer2Float () {
753 var buffer = new ArrayBuffer(16);
754 var float32View = new Float32Array(buffer);
755 for (var i = 0; i < float32View.length; i++) {
756 float32View[i] = i * 2.5;
758 call_test_method (""MarshalByteBufferToFloats"", ""o"", [ buffer ]);
761 Assert
.AreEqual (4, TestClass
.floatBuffer
.Length
);
762 Assert
.AreEqual (0, TestClass
.floatBuffer
[0]);
763 Assert
.AreEqual (2.5f
, TestClass
.floatBuffer
[1]);
764 Assert
.AreEqual (5, TestClass
.floatBuffer
[2]);
765 Assert
.AreEqual (7.5f
, TestClass
.floatBuffer
[3]);
769 public static void MarshalArrayBuffer2Float2 () {
770 // This really does not work to be honest
771 // The length of the marshalled array is 16 floats but
772 // the first 4 floats will be correct and the rest will
773 // probably be trash from memory
775 var buffer = new ArrayBuffer(16);
776 var float32View = new Float32Array(buffer);
777 for (var i = 0; i < float32View.length; i++) {
778 float32View[i] = i * 2.5;
780 call_test_method (""MarshalFloat32Array"", ""o"", [ buffer ]);
783 Assert
.AreEqual (16, TestClass
.floatBuffer
.Length
);
784 Assert
.AreEqual (0, TestClass
.floatBuffer
[0]);
785 Assert
.AreEqual (2.5f
, TestClass
.floatBuffer
[1]);
786 Assert
.AreEqual (5, TestClass
.floatBuffer
[2]);
787 Assert
.AreEqual (7.5f
, TestClass
.floatBuffer
[3]);
791 public static void MarshalTypedArray2Double () {
793 var typedArray = new Float64Array([1, 2.1334, 3, 4.2, 5]);
794 call_test_method (""MarshalFloat64Array"", ""o"", [ typedArray ]);
797 Assert
.AreEqual (1, TestClass
.doubleBuffer
[0]);
798 Assert
.AreEqual (2.1334d
, TestClass
.doubleBuffer
[1]);
799 Assert
.AreEqual (3, TestClass
.doubleBuffer
[2]);
800 Assert
.AreEqual (4.2d
, TestClass
.doubleBuffer
[3]);
801 Assert
.AreEqual (5, TestClass
.doubleBuffer
[4]);
805 public static void MarshalArrayBuffer2Double () {
807 var buffer = new ArrayBuffer(32);
808 var float64View = new Float64Array(buffer);
809 for (var i = 0; i < float64View.length; i++) {
810 float64View[i] = i * 2.5;
812 call_test_method (""MarshalByteBufferToDoubles"", ""o"", [ buffer ]);
815 Assert
.AreEqual (4, TestClass
.doubleBuffer
.Length
);
816 Assert
.AreEqual (0, TestClass
.doubleBuffer
[0]);
817 Assert
.AreEqual (2.5d
, TestClass
.doubleBuffer
[1]);
818 Assert
.AreEqual (5, TestClass
.doubleBuffer
[2]);
819 Assert
.AreEqual (7.5d
, TestClass
.doubleBuffer
[3]);
823 public static void MarshalArrayBuffer2Double2 () {
824 // This really does not work to be honest
825 // The length of the marshalled array is 32 doubles but
826 // the first 4 doubles will be correct and the rest will
827 // probably be trash from memory
829 var buffer = new ArrayBuffer(32);
830 var float64View = new Float64Array(buffer);
831 for (var i = 0; i < float64View.length; i++) {
832 float64View[i] = i * 2.5;
834 call_test_method (""MarshalFloat64Array"", ""o"", [ buffer ]);
837 Assert
.AreEqual (32, TestClass
.doubleBuffer
.Length
);
838 Assert
.AreEqual (0, TestClass
.doubleBuffer
[0]);
839 Assert
.AreEqual (2.5f
, TestClass
.doubleBuffer
[1]);
840 Assert
.AreEqual (5, TestClass
.doubleBuffer
[2]);
841 Assert
.AreEqual (7.5f
, TestClass
.doubleBuffer
[3]);
845 public static void MarshalTypedArraySByte () {
846 TestClass
.int_val
= 0;
849 call_test_method (""SetTypedArraySByte"", ""o"", [ obj ]);
850 call_test_method (""GetTypedArraySByte"", ""o"", [ obj ]);
852 Assert
.AreEqual (11, TestClass
.taSByte
.Length
);
853 Assert
.AreEqual (32, TestClass
.taSByte
[0]);
854 Assert
.AreEqual (32, TestClass
.taSByte
[TestClass
.taSByte
.Length
- 1]);
858 public static void MarshalTypedArrayByte () {
859 TestClass
.int_val
= 0;
862 call_test_method (""SetTypedArrayByte"", ""o"", [ obj ]);
863 call_test_method (""GetTypedArrayByte"", ""o"", [ obj ]);
865 Assert
.AreEqual (17, TestClass
.taByte
.Length
);
866 Assert
.AreEqual (104, TestClass
.taByte
[0]);
867 Assert
.AreEqual (115, TestClass
.taByte
[TestClass
.taByte
.Length
- 1]);
868 Assert
.AreEqual ("hic sunt dracones", System
.Text
.Encoding
.Default
.GetString(TestClass
.taByte
));
872 public static void MarshalTypedArrayShort () {
873 TestClass
.int_val
= 0;
876 call_test_method (""SetTypedArrayShort"", ""o"", [ obj ]);
877 call_test_method (""GetTypedArrayShort"", ""o"", [ obj ]);
879 Assert
.AreEqual (13, TestClass
.taShort
.Length
);
880 Assert
.AreEqual (32, TestClass
.taShort
[0]);
881 Assert
.AreEqual (32, TestClass
.taShort
[TestClass
.taShort
.Length
- 1]);
885 public static void MarshalTypedArrayUShort () {
886 TestClass
.int_val
= 0;
889 call_test_method (""SetTypedArrayUShort"", ""o"", [ obj ]);
890 call_test_method (""GetTypedArrayUShort"", ""o"", [ obj ]);
892 Assert
.AreEqual (14, TestClass
.taUShort
.Length
);
893 Assert
.AreEqual (32, TestClass
.taUShort
[0]);
894 Assert
.AreEqual (32, TestClass
.taUShort
[TestClass
.taUShort
.Length
- 1]);
899 public static void MarshalTypedArrayInt () {
900 TestClass
.int_val
= 0;
903 call_test_method (""SetTypedArrayInt"", ""o"", [ obj ]);
904 call_test_method (""GetTypedArrayInt"", ""o"", [ obj ]);
906 Assert
.AreEqual (15, TestClass
.taInt
.Length
);
907 Assert
.AreEqual (32, TestClass
.taInt
[0]);
908 Assert
.AreEqual (32, TestClass
.taInt
[TestClass
.taInt
.Length
- 1]);
912 public static void MarshalTypedArrayUInt () {
913 TestClass
.int_val
= 0;
916 call_test_method (""SetTypedArrayUInt"", ""o"", [ obj ]);
917 call_test_method (""GetTypedArrayUInt"", ""o"", [ obj ]);
919 Assert
.AreEqual (16, TestClass
.taUInt
.Length
);
920 Assert
.AreEqual (32, TestClass
.taUInt
[0]);
921 Assert
.AreEqual (32, TestClass
.taUInt
[TestClass
.taUInt
.Length
- 1]);
925 public static void MarshalTypedArrayFloat () {
926 TestClass
.int_val
= 0;
929 call_test_method (""SetTypedArrayFloat"", ""o"", [ obj ]);
930 call_test_method (""GetTypedArrayFloat"", ""o"", [ obj ]);
932 Assert
.AreEqual (17, TestClass
.taFloat
.Length
);
933 Assert
.AreEqual (3.14f
, TestClass
.taFloat
[0]);
934 Assert
.AreEqual (3.14f
, TestClass
.taFloat
[TestClass
.taFloat
.Length
- 1]);
939 public static void MarshalTypedArrayDouble () {
940 TestClass
.int_val
= 0;
943 call_test_method (""SetTypedArrayDouble"", ""o"", [ obj ]);
944 call_test_method (""GetTypedArrayDouble"", ""o"", [ obj ]);
946 Assert
.AreEqual (18, TestClass
.taDouble
.Length
);
947 Assert
.AreEqual (3.14d
, TestClass
.taDouble
[0]);
948 Assert
.AreEqual (3.14d
, TestClass
.taDouble
[TestClass
.taDouble
.Length
- 1]);
953 public static void HttpMessageHandler () {
954 TestClass
.fakeClientHandlerString
= string.Empty
;
955 TestClass
.fakeClientHandler
= null;
956 TestClass
.client
= null;
958 call_test_method (""SetMessageHandler"", ""o"", [ ]);
960 Assert
.AreEqual ("Fake HttpClientHandler", TestClass
.fakeClientHandlerString
);
961 Assert
.AreNotEqual (null, TestClass
.fakeClientHandler
);
962 Assert
.AreEqual (typeof(FakeHttpClientHandler
), TestClass
.fakeClientHandler
.GetType());
963 Assert
.AreNotEqual (null, TestClass
.client
);