Imported Upstream version 5.20.0.180

Former-commit-id: ff953ca879339fe1e1211f7220f563e1342e66cb
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-02-04 20:11:37 +00:00
parent 0e2d47d1c8
commit 0510252385
3360 changed files with 83827 additions and 39243 deletions

View File

@@ -1 +1 @@
bef88b0c599515481b21854be4e0073c3fea3617
d5529557985b2dfc14eb9efc721ef19175f2d627

View File

@@ -0,0 +1,69 @@
using System;
using System.Reflection;
using NUnit.Framework;
using Mono;
namespace MonoTests.Mono
{
[TestFixture]
public class NativePlatformTest
{
#if WIN_PLATFORM
[TestFixtureSetUp]
public void SetUp ()
{
Assert.Ignore ("Mono.Native is not supported on this platform.");
}
#endif
[Test]
public void PlatformType ()
{
var type = MonoNativePlatform.GetPlatformType ();
Assert.That ((int)type, Is.GreaterThan (0), "platform type");
}
[Test]
public void TestInitialize ()
{
MonoNativePlatform.Initialize ();
var initialized = MonoNativePlatform.IsInitialized ();
Assert.IsTrue (initialized, "MonoNativePlatform.IsInitialized()");
}
[Test]
public void TestReflectionInitialize ()
{
var asm = typeof (string).Assembly;
var type = asm.GetType ("Mono.MonoNativePlatform");
Assert.IsNotNull (type, "MonoNativePlatform");
var method = type.GetMethod ("Initialize", BindingFlags.Static | BindingFlags.Public);
Assert.IsNotNull (method, "MonoNativePlatform.Initialize");
var method2 = type.GetMethod ("IsInitialized", BindingFlags.Static | BindingFlags.Public);
Assert.IsNotNull (method2, "MonoNativePlatform.IsInitialized");
method.Invoke (null, null);
var result = (bool)method2.Invoke (null, null);
Assert.IsTrue (result, "MonoNativePlatform.IsInitialized()");
}
[Test]
public void TestInternalCounter ()
{
MonoNativePlatform.Initialize ();
var asm = typeof (string).Assembly;
var type = asm.GetType ("Mono.MonoNativePlatform");
Assert.IsNotNull (type, "MonoNativePlatform");
var method = type.GetMethod ("TestInternalCounter", BindingFlags.Static | BindingFlags.NonPublic);
Assert.IsNotNull (method, "MonoNativePlatform.TestInternalCounter");
var result = method.Invoke (null, null);
Assert.That (result, Is.GreaterThan (0), "MonoNativePlatform.TestInternalCounter()");
}
}
}

View File

@@ -1,5 +1,5 @@
//
// DecoupledTask.cs
// DebuggerTypeProxyAttribute.cs
//
// Authors:
// Marek Safar <marek.safar@gmail.com>

View File

@@ -12,6 +12,7 @@ using System.Diagnostics;
using System.Reflection;
using NUnit.Framework;
using System.Runtime.ExceptionServices;
using System.Threading.Tasks;
namespace MonoTests.System.Diagnostics
{
@@ -181,7 +182,7 @@ namespace MonoTests.System.Diagnostics
frame1.GetFileLineNumber (),
"Line number (1)");
Assert.AreEqual (135,
Assert.AreEqual (136,
frame2.GetFileLineNumber (),
"Line number (2)");
@@ -321,7 +322,7 @@ namespace MonoTests.System.Diagnostics
frame1.GetFileLineNumber (),
"Line number (1)");
Assert.AreEqual (271,
Assert.AreEqual (272,
frame2.GetFileLineNumber (),
"Line number (2)");
}
@@ -377,6 +378,47 @@ namespace MonoTests.System.Diagnostics
}
}
[Test]
// https://github.com/mono/mono/issues/12688
public void GetFrames_AsynsCalls ()
{
StartAsyncCalls ().Wait ();
}
private async Task StartAsyncCalls ()
{
try
{
await AsyncMethod1 ();
}
catch (Exception exception)
{
var stackTrace = new StackTrace (exception, true);
Assert.AreEqual (25, stackTrace.GetFrames ().Length);
}
}
private async Task<int> AsyncMethod1 ()
{
return await AsyncMethod2 ();
}
private async Task<int> AsyncMethod2 ()
{
return await AsyncMethod3 ();
}
private async Task<int> AsyncMethod3 ()
{
return await AsyncMethod4 ();
}
private async Task<int> AsyncMethod4 ()
{
await Task.Delay (10);
throw new Exception ("Test exception thrown!");
}
/// <summary>
/// Tests whether getting method associated with frame works.
/// </summary>

View File

