Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

3076
mcs/tests/ChangeLog Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

99
mcs/tests/Makefile Normal file
View File

@@ -0,0 +1,99 @@
#
# use make run-test PROFILE=net_2_0
#
thisdir = tests
SUBDIRS =
include ../build/rules.make
DISTFILES = $(wildcard dlls/**/*.cs) $(wildcard dlls/*.cs) $(wildcard dlls/*.inc)
DISTFILES += $(wildcard *.cs) $(wildcard *.il) $(wildcard *.xml) $(wildcard *.inc) $(wildcard known-issues-*) $(wildcard *.snk)
with_mono_path = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH"
ilasm = $(topdir)/class/lib/$(PROFILE)/ilasm.exe
ILASM = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(ilasm)
USE_MCS_FLAGS :=
# mention all targets
all-local $(STD_TARGETS:=-local):
VALID_PROFILE := $(filter net_4_5, $(PROFILE))
ifdef VALID_PROFILE
# casts
bootstrap-cast.exe: gen-cast-test.cs
$(BOOT_COMPILE) -target:exe /out:$@ $<
casts.cs: bootstrap-cast.exe
$(with_mono_path) $(RUNTIME) $(RUNTIME_FLAGS) $< >$@
casts-mcs.exe: casts.cs
$(CSCOMPILE) -target:exe /out:$@ $<
casts-boot.exe: casts.cs
$(BOOT_COMPILE) -target:exe /out:$@ $<
boot-casts.out: casts-boot.exe
$(with_mono_path) $(RUNTIME) $(RUNTIME_FLAGS) $< >$@
mcs-casts.out: casts-mcs.exe
$(with_mono_path) $(RUNTIME) $(RUNTIME_FLAGS) $< >$@
test-casts: boot-casts.out mcs-casts.out
cmp $^
-rm -f bootstrap-cast.exe casts.cs casts-boot.exe casts-mcs.exe boot-casts.out mcs-casts.out
TEST_PATTERN = 'v2'
ifeq (net_4_5, $(PROFILE))
TEST_PATTERN = 'v4'
DEFINES = -compiler-options:"-d:NET_4_0;NET_4_5"
endif
LOCAL_RUNTIME_FLAGS = --verify-all
COMPILER = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/mcs.exe
TESTER = MONO_RUNTIME='$(RUNTIME)' $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(LOCAL_RUNTIME_FLAGS) $(topdir)/class/lib/$(PROFILE)/compiler-tester.exe
TEST_ILS := $(wildcard *-lib.il)
build-compiler-lib:
cd ../class/Mono.CSharp && $(MAKE) NO_DIR_CHECK=yes
qcheck: build-compiler-lib qcheck2
qcheck2:
$(TESTER) -mode:pos -files:$(TEST_PATTERN) -compiler:$(COMPILER) -issues:known-issues-$(PROFILE) -log:$(PROFILE).log -il:ver-il-$(PROFILE).xml $(DEFINES) $(TOPTIONS)
gen-mt-tests:
$(TESTER) -mode:nunit -files:'v2' -compiler:$(COMPILER) -issues:known-issues-mt -compiler-options:"-lib:$(topdir)/class/lib/monotouch projects/MonoTouch/ivt.cs"
test-local:
@:
run-test-local: $(TEST_ILS:.il=.dll) setup qcheck
check: run-test-local
endif
clean-local:
-rm -fr dir-*
-rm -f *.exe *.dll *.netmodule *.out *.pdb *.mdb casts.cs *.log
-rm -f xml-*.xml
dist-local: dist-default
rm -f $(distdir)/casts.cs
csproj-local:
%-il.dll: %-il.il
$(ILASM) /dll $<
%-lib.dll: %-lib.il
$(ILASM) /dll /out:$@ $<
setup:
$(CSCOMPILE) -t:library dlls/test-679-2/test-679-lib-2.cs
$(CSCOMPILE) -t:library dlls/test-679-1/test-679-lib.cs -r:dlls/test-679-2/test-679-lib-2.dll
$(ILASM) -dll dlls/test-883.il

View File

@@ -0,0 +1,21 @@
using System;
[assembly: LibA ("b")]
public class LibBAttribute : Attribute {
public LibBAttribute (string s)
{
}
}
public class LibB : LibA {
public static new void A ()
{
LibA.A ();
}
public static void B ()
{
Console.WriteLine ("B");
}
}

View File

@@ -0,0 +1,14 @@
using System;
public class LibAAttribute : Attribute {
public LibAAttribute (string s)
{
}
}
public class LibA {
public static void A ()
{
Console.WriteLine ("A");
}
}

View File

@@ -0,0 +1,10 @@
public class RelativeTestPath
{
/// <summary>
/// Implements more features
/// </summary>
/// <include file='test-xml-025-relative.inc' path='/doc/remarks[@name="Foo"]'/>
public static void Foo ()
{
}
}

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<doc>
<remarks name="Foo">
implements the method in the most beautiful way possible.
</remarks>
</doc>

159
mcs/tests/dtest-001.cs Normal file
View File

@@ -0,0 +1,159 @@
//
// dynamic type attribute decoration
//
using System;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Linq;
interface I<T>
{
}
class C
{
public C (dynamic d)
{
}
public dynamic a;
public const dynamic c = default (dynamic);
public dynamic Prop { set; get; }
public dynamic Prop2 { set { } }
public dynamic this[dynamic d] { set { } get { return 1; } }
public dynamic Method (dynamic d)
{
return null;
}
// Transformation handling required
public dynamic[] t;
public dynamic[,] t2;
public Func<dynamic, int, dynamic[]> v;
public I<dynamic>[] iface;
public Action<int[], object, dynamic> d2;
}
delegate dynamic Del (dynamic d);
class Test
{
public static int Main ()
{
Type t = typeof (C);
Type ca = typeof (System.Runtime.CompilerServices.DynamicAttribute);
if (t.GetMember ("a")[0].GetCustomAttributes (ca, false).Length != 1)
return 1;
if (t.GetMember ("c")[0].GetCustomAttributes (ca, false).Length != 1)
return 3;
if (t.GetMember ("Prop")[0].GetCustomAttributes (ca, false).Length != 1)
return 4;
if (t.GetMember ("get_Prop")[0].GetCustomAttributes (ca, false).Length != 0)
return 5;
if (t.GetMethod ("get_Prop").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
return 6;
if (t.GetMember ("set_Prop")[0].GetCustomAttributes (ca, false).Length != 0)
return 7;
if (t.GetMethod ("set_Prop").ReturnParameter.GetCustomAttributes (ca, false).Length != 0)
return 8;
if (t.GetMethod ("set_Prop").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
return 9;
if (t.GetMember ("Prop2")[0].GetCustomAttributes (ca, false).Length != 1)
return 10;
if (t.GetMember ("set_Prop2")[0].GetCustomAttributes (ca, false).Length != 0)
return 11;
if (t.GetMember ("Item")[0].GetCustomAttributes (ca, false).Length != 1)
return 12;
if (t.GetMethod ("get_Item").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
return 13;
if (t.GetMethod ("get_Item").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
return 14;
if (t.GetMethod ("set_Item").ReturnParameter.GetCustomAttributes (ca, false).Length != 0)
return 15;
if (t.GetMethod ("set_Item").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
return 16;
if (t.GetMethod ("set_Item").GetParameters ()[1].GetCustomAttributes (ca, false).Length != 1)
return 17;
if (t.GetMember ("Method")[0].GetCustomAttributes (ca, false).Length != 0)
return 18;
if (t.GetMethod ("Method").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
return 19;
if (t.GetConstructors ()[0].GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
return 20;
if (t.GetConstructors ()[0].GetCustomAttributes (ca, false).Length != 0)
return 21;
// Transformations
DynamicAttribute da;
da = t.GetMember ("t")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
if (da == null)
return 40;
if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
return 41;
da = t.GetMember ("t2")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
if (da == null)
return 42;
if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
return 43;
da = t.GetMember ("v")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
if (da == null)
return 44;
if (!da.TransformFlags.SequenceEqual (new bool[] { false, true, false, false, true }))
return 45;
da = t.GetMember ("iface")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
if (da == null)
return 46;
if (!da.TransformFlags.SequenceEqual (new bool[] { false, false, true }))
return 47;
da = t.GetMember ("d2")[0].GetCustomAttributes (ca, false)[0] as DynamicAttribute;
if (da == null)
return 48;
if (!da.TransformFlags.SequenceEqual (new bool[] { false, false, false, false, true }))
return 49;
t = typeof (Del);
if (t.GetMember ("Invoke")[0].GetCustomAttributes (ca, false).Length != 0)
return 100;
if (t.GetMethod ("Invoke").GetParameters ()[0].GetCustomAttributes (ca, false).Length != 1)
return 101;
if (t.GetMethod ("Invoke").ReturnParameter.GetCustomAttributes (ca, false).Length != 1)
return 102;
Console.WriteLine ("ok");
return 0;
}
}

35
mcs/tests/dtest-002.cs Normal file
View File

@@ -0,0 +1,35 @@
public interface I
{
dynamic D ();
object D2 ();
}
public class C : I
{
public object D ()
{
return null;
}
public dynamic D2 ()
{
return null;
}
public static int Main ()
{
return 0;
}
}
abstract class AC
{
public abstract void Foo(dynamic[] d);
}
class BC : AC
{
public override void Foo(params object[] d)
{
}
}

1439
mcs/tests/dtest-003.cs Normal file

File diff suppressed because it is too large Load Diff

33
mcs/tests/dtest-004.cs Normal file
View File

@@ -0,0 +1,33 @@
// internal dynamic conversion tests
class G<T>
{
}
class C
{
public static dynamic Create ()
{
return 1;
}
static void M<T> ()
{
dynamic d = default (T);
var v = default (dynamic);
}
public static int Main ()
{
var d = Create ();
d.ToString ();
M<int> ();
M<C> ();
G<object> v1 = new G<dynamic>();
G<dynamic> v2 = new G<object>();
return 0;
}
}

42
mcs/tests/dtest-005.cs Normal file
View File

@@ -0,0 +1,42 @@
using System;
using System.Dynamic;
public class MyObject : DynamicObject
{
public static int Get, Invoke;
public override bool TryGetMember (GetMemberBinder binder, out object result)
{
Console.WriteLine ("Get");
Get++;
result = null;
return true;
}
public override bool TryInvokeMember (InvokeMemberBinder binder, object[] args, out object result)
{
Console.WriteLine ("Invoke");
Invoke++;
result = null;
return true;
}
}
public class Tests
{
public static int Main ()
{
dynamic d = new MyObject ();
var g = d.GetMe;
if (MyObject.Get != 1 && MyObject.Invoke != 0)
return 1;
d.printf ("Hello, World!");
if (MyObject.Get != 1 && MyObject.Invoke != 1)
return 2;
Console.WriteLine ("ok");
return 0;
}
}

2128
mcs/tests/dtest-006.cs Normal file

File diff suppressed because it is too large Load Diff

319
mcs/tests/dtest-007.cs Normal file
View File

@@ -0,0 +1,319 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.CSharp.RuntimeBinder;
// Dynamic member lookup tests
delegate void D ();
delegate void D2 (decimal d);
class Class
{
internal int IntValue = 5;
internal string StringStatic = "hi";
public const decimal Decimal = -0.3m;
public Class ()
{
}
public Class (sbyte extra)
{
IntValue = extra;
}
uint s = 77;
protected internal uint this[byte i] {
get {
return s * i;
}
set {
s = value;
}
}
byte b = 180;
internal byte Prop {
get {
return b;
}
set {
b = value;
}
}
public int FixedValue
{
set { }
get { return 823; }
}
internal string Method (string value)
{
return value;
}
public int Method (int a, byte b)
{
return a * b;
}
public void MethodInOut (ref int refValue, out string outValue)
{
refValue = 3;
outValue = "4";
}
public static void GenericVoid<T> (T i)
{
}
public static int StaticMethod (params int[] i)
{
return i [0] * i.Length;
}
public static void ArglistMethod (__arglist)
{
}
}
class EventClass
{
internal event Func<int> OutEvent;
public int CallEvent ()
{
return OutEvent ();
}
}
class Tester
{
static void Assert<T> (T expected, T value, string name)
{
if (!EqualityComparer<T>.Default.Equals (expected, value)) {
name += ": ";
throw new ApplicationException (name + expected + " != " + value);
}
}
static void AssertError (Action expected, string name)
{
try {
expected ();
throw new ApplicationException (name + ": RuntimeBinderException expected");
} catch (RuntimeBinderException) {
// passed
}
}
event Func<int> e;
int field;
#pragma warning disable 169
void GetIndexTest ()
{
dynamic d = new[] { 5, 8, 2 };
Assert (8, d[1], "#1");
d = new int[,] { { 1, 2 }, { 3, 4 } };
Assert (3, d[1, 0], "#2");
dynamic d2 = new Class ();
Assert<uint> (154, d2[2], "#3");
Assert<uint> (154, d2[i:2], "#3a");
}
void GetIndexError_Null ()
{
dynamic d = null;
AssertError (() => { var v = d[1]; }, "#1");
}
void InvokeTest ()
{
Func<string, string> f = new Class().Method;
dynamic d = f;
Assert ("bar", d ("bar"), "#1");
Action<bool> f2 = Class.GenericVoid;
d = f2;
d (true);
Func<string, int> f3 = (s) => 3;
d = f3;
d ("go");
}
void InvokeMember ()
{
dynamic d = new Class ();
Assert ("vv", d.Method ("vv"), "#1");
byte b = 2;
Assert (6, d.Method (b: b++, a: b), "#1a");
var arg1 = 1;
var arg2 = "a";
d.MethodInOut (ref arg1, out arg2);
d = 2;
Assert (2, Class.StaticMethod (d), "#2");
Class.StaticMethod (d);
}
void InvokeMember_Error ()
{
AssertError (() => {
dynamic d_arg = "a";
Class.ArglistMethod (d_arg);
}, "#1");
}
void InvokeConstructor ()
{
dynamic d = (sbyte) 8;
var r = new Class (d);
Assert (8, r.IntValue, "#1");
D2 method = (decimal e) => { };
d = method;
var r2 = new D2 (d);
}
void IsEvent ()
{
dynamic d = this;
d.e += new Func<int> (() => 3);
Assert (3, d.e (), "#1");
d.field += 5;
Assert (5, d.field, "#2");
int r = d.field += 7;
Assert (12, r, "#2a");
Assert (12, d.field, "#2b");
d = new EventClass ();
d.OutEvent += new Func<int> (() => 100);
Assert (100, d.CallEvent (), "#3");
}
void MemberGetTest ()
{
dynamic d = new Class ();
Assert (5, d.IntValue, "#1");
Assert (180, d.Prop, "#1a");
Assert ("hi", d.StringStatic, "#2");
d = new int[4];
Assert (4, d.Length, "#3");
}
void MemberGetError_Null ()
{
dynamic d = null;
AssertError (() => { var v = d.Foo; }, "#1");
}
void MemberSetTest ()
{
dynamic d = new Class ();
d.IntValue = 22;
Assert (22, d.IntValue, "#1");
d.Prop = 19;
Assert (19, d.Prop, "#1a");
d.Prop = byte.MaxValue;
Assert (byte.MaxValue, d.Prop++, "#1b");
Assert (1, ++d.Prop, "#1c");
d.Prop++;
Assert (2, d.Prop, "#1d");
d.Prop += 5;
Assert (7, d.Prop, "#1e");
d.StringStatic = "no";
Assert ("no", d.StringStatic, "#2");
var r = d.FixedValue = 44;
Assert (44, r, "#3");
}
void MemberSetError_Null ()
{
dynamic d = null;
AssertError (() => { d.Fo1 = 1; }, "#1");
}
void SetIndexTest ()
{
dynamic d = new[] { "b", "v" };
d[1] = "c";
Assert ("c", d[1], "#1");
d = new int[,] { { 1, 2 }, { 3, 4 } };
d[1, 0] = 100;
Assert (100, d[1, 0], "#2");
d[1, 0]++;
Assert (101, d[1, 0], "#2a");
d [0, 0] = d [1, 0] = 55;
Assert (55, d [0, 0], "#2a");
dynamic d2 = new Class ();
d2[2] = 500;
Assert<uint> (1000, d2[2], "#3");
d2[2]++;
Assert<uint> (2002, d2[2], "#3a");
d2[i:1] = 3;
Assert<uint> (3, d2[1], "#3b");
uint r = d2 [1] = 200;
Assert<uint> (200, r, "#4");
}
void SetIndexError_Null ()
{
dynamic d = null;
AssertError (() => { d [1] = 0; }, "#1");
}
#pragma warning restore 169
static bool RunTest (MethodInfo test)
{
Console.Write ("Running test {0, -25}", test.Name);
try {
test.Invoke (new Tester (), null);
Console.WriteLine ("OK");
return true;
} catch (Exception e) {
Console.WriteLine ("FAILED");
Console.WriteLine (e.ToString ());
// Console.WriteLine (e.InnerException.Message);
return false;
}
}
public static int Main ()
{
var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
where test.GetParameters ().Length == 0
orderby test.Name
select RunTest (test);
int failures = tests.Count (a => !a);
Console.WriteLine (failures + " tests failed");
return failures;
}
}

104
mcs/tests/dtest-008.cs Normal file
View File

@@ -0,0 +1,104 @@
using System;
using System.Collections.Generic;
// Dynamic statements
class Disposable : IDisposable
{
public static int Counter;
public void Dispose ()
{
++Counter;
}
public void Test ()
{
}
}
public class Test
{
bool ForEachTest ()
{
dynamic d = new List<int> { 5, 10, 7 };
dynamic res = 9;
foreach (var v in d) {
res += v;
}
return res == 31;
}
bool ForEachTest_2()
{
dynamic c = new int [] { 5, 7 };
int total = 0;
foreach (var v in c)
{
total += v;
}
return total == 12;
}
bool ForEachTest_3()
{
dynamic[] c = new dynamic [] { (byte) 1, 7 };
int total = 0;
foreach (var v in c)
{
total += v;
}
Console.WriteLine (total);
return total == 8;
}
bool UsingTest ()
{
dynamic d = new Disposable ();
try {
using (d) {
d.VV ();
}
} catch { }
if (Disposable.Counter != 1)
return false;
try {
using (dynamic u = new Disposable ()) {
u.VV ();
}
} catch { }
if (Disposable.Counter != 2)
return false;
using (dynamic u = new Disposable ()) {
u.Test ();
}
return true;
}
public static int Main ()
{
var t = new Test ();
if (!t.ForEachTest ())
return 1;
if (!t.ForEachTest_2 ())
return 2;
if (!t.ForEachTest_3 ())
return 3;
if (!t.UsingTest ())
return 10;
Console.WriteLine ("ok");
return 0;
}
}

18
mcs/tests/dtest-009.cs Normal file
View File

@@ -0,0 +1,18 @@
partial class B
{
static partial void Test (int a);
static partial void Test (int x)
{
}
public static int Main ()
{
Test (a: 5);
dynamic d = -1;
Test (a: d);
return 0;
}
}

29
mcs/tests/dtest-010.cs Normal file
View File

@@ -0,0 +1,29 @@
class A
{
public static T Test<T> (T a, T b)
{
return b;
}
}
class C
{
int TestCall ()
{
return 1;
}
public static int Main ()
{
dynamic d = 0;
object o = new C ();
if (A.Test<dynamic> (d, o).TestCall () != 1)
return 1;
if (A.Test (d, o).TestCall () != 1)
return 2;
return 0;
}
}

46
mcs/tests/dtest-011.cs Normal file
View File

@@ -0,0 +1,46 @@
using System;
class C
{
void foo (int i)
{
Console.WriteLine ("Got int: {0}", i);
}
void foo (string message)
{
throw new ApplicationException ();
}
static void foo_static (long l)
{
Console.WriteLine ("Got static long: {0}", l);
}
static int MethodBest (short d)
{
return 1;
}
static int MethodBest (dynamic d)
{
return -1;
}
void test ()
{
dynamic d = 1;
foo (d);
foo_static (d);
}
public static int Main ()
{
new C ().test ();
if (MethodBest (1) != 1)
return 1;
return 0;
}
}

23
mcs/tests/dtest-012.cs Normal file
View File

@@ -0,0 +1,23 @@
using System.Linq;
using System.Runtime.CompilerServices;
public class G<T>
{
}
namespace dynamic
{
public class C : G<dynamic>
{
public static int Main ()
{
var da = typeof (C).GetCustomAttributes (typeof (System.Runtime.CompilerServices.DynamicAttribute), false) [0] as DynamicAttribute;
if (!da.TransformFlags.SequenceEqual (new bool[] { false, true }))
return 1;
return 0;
}
}
}

15
mcs/tests/dtest-013.cs Normal file
View File

@@ -0,0 +1,15 @@
using System.Collections.Generic;
namespace ndynamic
{
public class C<U> : List<dynamic>
{
}
class C
{
public static void Main ()
{
}
}
}

Some files were not shown because too many files have changed in this diff Show More