Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -239,18 +239,6 @@ namespace MonoCasTests.System.Reflection {
// e.g. in this case both assemblies are already loaded in memory
at.LoadWithPartialName ();
}
#if !NET_2_0
// that one is unclear (undocumented) and doesn't happen in 2.0
// will not be implemented in Mono unless if find out why...
[Category ("NotWorking")]
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void LoadWithPartialName_Deny_SecurityPermission ()
{
at.LoadWithPartialName ();
}
#endif
// we use reflection to call Assembly as some methods and events are protected
// by LinkDemand (which will be converted into full demand, i.e. a stack walk)
// when reflection is used (i.e. it gets testable).

View File

@@ -88,12 +88,8 @@ namespace MonoTests.System.Reflection
}
[Test] // bug #49114
#if NET_2_0
[Category ("NotWorking")]
[ExpectedException (typeof (ArgumentException))]
#else
[ExpectedException (typeof (TypeLoadException))]
#endif
public void GetType_TypeName_Invalid ()
{
typeof (int).Assembly.GetType ("&blabla", true, true);
@@ -104,7 +100,6 @@ namespace MonoTests.System.Reflection
{
Assembly a = typeof (int).Assembly;
string typeName = typeof (string).AssemblyQualifiedName;
#if NET_2_0
try {
a.GetType (typeName, true, false);
Assert.Fail ("#A1");
@@ -114,17 +109,6 @@ namespace MonoTests.System.Reflection
Assert.IsNotNull (ex.Message, "#A4");
Assert.IsNull (ex.ParamName, "#A5");
}
#else
try {
a.GetType (typeName, true, false);
Assert.Fail ("#A1");
} catch (TypeLoadException ex) {
Assert.AreEqual (typeof (TypeLoadException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.IsTrue (ex.Message.IndexOf (typeName) != -1, "#A5");
}
#endif
Type type = a.GetType (typeName, false);
Assert.IsNull (type, "#B1");
@@ -141,14 +125,10 @@ namespace MonoTests.System.Reflection
string fname = AppDomain.CurrentDomain.FriendlyName;
if (fname.EndsWith (".dll")) { // nunit-console
Assert.IsNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
#if NET_2_0
Assert.IsFalse (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
#endif
} else { // gnunit
Assert.IsNotNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
#if NET_2_0
Assert.IsTrue (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
#endif
}
}
@@ -358,9 +338,6 @@ namespace MonoTests.System.Reflection
}
[Test] // bug #78517
#if ONLY_1_1
[Category ("NotDotNet")] // MS.NET 1.x throws FileLoadException
#endif
public void LoadFrom_Empty_Assembly ()
{
string tempFile = Path.GetTempFileName ();
@@ -589,15 +566,11 @@ namespace MonoTests.System.Reflection
Assert.AreEqual ("readme.txt", resInfo.FileName, "#A6");
Assert.IsNull (resInfo.ReferencedAssembly, "#A7");
Assert.AreEqual ((ResourceLocation) 0, resInfo.ResourceLocation, "#A8");
#if NET_2_0
try {
assembly.GetManifestResourceStream ("read");
Assert.Fail ("#A9");
} catch (FileNotFoundException) {
}
#else
Assert.IsNull (assembly.GetManifestResourceStream ("read"), "#A9");
#endif
try {
assembly.GetFile ("readme.txt");
Assert.Fail ("#A10");
@@ -621,7 +594,6 @@ namespace MonoTests.System.Reflection
}
}
#if NET_2_0
[Test]
[Category ("NotWorking")]
public void ReflectionOnlyLoad ()
@@ -650,7 +622,6 @@ namespace MonoTests.System.Reflection
Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (AssemblyTest).Assembly.FullName);
assembly.CreateInstance ("MonoTests.System.Reflection.AssemblyTest");
}
#endif
[Test]
[Category ("NotWorking")] // patch for bug #79720 must be committed first
@@ -760,11 +731,7 @@ namespace MonoTests.System.Reflection
}
[Test] // bug #79712
#if NET_2_0
[Category ("NotWorking")] // in non-default domain, MS throws FileNotFoundException
#else
[Category ("NotWorking")]
#endif
public void Load_Culture_Mismatch ()
{
string tempDir = Path.Combine (Path.GetTempPath (),
@@ -787,11 +754,7 @@ namespace MonoTests.System.Reflection
aname = new AssemblyName ();
aname.Name = "bug79712a";
aname.CultureInfo = CultureInfo.InvariantCulture;
#if NET_2_0
Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#A1");
#else
Assert.IsTrue (cdt.AssertFileLoadException (aname), "#A2");
#endif
// PART B
@@ -803,11 +766,7 @@ namespace MonoTests.System.Reflection
aname = new AssemblyName ();
aname.Name = "bug79712b";
aname.CultureInfo = new CultureInfo ("en-US");
#if NET_2_0
Assert.IsTrue (cdt.AssertFileNotFoundException (aname), "#B1");
#else
Assert.IsTrue (cdt.AssertFileLoadException (aname), "#B2");
#endif
} finally {
AppDomain.Unload (ad);
if (Directory.Exists (tempDir))

View File

@@ -370,19 +370,11 @@ namespace MonoTests.System.Reflection
MethodInfo mi_run = type.GetMethod ("Run", flags, binder,
new Type [] { typeof (int) }, null);
Assert.IsFalse (mi_run.GetParameters () [0].ParameterType.IsByRef, "#A1");
#if NET_2_0
MethodInfo mi_run_ref = type.GetMethod ("Run", flags, binder,
new Type [] { typeof (int).MakeByRefType () }, null);
#else
MethodInfo mi_run_ref = type.GetMethod ("RunV1", flags);
#endif
Assert.IsTrue (mi_run_ref.GetParameters () [0].ParameterType.IsByRef, "#A2");
#if NET_2_0
ref_int = typeof (int).MakeByRefType ();
#else
ref_int = mi_run_ref.GetParameters () [0].ParameterType;
#endif
match = new MethodBase [] { mi_run_ref };
types = new Type [] { typeof (int) };
@@ -568,12 +560,8 @@ namespace MonoTests.System.Reflection
MethodInfo mi_run = type.GetMethod ("Run", flags, binder,
new Type [] { typeof (int) }, null);
Assert.IsFalse (mi_run.GetParameters () [0].ParameterType.IsByRef, "#A1");
#if NET_2_0
MethodInfo mi_run_ref = type.GetMethod ("Run", flags, binder,
new Type [] { typeof (int).MakeByRefType () }, null);
#else
MethodInfo mi_run_ref = type.GetMethod ("RunV1", flags);
#endif
Assert.IsTrue (mi_run_ref.GetParameters () [0].ParameterType.IsByRef, "#A2");
match = new MethodBase [] { mi_run };
@@ -1048,7 +1036,6 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (3, bug42457_2, "#6");
}
#if NET_2_0
[Test]
public void NullableArg () {
MethodInfo method = (typeof (BinderTest)).GetMethod("SetA", new [] {typeof (Int32)});
@@ -1058,7 +1045,6 @@ namespace MonoTests.System.Reflection
public int SetA(Int32? a) {
return (int)a;
}
#endif
static void MethodWithLongParam(long param)
{
@@ -1355,11 +1341,7 @@ namespace MonoTests.System.Reflection
{
}
#if NET_2_0
public void Run (out int i)
#else
public void RunV1 (out int i)
#endif
{
i = 0;
}

View File

@@ -133,5 +133,12 @@ namespace MonoTests.System.Reflection
{
typeof (Foo).GetConstructors ()[0].Invoke (new object (), BindingFlags.Default, null, null, null);
}
[Test]
public void ContainsGenericParametersOnGenericType ()
{
var ctor = typeof (Gen<>).GetConstructor (Type.EmptyTypes);
Assert.IsTrue (ctor.ContainsGenericParameters);
}
}
}

View File

@@ -70,7 +70,6 @@ namespace MonoTests.System.Reflection
Assert.IsNotNull (pub.GetRemoveMethod (), "#B3");
}
#if NET_2_0
[Test]
public void AddHandlerToNullInstanceEventRaisesTargetException ()
{
@@ -114,7 +113,6 @@ namespace MonoTests.System.Reflection
Assert.Fail ("#1");
} catch (InvalidOperationException) {}
}
#endif
#pragma warning disable 67
public class PrivateEvent