@@ -65,13 +65,12 @@ namespace MonoTests.System.Globalization {
}
static private byte[] serialized_daylighttime = {
0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x04, 0x01, 0x00, 0x00, 0x00, 0x21, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62,
0x61, 0x6C, 0x69, 0x7A, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x44, 0x61, 0x79, 0x6C, 0x69, 0x67, 0x68,
0x74, 0x54, 0x69, 0x6D, 0x65, 0x03, 0x00, 0x00, 0x00, 0x07, 0x6D, 0x5F, 0x73, 0x74, 0x61, 0x72, 0x74,
0x05, 0x6D, 0x5F, 0x65, 0x6E, 0x64, 0x07, 0x6D, 0x5F, 0x64, 0x65, 0x6C, 0x74, 0x61, 0x00, 0x00, 0x00,
0x0D, 0x0D, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x3F, 0x37, 0xF4, 0x75, 0x28,
0xCA, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x0B
0x0, 0x1, 0x0, 0x0, 0x0, 0xFF, 0xFF, 0xFF, 0xFF, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x1, 0x0, 0x0,
0x0, 0x21, 0x53, 0x79, 0x73, 0x74, 0x65, 0x6D, 0x2E, 0x47, 0x6C, 0x6F, 0x62, 0x61, 0x6C, 0x69, 0x7A, 0x61,
0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x44, 0x61, 0x79, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x54, 0x69, 0x6D, 0x65, 0x3,
0x0, 0x0, 0x0, 0x6, 0x5F, 0x73, 0x74, 0x61, 0x72, 0x74, 0x4, 0x5F, 0x65, 0x6E, 0x64, 0x6, 0x5F, 0x64, 0x65,
0x6C, 0x74, 0x61, 0x0, 0x0, 0x0, 0xD, 0xD, 0xC, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xFF, 0x3F, 0x37,
0xF4, 0x75, 0x28, 0xCA, 0x2B, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80, 0xB
};
[Test]

View File

@@ -649,8 +649,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (1, reader.Read (), "test#03");
Assert.AreEqual (2, reader.PeekChar (), "test#03");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -687,8 +689,10 @@ namespace MonoTests.System.IO
reader.Close ();
reader.PeekChar ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -706,8 +710,10 @@ namespace MonoTests.System.IO
reader.Close ();
reader.ReadBytes (1);
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -727,8 +733,10 @@ namespace MonoTests.System.IO
reader.Close ();
Assert.AreEqual (null, reader.BaseStream, "test#03");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -767,8 +775,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (0, bytes [0], "test#10");
Assert.AreEqual (0, bytes [1], "test#11");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -804,8 +814,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (0, chars [0], "test#08");
Assert.AreEqual (0, chars [1], "test#09");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -827,8 +839,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (false, reader.ReadBoolean (), "test#04");
Assert.AreEqual (true, reader.ReadBoolean (), "test#05");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -848,8 +862,10 @@ namespace MonoTests.System.IO
reader.ReadBoolean ();
reader.ReadBoolean ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -872,8 +888,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (0, reader.ReadByte (), "test#04");
Assert.AreEqual (13, reader.ReadByte (), "test#05");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -894,8 +912,10 @@ namespace MonoTests.System.IO
reader.ReadByte ();
reader.ReadByte ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -925,8 +945,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (1, bytes.Length, "test#06");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -945,8 +967,10 @@ namespace MonoTests.System.IO
reader = new BinaryReader (stream);
reader.ReadBytes (-1);
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -968,8 +992,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (0, reader.ReadChar (), "test#04");
Assert.AreEqual (13, reader.ReadChar (), "test#05");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -990,8 +1016,10 @@ namespace MonoTests.System.IO
reader.ReadChar ();
reader.ReadChar ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1018,8 +1046,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (13, chars [0], "test#05");
Assert.AreEqual (1, chars.Length, "test#06");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1037,8 +1067,10 @@ namespace MonoTests.System.IO
reader = new BinaryReader (stream);
reader.ReadChars (-1);
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1056,8 +1088,10 @@ namespace MonoTests.System.IO
reader = new BinaryReader (stream);
Assert.AreEqual (-18295873486192640, reader.ReadDecimal (), "test#01");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1071,8 +1105,10 @@ namespace MonoTests.System.IO
reader.ReadDecimal ();
reader.ReadDecimal ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1085,8 +1121,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (1.8913127797311212E-307d, reader.ReadDouble (), "test#01");
Assert.AreEqual (1.2024538023802026E+111d, reader.ReadDouble (), "test#02");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1117,8 +1155,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (773, reader.ReadInt16 (), "test#03");
Assert.AreEqual (54, reader.ReadInt16 (), "test#04");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1132,8 +1172,10 @@ namespace MonoTests.System.IO
reader.ReadInt16 ();
reader.ReadInt16 ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1146,8 +1188,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (723517761, reader.ReadInt32 (), "test#01");
Assert.AreEqual (3539717, reader.ReadInt32 (), "test#02");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1161,8 +1205,10 @@ namespace MonoTests.System.IO
reader.ReadInt32 ();
reader.ReadInt32 ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1175,8 +1221,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (15202969475612993, reader.ReadInt64 (), "test#01");
Assert.AreEqual (2471354792417887522, reader.ReadInt64 (), "test#02");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1192,8 +1240,10 @@ namespace MonoTests.System.IO
reader.ReadInt64 ();
reader.ReadInt64 ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1208,8 +1258,10 @@ namespace MonoTests.System.IO
Assert.AreEqual (-56, reader.ReadSByte (), "test#02");
Assert.AreEqual (32, reader.ReadSByte (), "test#03");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1225,8 +1277,10 @@ namespace MonoTests.System.IO
reader.ReadSByte ();
reader.ReadSByte ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1255,8 +1309,10 @@ namespace MonoTests.System.IO
reader.ReadSingle ();
reader.ReadSingle ();
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}
@@ -1275,8 +1331,10 @@ namespace MonoTests.System.IO
Assert.AreEqual ("mo", reader.ReadString (), "test#02");
Assert.AreEqual ("o::", reader.ReadString (), "test#03");
} finally {
reader.Close ();
stream.Close ();
if (reader != null)
reader.Close ();
if (stream != null)
stream.Close ();
}
}

