Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@ -1112,6 +1112,7 @@ public class AssemblyNameTest {
}
[Test]
[Category ("AndroidNotWorking")] // Accessing assemblies by asm.Location is not supported
public void GetAssemblyName_CodeBase ()
{
Assembly execAssembly = Assembly.GetExecutingAssembly ();
@ -1845,6 +1846,15 @@ public class AssemblyNameTest {
Assert.IsTrue (AssemblyName.ReferenceMatchesDefinition (an3, an4));
Assert.IsFalse (AssemblyName.ReferenceMatchesDefinition (an5, an6));
}
[Test]
public void CultureNameInvariant ()
{
var an = new AssemblyName ("TestDll");
an.CultureInfo = new CultureInfo (CultureInfo.InvariantCulture.LCID);
Assert.AreEqual ("", an.CultureName);
}
}
}

View File

@ -42,6 +42,7 @@ using System.Threading;
using System.Runtime.Serialization;
using System.Security;
using System.Linq;
using System.Resources;
namespace MonoTests.System.Reflection
{
@ -122,6 +123,7 @@ namespace MonoTests.System.Reflection
// note: only available in default appdomain
// http://weblogs.asp.net/asanto/archive/2003/09/08/26710.aspx
// Not sure we should emulate this behavior.
#if !MONODROID
string fname = AppDomain.CurrentDomain.FriendlyName;
if (fname.EndsWith (".dll")) { // nunit-console
Assert.IsNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
@ -130,10 +132,15 @@ namespace MonoTests.System.Reflection
Assert.IsNotNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
Assert.IsTrue (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
}
#else
Assert.IsNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
Assert.IsTrue (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
#endif
}
#if !MONOTOUCH // Reflection.Emit is not supported.
[Test]
[Category("AndroidNotWorking")] // Missing Mono.CompilerServices.SymbolWriter
public void GetModules_MissingFile ()
{
AssemblyName newName = new AssemblyName ();
@ -183,7 +190,10 @@ namespace MonoTests.System.Reflection
public void Corlib_test ()
{
Assembly corlib_test = Assembly.GetExecutingAssembly ();
#if MOBILE
#if MONODROID
Assert.IsNull (corlib_test.EntryPoint, "EntryPoint");
Assert.IsNull (corlib_test.Evidence, "Evidence");
#elif MOBILE
Assert.IsNotNull (corlib_test.EntryPoint, "EntryPoint");
Assert.IsNull (corlib_test.Evidence, "Evidence");
#else
@ -194,11 +204,7 @@ namespace MonoTests.System.Reflection
Assert.IsTrue (corlib_test.GetReferencedAssemblies ().Length > 0, "GetReferencedAssemblies");
Assert.AreEqual (0, corlib_test.HostContext, "HostContext");
#if NET_4_0 && !MOBILE
Assert.AreEqual ("v4.0.30319", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
#else
Assert.AreEqual ("v2.0.50727", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
#endif
Assert.IsNotNull (corlib_test.ManifestModule, "ManifestModule");
Assert.IsFalse (corlib_test.ReflectionOnly, "ReflectionOnly");
@ -241,6 +247,7 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("AndroidNotWorking")] // Assemblies in Xamarin.Android cannot be accessed as FileStream
public void GetFiles_False ()
{
Assembly corlib = typeof (int).Assembly;
@ -253,6 +260,7 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("AndroidNotWorking")] // Assemblies in Xamarin.Android cannot be accessed as FileStream
public void GetFiles_True ()
{
Assembly corlib = typeof (int).Assembly;
@ -390,7 +398,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" };
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" };
foreach (string s in names)
if (Assembly.LoadWithPartialName (s) != null)
@ -464,6 +472,63 @@ namespace MonoTests.System.Reflection
}
}
[Test]
public void SateliteAssemblyForInMemoryAssembly ()
{
string assemblyFileName = Path.Combine (
Path.GetTempPath (), "AssemblyLocation1.dll");
try {
AssemblyName assemblyName = new AssemblyName ();
assemblyName.Name = "AssemblyLocation1";
AssemblyBuilder ab = AppDomain.CurrentDomain
.DefineDynamicAssembly (assemblyName,
AssemblyBuilderAccess.Save,
Path.GetTempPath ());
ModuleBuilder moduleBuilder = ab.DefineDynamicModule (assemblyName.Name, assemblyName.Name + ".dll");
TypeBuilder typeBuilder = moduleBuilder.DefineType ("Program", TypeAttributes.Public);
MethodBuilder methodBuilder = typeBuilder.DefineMethod ("TestCall", MethodAttributes.Public | MethodAttributes.Static, typeof(void), Type.EmptyTypes);
ILGenerator gen = methodBuilder.GetILGenerator ();
//
// var resourceManager = new ResourceManager (typeof (Program));
// resourceManager.GetString ("test");
//
gen.Emit (OpCodes.Ldtoken, typeBuilder);
gen.Emit (OpCodes.Call, typeof(Type).GetMethod ("GetTypeFromHandle"));
gen.Emit (OpCodes.Newobj, typeof(ResourceManager).GetConstructor (new Type[] { typeof(Type) }));
gen.Emit (OpCodes.Ldstr, "test");
gen.Emit (OpCodes.Callvirt, typeof(ResourceManager).GetMethod ("GetString", new Type[] { typeof(string) }));
gen.Emit (OpCodes.Pop);
gen.Emit (OpCodes.Ret);
typeBuilder.CreateType ();
ab.Save (Path.GetFileName (assemblyFileName));
using (FileStream fs = File.OpenRead (assemblyFileName)) {
byte[] buffer = new byte[fs.Length];
fs.Read (buffer, 0, buffer.Length);
Assembly assembly = Assembly.Load (buffer);
var mm = assembly.GetType ("Program").GetMethod ("TestCall");
try {
mm.Invoke (null, null);
Assert.Fail ();
} catch (TargetInvocationException e) {
Assert.IsTrue (e.InnerException is MissingManifestResourceException);
}
fs.Close ();
}
} finally {
File.Delete (assemblyFileName);
}
}
[Test]
[Category ("NotWorking")]
public void bug78464 ()
@ -486,6 +551,7 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category("MobileNotWorking")]
public void bug78465 ()
{
string assemblyFileName = Path.Combine (
@ -523,6 +589,7 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category("MobileNotWorking")]
public void bug78468 ()
{
string assemblyFileNameA = Path.Combine (Path.GetTempPath (),
@ -605,6 +672,7 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("AndroidNotWorking")] // Assemblies in Xamarin.Android cannot be directly as files
public void ReflectionOnlyLoadFrom ()
{
string loc = typeof (AssemblyTest).Assembly.Location;
@ -776,6 +844,7 @@ namespace MonoTests.System.Reflection
[Test] // bug #79715
[Category("MobileNotWorking")]
public void Load_PartialVersion ()
{
string tempDir = Path.Combine (Path.GetTempPath (),

View File

@ -318,7 +318,6 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("NotWorking")]
public void SelectMethod_AmbiguousMatch ()
{
Type type = typeof (BinderTest);
@ -402,7 +401,6 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("NotWorking")]
public void SelectMethod_Params ()
{
Type type = typeof (BinderTest);
@ -542,8 +540,11 @@ namespace MonoTests.System.Reflection
BindingFlags.Public |
BindingFlags.Instance);
PropertyInfo prop = binder.SelectProperty (0, props, null, new Type [] {null}, null);
Assert.IsNotNull (prop);
try {
binder.SelectProperty (0, props, null, new Type [] {null}, null);
Assert.Fail ();
} catch (ArgumentNullException) {
}
}
[Test]
@ -586,7 +587,6 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("NotWorking")]
public void BindToMethod_AmbiguousMatch ()
{
Type type = typeof (BinderTest);
@ -651,7 +651,6 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("NotWorking")]
public void BindToMethod_Params ()
{
Type type = typeof (BinderTest);
@ -811,8 +810,6 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("NotDotNet")]
[Category ("NotWorking")]
public void BindToMethod_Params_Mono ()
{
Type type = typeof (BinderTest);
@ -872,7 +869,6 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("NotWorking")]
public void BindToMethod_Params_MS ()
{
Type type = typeof (BinderTest);
@ -908,26 +904,11 @@ namespace MonoTests.System.Reflection
null, out state);
Assert.AreSame (mi_params, selected, "#D1");
args = new object [] { new object (), new object () };
try {
binder.BindToMethod (flags, match, ref args, null, culture,
null, out state);
Assert.Fail ("#D2");
} catch (AmbiguousMatchException) {
}
binder.BindToMethod (flags, match, ref args, null, culture, null, out state);
args = new object [] { new object (), new object [0] };
try {
binder.BindToMethod (flags, match, ref args, null, culture,
null, out state);
Assert.Fail ("#D3");
} catch (AmbiguousMatchException) {
}
binder.BindToMethod (flags, match, ref args, null, culture, null, out state);
args = new object [] { new object (), new object (), new object () };
try {
binder.BindToMethod (flags, match, ref args, null, culture,
null, out state);
Assert.Fail ("#D4");
} catch (IndexOutOfRangeException) {
}
binder.BindToMethod (flags, match, ref args, null, culture, null, out state);
match = new MethodBase [] { mi_params, mi_non_params, mi_single_param };
args = new object [] { new object () };
@ -937,7 +918,7 @@ namespace MonoTests.System.Reflection
args = new object [] { new object (), new object () };
selected = binder.BindToMethod (flags, match, ref args, null, culture,
null, out state);
Assert.AreSame (mi_params, selected, "#E2");
Assert.AreNotSame (mi_params, selected, "#E2");
}
[Test] // bug #41691
@ -1461,7 +1442,6 @@ namespace MonoTests.System.Reflection
}
[Test] // bug #636939
[Category ("NotWorking")]
public void SelectMethodWithParamArrayAndNonEqualTypeArguments ()
{
const BindingFlags flags =

View File

@ -140,5 +140,14 @@ namespace MonoTests.System.Reflection
var ctor = typeof (Gen<>).GetConstructor (Type.EmptyTypes);
Assert.IsTrue (ctor.ContainsGenericParameters);
}
[Test]
public void ConstructorInfoModule ()
{
Type type = typeof (Foo);
ConstructorInfo co = type.GetConstructors ()[0];
Assert.AreEqual (type.Module, co.Module);
}
}
}

View File

@ -114,6 +114,15 @@ namespace MonoTests.System.Reflection
} catch (InvalidOperationException) {}
}
[Test]
public void EventInfoModule ()
{
Type type = typeof (TestClass);
EventInfo ev = type.GetEvent ("pub");
Assert.AreEqual (type.Module, ev.Module);
}
#pragma warning disable 67
public class PrivateEvent
{

View File

@ -58,13 +58,13 @@ namespace MonoTests.System.Reflection
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=100)]
public string f2;
#if FEATURE_COMINTEROP
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef=typeof (Marshal1), MarshalCookie="5")]
public int f3;
[MarshalAs (UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof (Marshal1), MarshalCookie = "5")]
public object f4;
#endif
[Obsolete]
public int f5;
}
@ -170,6 +170,15 @@ namespace MonoTests.System.Reflection
}
}
[Test]
public void FieldInfoModule ()
{
Type type = typeof (FieldInfoTest);
FieldInfo field = type.GetField ("i");
Assert.AreEqual (type.Module, field.Module);
}
[Test]
public void GetCustomAttributes ()
{
@ -347,10 +356,12 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (UnmanagedType.ByValTStr, attr.Value, "#E2");
Assert.AreEqual (100, attr.SizeConst, "#E3");
#if FEATURE_COMINTEROP
attrs = typeof (Class2).GetField ("f3").GetCustomAttributes (true);
Assert.AreEqual (1, attrs.Length, "#F1");
attr = (MarshalAsAttribute) attrs [0];
Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#F2");
Assert.AreEqual ("5", attr.MarshalCookie, "#F3");
Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#F4");
@ -375,6 +386,7 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (UnmanagedType.CustomMarshaler, attr.Value, "#I2");
Assert.AreEqual ("5", attr.MarshalCookie, "#I3");
Assert.AreEqual (typeof (Marshal1), Type.GetType (attr.MarshalType), "#I4");
#endif
}
// Disable "field not used warning", this is intended.
@ -1329,6 +1341,27 @@ namespace MonoTests.System.Reflection
Throws (field, instance, new int[] { 3 });
}
struct TestFields {
public int MaxValue;
public string str;
}
[Test]
public void SetValueDirect ()
{
TestFields fields = new TestFields { MaxValue = 1234, str = "A" };
FieldInfo info = fields.GetType ().GetField ("MaxValue");
TypedReference reference = __makeref(fields);
info.SetValueDirect (reference, 4096);
Assert.AreEqual (4096, fields.MaxValue);
info = fields.GetType ().GetField ("str");
reference = __makeref(fields);
info.SetValueDirect (reference, "B");
Assert.AreEqual ("B", fields.str);
}
public IntEnum PPP;
public class Foo<T>