View File

@@ -232,7 +232,6 @@ namespace MonoTests.System.Reflection
}
}
#if NET_2_0
[Test] // GetFieldFromHandle (RuntimeFieldHandle, RuntimeTypeHandle)
public void GetFieldFromHandle2_DeclaringType_Zero ()
{
@@ -315,7 +314,6 @@ namespace MonoTests.System.Reflection
FieldInfo fi2 = FieldInfo.GetFieldFromHandle (fh, th);
}
#endif
[Test]
public void PseudoCustomAttributes ()
@@ -519,6 +517,10 @@ namespace MonoTests.System.Reflection
[Test]
public unsafe void GetSetValuePointers ()
{
Pointer p0 = (Pointer)typeof (FieldInfoTest).GetField ("ip").GetValue (null);
int *p0i = (int*)Pointer.Unbox (p0);
Assert.AreEqual (IntPtr.Zero, new IntPtr (p0i));
int i = 5;
void *p = &i;
typeof (FieldInfoTest).GetField ("ip").SetValue (null, (IntPtr)p);

View File

@@ -37,9 +37,7 @@ using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
#if NET_2_0
using System.Collections.Generic;
#endif
namespace A.B.C {
// Disable expected warning
@@ -97,7 +95,6 @@ namespace MonoTests.System.Reflection
}
}
#if NET_2_0
[Test]
public void PseudoCustomAttributes ()
{
@@ -135,7 +132,6 @@ namespace MonoTests.System.Reflection
Assert.IsTrue (mi.ReturnTypeCustomAttributes.GetCustomAttributes (typeof (MarshalAsAttribute), true).Length == 1);
}
#endif
public static int foo (int i, int j)
{
@@ -173,9 +169,6 @@ namespace MonoTests.System.Reflection
}
[Test]
#if ONLY_1_1
[Category ("NotDotNet")] // #A2 fails on MS.NET 1.x
#endif
public void ByrefVtypeInvoke ()
{
MethodInfo mi = typeof (MethodInfoTest).GetMethod ("ByrefVtype");
@@ -215,18 +208,10 @@ namespace MonoTests.System.Reflection
method.Invoke (null, new object [0]);
Assert.Fail ("#1");
}
#if NET_2_0
catch (ThreadAbortException ex) {
Thread.ResetAbort ();
Assert.IsNull (ex.InnerException, "#2");
}
#else
catch (TargetInvocationException ex) {
Thread.ResetAbort ();
Assert.IsNotNull (ex.InnerException, "#2");
Assert.AreEqual (typeof (ThreadAbortException), ex.InnerException.GetType (), "#3");
}
#endif
}
public static void AbortIt ()
@@ -316,7 +301,6 @@ namespace MonoTests.System.Reflection
Assert.AreSame (inheritedMethod, baseMethod);
}
#if NET_2_0
[Test]
public void GetMethodBody_Abstract ()
{
@@ -740,7 +724,6 @@ namespace MonoTests.System.Reflection
{
}
}
#endif
#if NET_4_0
interface IMethodInvoke<out T>
{
@@ -826,7 +809,6 @@ namespace MonoTests.System.Reflection
#endif
}
#if NET_2_0
// Helper class
class RefOnlyMethodClass
{
@@ -850,5 +832,4 @@ namespace MonoTests.System.Reflection
set { _myList = value; }
}
}
#endif
}

