You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="Build">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<AssemblyName>System.Private.Reflection.Metadata</AssemblyName>
|
||||
<AssemblyVersion>4.0.0.0</AssemblyVersion>
|
||||
<OutputType>Library</OutputType>
|
||||
<ProjectGuid>{45A617DF-FEC7-59C8-FD0D-BD27938DC940}</ProjectGuid>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<!-- Ignore the CLSCompliance of the generated cs files we are using here -->
|
||||
<NoWarn>$(NoWarn);3003</NoWarn>
|
||||
<CLSCompliant>false</CLSCompliant>
|
||||
</PropertyGroup>
|
||||
|
||||
<!-- Default configurations to help VS understand the options -->
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'" />
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\System.Private.CoreLib\src\System.Private.CoreLib.csproj" />
|
||||
<ProjectReference Include="..\..\AotPackageReference\AotPackageReference.depproj">
|
||||
<ReferenceOutputAssembly>false</ReferenceOutputAssembly>
|
||||
</ProjectReference>
|
||||
|
||||
<ReferencePath Include="$(AotPackageReferencePath)\System.Runtime.dll" />
|
||||
<ReferencePath Include="$(AotPackageReferencePath)\System.Runtime.Extensions.dll" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<NativeFormatCommonPath>..\..\Common\src\Internal\NativeFormat</NativeFormatCommonPath>
|
||||
<MetadataCommonPath>..\..\Common\src\Internal\Metadata\NativeFormat</MetadataCommonPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(NativeFormatCommonPath)\NativeFormat.cs" />
|
||||
<Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.cs" />
|
||||
<Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.Primitives.cs" />
|
||||
<Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.String.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MetadataCommonPath)\NativeFormatReaderCommonGen.cs" />
|
||||
<Compile Include="$(MetadataCommonPath)\MdBinaryReader.cs" />
|
||||
<Compile Include="$(MetadataCommonPath)\MdBinaryReaderGen.cs" />
|
||||
<Compile Include="$(MetadataCommonPath)\NativeMetadataReader.cs" />
|
||||
<Compile Include="$(MetadataCommonPath)\NativeFormatReaderGen.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
202
external/corert/src/System.Private.Reflection.Metadata/tests/HashCodeTests.cs
vendored
Normal file
202
external/corert/src/System.Private.Reflection.Metadata/tests/HashCodeTests.cs
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
// Need to use "extern alias", because both the writer and reader define types with same names.
|
||||
extern alias writer;
|
||||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using Xunit;
|
||||
|
||||
using Reader = Internal.Metadata.NativeFormat;
|
||||
using Writer = writer.Internal.Metadata.NativeFormat.Writer;
|
||||
|
||||
using TypeAttributes = System.Reflection.TypeAttributes;
|
||||
using MetadataTypeHashingAlgorithms = Internal.Metadata.NativeFormat.MetadataTypeHashingAlgorithms;
|
||||
using TypeHashingAlgorithms = Internal.NativeFormat.TypeHashingAlgorithms;
|
||||
|
||||
namespace System.Private.Reflection.Metadata.Tests
|
||||
{
|
||||
public class HashCodeTests
|
||||
{
|
||||
private static Writer.ScopeDefinition BuildSimpleTestDefinitionData()
|
||||
{
|
||||
// Scope for System.Runtime, 4.0.0.0
|
||||
var systemRuntimeScope = new Writer.ScopeDefinition
|
||||
{
|
||||
Name = (Writer.ConstantStringValue)"System.Runtime",
|
||||
MajorVersion = 4,
|
||||
};
|
||||
|
||||
// Root namespace (".")
|
||||
var rootNamespaceDefinition = new Writer.NamespaceDefinition
|
||||
{
|
||||
ParentScopeOrNamespace = systemRuntimeScope,
|
||||
};
|
||||
systemRuntimeScope.RootNamespaceDefinition = rootNamespaceDefinition;
|
||||
|
||||
// The <Module> type
|
||||
var moduleTypeDefinition = new Writer.TypeDefinition
|
||||
{
|
||||
Flags = TypeAttributes.Abstract | TypeAttributes.Public,
|
||||
Name = (Writer.ConstantStringValue)"<Module>",
|
||||
NamespaceDefinition = rootNamespaceDefinition,
|
||||
};
|
||||
rootNamespaceDefinition.TypeDefinitions.Add(moduleTypeDefinition);
|
||||
|
||||
// System namespace
|
||||
var systemNamespaceDefinition = new Writer.NamespaceDefinition
|
||||
{
|
||||
Name = (Writer.ConstantStringValue)"System",
|
||||
ParentScopeOrNamespace = rootNamespaceDefinition,
|
||||
};
|
||||
rootNamespaceDefinition.NamespaceDefinitions.Add(systemNamespaceDefinition);
|
||||
|
||||
// System.Object type
|
||||
var objectType = new Writer.TypeDefinition
|
||||
{
|
||||
Flags = TypeAttributes.Public | TypeAttributes.SequentialLayout,
|
||||
Name = (Writer.ConstantStringValue)"Object",
|
||||
NamespaceDefinition = systemNamespaceDefinition
|
||||
};
|
||||
systemNamespaceDefinition.TypeDefinitions.Add(objectType);
|
||||
|
||||
// System.Object+Nested type
|
||||
var nestedType = new Writer.TypeDefinition
|
||||
{
|
||||
Flags = TypeAttributes.SequentialLayout | TypeAttributes.NestedPublic,
|
||||
Name = (Writer.ConstantStringValue)"Nested",
|
||||
NamespaceDefinition = null,
|
||||
EnclosingType = objectType
|
||||
};
|
||||
objectType.NestedTypes.Add(nestedType);
|
||||
|
||||
// System.Object+Nested+ReallyNested type
|
||||
var reallyNestedType = new Writer.TypeDefinition
|
||||
{
|
||||
Flags = TypeAttributes.SequentialLayout | TypeAttributes.NestedPublic,
|
||||
Name = (Writer.ConstantStringValue)"ReallyNested",
|
||||
NamespaceDefinition = null,
|
||||
EnclosingType = nestedType
|
||||
};
|
||||
nestedType.NestedTypes.Add(reallyNestedType);
|
||||
|
||||
return systemRuntimeScope;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public unsafe void TestDefinitionHashCodes()
|
||||
{
|
||||
var wr = new Writer.MetadataWriter();
|
||||
wr.ScopeDefinitions.Add(BuildSimpleTestDefinitionData());
|
||||
var ms = new MemoryStream();
|
||||
wr.Write(ms);
|
||||
|
||||
fixed (byte* pBuffer = ms.ToArray())
|
||||
{
|
||||
var rd = new Reader.MetadataReader((IntPtr)pBuffer, (int)ms.Length);
|
||||
|
||||
Reader.ScopeDefinitionHandle scopeHandle = rd.ScopeDefinitions.Single();
|
||||
Reader.ScopeDefinition systemRuntimeScope = scopeHandle.GetScopeDefinition(rd);
|
||||
|
||||
// Validate root type hash code
|
||||
Reader.NamespaceDefinition rootNamespace = systemRuntimeScope.RootNamespaceDefinition.GetNamespaceDefinition(rd);
|
||||
Reader.TypeDefinitionHandle moduleTypeHandle = rootNamespace.TypeDefinitions.Single();
|
||||
Assert.Equal(TypeHashingAlgorithms.ComputeNameHashCode("<Module>"), MetadataTypeHashingAlgorithms.ComputeHashCode(moduleTypeHandle, rd));
|
||||
|
||||
// Validate namespace type hashcode
|
||||
Reader.NamespaceDefinition systemNamespace = rootNamespace.NamespaceDefinitions.Single().GetNamespaceDefinition(rd);
|
||||
Reader.TypeDefinitionHandle objectTypeHandle = systemNamespace.TypeDefinitions.Single();
|
||||
int objectHashCode = TypeHashingAlgorithms.ComputeNameHashCode("System.Object");
|
||||
Assert.Equal(objectHashCode, MetadataTypeHashingAlgorithms.ComputeHashCode(objectTypeHandle, rd));
|
||||
|
||||
// Validate nested type hashcode
|
||||
Reader.TypeDefinitionHandle nestedTypeHandle = objectTypeHandle.GetTypeDefinition(rd).NestedTypes.Single();
|
||||
int nestedHashCode = TypeHashingAlgorithms.ComputeNestedTypeHashCode(objectHashCode, TypeHashingAlgorithms.ComputeNameHashCode("Nested"));
|
||||
Assert.Equal(nestedHashCode, MetadataTypeHashingAlgorithms.ComputeHashCode(nestedTypeHandle, rd));
|
||||
|
||||
// Validate really nested type hashcode
|
||||
Reader.TypeDefinitionHandle reallyNestedTypeHandle = nestedTypeHandle.GetTypeDefinition(rd).NestedTypes.Single();
|
||||
int reallyNestedHashCode = TypeHashingAlgorithms.ComputeNestedTypeHashCode(nestedHashCode, TypeHashingAlgorithms.ComputeNameHashCode("ReallyNested"));
|
||||
Assert.Equal(reallyNestedHashCode, MetadataTypeHashingAlgorithms.ComputeHashCode(reallyNestedTypeHandle, rd));
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public unsafe void TestReferenceHashCodes()
|
||||
{
|
||||
var wr = new Writer.MetadataWriter();
|
||||
|
||||
var systemRuntimeScopeRecord = new Writer.ScopeReference
|
||||
{
|
||||
Name = (Writer.ConstantStringValue)"System.Runtime",
|
||||
MajorVersion = 4,
|
||||
};
|
||||
|
||||
var rootNamespaceRecord = new Writer.NamespaceReference
|
||||
{
|
||||
Name = null,
|
||||
ParentScopeOrNamespace = systemRuntimeScopeRecord,
|
||||
};
|
||||
|
||||
var fooTypeRecord = new Writer.TypeReference
|
||||
{
|
||||
ParentNamespaceOrType = rootNamespaceRecord,
|
||||
TypeName = (Writer.ConstantStringValue)"Foo",
|
||||
};
|
||||
|
||||
var nestedTypeRecord = new Writer.TypeReference
|
||||
{
|
||||
ParentNamespaceOrType = fooTypeRecord,
|
||||
TypeName = (Writer.ConstantStringValue)"Nested",
|
||||
};
|
||||
|
||||
var reallyNestedTypeRecord = new Writer.TypeReference
|
||||
{
|
||||
ParentNamespaceOrType = nestedTypeRecord,
|
||||
TypeName = (Writer.ConstantStringValue)"ReallyNested",
|
||||
};
|
||||
|
||||
var systemNamespaceRecord = new Writer.NamespaceReference
|
||||
{
|
||||
Name = (Writer.ConstantStringValue)"System",
|
||||
ParentScopeOrNamespace = rootNamespaceRecord,
|
||||
};
|
||||
|
||||
var objectTypeRecord = new Writer.TypeReference
|
||||
{
|
||||
ParentNamespaceOrType = systemNamespaceRecord,
|
||||
TypeName = (Writer.ConstantStringValue)"Object",
|
||||
};
|
||||
|
||||
wr.AdditionalRootRecords.Add(objectTypeRecord);
|
||||
wr.AdditionalRootRecords.Add(fooTypeRecord);
|
||||
wr.AdditionalRootRecords.Add(nestedTypeRecord);
|
||||
wr.AdditionalRootRecords.Add(reallyNestedTypeRecord);
|
||||
var ms = new MemoryStream();
|
||||
wr.Write(ms);
|
||||
|
||||
fixed (byte* pBuffer = ms.ToArray())
|
||||
{
|
||||
var rd = new Reader.MetadataReader((IntPtr)pBuffer, (int)ms.Length);
|
||||
|
||||
var fooTypeHandle = new Reader.TypeReferenceHandle(wr.GetRecordHandle(fooTypeRecord));
|
||||
var fooTypeHashCode = TypeHashingAlgorithms.ComputeNameHashCode("Foo");
|
||||
Assert.Equal(fooTypeHashCode, MetadataTypeHashingAlgorithms.ComputeHashCode(fooTypeHandle, rd));
|
||||
|
||||
var objectTypeHandle = new Reader.TypeReferenceHandle(wr.GetRecordHandle(objectTypeRecord));
|
||||
Assert.Equal(TypeHashingAlgorithms.ComputeNameHashCode("System.Object"), MetadataTypeHashingAlgorithms.ComputeHashCode(objectTypeHandle, rd));
|
||||
|
||||
var nestedTypeHandle = new Reader.TypeReferenceHandle(wr.GetRecordHandle(nestedTypeRecord));
|
||||
var nestedTypeHashCode = TypeHashingAlgorithms.ComputeNestedTypeHashCode(fooTypeHashCode, TypeHashingAlgorithms.ComputeNameHashCode("Nested"));
|
||||
Assert.Equal(nestedTypeHashCode , MetadataTypeHashingAlgorithms.ComputeHashCode(nestedTypeHandle, rd));
|
||||
|
||||
var reallyNestedTypeHandle = new Reader.TypeReferenceHandle(wr.GetRecordHandle(reallyNestedTypeRecord));
|
||||
var reallyNestedTypeHashCode = TypeHashingAlgorithms.ComputeNestedTypeHashCode(nestedTypeHashCode, TypeHashingAlgorithms.ComputeNameHashCode("ReallyNested"));
|
||||
Assert.Equal(reallyNestedTypeHashCode, MetadataTypeHashingAlgorithms.ComputeHashCode(reallyNestedTypeHandle, rd));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
239
external/corert/src/System.Private.Reflection.Metadata/tests/RoundTripTests.cs
vendored
Normal file
239
external/corert/src/System.Private.Reflection.Metadata/tests/RoundTripTests.cs
vendored
Normal file
@@ -0,0 +1,239 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
// Need to use "extern alias", because both the writer and reader define types with same names.
|
||||
extern alias writer;
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
using Xunit;
|
||||
|
||||
using Reader = Internal.Metadata.NativeFormat;
|
||||
using Writer = writer.Internal.Metadata.NativeFormat.Writer;
|
||||
|
||||
using TypeAttributes = System.Reflection.TypeAttributes;
|
||||
using MethodAttributes = System.Reflection.MethodAttributes;
|
||||
using CallingConventions = System.Reflection.CallingConventions;
|
||||
|
||||
namespace System.Private.Reflection.Metadata.Tests
|
||||
{
|
||||
/// <summary>
|
||||
/// Tests for metadata roundtripping. We emit a metadata blob, and read it back
|
||||
/// to check if it has expected values.
|
||||
/// </summary>
|
||||
public class RoundTripTests
|
||||
{
|
||||
/// <summary>
|
||||
/// Builds a graph of simple metadata test data.
|
||||
/// </summary>
|
||||
private static Writer.ScopeDefinition BuildSimpleTestData()
|
||||
{
|
||||
// Scope for System.Runtime, 4.0.0.0
|
||||
var systemRuntimeScope = new Writer.ScopeDefinition
|
||||
{
|
||||
Name = (Writer.ConstantStringValue)"System.Runtime",
|
||||
MajorVersion = 4,
|
||||
};
|
||||
|
||||
// Root namespace (".")
|
||||
var rootNamespaceDefinition = new Writer.NamespaceDefinition
|
||||
{
|
||||
ParentScopeOrNamespace = systemRuntimeScope,
|
||||
};
|
||||
systemRuntimeScope.RootNamespaceDefinition = rootNamespaceDefinition;
|
||||
|
||||
// The <Module> type
|
||||
var moduleTypeDefinition = new Writer.TypeDefinition
|
||||
{
|
||||
Flags = TypeAttributes.Abstract | TypeAttributes.Public,
|
||||
Name = (Writer.ConstantStringValue)"<Module>",
|
||||
NamespaceDefinition = rootNamespaceDefinition,
|
||||
};
|
||||
rootNamespaceDefinition.TypeDefinitions.Add(moduleTypeDefinition);
|
||||
|
||||
// System namespace
|
||||
var systemNamespaceDefinition = new Writer.NamespaceDefinition
|
||||
{
|
||||
Name = (Writer.ConstantStringValue)"System",
|
||||
ParentScopeOrNamespace = rootNamespaceDefinition,
|
||||
};
|
||||
rootNamespaceDefinition.NamespaceDefinitions.Add(systemNamespaceDefinition);
|
||||
|
||||
// System.Object type
|
||||
var objectType = new Writer.TypeDefinition
|
||||
{
|
||||
Flags = TypeAttributes.Public | TypeAttributes.SequentialLayout,
|
||||
Name = (Writer.ConstantStringValue)"Object",
|
||||
NamespaceDefinition = systemNamespaceDefinition
|
||||
};
|
||||
systemNamespaceDefinition.TypeDefinitions.Add(objectType);
|
||||
|
||||
// System.ValueType type
|
||||
var valueTypeType = new Writer.TypeDefinition
|
||||
{
|
||||
BaseType = objectType,
|
||||
Flags = TypeAttributes.Public,
|
||||
Name = (Writer.ConstantStringValue)"ValueType",
|
||||
NamespaceDefinition = systemNamespaceDefinition
|
||||
};
|
||||
systemNamespaceDefinition.TypeDefinitions.Add(valueTypeType);
|
||||
|
||||
// System.Void type
|
||||
var voidType = new Writer.TypeDefinition
|
||||
{
|
||||
BaseType = valueTypeType,
|
||||
Flags = TypeAttributes.Public,
|
||||
Name = (Writer.ConstantStringValue)"Void",
|
||||
NamespaceDefinition = systemNamespaceDefinition
|
||||
};
|
||||
systemNamespaceDefinition.TypeDefinitions.Add(voidType);
|
||||
|
||||
// System.String type
|
||||
var stringType = new Writer.TypeDefinition
|
||||
{
|
||||
BaseType = objectType,
|
||||
Flags = TypeAttributes.Public,
|
||||
Name = (Writer.ConstantStringValue)"String",
|
||||
NamespaceDefinition = systemNamespaceDefinition
|
||||
};
|
||||
systemNamespaceDefinition.TypeDefinitions.Add(stringType);
|
||||
|
||||
// System.Object..ctor() method
|
||||
var objectCtorMethod = new Writer.Method
|
||||
{
|
||||
Flags = MethodAttributes.Public
|
||||
| MethodAttributes.RTSpecialName
|
||||
| MethodAttributes.SpecialName,
|
||||
Name = (Writer.ConstantStringValue)".ctor",
|
||||
Signature = new Writer.MethodSignature
|
||||
{
|
||||
CallingConvention = CallingConventions.HasThis,
|
||||
ReturnType = voidType,
|
||||
},
|
||||
};
|
||||
objectType.Methods.Add(objectCtorMethod);
|
||||
|
||||
// System.String..ctor() method
|
||||
var stringCtorMethod = new Writer.Method
|
||||
{
|
||||
Flags = MethodAttributes.Public
|
||||
| MethodAttributes.RTSpecialName
|
||||
| MethodAttributes.SpecialName,
|
||||
Name = (Writer.ConstantStringValue)".ctor",
|
||||
Signature = new Writer.MethodSignature
|
||||
{
|
||||
CallingConvention = CallingConventions.HasThis,
|
||||
ReturnType = voidType,
|
||||
},
|
||||
};
|
||||
stringType.Methods.Add(stringCtorMethod);
|
||||
|
||||
return systemRuntimeScope;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static unsafe void TestSimpleRoundTripping()
|
||||
{
|
||||
var wr = new Writer.MetadataWriter();
|
||||
wr.ScopeDefinitions.Add(BuildSimpleTestData());
|
||||
var ms = new MemoryStream();
|
||||
wr.Write(ms);
|
||||
|
||||
fixed (byte* pBuffer = ms.ToArray())
|
||||
{
|
||||
var rd = new Reader.MetadataReader((IntPtr)pBuffer, (int)ms.Length);
|
||||
|
||||
// Validate the System.Runtime scope
|
||||
Reader.ScopeDefinitionHandle scopeHandle = rd.ScopeDefinitions.Single();
|
||||
Reader.ScopeDefinition systemRuntimeScope = scopeHandle.GetScopeDefinition(rd);
|
||||
Assert.Equal(4, systemRuntimeScope.MajorVersion);
|
||||
Assert.Equal("System.Runtime", systemRuntimeScope.Name.GetConstantStringValue(rd).Value);
|
||||
|
||||
// Validate the root namespace and <Module> type
|
||||
Reader.NamespaceDefinition rootNamespace = systemRuntimeScope.RootNamespaceDefinition.GetNamespaceDefinition(rd);
|
||||
Assert.Equal(1, rootNamespace.TypeDefinitions.Count());
|
||||
Reader.TypeDefinition moduleType = rootNamespace.TypeDefinitions.Single().GetTypeDefinition(rd);
|
||||
Assert.Equal("<Module>", moduleType.Name.GetConstantStringValue(rd).Value);
|
||||
Assert.Equal(1, rootNamespace.NamespaceDefinitions.Count());
|
||||
|
||||
// Validate the System namespace
|
||||
Reader.NamespaceDefinition systemNamespace = rootNamespace.NamespaceDefinitions.Single().GetNamespaceDefinition(rd);
|
||||
Assert.Equal(4, systemNamespace.TypeDefinitions.Count());
|
||||
foreach (var typeHandle in systemNamespace.TypeDefinitions)
|
||||
{
|
||||
Reader.TypeDefinition type = typeHandle.GetTypeDefinition(rd);
|
||||
string typeName = type.Name.GetConstantStringValue(rd).Value;
|
||||
|
||||
string baseTypeName = null;
|
||||
if (!type.BaseType.IsNull(rd))
|
||||
{
|
||||
baseTypeName = type.BaseType.ToTypeDefinitionHandle(rd).GetTypeDefinition(rd).Name.GetConstantStringValue(rd).Value;
|
||||
}
|
||||
|
||||
switch (typeName)
|
||||
{
|
||||
case "Object":
|
||||
Assert.Null(baseTypeName);
|
||||
Assert.Equal(1, type.Methods.Count());
|
||||
break;
|
||||
case "Void":
|
||||
Assert.Equal("ValueType", baseTypeName);
|
||||
Assert.Equal(0, type.Methods.Count());
|
||||
break;
|
||||
case "String":
|
||||
Assert.Equal("Object", baseTypeName);
|
||||
Assert.Equal(1, type.Methods.Count());
|
||||
break;
|
||||
case "ValueType":
|
||||
Assert.Equal("Object", baseTypeName);
|
||||
Assert.Equal(0, type.Methods.Count());
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public static unsafe void TestCommonTailOptimization()
|
||||
{
|
||||
var wr = new Writer.MetadataWriter();
|
||||
wr.ScopeDefinitions.Add(BuildSimpleTestData());
|
||||
var ms = new MemoryStream();
|
||||
wr.Write(ms);
|
||||
|
||||
fixed (byte* pBuffer = ms.ToArray())
|
||||
{
|
||||
var rd = new Reader.MetadataReader((IntPtr)pBuffer, (int)ms.Length);
|
||||
|
||||
Reader.ScopeDefinitionHandle scopeHandle = rd.ScopeDefinitions.Single();
|
||||
Reader.ScopeDefinition systemRuntimeScope = scopeHandle.GetScopeDefinition(rd);
|
||||
Reader.NamespaceDefinition rootNamespace = systemRuntimeScope.RootNamespaceDefinition.GetNamespaceDefinition(rd);
|
||||
Reader.NamespaceDefinition systemNamespace =
|
||||
rootNamespace.NamespaceDefinitions.Single(
|
||||
ns => ns.GetNamespaceDefinition(rd).Name.StringEquals("System", rd)
|
||||
).GetNamespaceDefinition(rd);
|
||||
|
||||
// This validates the common tail optimization.
|
||||
// Since both System.Object and System.String define a default constructor and the
|
||||
// records are structurally equivalent, there should only be one metadata record
|
||||
// representing a default .ctor in the blob.
|
||||
Reader.TypeDefinition objectType = systemNamespace.TypeDefinitions.Single(
|
||||
t => t.GetTypeDefinition(rd).Name.StringEquals("Object", rd)
|
||||
).GetTypeDefinition(rd);
|
||||
Reader.TypeDefinition stringType = systemNamespace.TypeDefinitions.Single(
|
||||
t => t.GetTypeDefinition(rd).Name.StringEquals("String", rd)
|
||||
).GetTypeDefinition(rd);
|
||||
|
||||
Reader.MethodHandle objectCtor = objectType.Methods.Single();
|
||||
Reader.MethodHandle stringCtor = stringType.Methods.Single();
|
||||
|
||||
Assert.True(objectCtor.Equals(stringCtor));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{3A6D978E-156A-4BFF-B394-7F6F6BB22AE1}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AssemblyName>System.Private.Reflection.Metadata.Tests</AssemblyName>
|
||||
<RootNamespace>System.Private.Reflection.Metadata.Tests</RootNamespace>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<NugetTargetMoniker>.NETStandard,Version=v1.3</NugetTargetMoniker>
|
||||
<TestTFM>netcoreapp1.0</TestTFM>
|
||||
</PropertyGroup>
|
||||
<!-- Default configurations to help VS understand the configurations -->
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<NativeFormatCommonPath>..\..\Common\src\Internal\NativeFormat</NativeFormatCommonPath>
|
||||
<MetadataCommonPath>..\..\Common\src\Internal\Metadata\NativeFormat</MetadataCommonPath>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(NativeFormatCommonPath)\NativeFormat.cs" />
|
||||
<Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.cs" />
|
||||
<Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.Primitives.cs" />
|
||||
<Compile Include="$(NativeFormatCommonPath)\NativeFormatReader.String.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="$(MetadataCommonPath)\NativeFormatReaderCommonGen.cs" />
|
||||
<Compile Include="$(MetadataCommonPath)\MdBinaryReader.cs" />
|
||||
<Compile Include="$(MetadataCommonPath)\MdBinaryReaderGen.cs" />
|
||||
<Compile Include="$(MetadataCommonPath)\NativeMetadataReader.cs" />
|
||||
<Compile Include="$(MetadataCommonPath)\NativeFormatReaderGen.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ILCompiler.MetadataWriter\src\ILCompiler.MetadataWriter.csproj">
|
||||
<Project>{D66338D4-F9E4-4051-B302-232C6BFB6EF6}</Project>
|
||||
<Name>ILCompiler.MetadataWriter</Name>
|
||||
<Aliases>writer</Aliases>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\Common\src\Internal\Metadata\NativeFormat\MetadataTypeHashingAlgorithms.cs">
|
||||
<Link>MetadataTypeHashingAlgorithms.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\Common\src\System\FormattingHelpers.cs">
|
||||
<Link>FormattingHelpers.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\..\Common\src\TypeSystem\Common\TypeHashingAlgorithms.cs">
|
||||
<Link>TypeHashingAlgorithms.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="HashCodeTests.cs" />
|
||||
<Compile Include="RoundTripTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
|
||||
</Project>
|
||||
17
external/corert/src/System.Private.Reflection.Metadata/tests/project.json
vendored
Normal file
17
external/corert/src/System.Private.Reflection.Metadata/tests/project.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.6.0",
|
||||
"Microsoft.NETCore.Platforms": "1.0.2-beta-24522-03",
|
||||
"Microsoft.DotNet.BuildTools.TestSuite": "1.0.0-prerelease-00807-03",
|
||||
"test-runtime": {
|
||||
"target": "project",
|
||||
"exclude": "compile"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.3": { }
|
||||
},
|
||||
"supports": {
|
||||
"coreFx.Test.netcoreapp1.0": { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user