View File

@ -64,6 +64,11 @@ namespace MonoTests.System.Reflection
{
}
public interface InterfaceTest
{
void Clone ();
}
[Test]
public void IsDefined_AttributeType_Null ()
{
@ -304,7 +309,7 @@ namespace MonoTests.System.Reflection
[Test]
public void GetMethodBody_Abstract ()
{
MethodBody mb = typeof (ICloneable).GetMethod ("Clone").GetMethodBody ();
MethodBody mb = typeof (InterfaceTest).GetMethod ("Clone").GetMethodBody ();
Assert.IsNull (mb);
}
@ -395,6 +400,15 @@ namespace MonoTests.System.Reflection
//Assert.IsTrue (pi.IsRetval, "#3");
}
[Test]
public void MethodInfoModule ()
{
Type type = typeof (MethodInfoTest);
MethodInfo me = type.GetMethod ("return_parameter_test");
Assert.AreEqual (type.Module, me.Module);
}
[Test]
public void InvokeOnRefOnlyAssembly ()
{

View File

@ -193,19 +193,19 @@ public class ModuleTest
try {
module.ResolveMethod (1234);
Assert.Fail ();
Assert.Fail ("1234");
} catch (ArgumentException) {
}
try {
module.ResolveMethod (t.MetadataToken);
Assert.Fail ();
Assert.Fail ("MetadataToken");
} catch (ArgumentException) {
}
try {
module.ResolveMethod (t.GetMethod ("ResolveMethod").MetadataToken + 10000);
Assert.Fail ();
module.ResolveMethod (t.GetMethod ("ResolveMethod").MetadataToken + 100000);
Assert.Fail ("GetMethod");
} catch (ArgumentOutOfRangeException) {
}
}
@ -330,6 +330,7 @@ public class ModuleTest
}
#if !MONOTOUCH
[Test]
[Category ("AndroidNotWorking")] // Mono.CompilerServices.SymbolWriter not available for Xamarin.Android
public void GetTypes ()
{
AssemblyName newName = new AssemblyName ();

View File

@ -68,10 +68,10 @@ namespace MonoTests.System.Reflection.Emit
Assert.AreEqual ("type", inst.Name, "#1");
Assert.AreEqual ("foo", inst.Namespace, "#2");
#if NET_4_0
#if NET_4_0 && !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
#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

View File

@ -14,6 +14,7 @@ using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
@ -260,6 +261,26 @@ namespace MonoTests.System.Reflection
}
#endif
class TestParamAttribute : Attribute
{
}
public static int TestCustomAttribute_Method ([TestParamAttribute] string arg)
{
return arg.Length;
}
[Test]
public void TestCustomAttribute ()
{
var metInfo = GetType ().GetMethod ("TestCustomAttribute_Method", new Type[] { typeof(string) });
var paramInfos = metInfo.GetParameters ();
var argParamInfo = paramInfos[0];
var custAttrs = argParamInfo.GetCustomAttributes ();
Assert.AreEqual (1, custAttrs.Count ());
}
class MyParameterInfo2 : ParameterInfo
{
public ParameterAttributes MyAttrsImpl;
@ -332,7 +353,9 @@ namespace MonoTests.System.Reflection
}
#endif
Assert.IsFalse (p.IsIn, "#7");
#if FEATURE_USE_LCID
Assert.IsFalse (p.IsLcid, "#8");
#endif
Assert.IsFalse (p.IsOptional, "#9");
Assert.IsFalse (p.IsOut, "#10");
Assert.IsFalse (p.IsRetval, "#10");

View File

@ -48,6 +48,7 @@ namespace MonoTests.System.Reflection
{
Type type = typeof (TestClass);
PropertyInfo property = type.GetProperty ("ReadOnlyProperty");
Assert.IsNotNull (property.Module, "#0");
MethodInfo [] methods = property.GetAccessors (true);
Assert.AreEqual (1, methods.Length, "#A1");