[LoongArch64] Part-5:add loongarch support in some files for LoongArch64. (#21769)
[mono-project.git] / mcs / tests / test-async-20.cs
blobe0f53ea68f8f5f71c6ce948dd045944aa29965db
1 using System;
2 using System.Threading.Tasks;
3 using System.Threading;
4 using System.Reflection;
5 using System.Linq;
6 using System.Collections.Generic;
8 // Dynamic tests
10 class Base
12 public int Value;
15 class Tester : Base
17 async Task<bool> Add_1 ()
19 dynamic d = 1;
20 int total = d + await Task.Factory.StartNew (() => 2);
21 return total == 3;
24 async Task<bool> AssignCompound_1 ()
26 dynamic d = new Base ();
27 d.Value = 3;
28 d.Value += await Task.Factory.StartNew (() => 2);
29 return d.Value == 5;
32 async Task<bool> Convert_1 ()
34 string s = await Task.Factory.StartNew (() => (dynamic) "x");
35 return s == "x";
38 async Task<bool> Invocation_1 ()
40 var r = (await Task.Factory.StartNew (() => (dynamic) "x|y|z")).Split ('|');
41 return r[2] == "z";
44 static bool RunTest (MethodInfo test)
46 Console.Write ("Running test {0, -25}", test.Name);
47 try {
48 Task t = test.Invoke (new Tester (), null) as Task;
49 if (!Task.WaitAll (new[] { t }, 1000)) {
50 Console.WriteLine ("FAILED (Timeout)");
51 return false;
54 var tb = t as Task<bool>;
55 if (tb != null) {
56 if (!tb.Result) {
57 Console.WriteLine ("FAILED (Result={0})", tb.Result);
58 return false;
62 Console.WriteLine ("OK");
63 return true;
64 } catch (Exception e) {
65 Console.WriteLine ("FAILED");
66 Console.WriteLine (e.ToString ());
67 return false;
71 public static int Main ()
73 var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
74 where test.GetParameters ().Length == 0
75 orderby test.Name
76 select RunTest (test);
78 int failures = tests.Count (a => !a);
79 Console.WriteLine (failures + " tests failed");
80 return failures;