View File

@@ -72,12 +72,10 @@ namespace MonoCasTests.System.Reflection {
{
// call "normal" unit with reduced privileges
mt.FindTypes ();
#if NET_2_0
mt.ResolveType ();
mt.ResolveMethod ();
mt.ResolveField ();
mt.ResolveMember ();
#endif
// properties
Assert.IsNotNull (main.Assembly, "Assembly");
Assert.IsNotNull (main.ScopeName, "ScopeName");

View File

@@ -155,7 +155,6 @@ public class ModuleTest
}
#endif
#if NET_2_0
[Test]
public void ResolveType ()
{
@@ -304,7 +303,6 @@ public class ModuleTest
MethodBase res = mod.ResolveMethod (method.MetadataToken);
Assert.AreEqual (method, res, "#1");
}
#endif
[Test]
public void FindTypes ()

View File

@@ -72,7 +72,7 @@ namespace MonoTests.System.Reflection
}
}
#if NET_2_0 && !NET_2_1
#if !NET_2_1
public enum ParamEnum {
None = 0,
Foo = 1,

View File

@@ -98,7 +98,6 @@ namespace MonoTests.System.Reflection
methods = property.GetAccessors ();
Assert.AreEqual (0, methods.Length, "#H");
#if NET_2_0
property = typeof (TestClass).GetProperty ("PrivateSetter");
methods = property.GetAccessors (true);
@@ -117,7 +116,6 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (1, methods.Length, "#J1");
Assert.IsNotNull (methods [0], "#J2");
Assert.AreEqual ("get_PrivateSetter", methods [0].Name, "#J3");
#endif
}
[Test]
@@ -480,12 +478,10 @@ namespace MonoTests.System.Reflection
set { }
}
#if NET_2_0
public string PrivateSetter {
get { return null; }
private set { }
}
#endif
}
[Test] // bug #633671