View File

@@ -2774,7 +2774,7 @@ namespace MonoTests.System.IO
public static extern int symlink (string oldpath, string newpath);
[Test]
#if __TVOS__
#if MONOTOUCH_TV
[Ignore ("See bug #59239")]
#endif
public void SymLinkLoop ()

View File

@@ -13,6 +13,8 @@ using System.Threading.Tasks;
using NUnit.Framework;
using MonoTests.Helpers;
namespace MonoTests.System.IO
{
[TestFixture]
@@ -780,7 +782,7 @@ public class StreamReaderTest
[Category ("MobileNotWorking")]
public void EndOfBufferIsCR ()
{
using (StreamReader reader = new StreamReader ("Test/resources/Fergie.GED")) {
using (StreamReader reader = new StreamReader (TestResourceHelper.GetFullPathOfResource ("Test/resources/Fergie.GED"))) {
string line;
int count = 0;
while ((line = reader.ReadLine ()) != null) {

View File

@@ -195,7 +195,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 __WATCHOS__
#if MONOTOUCH_WATCH
Assert.IsNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
Assert.IsTrue (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
#elif !MONODROID

View File

@@ -29,20 +29,60 @@
using NUnit.Framework;
using System;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace MonoTests.System.Reflection
{
enum Levels { one, two, three }
class Attr : Attribute {
public Attr (byte[] arr) {
}
}
[AttributeUsage (AttributeTargets.Method)]
class TestAttrWithObjectCtorParam : Attribute {
object o;
public TestAttrWithObjectCtorParam (object o) => this.o = o;
}
[AttributeUsage (AttributeTargets.Method)]
class TestAttrWithEnumCtorParam : Attribute {
Levels level;
public TestAttrWithEnumCtorParam (Levels level) => this.level = level;
}
[AttributeUsage (AttributeTargets.Method)]
class TestAttrWithObjectArrayCtorParam : Attribute {
object[] o;
public TestAttrWithObjectArrayCtorParam (object[] o) => this.o = o;
}
[AttributeUsage (AttributeTargets.Method)]
class TestAttrWithObjectArrayCtorParamAndParamsKeyword : Attribute {
object[] o;
public TestAttrWithObjectArrayCtorParamAndParamsKeyword (params object[] o) => this.o = o;
}
[AttributeUsage (AttributeTargets.Method)]
class TestAttrWithObjectArrayCtorParams : Attribute {
object[] o1;
object[] o2;
public TestAttrWithObjectArrayCtorParams (object[] o1, params object[] o2) {
this.o1 = o1;
this.o2 = o2;
}
}
[TestFixture]
public class CustomAttributeDataTest
{
[DllImport ("libc")]
public static extern void pinvoke ();
[MarshalAs (UnmanagedType.LPStr)]
[NonSerialized]
public string fieldDecoratedWithPseudoCustomAttributes = "test";
@@ -51,6 +91,31 @@ namespace MonoTests.System.Reflection
public void MethodWithAttr () {
}
[TestAttrWithObjectCtorParam (Levels.two)]
public void MethodDecoratedWithAttribute1 ()
{
}
[TestAttrWithEnumCtorParam (Levels.two)]
public void MethodDecoratedWithAttribute2 ()
{
}
[TestAttrWithObjectArrayCtorParam (new object[] { Levels.one, Levels.two})]
public void MethodDecoratedWithAttribute3 ()
{
}
[TestAttrWithObjectArrayCtorParamAndParamsKeyword (Levels.one, Levels.two)]
public void MethodDecoratedWithAttribute4 ()
{
}
[TestAttrWithObjectArrayCtorParams (new object[] { Levels.one, Levels.two}, Levels.three, Levels.two)]
public void MethodDecoratedWithAttribute5 ()
{
}
public void MethodWithParamDecoratedWithPseudoCustomAttributes ([Optional, In, Out, MarshalAs (UnmanagedType.LPStr)] String s)
{
}
@@ -62,7 +127,6 @@ namespace MonoTests.System.Reflection
}
[Test]
[Category ("MobileNotWorking")] // #10263
public void Arrays () {
IList<CustomAttributeData> cdata = CustomAttributeData.GetCustomAttributes (typeof (CustomAttributeDataTest).GetMethod ("MethodWithAttr"));
Assert.AreEqual (1, cdata.Count);
@@ -75,6 +139,78 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (typeof (byte), arr [1].ArgumentType);
Assert.AreEqual (2, arr [1].Value);
}
[Test]
// https://github.com/mono/mono/issues/10951
public void ObjectArrays ()
{
CheckObjectArrayParam (nameof (MethodDecoratedWithAttribute3));
CheckObjectArrayParam (nameof (MethodDecoratedWithAttribute4));
}
private void CheckObjectArrayParam (string methodName)
{
IList<CustomAttributeData> cdata = CustomAttributeData.GetCustomAttributes (typeof (CustomAttributeDataTest).GetMethod (methodName));
Assert.AreEqual (1, cdata.Count, $"{methodName}#0");
CustomAttributeTypedArgument arg = cdata [0].ConstructorArguments [0];
Assert.IsTrue (typeof (IList<CustomAttributeTypedArgument>).IsAssignableFrom (arg.Value.GetType ()), $"{methodName}#1");
IList<CustomAttributeTypedArgument> arr = (IList<CustomAttributeTypedArgument>)arg.Value;
Assert.AreEqual (2, arr.Count, $"{methodName}#2");
Assert.AreEqual (typeof (Levels), arr [0].ArgumentType, $"{methodName}#3");
Assert.IsTrue (arr [0].ArgumentType.GetTypeInfo().IsEnum, $"{methodName}#4");
Assert.AreEqual (0, arr [0].Value, $"{methodName}#5");
Assert.AreEqual (typeof (int), arr [0].Value.GetType (), $"{methodName}#6");
Assert.AreEqual (typeof (Levels), arr [1].ArgumentType, $"{methodName}#7");
Assert.IsTrue (arr [1].ArgumentType.GetTypeInfo().IsEnum, $"{methodName}#8");
Assert.AreEqual (1, arr [1].Value, $"{methodName}#9");
Assert.AreEqual (typeof (int), arr [1].Value.GetType (), $"{methodName}#10");
}
[Test]
// https://github.com/mono/mono/issues/10951
public void CheckObjectArrayParams ()
{
string methodName = nameof (MethodDecoratedWithAttribute5);
IList<CustomAttributeData> cdata = CustomAttributeData.GetCustomAttributes (typeof (CustomAttributeDataTest).GetMethod (methodName));
Assert.AreEqual (1, cdata.Count, $"{methodName}#0");
Assert.AreEqual (2, cdata [0].ConstructorArguments.Count, $"{methodName}#00");
CustomAttributeTypedArgument arg = cdata [0].ConstructorArguments [0];
Assert.IsTrue (typeof (IList<CustomAttributeTypedArgument>).IsAssignableFrom (arg.Value.GetType ()), $"{methodName}#1");
IList<CustomAttributeTypedArgument> arr = (IList<CustomAttributeTypedArgument>)arg.Value;
Assert.AreEqual (2, arr.Count, $"{methodName}#2");
Assert.AreEqual (typeof (Levels), arr [0].ArgumentType, $"{methodName}#3");
Assert.IsTrue (arr [0].ArgumentType.GetTypeInfo().IsEnum, $"{methodName}#4");
Assert.AreEqual (0, arr [0].Value, $"{methodName}#5");
Assert.AreEqual (typeof (int), arr [0].Value.GetType (), $"{methodName}#6");
Assert.AreEqual (typeof (Levels), arr [1].ArgumentType, $"{methodName}#7");
Assert.IsTrue (arr [1].ArgumentType.GetTypeInfo().IsEnum, $"{methodName}#8");
Assert.AreEqual (1, arr [1].Value, $"{methodName}#9");
Assert.AreEqual (typeof (int), arr [1].Value.GetType (), $"{methodName}#10");
arg = cdata [0].ConstructorArguments [1];
Assert.IsTrue (typeof (IList<CustomAttributeTypedArgument>).IsAssignableFrom (arg.Value.GetType ()), $"{methodName}#11");
arr = (IList<CustomAttributeTypedArgument>)arg.Value;
Assert.AreEqual (2, arr.Count, $"{methodName}#12");
Assert.AreEqual (typeof (Levels), arr [0].ArgumentType, $"{methodName}#13");
Assert.IsTrue (arr [0].ArgumentType.GetTypeInfo().IsEnum, $"{methodName}#14");
Assert.AreEqual (2, arr [0].Value, $"{methodName}#15");
Assert.AreEqual (typeof (int), arr [0].Value.GetType (), $"{methodName}#16");
Assert.AreEqual (typeof (Levels), arr [1].ArgumentType, $"{methodName}#17");
Assert.IsTrue (arr [1].ArgumentType.GetTypeInfo().IsEnum, $"{methodName}#18");
Assert.AreEqual (1, arr [1].Value, $"{methodName}#19");
Assert.AreEqual (typeof (int), arr [1].Value.GetType (), $"{methodName}#20");
}
[Test]
public void ParameterIncludesPseudoCustomAttributesData ()
@@ -86,19 +222,19 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (4, customAttributesData.Count);
var inAttributeData = customAttributesData [0];
var optionalAttributeData = customAttributesData [1];
var outAttributeData = customAttributesData [2];
var outAttributeData = customAttributesData [1];
var optionalAttributeData = customAttributesData [2];
var marshalAsAttributeData = customAttributesData [3];
var marshalAsAttributeCtorArg = marshalAsAttributeData.ConstructorArguments [0];
Assert.AreEqual (typeof (InAttribute), inAttributeData.AttributeType);
Assert.AreEqual (typeof (OptionalAttribute), optionalAttributeData.AttributeType);
Assert.AreEqual (typeof (OutAttribute), outAttributeData.AttributeType);
Assert.AreEqual (typeof (OptionalAttribute), optionalAttributeData.AttributeType);
Assert.AreEqual (typeof (MarshalAsAttribute), marshalAsAttributeData.AttributeType);
Assert.AreEqual (typeof (UnmanagedType), marshalAsAttributeCtorArg.ArgumentType);
Assert.AreEqual (UnmanagedType.LPStr, marshalAsAttributeCtorArg.Value);
Assert.AreEqual ((int)UnmanagedType.LPStr, marshalAsAttributeCtorArg.Value);
}
[Test]
@@ -116,7 +252,7 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (typeof (NonSerializedAttribute), nonSerializedAttributeData.AttributeType);
Assert.AreEqual (typeof (MarshalAsAttribute), marshalAsAttributeData.AttributeType);
Assert.AreEqual (typeof (UnmanagedType), marshalAsAttributeDataCtorArg.ArgumentType);
Assert.AreEqual (UnmanagedType.LPStr, marshalAsAttributeDataCtorArg.Value);
Assert.AreEqual ((int)UnmanagedType.LPStr, marshalAsAttributeDataCtorArg.Value);
}
[Test]
@@ -131,7 +267,52 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (1, customAttributesData.Count);
Assert.AreEqual (typeof (MarshalAsAttribute), marshalAsAttributeData.AttributeType);
Assert.AreEqual (typeof (UnmanagedType), ctorArg.ArgumentType);
Assert.AreEqual (UnmanagedType.LPStr, ctorArg.Value);
Assert.AreEqual ((int)UnmanagedType.LPStr, ctorArg.Value);
}
[Test]
// https://github.com/mono/mono/issues/10544
public void MethodIncludesDllImportAttributeData ()
{
var mi = typeof (CustomAttributeDataTest).FindMembers (MemberTypes.Method, BindingFlags.Static | BindingFlags.Public, (m, criteria) => m.Name == "pinvoke", null);
var data = ((MethodInfo)(mi[0])).CustomAttributes;
Assert.AreEqual (2, data.Count ());
Assert.AreEqual (typeof (PreserveSigAttribute), data.First ().AttributeType);
var dllImportAttributeData = data.Last ();
var ctorArg = dllImportAttributeData.ConstructorArguments [0];
Assert.AreEqual (typeof (DllImportAttribute), dllImportAttributeData.AttributeType);
Assert.AreEqual ("libc", ctorArg.Value);
}
[Test]
// https://github.com/mono/mono/issues/10555
public void CustomAttributeCtor_TakesEnumArg ()
{
var method = GetMethod (nameof (MethodDecoratedWithAttribute1));
var data = method.CustomAttributes;
var ctorArg = data.First ().ConstructorArguments [0];
Assert.AreEqual (typeof (Levels), ctorArg.ArgumentType);
Assert.AreEqual (1, ctorArg.Value);
Assert.AreEqual (typeof (int), ctorArg.Value.GetType ());
method = GetMethod (nameof (MethodDecoratedWithAttribute2));
data = method.CustomAttributes;
ctorArg = data.First ().ConstructorArguments [0];
Assert.AreEqual (typeof (Levels), ctorArg.ArgumentType);
Assert.AreEqual (1, ctorArg.Value);
Assert.AreEqual (typeof (int), ctorArg.Value.GetType ());
}
private MethodInfo GetMethod (string methodName)
{
var mi = typeof (CustomAttributeDataTest).FindMembers (MemberTypes.Method, BindingFlags.Instance | BindingFlags.Public, (m, criteria) => m.Name == methodName, null);
return (MethodInfo)(mi [0]);
}
}
}

View File

@@ -123,6 +123,13 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (type.Module, ev.Module);
}
[Test]
public void MetadataToken ()
{
EventInfo ev = typeof (TestClass).GetEvent ("pub");
Assert.IsTrue ((int)ev.MetadataToken > 0);
}
#pragma warning disable 67
public class PrivateEvent
{

View File

@@ -29,6 +29,7 @@
//
using System;
using System.Globalization;
using System.Threading;
using System.Reflection;
#if !MONOTOUCH && !FULL_AOT_RUNTIME
@@ -224,6 +225,14 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (typeof (ObsoleteAttribute), attrs [0].GetType (), "#D10");
}
[Test]
public void MetadataToken ()
{
Type type = typeof (FieldInfoTest);
FieldInfo field = type.GetField ("i");
Assert.IsTrue ((int)field.MetadataToken > 0);
}
[Test] // GetFieldFromHandle (RuntimeFieldHandle)
public void GetFieldFromHandle1_Handle_Zero ()
{
@@ -1455,6 +1464,41 @@ namespace MonoTests.System.Reflection
public const FieldInfoTest object_field = null;
public int non_const_field;
class FieldInfoWrapper : FieldInfo
{
private FieldInfo fieldInfo;
public FieldInfoWrapper (FieldInfo fieldInfo)
{
this.fieldInfo = fieldInfo;
}
public override FieldAttributes Attributes => fieldInfo.Attributes;
public override Type DeclaringType => fieldInfo.DeclaringType;
public override RuntimeFieldHandle FieldHandle => fieldInfo.FieldHandle;
public override Type FieldType => fieldInfo.FieldType;
public override string Name => fieldInfo.Name;
public override Type ReflectedType => fieldInfo.ReflectedType;
public override object[] GetCustomAttributes (bool inherit) => fieldInfo.GetCustomAttributes (inherit);
public override object[] GetCustomAttributes (Type attributeType, bool inherit) => fieldInfo.GetCustomAttributes (attributeType, inherit);
public override object GetValue (object obj) => fieldInfo.GetValue (obj);
public override bool IsDefined (Type attributeType, bool inherit) => fieldInfo.IsDefined (attributeType, inherit);
public override void SetValue (object obj, object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) =>
fieldInfo.SetValue (obj, value, invokeAttr, binder, culture);
}
[Test]
public void CustomFieldInfo ()
{
var fieldInfoWrapper = new FieldInfoWrapper (GetType ().GetField (nameof (non_const_field)));
MethodInfo method = typeof (FieldInfoWrapper).GetMethod ("GetFieldOffset", BindingFlags.NonPublic | BindingFlags.Instance);
Assert.IsNotNull (method);
Assert.IsTrue (method.IsVirtual);
var ex = Assert.Catch<Exception> (() => method.Invoke (fieldInfoWrapper, new object[] {}));
Assert.IsTrue (ex.InnerException is SystemException);
}
}
// We do not refernece the field, that is expected

View File

@@ -317,6 +317,13 @@ public class ModuleTest
Assert.AreEqual (method, res, "#1");
}
[Test]
public void ResolveInvalidMember () // https://github.com/mono/mono/issues/9604
{
Module m = typeof (ModuleTest).Module;
Assert.Throws<ArgumentOutOfRangeException> (() => m.ResolveMember(0x0A00F000));
}
[Test]
public void FindTypes ()
{

View File

@@ -507,6 +507,26 @@ namespace MonoTests.System.Reflection
Assert.AreEqual (expected, actual, "#1");
}
public class Dummy {
public void M1 (decimal? arg = 12.345M) { }
public void M2 ([Optional, DecimalConstant (1, 2, 3, 4, 5)] decimal? arg) { }
public void M3 (decimal? arg = null) { }
public void M4 ([Optional, DateTimeConstant (1L)] DateTime? arg) { }
public void M5 (DateTime? arg = null) { }
}
[Test]
// https://github.com/mono/mono/issues/11303
public void RawDefaultValue_Nullable ()
{
var type = typeof (Dummy);
Assert.AreEqual (12.345M, type.GetMethod("M1").GetParameters () [0].RawDefaultValue);
Assert.AreEqual (new DecimalConstantAttribute (1, 2, 3, 4, 5).Value, type.GetMethod ("M2").GetParameters () [0].RawDefaultValue);
Assert.AreEqual (null, type.GetMethod ("M3").GetParameters () [0].RawDefaultValue);
Assert.AreEqual (new DateTime (1), type.GetMethod ("M4").GetParameters () [0].RawDefaultValue);
Assert.AreEqual (null, type.GetMethod ("M5").GetParameters () [0].RawDefaultValue);
}
[Test]
public void ReturnParameter_IsDefined_False ()
{

View File

@@ -560,5 +560,12 @@ namespace MonoTests.System.Reflection
Assert.AreEqual ("param", defaultParam.Name, "#1");
Assert.AreEqual ("test", defaultParam.DefaultValue, "#2");
}
[Test]
public void MetadataToken ()
{
PropertyInfo property = typeof (Base).GetProperty ("P");
Assert.IsTrue ((int)property.MetadataToken > 0);
}
}
}

