2 using System
.Threading
.Tasks
;
3 using System
.Threading
;
4 using System
.Reflection
;
6 using System
.Runtime
.CompilerServices
;
13 public S (int a1
, string a2
)
19 public void SetValue (int value)
24 public static implicit operator S (Base b
)
26 return new S (400, "a");
29 public static S
operator + (S a
, S b
)
32 Value
= a
.Value
+ b
.Value
49 public volatile int field_int
;
50 protected int field_this
;
51 protected int property_this_counter
;
53 public event Action Event
;
59 public Base (int arg
, int arg2
)
64 public bool PropertyBool
{
70 public int PropertyInt
{
79 protected Base PropertyThis
{
81 ++property_this_counter
;
86 public int this [int arg
] {
91 field_this
+= value * arg
;
95 public static bool operator true (Base a
)
100 public static bool operator false (Base a
)
105 public static Base
operator & (Base a
, Base b
)
112 public static Base
operator | (Base a
, Base b
)
119 protected int Call (int arg1
, int arg2
, int arg3
)
133 protected int Call(ref char ch
, int arg
)
139 public void CallBool (bool b
)
143 public int CallS (S s
)
148 public T
[] CreateArray
<T
> (int size
)
153 protected static void CallRefParams (ref int i
, params int[] i2
)
158 protected int CallNamed (int a
, int b
)
163 protected void CallEvent ()
171 async Task
<bool> ArrayAccessTest_1 ()
173 bool[] b
= new bool[1];
174 b
[0] = await Task
.Factory
.StartNew (() => true);
175 return b
[await Task
.Factory
.StartNew (() => 0)];
178 async Task
<int> ArrayAccessTest_2 ()
180 double[] b
= new double[2];
181 b
[await Task
.Factory
.StartNew (() => 1)] = 5.5;
185 var d
= b
[await Task
.Factory
.StartNew (() => 1)] = 2.5;
192 d
= b
[await Task
.Factory
.StartNew (() => 1)] = await Task
.Factory
.StartNew (() => 4.4);
199 async Task
<int> ArrayAccessTest_3 ()
201 decimal[] d
= new decimal [4];
204 var r
= ++d
[await Task
.Factory
.StartNew (() => 1)];
209 d
[await Task
.Factory
.StartNew (() => 1)] += await Task
.Factory
.StartNew (() => 9.9m
);
214 r
= d
[await Task
.Factory
.StartNew (() => 1)] -= await Task
.Factory
.StartNew (() => 5.9m
);
221 async Task
<bool> ArrayAccessTest_4 ()
223 string[] s
= new string [4];
226 s
[await Task
.Factory
.StartNew (() => 1)] += await Task
.Factory
.StartNew (() => "b");
227 return s
[1] == "ab";
230 async Task
<bool> ArrayAccessTest_5 ()
232 int[][] a
= new int[3][];
235 CallRefParams (ref a
[await Task
.Factory
.StartNew (() => index
++)][0], await Task
.Factory
.StartNew (() => 3));
236 return a
[1][0] == 5;
239 async Task
<int> ArrayAccessTest_6 ()
242 int[] a
= new int[3] { 3, 6, 9 }
;
243 return a
[await Task
.Factory
.StartNew (() => (long)1)] + value;
246 async Task
<bool> ArrayAccessTest_7 ()
248 short?[] s
= new short?[] { 3, 2, 1 }
;
249 var r
= s
[await Task
.Factory
.StartNew (() => 1)]++;
253 async Task
<int> ArrayAccessTest_8 ()
255 var s
= new byte?[] { 3, 2, 1 }
;
256 var r
= s
[await Task
.Factory
.StartNew (() => 1)] += await Task
.Factory
.StartNew (() => (byte)30);
266 async Task
<int> ArrayAccessTest_9 ()
269 s
.CreateArray
<int> (await Task
.Factory
.StartNew (() => 5)) [2] += 9;
270 s
.CreateArray
<int> (await Task
.Factory
.StartNew (() => 5)) [2] += await Task
.Factory
.StartNew (() => 9);
272 var res
= s
.CreateArray
<int> (await Task
.Factory
.StartNew (() => 5)) [2] += await Task
.Factory
.StartNew (() => 9);
276 s
.CreateArray
<S
> (await Task
.Factory
.StartNew (() => 5)) [2] += await Task
.Factory
.StartNew (() => new S () { Value = 4 }
);
280 async Task
<bool> ArrayAccessTest_10 ()
282 var b
= new bool [1] { true }
;
284 var r
= b
[await Task
.Factory
.StartNew (() => 0)];
288 async Task
<bool> ArrayAccessTest_11 ()
291 a
[await Task
.Factory
.StartNew (() => 0)].s2
.Value
+= 5;
292 return a
[await Task
.Factory
.StartNew(() => 0)].s2
.Value
== 5;
295 async Task
<int> AssignTest_1 ()
297 field_int
= await Task
.Factory
.StartNew (() => 0);
301 async Task
<bool> AssignTest_2 ()
303 long? l
= await Task
.Factory
.StartNew
<sbyte?> (() => null);
307 async Task
<int> AssignTest_3 ()
309 int a
= await Task
.Factory
.StartNew (() => 1), b
= await Task
.Factory
.StartNew (() => 2);
318 async Task
<int> BinaryTest_1 ()
320 return await Task
.Factory
.StartNew (() => { Thread.Sleep (10); return 5; }
) +
321 await Task
.Factory
.StartNew (() => -3) +
322 await Task
.Factory
.StartNew (() => -2);
325 async Task
<int> BinaryTest_2 ()
328 var b
= await Task
.Factory
.StartNew (() => { i += 3; return true; }
) &&
329 await Task
.Factory
.StartNew (() => { i += 4; return false; }
) &&
330 await Task
.Factory
.StartNew (() => { i += 5; return true; }
);
332 return b
? -1 : i
== 8 ? 0 : i
;
335 async Task
<int> BinaryTest_3 ()
337 var r
= await Task
.Factory
.StartNew
<bool?> (() => true) & await Task
.Factory
.StartNew
<bool?> (() => null);
341 r
= await Task
.Factory
.StartNew
<bool?> (() => null) | await Task
.Factory
.StartNew
<bool?> (() => true);
345 r
= await Task
.Factory
.StartNew
<bool?> (() => null) != await Task
.Factory
.StartNew
<bool?> (() => true);
352 async Task
<int> BinaryTest_4 ()
354 var r1
= await Task
.Factory
.StartNew
<short?> (() => 2) * await Task
.Factory
.StartNew
<byte?> (() => null);
358 var r2
= await Task
.Factory
.StartNew
<decimal?> (() => 100) / await Task
.Factory
.StartNew
<decimal?> (() => null);
365 async Task
<int> BinaryTest_5 ()
367 var r1
= await Task
.FromResult (1) == 9;
371 var r2
= 1 == await Task
.FromResult (1);
378 async Task
<bool> BinaryTest_6 ()
380 var t
= Task
.Delay (1);
381 if (t
== await Task
.WhenAny(new [] { t }
))
387 async Task
<int> CallTest_1 ()
390 await Task
.Factory
.StartNew (() => { Thread.Sleep (10); return 5; }
),
391 await Task
.Factory
.StartNew (() => -3),
392 await Task
.Factory
.StartNew (() => 6));
395 async Task
<bool> CallTest_2 ()
400 await Task
.Factory
.StartNew (() => { Thread.Sleep (10); return 5; }
));
402 return ch
== 'z' && r
== 5;
405 async Task
<int> CallTest_3 ()
408 s
.SetValue (await Task
.Factory
.StartNew (() => 10));
412 async Task
<bool> CallTest_4 ()
414 return E
.E_1
.Equals (unchecked (await Task
.Factory
.StartNew (() => E
.E_1
)));
417 async Task
<int> CallTest_5 ()
421 b: await Task
.Factory
.StartNew (() => value++),
425 async Task
<bool> CastTest_1 ()
428 return (value - await Task
.Factory
.StartNew (() => 66m
)) == 1;
431 async Task
<bool> CastTest_2 ()
433 var t
= new Tester ();
434 return t
.CallS (await Task
.Factory
.StartNew (() => this)) == 400;
437 async Task
<bool> CoalescingTest_1 ()
439 var r
= await Task
.Factory
.StartNew
<string> (() => null) ?? await Task
.Factory
.StartNew (() => "x");
443 async Task
<bool> CoalescingTest_2 ()
445 var r
= await Task
.Factory
.StartNew
<short?> (() => null) ?? await Task
.Factory
.StartNew
<byte> (() => 2);
449 async Task
<int> ConditionalTest_1 ()
451 return true ? await Task
.Factory
.StartNew (() => 0) : await Task
.Factory
.StartNew (() => 1);
454 async Task
<int> ConditionalTest_2 ()
456 return PropertyBool
? await Task
.Factory
.StartNew (() => 0) : await Task
.Factory
.StartNew (() => 1);
459 async Task
<int> ConditionalTest_3 ()
462 return v
* (await Task
.Factory
.StartNew (() => true) ? 0 : await Task
.Factory
.StartNew (() => 1));
465 async Task
<int> ConditionalTest_4 ()
468 return v
* (v
== 2 ? 3 : await Task
.Factory
.StartNew (() => 0));
471 async Task
<int> DelegateInvoke_4 ()
473 Func
<int, int> d
= l
=> l
- 3;
475 return value + d (await Task
.Factory
.StartNew (() => 2));
478 async Task
<int> EventInvoke_1 ()
481 Event
+= await Task
.Factory
.StartNew (() => {
482 Action a
= () => { value = 5; }
;
490 async Task
<int> FieldTest_1 ()
494 s
.field_int
+= await Task
.Factory
.StartNew (() => 6);
495 if (s
.field_int
!= 9)
498 var r
= s
.field_int
-= await Task
.Factory
.StartNew (() => 5);
502 if (s
.field_int
!= 4)
507 async Task
<bool> IndexerTest_1 ()
509 this[2] = await Task
.Factory
.StartNew (() => 6);
510 return this[2] == 12;
513 async Task
<bool> IndexerTest_2 ()
515 this[await Task
.Factory
.StartNew (() => 3)] = await Task
.Factory
.StartNew (() => 6);
516 return this[3] == 18;
519 async Task
<int> IndexerTest_3 ()
522 this[await Task
.Factory
.StartNew (() => value++)] += await Task
.Factory
.StartNew (() => 5);
526 async Task
<int> IndexerTest_4 ()
529 PropertyThis
[await Task
.Factory
.StartNew (() => value++)] += await Task
.Factory
.StartNew (() => -5);
530 return PropertyThis
[3] + value + 11;
533 async Task
<int> IndexerTest_5 ()
537 int res
= PropertyThis
[await Task
.Factory
.StartNew (() => value++)]++;
541 if (PropertyThis
[0] != 27)
544 return PropertyThis
[5] -= await Task
.Factory
.StartNew (() => 27);
547 async Task
<int> IndexerTest_6 ()
549 var r
= this[3] = await Task
.Factory
.StartNew (() => 9);
553 var r2
= this[await Task
.Factory
.StartNew (() => 55)] = await Task
.Factory
.StartNew (() => 8);
561 async Task
<bool> IndexerTest_7 ()
564 var res
= ++this[await Task
.Factory
.StartNew (() => value++)];
568 async Task
<bool> IsTest_1 ()
570 new Tester ().CallBool (await Task
.Factory
.StartNew (() => new Tester ()) is Base
);
574 async Task
<bool> IsTest_2 ()
576 var r
= await Task
.Factory
.StartNew
<uint?> (() => 1) is uint;
580 async Task
<bool> LogicalUserOperator_1 ()
582 var r
= await Task
.Factory
.StartNew (() => new Base ()) && await Task
.Factory
.StartNew (() => new Base ());
583 return r
.field_int
== 100;
586 async Task
<bool> LogicalUserOperator_2 ()
588 var r
= new Base () && await Task
.Factory
.StartNew (() => new Base ());
589 return r
.field_int
== 100;
592 async Task
<bool> LogicalUserOperator_3 ()
594 var r
= await Task
.Factory
.StartNew (() => new Base ()) || await Task
.Factory
.StartNew (() => new Base ());
595 return r
.field_int
== 0;
598 async Task
<bool> NewTest_1 ()
601 var b
= new Base (value, await Task
.Factory
.StartNew (() => 33));
602 return b
.field_int
== 9;
605 async Task
<bool> NewTest_2 ()
607 var s
= new S (await Task
.Factory
.StartNew (() => 77), await Task
.Factory
.StartNew (() => "b"));
608 return s
.Value
== 77;
611 async Task
<int> NewDelegate_1 ()
613 var f
= new Func
<int> (await NewDelegate_1_0 ());
617 static async Task
<Func
<int>> NewDelegate_1_0 ()
619 await Task
.Factory
.StartNew (() => { }
);
623 async Task
<int> NewInitTest_1 ()
627 var b
= new Base (value, await Task
.Factory
.StartNew (() => 33)) { }
;
628 if (b
.field_int
!= 9)
631 b
= new Base (value, await Task
.Factory
.StartNew (() => 11)) {
632 field_int
= await Task
.Factory
.StartNew (() => 12),
633 PropertyInt
= await Task
.Factory
.StartNew (() => 13)
636 if (b
.field_int
!= 25)
640 field_int
= await Task
.Factory
.StartNew (() => 12),
641 PropertyInt
= await Task
.Factory
.StartNew (() => 13)
644 if (b
.field_int
!= 25)
650 async Task
<int> NewInitTest_2 ()
654 var s
= new S (value, await Task
.Factory
.StartNew (() => "x")) { }
;
658 s
= new S (value, await Task
.Factory
.StartNew (() => "y")) {
659 Value
= await Task
.Factory
.StartNew (() => 12)
666 Value
= await Task
.Factory
.StartNew (() => 13)
675 async Task
<bool> NewArrayInitTest_1 ()
677 var a
= new int[await Task
.Factory
.StartNew (() => 5)];
678 return a
.Length
== 5;
681 async Task
<bool> NewArrayInitTest_2 ()
683 var a
= new short[await Task
.Factory
.StartNew (() => 3), await Task
.Factory
.StartNew (() => 4)];
684 return a
.Length
== 12;
687 async Task
<int> NewArrayInitTest_3 ()
689 var a
= new byte[] { await Task.Factory.StartNew (() => (byte)5) }
;
693 async Task
<bool> NewArrayInitTest_4 ()
695 var a
= new ushort[,] {
696 { await Task.Factory.StartNew (() => (ushort) 5), 50 }
,
697 { 30, await Task.Factory.StartNew (() => (ushort) 3) }
700 return a
[0, 0] * a
[1, 1] == 15;
703 async Task
<int> NewArrayInitTest_5 ()
705 var a
= new S
[] { await Task.Factory.StartNew (() => new S () { Value = 4 }
) };
706 return a
[0].Value
- 4;
709 async Task
<bool> NewArrayInitTest_6 ()
711 var a
= new int[] { 2, 3, 2, 3, 5, 6, 7, 2, 4, await Task.Factory.StartNew (() => 5), 11, 23, 45 }
;
712 return a
.Length
== 13;
715 async Task
<bool> NewArrayInitTest_7 ()
717 var res
= new [] { "a", new [] { "1", await Task.FromResult ("2") }
[1], "b" };
718 return res
[1] == "2";
721 async Task
<bool> PropertyTest_1 ()
723 PropertyInt
= await Task
.Factory
.StartNew (() => 6);
724 return PropertyInt
== 6;
727 async Task
<int> PropertyTest_2 ()
729 PropertyThis
.PropertyInt
+= await Task
.Factory
.StartNew (() => 6);
730 if (property_this_counter
!= 1)
733 return PropertyInt
- 6;
736 async Task
<int> PropertyTest_3 ()
738 var r
= PropertyThis
.PropertyInt
= await Task
.Factory
.StartNew (() => 9);
742 PropertyThis
.PropertyInt
= 4;
743 int[] a
= new int[4];
744 a
[await Task
.Factory
.StartNew (() => 1)] = PropertyThis
.PropertyInt
+= await Task
.Factory
.StartNew (() => 8);
748 if (PropertyThis
.PropertyInt
!= 34)
754 async Task
<bool> StringConcatTest_1 ()
756 return (await Task
.Factory
.StartNew (() => "a") +
757 await Task
.Factory
.StartNew (() => "b") +
758 await Task
.Factory
.StartNew (() => (string) null) == "ab");
761 async Task
<bool> UnaryTest_1 ()
764 return (a
+ checked (-await Task
.Factory
.StartNew (() => 2))) == -1;
767 async Task
<bool> UnaryTest_2 ()
771 return (value * ~
await Task
.Factory
.StartNew (() => s
)) == -6;
774 async Task
<bool> UnaryTest_3 ()
776 var d
= new decimal? [2];
778 var r
= ++d
[await Task
.Factory
.StartNew (() => 1)];
782 async Task
<bool> VariableInitializer_1 ()
784 int a
= 2, b
= await Task
.Factory
.StartNew (() => 1), c
= await Task
.Factory
.StartNew (() => 1);
788 static bool RunTest (MethodInfo test
)
790 Console
.Write ("Running test {0, -25}", test
.Name
);
792 Task t
= test
.Invoke (new Tester (), null) as Task
;
793 if (!Task
.WaitAll (new[] { t }
, 1000)) {
794 Console
.WriteLine ("FAILED (Timeout)");
798 var ti
= t
as Task
<int>;
800 if (ti
.Result
!= 0) {
801 Console
.WriteLine ("FAILED (Result={0})", ti
.Result
);
805 var tb
= t
as Task
<bool>;
808 Console
.WriteLine ("FAILED (Result={0})", tb
.Result
);
814 Console
.WriteLine ("OK");
816 } catch (Exception e
) {
817 Console
.WriteLine ("FAILED");
818 Console
.WriteLine (e
.ToString ());
823 public static int Main ()
825 var tests
= from test
in typeof (Tester
).GetMethods (BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.DeclaredOnly
)
826 where test
.GetParameters ().Length
== 0 && !test
.IsDefined (typeof (CompilerGeneratedAttribute
), false)
828 select RunTest (test
);
830 int failures
= tests
.Count (a
=> !a
);
831 Console
.WriteLine (failures
+ " tests failed");