View File

@@ -0,0 +1,98 @@
// VisibilityTest.cs
//
//
// Author:
// Marius Ungureanu <marius.ungureanu@xamarin.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 "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#if !MONOTOUCH
using System;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
namespace MonoTests.System.Reflection.VisibilityTypes
{
[TestFixture]
public class VisibilityTests
{
[Test]
public void TestsExportedTypes ()
{
var types = typeof (VisibilityTests).Assembly.GetExportedTypes ();
// Test visibility means that the class is public by applying and on the 'public' visibility of the nested items.
CollectionAssert.DoesNotContain (types, typeof (InternalClass));
CollectionAssert.Contains (types, typeof (PublicClass));
CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+InternalNested", true));
CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PrivateNested", true));
CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+ProtectedNested", true));
CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PublicNested", true));
CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+InternalNested", true));
CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PrivateNested", true));
CollectionAssert.DoesNotContain (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+ProtectedNested", true));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PublicNested", true));
}
[Test]
public void TestsModuleTypes ()
{
var types = typeof (VisibilityTests).Module.GetTypes ();
// Test that all the types defined exist.
CollectionAssert.Contains (types, typeof (InternalClass));
CollectionAssert.Contains (types, typeof (PublicClass));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+InternalNested", true));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PrivateNested", true));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+ProtectedNested", true));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+InternalClass+PublicNested", true));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+InternalNested", true));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PrivateNested", true));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+ProtectedNested", true));
CollectionAssert.Contains (types, Type.GetType ("MonoTests.System.Reflection.VisibilityTypes.VisibilityTests+PublicClass+PublicNested", true));
}
class InternalClass
{
internal class InternalNested {}
private class PrivateNested {}
protected class ProtectedNested {}
public class PublicNested {}
}
public class PublicClass
{
internal class InternalNested {}
private class PrivateNested {}
protected class ProtectedNested {}
public class PublicNested {}
}
}
}
#endif