View File

@@ -41,6 +41,8 @@ using System.IO;
using NUnit.Framework;
using MonoTests.Helpers;
namespace MonoTests.System.Resources
{
[TestFixture]
@@ -350,7 +352,7 @@ namespace MonoTests.System.Resources
public void CreateFileBasedResourceManager_BaseName_Resources ()
{
ResourceManager rm = ResourceManager.CreateFileBasedResourceManager (
"MyResources.resources", "Test/resources", null);
"MyResources.resources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
try {
rm.GetResourceSet (CultureInfo.InvariantCulture, true, true);
Assert.Fail ("#1");
@@ -385,7 +387,7 @@ namespace MonoTests.System.Resources
public void CreateFileBasedResourceManager_UsingResourceSet_Invalid ()
{
ResourceManager rm = ResourceManager.CreateFileBasedResourceManager (
"MyResources", "Test/resources", typeof (string));
"MyResources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), typeof (string));
Assert.IsNotNull (rm.BaseName, "#1");
Assert.AreEqual ("MyResources", rm.BaseName, "#2");
Assert.IsFalse (rm.IgnoreCase, "#3");
@@ -397,7 +399,7 @@ namespace MonoTests.System.Resources
public void CreateFileBasedResourceManager_UsingResourceSet_Null ()
{
ResourceManager rm = ResourceManager.CreateFileBasedResourceManager (
"MyResources", "Test/resources", (Type) null);
"MyResources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), (Type) null);
Assert.IsNotNull (rm.BaseName, "#1");
Assert.AreEqual ("MyResources", rm.BaseName, "#2");
Assert.IsFalse (rm.IgnoreCase, "#3");
@@ -412,7 +414,7 @@ namespace MonoTests.System.Resources
public void GetObject ()
{
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("MyResources", "Test/resources", null);
CreateFileBasedResourceManager ("MyResources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
Assert.AreEqual ("Hello World", rm.GetObject ("HelloWorld"), "#A1");
@@ -474,7 +476,7 @@ namespace MonoTests.System.Resources
{
Thread.CurrentThread.CurrentUICulture = new CultureInfo ("de");
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("MyResources", "Test/resources", null);
CreateFileBasedResourceManager ("MyResources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
ResourceSet rs = rm.GetResourceSet (new CultureInfo ("de"),
true, true);
rs.Dispose ();
@@ -545,7 +547,7 @@ namespace MonoTests.System.Resources
public void GetString ()
{
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("MyResources", "Test/resources", null);
CreateFileBasedResourceManager ("MyResources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
Assert.AreEqual ("Hello World", rm.GetString ("HelloWorld"), "#A1");
@@ -607,7 +609,7 @@ namespace MonoTests.System.Resources
public void GetString_ResourceSet_Disposed ()
{
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("MyResources", "Test/resources", null);
CreateFileBasedResourceManager ("MyResources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
ResourceSet rs = rm.GetResourceSet (new CultureInfo ("de"),
true, true);
rs.Dispose ();
@@ -622,7 +624,7 @@ namespace MonoTests.System.Resources
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("StreamTest", "Test/resources", null);
CreateFileBasedResourceManager ("StreamTest", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
UnmanagedMemoryStream s = rm.GetStream ("test");
Assert.AreEqual (22, s.Length, "#A1");
Assert.AreEqual ("veritas vos liberabit\n", new StreamReader (s).ReadToEnd (), "#A2");
@@ -647,7 +649,7 @@ namespace MonoTests.System.Resources
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("StreamTest", "Test/resources", null);
CreateFileBasedResourceManager ("StreamTest", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
UnmanagedMemoryStream s = rm.GetStream ("test", new CultureInfo ("ja-JP"));
Assert.AreEqual (22, s.Length, "#1");
Assert.AreEqual ("Veritas Vos Liberabit\n", new StreamReader (s).ReadToEnd (), "#2");
@@ -700,7 +702,7 @@ namespace MonoTests.System.Resources
public void GetStream_Resource_DoesNotExist ()
{
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("StreamTest", "Test/resources", null);
CreateFileBasedResourceManager ("StreamTest", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
Assert.IsNull (rm.GetStream ("HelloWorld"));
rm.ReleaseAllResources ();
}
@@ -710,7 +712,7 @@ namespace MonoTests.System.Resources
public void GetStream_Resource_NonStream ()
{
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("MyResources", "Test/resources", null);
CreateFileBasedResourceManager ("MyResources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
try {
rm.GetStream ("HelloWorld", CultureInfo.InvariantCulture);
@@ -730,7 +732,7 @@ namespace MonoTests.System.Resources
public void GetStream_ResourceFile_DoesNotExist ()
{
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("DoesNotExist", "Test/resources", null);
CreateFileBasedResourceManager ("DoesNotExist", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
try {
rm.GetStream ("HelloWorld");
Assert.Fail ("#1");
@@ -750,7 +752,7 @@ namespace MonoTests.System.Resources
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("StreamTest", "Test/resources", null);
CreateFileBasedResourceManager ("StreamTest", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
ResourceSet rs = rm.GetResourceSet (new CultureInfo ("ja-JP"),
true, true);
rs.Dispose ();
@@ -773,7 +775,7 @@ namespace MonoTests.System.Resources
public void IgnoreCase ()
{
ResourceManager rm = ResourceManager.
CreateFileBasedResourceManager ("MyResources", "Test/resources", null);
CreateFileBasedResourceManager ("MyResources", TestResourceHelper.GetFullPathOfResource ("Test/resources"), null);
Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;
Assert.IsFalse (rm.IgnoreCase, "#A1");
@@ -785,7 +787,6 @@ namespace MonoTests.System.Resources
}
[Test]
[Category ("SatelliteAssembliesNotWorking")]
public void TestSatellites ()
{
ResourceManager manager = new ResourceManager("Resources", GetType ().Assembly);

View File

@@ -16,6 +16,8 @@ using System.Resources;
using NUnit.Framework;
using MonoTests.Helpers;
namespace MonoTests.System.Resources
{
[TestFixture]
@@ -28,9 +30,8 @@ namespace MonoTests.System.Resources
[TestFixtureSetUp]
public void FixtureSetUp ()
{
string base_path = Path.Combine (Directory.GetCurrentDirectory (), Path.Combine ("Test", "resources"));
m_ResourceFile = Path.Combine (base_path, "MyResources.resources");
m_BadResourceFile = Path.Combine (base_path, "Empty.resources");
m_ResourceFile = TestResourceHelper.GetFullPathOfResource ("Test/resources/MyResources.resources");
m_BadResourceFile = TestResourceHelper.GetFullPathOfResource ("Test/resources/Empty.resources");
}
[SetUp]
@@ -231,7 +232,7 @@ namespace MonoTests.System.Resources
[Category ("MobileNotWorking")]
public void GetResourceDataNullName ()
{
ResourceReader r = new ResourceReader ("Test/resources/StreamTest.resources");
ResourceReader r = new ResourceReader (TestResourceHelper.GetFullPathOfResource ("Test/resources/StreamTest.resources"));
string type;
byte [] bytes;
@@ -257,7 +258,7 @@ namespace MonoTests.System.Resources
byte [] t2 = new byte [] {0x0A, 0x73, 0x6F, 0x6D, 0x65, 0x73, 0x74, 0x72, 0x69, 0x6E, 0x67};
byte [] t3 = new byte [] {0x0E, 0x00, 0x00, 0x00, 0x73, 0x68, 0x61, 0x72, 0x64, 0x65, 0x6E, 0x66, 0x72, 0x65, 0x75, 0x64, 0x65, 0x0A};
ResourceReader r = new ResourceReader ("Test/resources/StreamTest.resources");
ResourceReader r = new ResourceReader (TestResourceHelper.GetFullPathOfResource ("Test/resources/StreamTest.resources"));
Hashtable items = new Hashtable ();
foreach (DictionaryEntry de in r) {
string type;
@@ -307,7 +308,7 @@ namespace MonoTests.System.Resources
0x68, 0x74, 0x00, 0x00, 0x08, 0x08, 0x02, 0x00,
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x0B};
ResourceReader r = new ResourceReader ("Test/resources/bug81759.resources");
ResourceReader r = new ResourceReader (TestResourceHelper.GetFullPathOfResource ("Test/resources/bug81759.resources"));
string type;
byte [] bytes;
r.GetResourceData ("imageList.ImageSize", out type, out bytes);

View File

@@ -16,6 +16,8 @@ using System.Text;
using NUnit.Framework;
using MonoTests.Helpers;
namespace MonoTests.System.Resources
{
[TestFixture]
@@ -356,11 +358,11 @@ namespace MonoTests.System.Resources
stream.Write (buff, 0, buff.Length);
stream.Position = 0;
ResourceWriter rw = new ResourceWriter ("Test/resources/AddResource_Stream.resources");
ResourceWriter rw = new ResourceWriter (TestResourceHelper.GetFullPathOfResource ("Test/resources/AddResource_Stream.resources"));
rw.AddResource ("Name", (object)stream);
rw.Close ();
ResourceReader rr = new ResourceReader ("Test/resources/AddResource_Stream.resources");
ResourceReader rr = new ResourceReader (TestResourceHelper.GetFullPathOfResource ("Test/resources/AddResource_Stream.resources"));
IDictionaryEnumerator enumerator = rr.GetEnumerator ();
// Get the first element
@@ -587,7 +589,7 @@ namespace MonoTests.System.Resources
{
MemoryStream ms = new MemoryStream ();
using (ResourceReader xr = new ResourceReader (
"Test/resources/bug81759.resources")) {
TestResourceHelper.GetFullPathOfResource ("Test/resources/bug81759.resources"))) {
ResourceWriter rw = new ResourceWriter (ms);
foreach (DictionaryEntry de in xr)
rw.AddResource ((string) de.Key, de.Value);

View File

@@ -40,9 +40,8 @@ namespace MonoTests.System.Runtime.Remoting
[Test]
public void Bug46473 () // concurrent serialization/deserialization
{
bool success = true;
crossDomainSerializedObject = new CrossDomainSerializedObject();
Task[] tasks = new Task [20];
Task[] tasks = new Task [5];
for (int i = 0; i < tasks.Length; i++)
{
var assembly = Assembly.GetAssembly(typeof(AppDomainObject));
@@ -50,7 +49,7 @@ namespace MonoTests.System.Runtime.Remoting
tasks [i] = Task.Factory.StartNew(() => AppDomainWithRemotingSerialization(assembly, name));
}
Assert.IsTrue (Task.WaitAll (tasks, 5000));
Assert.IsTrue (Task.WaitAll (tasks, 20000));
}
#endif
}

View File

@@ -19,6 +19,8 @@ using DecoderException = System.Text.DecoderFallbackException;
using AssertType = NUnit.Framework.Assert;
using MonoTests.Helpers;
namespace MonoTests.System.Text
{
[TestFixture]
@@ -1043,9 +1045,7 @@ namespace MonoTests.System.Text
[Category ("MobileNotWorking")]
public void Bug415628 ()
{
DirectoryInfo bcl_output_dir = Directory.GetParent (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location)).Parent;
string namespace_dir = Path.Combine (bcl_output_dir.Parent.FullName, "corlib");
using (var f = File.Open (Path.Combine (namespace_dir, "Test/resources/415628.bin"), FileMode.Open)) {
using (var f = File.Open (TestResourceHelper.GetFullPathOfResource ("Test/resources/415628.bin"), FileMode.Open)) {
BinaryReader br = new BinaryReader (f);
byte [] buf = br.ReadBytes (8000);
Encoding.UTF8.GetString(buf);

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