Imported Upstream version 5.14.0.78

Former-commit-id: 3494343bcc9ddb42b36b82dd9ae7b69e85e0229f
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-05-10 08:37:03 +00:00
parent 74b74abd9f
commit 19234507ba
1776 changed files with 67755 additions and 31107 deletions

View File

@@ -2,9 +2,13 @@
<ItemGroup>
<Compile Include="*.cs" />
<ProjectReference Include="CpObj.ilproj" />
<IlcArg Include="-r:$(IntermediateOutputPath)\CpObj.dll" />
<ProjectReference Include="CpObj.ilproj" Condition="'$(OS)' == 'Windows_NT'" />
<IlcArg Include="-r:$(IntermediateOutputPath)\CpObj.dll" Condition="'$(OS)' == 'Windows_NT'" />
</ItemGroup>
<PropertyGroup Condition="'$(OS)' == 'Windows_NT'">
<DefineConstants>PLATFORM_WINDOWS;$(DefineConstants)</DefineConstants>
</PropertyGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), SimpleTest.targets))\SimpleTest.targets" />
</Project>

View File

@@ -4,7 +4,9 @@
using System;
using System.Runtime.InteropServices;
#if PLATFORM_WINDOWS
using CpObj;
#endif
internal static class Program
{
@@ -62,6 +64,18 @@ internal static class Program
var boxedStruct = (object)new BoxStubTest { Value = "Boxed Stub Test: Ok." };
PrintLine(boxedStruct.ToString());
int subResult = tempInt - 1;
if (subResult == 8)
{
PrintLine("Subtraction Test: Ok.");
}
int divResult = tempInt / 3;
if (divResult == 3)
{
PrintLine("Division Test: Ok.");
}
var not = Not(0xFFFFFFFF) == 0x00000000;
if (not)
{
@@ -110,6 +124,7 @@ internal static class Program
PrintLine("SwitchOpDefault test: Ok.");
}
#if PLATFORM_WINDOWS
var cpObjTestA = new TestValue { Field = 1234 };
var cpObjTestB = new TestValue { Field = 5678 };
CpObjTest.CpObj(ref cpObjTestB, ref cpObjTestA);
@@ -117,6 +132,98 @@ internal static class Program
{
PrintLine("CpObj test: Ok.");
}
#endif
Func<int> staticDelegate = StaticDelegateTarget;
if(staticDelegate() == 7)
{
PrintLine("Static delegate test: Ok.");
}
tempObj.TestInt = 8;
Func<int> instanceDelegate = tempObj.InstanceDelegateTarget;
if(instanceDelegate() == 8)
{
PrintLine("Instance delegate test: Ok.");
}
Action virtualDelegate = tempObj.VirtualDelegateTarget;
virtualDelegate();
var arrayTest = new BoxStubTest[] { new BoxStubTest { Value = "Hello" }, new BoxStubTest { Value = "Array" }, new BoxStubTest { Value = "Test" } };
foreach(var element in arrayTest)
PrintLine(element.Value);
arrayTest[1].Value = "Array load/store test: Ok.";
PrintLine(arrayTest[1].Value);
var largeArrayTest = new long[] { Int64.MaxValue, 0, Int64.MinValue, 0 };
if(largeArrayTest[0] == Int64.MaxValue &&
largeArrayTest[1] == 0 &&
largeArrayTest[2] == Int64.MinValue &&
largeArrayTest[3] == 0)
{
PrintLine("Large array load/store test: Ok.");
}
var smallArrayTest = new long[] { Int16.MaxValue, 0, Int16.MinValue, 0 };
if(smallArrayTest[0] == Int16.MaxValue &&
smallArrayTest[1] == 0 &&
smallArrayTest[2] == Int16.MinValue &&
smallArrayTest[3] == 0)
{
PrintLine("Small array load/store test: Ok.");
}
IntPtr returnedIntPtr = NewobjValueType();
if (returnedIntPtr.ToInt32() == 3)
{
PrintLine("Newobj value type test: Ok.");
}
StackallocTest();
IntToStringTest();
CastingTestClass castingTest = new DerivedCastingTestClass1();
if (((DerivedCastingTestClass1)castingTest).GetValue() == 1 && !(castingTest is DerivedCastingTestClass2))
{
PrintLine("Type casting with isinst & castclass to class test: Ok.");
}
// Instead of checking the result of `GetValue`, we use null check by now until interface dispatch is implemented.
if ((ICastingTest1)castingTest != null && !(castingTest is ICastingTest2))
{
PrintLine("Type casting with isinst & castclass to interface test: Ok.");
}
object arrayCastingTest = new BoxStubTest[] { new BoxStubTest { Value = "Array" }, new BoxStubTest { Value = "Cast" }, new BoxStubTest { Value = "Test" } };
PrintLine(((BoxStubTest[])arrayCastingTest)[0].Value);
PrintLine(((BoxStubTest[])arrayCastingTest)[1].Value);
PrintLine(((BoxStubTest[])arrayCastingTest)[2].Value);
if (!(arrayCastingTest is CastingTestClass[]))
{
PrintLine("Type casting with isinst & castclass to array test: Ok.");
}
ldindTest();
System.Diagnostics.Debugger.Break();
var testRuntimeHelpersInitArray = new long[] {1, 2, 3};
if(testRuntimeHelpersInitArray[0] == 1 &&
testRuntimeHelpersInitArray[1] == 2 &&
testRuntimeHelpersInitArray[2] == 3)
{
PrintLine("Runtime.Helpers array initialization test: Ok.");
}
PrintLine("Done");
}
private static int StaticDelegateTarget()
{
return 7;
}
private static unsafe void PrintString(string s)
@@ -186,6 +293,59 @@ internal static class Program
}
}
private static IntPtr NewobjValueType()
{
return new IntPtr(3);
}
private unsafe static void StackallocTest()
{
int* intSpan = stackalloc int[2];
intSpan[0] = 3;
intSpan[1] = 7;
if (intSpan[0] == 3 && intSpan[1] == 7)
{
PrintLine("Stackalloc test: Ok.");
}
}
private static void IntToStringTest()
{
PrintLine("Int to String Test: Ok if next line says 42.");
string intString = 42.ToString();
PrintLine(intString);
}
private unsafe static void ldindTest()
{
var ldindTarget = new TwoByteStr { first = byte.MaxValue, second = byte.MinValue };
var ldindField = &ldindTarget.first;
if((*ldindField) == byte.MaxValue)
{
ldindTarget.second = byte.MaxValue;
*ldindField = byte.MinValue;
//ensure there isnt any overwrite of nearby fields
if(ldindTarget.first == byte.MinValue && ldindTarget.second == byte.MaxValue)
{
PrintLine("ldind test: Ok.");
}
else if(ldindTarget.first != byte.MinValue)
{
PrintLine("ldind test: Failed didnt update target.");
}
else
{
PrintLine("ldind test: Failed overwrote data");
}
}
else
{
uint ldindFieldValue = *ldindField;
PrintLine("ldind test: Failed." + ldindFieldValue.ToString());
}
}
[DllImport("*")]
private static unsafe extern int printf(byte* str, byte* unused);
}
@@ -203,11 +363,19 @@ public struct BoxStubTest
{
return Value;
}
public string GetValue()
{
Program.PrintLine("BoxStubTest.GetValue called");
Program.PrintLine(Value);
return Value;
}
}
public class TestClass
{
public string TestString {get; set;}
public string TestString { get; set; }
public int TestInt { get; set; }
public TestClass(int number)
{
@@ -230,6 +398,16 @@ public class TestClass
{
Program.PrintLine("Virtual Slot Test 2: Ok");
}
public int InstanceDelegateTarget()
{
return TestInt;
}
public virtual void VirtualDelegateTarget()
{
Program.PrintLine("Virtual delegate incorrectly dispatched to base.");
}
}
public class TestDerivedClass : TestClass
@@ -248,5 +426,34 @@ public class TestDerivedClass : TestClass
{
throw new Exception();
}
public override void VirtualDelegateTarget()
{
Program.PrintLine("Virtual Delegate Test: Ok");
}
}
public interface ICastingTest1
{
int GetValue();
}
public interface ICastingTest2
{
int GetValue();
}
public abstract class CastingTestClass
{
public abstract int GetValue();
}
public class DerivedCastingTestClass1 : CastingTestClass, ICastingTest1
{
public override int GetValue() => 1;
}
public class DerivedCastingTestClass2 : CastingTestClass, ICastingTest2
{
public override int GetValue() => 2;
}

View File

@@ -1 +0,0 @@
Doesn't work on OSX.

View File

@@ -19,7 +19,7 @@
</PropertyGroup>
<ItemGroup>
<AdditionalNativeLibrary Include="$(PInvokeNativeObject)" />
<NativeLibrary Include="$(PInvokeNativeObject)" />
</ItemGroup>

View File

@@ -423,6 +423,21 @@ internal class ReflectionTest
}
}
class Gen<T> { }
interface IFoo<out T>
{
string Frob();
}
class Foo<T> : IFoo<Gen<T>>
{
public string Frob()
{
return typeof(T).ToString();
}
}
public static void Run()
{
Console.WriteLine(nameof(TestInterfaceMethod));
@@ -431,11 +446,16 @@ internal class ReflectionTest
if (string.Empty.Length > 0)
{
((IFoo)new Foo()).Frob(1);
((IFoo<object>)new Foo<string>()).Frob();
}
object result = InvokeTestMethod(typeof(IFoo), "Frob", new Foo(), 42);
if ((string)result != "42")
throw new Exception();
result = InvokeTestMethod(typeof(IFoo<object>), "Frob", new Foo<string>());
if ((string)result != "System.String")
throw new Exception();
}
}