Imported Upstream version 4.3.2.467

Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
This commit is contained in:
Xamarin Public Jenkins
2016-02-22 11:00:01 -05:00
parent f302175246
commit f3e3aab35a
4097 changed files with 122406 additions and 82300 deletions

View File

@@ -385,10 +385,8 @@ public class AssemblyNameTest {
string AssemblyCorlib;
#if MOBILE
AssemblyCorlib = "mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e";
#elif NET_4_0
AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
#else
AssemblyCorlib = "mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
AssemblyCorlib = "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";
#endif
Assert.AreEqual (AssemblyCorlib, an.FullName, "#2");
}
@@ -1294,19 +1292,8 @@ public class AssemblyNameTest {
try {
new AssemblyName (assemblyName + ", Culture=aa-AA");
Assert.Fail ("#1");
#if NET_4_0
} catch (CultureNotFoundException ex) {
}
#else
} catch (ArgumentException ex) {
// Culture name 'aa-aa' is not supported
Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");
Assert.IsNull (ex.InnerException, "#3");
Assert.IsNotNull (ex.Message, "#4");
Assert.IsNotNull (ex.ParamName, "#5");
Assert.AreEqual ("name", ex.ParamName, "#6");
}
#endif
}
[Test] // ctor (String)
@@ -1820,6 +1807,28 @@ public class AssemblyNameTest {
}
}
[Test] // ctor (String)
public void Constructor1_Quoted ()
{
AssemblyName an;
an = new AssemblyName ("'System', Version=\"10.0.0.0\", Culture='Neutral', PublicKeyToken='b67a5c561934e089', Retargetable='Yes', ProcessorArchitecture='AMD64'");
Assert.AreEqual ("System, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b67a5c561934e089, Retargetable=Yes", an.ToString ());
Assert.AreEqual (ProcessorArchitecture.Amd64, an.ProcessorArchitecture, "Amd64");
}
[Test] // ctor (String)
public void Constructor1_Quoted_Invalid ()
{
AssemblyName an;
try {
an = new AssemblyName ("System, Version=\"10.0.0.0'");
Assert.Fail ("#1");
} catch (FileLoadException) {
}
}
[Test (Description="Xamarin bug #99 - whitespaces in key=value")]
public void WhiteSpaceInKeyValue ()
{

View File

@@ -5,9 +5,11 @@
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
// Philippe Lavoie (philippe.lavoie@cactus.ca)
// Sebastien Pouliot (sebastien@ximian.com)
// Aleksey Kliger (aleksey@xamarin.com)
//
// (c) 2003 Ximian, Inc. (http://www.ximian.com)
// Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
// Copyright (C) 2015 Xamarin, Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -40,10 +42,14 @@ using System.Reflection.Emit;
#endif
using System.Threading;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Security;
using System.Linq;
using System.Resources;
// Used by GetType_TypeForwarder_Nested ()
[assembly: System.Runtime.CompilerServices.TypeForwardedToAttribute(typeof(System.Globalization.CultureInfo))]
namespace MonoTests.System.Reflection
{
[TestFixture]
@@ -89,13 +95,58 @@ namespace MonoTests.System.Reflection
}
[Test] // bug #49114
[Category ("NotWorking")]
[ExpectedException (typeof (ArgumentException))]
public void GetType_TypeName_Invalid ()
{
typeof (int).Assembly.GetType ("&blabla", true, true);
}
[Test] // bug #17571
[ExpectedException (typeof (ArgumentException))]
public void GetType_Invalid_RefPtr () {
typeof (int).Assembly.GetType ("System.Int32&*", true, true);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetType_Invalid_RefArray () {
typeof (int).Assembly.GetType ("System.Int32&[]", true, true);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetType_Invalid_RefGeneric () {
typeof (int).Assembly.GetType ("System.Tuple`1&[System.Int32]", true, true);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void GetType_Invalid_PtrGeneric () {
typeof (int).Assembly.GetType ("System.Tuple`1*[System.Int32]", true, true);
}
[Test]
public void GetType_ComposeModifiers () {
var a = typeof(int).Assembly;
var e1 = typeof (Int32).MakePointerType().MakeByRefType();
var t1 = a.GetType ("System.Int32*&", true, true);
Assert.AreEqual (e1, t1, "#1");
var e2 = typeof (Int32).MakeArrayType(2).MakeByRefType();
var t2 = a.GetType ("System.Int32[,]&", true, true);
Assert.AreEqual (e2, t2, "#2");
var e3 = typeof (Int32).MakePointerType().MakeArrayType();
var t3 = a.GetType ("System.Int32*[]", true, true);
Assert.AreEqual (e3, t3, "#3");
var e4 = typeof (Int32).MakeArrayType().MakePointerType().MakePointerType().MakeArrayType().MakePointerType().MakeByRefType();
var t4 = a.GetType ("System.Int32[]**[]*&", true, true);
Assert.AreEqual (e4, t4, "#4");
}
[Test] // bug #334203
public void GetType_TypeName_AssemblyName ()
{
@@ -117,6 +168,14 @@ namespace MonoTests.System.Reflection
Assert.IsNull (type, "#B2");
}
[Test]
public void GetType_TypeForwarder_Nested () {
// System.Globalization is a PCL assembly
Type t = typeof (AssemblyTest).Assembly.GetType ("System.Globalization.CultureInfo/Data");
Assert.IsNotNull (t);
Assert.AreEqual ("System.Globalization.CultureInfo+Data", t.FullName);
}
[Test]
public void GetEntryAssembly ()
{
@@ -398,7 +457,7 @@ namespace MonoTests.System.Reflection
[Test]
public void LoadWithPartialName ()
{
string [] names = { "corlib_test_net_1_1", "corlib_test_net_2_0", "corlib_test_net_4_0", "corlib_test_net_4_5", "corlib_plattest", "mscorlibtests", "BclTests" };
string [] names = { "corlib_test_net_1_1", "corlib_test_net_2_0", "corlib_test_net_4_0", "corlib_test_net_4_5", "corlib_test_net_4_x", "corlib_plattest", "mscorlibtests", "BclTests" };
foreach (string s in names)
if (Assembly.LoadWithPartialName (s) != null)
@@ -1114,11 +1173,7 @@ namespace MonoTests.System.Reflection
Module module = assembly.ManifestModule;
Assert.IsNotNull (module, "#1");
#if NET_4_0
Assert.AreEqual ("MonoModule", module.GetType ().Name, "#2");
#else
Assert.AreEqual (typeof (Module), module.GetType (), "#2");
#endif
#if !MONOTOUCH
Assert.AreEqual ("mscorlib.dll", module.Name, "#3");
@@ -1190,6 +1245,67 @@ namespace MonoTests.System.Reflection
} catch (ArgumentException) {}
}
class GetCallingAssemblyCallee {
static int _dummy;
static void sideEffect () {
_dummy++;
}
// GetCallingAssembly may see an unpredictable
// view of the stack if it's called in tail
// position, or if its caller or the caller's
// caller is inlined. So we put in a side
// effect to get out of tail position, and we
// tag the methods NoInlining to discourage
// the inliner.
[MethodImplAttribute (MethodImplOptions.NoInlining)]
public static Assembly Leaf () {
var a = Assembly.GetCallingAssembly ();
sideEffect();
return a;
}
[MethodImplAttribute (MethodImplOptions.NoInlining)]
public static Assembly DirectCall () {
var a = Leaf();
sideEffect();
return a;
}
[MethodImplAttribute (MethodImplOptions.NoInlining)]
public static Assembly InvokeCall () {
var ty = typeof (GetCallingAssemblyCallee);
var mi = ty.GetMethod("Leaf");
var o = mi.Invoke(null, null);
sideEffect();
return (Assembly)o;
}
}
[Test]
public void GetCallingAssembly_Direct() {
var a = GetCallingAssemblyCallee.DirectCall ();
Assert.IsNotNull (a);
Assert.AreEqual (GetType().Assembly, a);
}
[Test]
public void GetCallingAssembly_SkipsReflection () {
// check that the calling assembly is this
// one, not mscorlib (aka, the reflection
// API).
var a = GetCallingAssemblyCallee.InvokeCall ();
Assert.IsNotNull (a);
var invokeAssembly =
typeof (MethodInfo).Assembly;
Assert.AreNotEqual (invokeAssembly, a);
Assert.AreEqual (GetType().Assembly, a);
}
#if NET_4_5
[Test]
public void DefinedTypes_Equality ()

View File

@@ -3,9 +3,11 @@
//
// Authors:
// Zoltan Varga (vargaz@gmail.com)
// Aleksey Kliger (aleksey@xamarin.com)
//
// (c) 2003 Ximian, Inc. (http://www.ximian.com)
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
// Copyright (C) 2015 Xamarin, Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
@@ -52,7 +54,12 @@ namespace MonoTests.System.Reflection
[TestFixture]
public class MethodInfoTest
{
#if MONOTOUCH
// use an existing symbol - so we can build without dlsym. It does not matter that the signature does not match for the test
[DllImport ("libc", EntryPoint="readlink", CharSet=CharSet.Unicode, ExactSpelling=false, PreserveSig=true, SetLastError=true, BestFitMapping=true, ThrowOnUnmappableChar=true)]
#else
[DllImport ("libfoo", EntryPoint="foo", CharSet=CharSet.Unicode, ExactSpelling=false, PreserveSig=true, SetLastError=true, BestFitMapping=true, ThrowOnUnmappableChar=true)]
#endif
public static extern void dllImportMethod ();
[MethodImplAttribute(MethodImplOptions.PreserveSig)]
public void preserveSigMethod ()
@@ -108,8 +115,13 @@ namespace MonoTests.System.Reflection
DllImportAttribute attr = (DllImportAttribute)((t.GetMethod ("dllImportMethod").GetCustomAttributes (typeof (DllImportAttribute), true)) [0]);
Assert.AreEqual (CallingConvention.Winapi, attr.CallingConvention, "#1");
#if MONOTOUCH
Assert.AreEqual ("readlink", attr.EntryPoint, "#2");
Assert.AreEqual ("libc", attr.Value, "#3");
#else
Assert.AreEqual ("foo", attr.EntryPoint, "#2");
Assert.AreEqual ("libfoo", attr.Value, "#3");
#endif
Assert.AreEqual (CharSet.Unicode, attr.CharSet, "#4");
Assert.AreEqual (false, attr.ExactSpelling, "#5");
Assert.AreEqual (true, attr.PreserveSig, "#6");
@@ -205,6 +217,7 @@ namespace MonoTests.System.Reflection
return (int*) 0;
}
#if MONO_FEATURE_THREAD_ABORT
[Test] // bug #81538
public void InvokeThreadAbort ()
{
@@ -223,6 +236,7 @@ namespace MonoTests.System.Reflection
{
Thread.CurrentThread.Abort ();
}
#endif
[Test] // bug #76541
public void ToStringByRef ()
@@ -281,6 +295,35 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (typeof (GBD_D), typeof (GBD_E).GetMethod ("f").GetBaseDefinition ().DeclaringType);
}
class GenericBase<T,H> {
public virtual void f2 () { }
}
class GenericMid<T, U> : GenericBase<T, Action<U>> {
public virtual T f1 () { return default (T); }
}
class GenericChild<T> : GenericMid<T, int> {
public override T f1 () { return default (T); }
public override void f2 () { }
}
[Test]
public void GetBaseDefinition_OpenConstructedBaseType () // 36305
{
var t = typeof (GenericChild<string>);
var mi1 = t.GetMethod ("f1");
var mi1_base = mi1.GetBaseDefinition ();
Assert.AreEqual (typeof (GenericMid<string, int>), mi1_base.DeclaringType, "#1");
var mi2 = t.GetMethod ("f2");
var mi2_base = mi2.GetBaseDefinition ();
Assert.AreEqual (typeof (GenericBase<string, Action<int>>), mi2_base.DeclaringType, "#2");
}
class TestInheritedMethodA {
private void TestMethod ()
{
@@ -744,7 +787,6 @@ namespace MonoTests.System.Reflection
{
}
}
#if NET_4_0
interface IMethodInvoke<out T>
{
T Test ();
@@ -768,7 +810,6 @@ namespace MonoTests.System.Reflection
Assert.AreEqual ("MethodInvoke", m0.Invoke (obj, new Object [0]));
Assert.AreEqual ("MethodInvoke", m1.Invoke (obj, new Object [0]));
}
#endif
public int? Bug12856 ()

View File

@@ -68,17 +68,14 @@ namespace MonoTests.System.Reflection.Emit
Assert.AreEqual ("type", inst.Name, "#1");
Assert.AreEqual ("foo", inst.Namespace, "#2");
#if NET_4_0 && !MOBILE
#if !MOBILE
Assert.AreEqual ("foo.type[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", inst.FullName, "#3");
Assert.AreEqual ("foo.type[[System.Double, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], MonoTests.System.Reflection.Emit.MonoGenericClassTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", inst.AssemblyQualifiedName, "#4");
#elif NET_2_1 || MOBILE
Assert.AreEqual ("foo.type[[System.Double, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]", inst.FullName, "#3");
Assert.AreEqual ("foo.type[[System.Double, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[System.String, mscorlib, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]], MonoTests.System.Reflection.Emit.MonoGenericClassTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", inst.AssemblyQualifiedName, "#4");
#else
Assert.AreEqual ("foo.type[[System.Double, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]", inst.FullName, "#3");
Assert.AreEqual ("foo.type[[System.Double, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], MonoTests.System.Reflection.Emit.MonoGenericClassTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", inst.AssemblyQualifiedName, "#4");
#endif
Assert.AreEqual ("foo.type[System.Double,System.String]", inst.ToString (), "#5");
#endif
}
static void CheckInst (string prefix, Type inst, int a, int b)
@@ -204,7 +201,90 @@ namespace MonoTests.System.Reflection.Emit
Assert.AreSame (expected, t.BaseType, "#1");
}
[Test]
public void GenericClassFromStaleTypeBuilderDoesNotClassInit ()
{
// interface JJJ<T> {
// abstract void W (x : T)
// }
MethodInfo winfo = null;
TypeBuilder ib = null;
Type ic = null;
Type icreated = null;
{
ib = module.DefineType ("Foo.JJJ`1",
TypeAttributes.Public
| TypeAttributes.Interface
| TypeAttributes.Abstract);
String[] gens = { "T" };
GenericTypeParameterBuilder[] gbs = ib.DefineGenericParameters (gens);
var gb = gbs[0];
winfo = ib.DefineMethod ("W",
MethodAttributes.Public |
MethodAttributes.Abstract |
MethodAttributes.Virtual,
CallingConventions.HasThis,
typeof(void),
new Type[] { gb });
icreated = ib.CreateType();
}
// class SSS : JJJ<char> {
// bool wasCalled;
// void JJJ.W (x : T) { wasCalled = true; return; }
// }
TypeBuilder tb = null;
MethodBuilder mb = null;
{
tb = module.DefineType ("Foo.SSS",
TypeAttributes.Public,
null,
new Type[]{ icreated.MakeGenericType(typeof(char)) });
var wasCalledField = tb.DefineField ("wasCalled",
typeof(bool),
FieldAttributes.Public);
mb = tb.DefineMethod ("W_impl",
MethodAttributes.Public | MethodAttributes.Virtual,
CallingConventions.HasThis,
typeof (void),
new Type[] { typeof (char) });
{
var il = mb.GetILGenerator ();
il.Emit (OpCodes.Ldarg_0); // this
il.Emit (OpCodes.Ldc_I4_1);
il.Emit (OpCodes.Stfld, wasCalledField); // this.wasCalled = true
il.Emit (OpCodes.Ret);
}
}
ic = ib.MakeGenericType(typeof (char)); // this is a MonoGenericMethod
var mintf = TypeBuilder.GetMethod(ic, winfo);
// the next line causes mono_class_init() to
// be called on JJJ<char> when we try to setup
// the vtable for SSS
tb.DefineMethodOverride(mb, mintf);
var result = tb.CreateType();
// o = new SSS()
object o = Activator.CreateInstance(result);
Assert.IsNotNull(o, "#1");
// ((JJJ<char>)o).W('a');
var m = icreated.MakeGenericType(typeof(char)).GetMethod("W", BindingFlags.Public | BindingFlags.Instance);
Assert.IsNotNull(m, "#2");
m.Invoke(o, new object[] {'a'});
var f = result.GetField("wasCalled", BindingFlags.Public | BindingFlags.Instance);
Assert.IsNotNull(f, "#3");
var wasCalledVal = f.GetValue(o);
Assert.IsNotNull(wasCalledVal, "#4");
Assert.AreEqual (wasCalledVal.GetType(), typeof(Boolean), "#5");
Assert.AreEqual (wasCalledVal, true, "#6");
}
}
}
#endif
#endif

View File

@@ -243,7 +243,6 @@ namespace MonoTests.System.Reflection
{
}
#if NET_4_0
public static void TestC (decimal u = decimal.MaxValue) {
}
@@ -451,6 +450,5 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (p2.myList, p2.CustomAttributes, "#3");
#endif
}
#endif
}
}

View File

@@ -498,8 +498,20 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (typeof (ClassWithNullableDateTime), siblingProperty.DeclaringType, "#3");
Assert.AreEqual (typeof (InheritsFromClassWithNullableDateTime), siblingProperty.ReflectedType, "#4");
}
class Super { public long A { get; private set; } }
class Sub : Super { }
[Test]
public void PrivateSetterFromDerivedType ()
{
var prop = typeof (Sub).GetProperty ("A");
Assert.AreEqual (1, prop.GetAccessors (true).Length, "#1");
Assert.IsFalse (prop.CanWrite, "#2");
Assert.IsNull (prop.GetSetMethod (true), "#3");
}
public class ClassWithNullableDateTime
{
public DateTime? Property1 { get; set; }