This repository was archived by the owner on Nov 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 503
Add field layout tests #30
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/TypeSystem/tests/CoreTestAssembly/CoreTestAssembly.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| <?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> | ||
| <OutputType>Library</OutputType> | ||
| <AssemblyName>CoreTestAssembly</AssemblyName> | ||
|
|
||
| <GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
| <IsCoreAssembly>true</IsCoreAssembly> | ||
|
|
||
| <!-- | ||
| Need to avoid target platform being empty because that would drag in an mscorlib design-time | ||
| facade into the references and break us. | ||
| --> | ||
| <TargetPlatformIdentifier>Portable</TargetPlatformIdentifier> | ||
| <TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier> | ||
| <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> | ||
| <TargetFrameworkProfile>Profile7</TargetFrameworkProfile> | ||
| <TargetFrameworkMonikerDisplayName>.NET Portable Subset</TargetFrameworkMonikerDisplayName> | ||
| <ImplicitlyExpandTargetFramework>false</ImplicitlyExpandTargetFramework> | ||
|
|
||
| </PropertyGroup> | ||
|
|
||
| <!-- Default configurations to help VS understand the configurations --> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
| </PropertyGroup> | ||
| <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Platform.cs" /> | ||
| <Compile Include="InstanceFieldLayout.cs" /> | ||
| </ItemGroup> | ||
|
|
||
| <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> | ||
| </Project> |
132 changes: 132 additions & 0 deletions
132
src/TypeSystem/tests/CoreTestAssembly/InstanceFieldLayout.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,132 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System; | ||
| using System.Runtime.InteropServices; | ||
|
|
||
| #pragma warning disable 169 | ||
|
|
||
| namespace ContainsPointers | ||
| { | ||
| struct NoPointers | ||
| { | ||
| int int1; | ||
| byte byte1; | ||
| char char1; | ||
| } | ||
|
|
||
| struct StillNoPointers | ||
| { | ||
| NoPointers noPointers1; | ||
| bool bool1; | ||
| } | ||
|
|
||
| class ClassNoPointers | ||
| { | ||
| char char1; | ||
| } | ||
|
|
||
| struct HasPointers | ||
| { | ||
| string string1; | ||
| } | ||
|
|
||
| struct FieldHasPointers | ||
| { | ||
| HasPointers hasPointers1; | ||
| } | ||
|
|
||
| class ClassHasPointers | ||
| { | ||
| ClassHasPointers classHasPointers1; | ||
| } | ||
|
|
||
| class BaseClassHasPointers : ClassHasPointers | ||
| { | ||
| } | ||
|
|
||
| public class ClassHasIntArray | ||
| { | ||
| int[] intArrayField; | ||
| } | ||
|
|
||
| public class ClassHasArrayOfClassType | ||
| { | ||
| ClassNoPointers[] classTypeArray; | ||
| } | ||
| } | ||
|
|
||
| namespace Explicit | ||
| { | ||
| [StructLayout(LayoutKind.Explicit)] | ||
| class Class1 | ||
| { | ||
| static int Stat; | ||
| [FieldOffset(4)] | ||
| bool Bar; | ||
| [FieldOffset(10)] | ||
| char Baz; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| class Class2 : Class1 | ||
| { | ||
| [FieldOffset(0)] | ||
| int Lol; | ||
| [FieldOffset(20)] | ||
| byte Omg; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit, Size = 40)] | ||
| class ExplicitSize : Class1 | ||
| { | ||
| [FieldOffset(0)] | ||
| int Lol; | ||
| [FieldOffset(20)] | ||
| byte Omg; | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public class ExplicitEmptyClass | ||
| { | ||
| } | ||
|
|
||
| [StructLayout(LayoutKind.Explicit)] | ||
| public struct ExplicitEmptyStruct | ||
| { | ||
| } | ||
| } | ||
|
|
||
| namespace Sequential | ||
| { | ||
| class Class1 | ||
| { | ||
| int MyInt; | ||
| bool MyBool; | ||
| char MyChar; | ||
| string MyString; | ||
| byte[] MyByteArray; | ||
| Class1 MyClass1SelfRef; | ||
| } | ||
|
|
||
| class Class2 : Class1 | ||
| { | ||
| int MyInt2; | ||
| } | ||
|
|
||
| struct Struct0 | ||
| { | ||
| bool b1; | ||
| bool b2; | ||
| bool b3; | ||
| int i1; | ||
| string s1; | ||
| } | ||
|
|
||
| struct Struct1 | ||
| { | ||
| Struct0 MyStruct0; | ||
| bool MyBool; | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| #pragma warning disable 649 | ||
|
|
||
| namespace System | ||
| { | ||
| // Dummy core types to allow us compiling this assembly as a core library so that the type | ||
| // system tests don't have a dependency on a real core library. | ||
|
|
||
| // We might need to bring in some extra things (Interface lists? Virtual methods on Object?), | ||
| // but let's postpone that until actually needed. | ||
|
|
||
| public class Object | ||
| { | ||
| internal IntPtr m_pEEType; | ||
| } | ||
|
|
||
| public struct Void { } | ||
| public struct Boolean { } | ||
| public struct Char { } | ||
| public struct SByte { } | ||
| public struct Byte { } | ||
| public struct Int16 { } | ||
| public struct UInt16 { } | ||
| public struct Int32 { } | ||
| public struct UInt32 { } | ||
| public struct Int64 { } | ||
| public struct UInt64 { } | ||
| public struct IntPtr { } | ||
| public struct UIntPtr { } | ||
| public struct Single { } | ||
| public struct Double { } | ||
| public abstract class ValueType { } | ||
| public abstract class Enum : ValueType { } | ||
| public struct Nullable<T> where T : struct { } | ||
|
|
||
| public sealed class String { } | ||
| public abstract class Array { } | ||
| public abstract class Delegate { } | ||
| public abstract class MulticastDelegate : Delegate { } | ||
|
|
||
| public struct RuntimeTypeHandle { } | ||
| public struct RuntimeMethodHandle { } | ||
| public struct RuntimeFieldHandle { } | ||
|
|
||
| public class Attribute { } | ||
| } | ||
|
|
||
| namespace System.Runtime.InteropServices | ||
| { | ||
| public enum LayoutKind | ||
| { | ||
| Sequential = 0, // 0x00000008, | ||
| Explicit = 2, // 0x00000010, | ||
| Auto = 3, // 0x00000000, | ||
| } | ||
|
|
||
| public sealed class StructLayoutAttribute : Attribute | ||
| { | ||
| internal LayoutKind _val; | ||
|
|
||
| public StructLayoutAttribute(LayoutKind layoutKind) | ||
| { | ||
| _val = layoutKind; | ||
| } | ||
|
|
||
| public LayoutKind Value { get { return _val; } } | ||
| public int Pack; | ||
| public int Size; | ||
| } | ||
|
|
||
| public sealed class FieldOffsetAttribute : Attribute | ||
| { | ||
| private int _val; | ||
| public FieldOffsetAttribute(int offset) | ||
| { | ||
| _val = offset; | ||
| } | ||
| public int Value { get { return _val; } } | ||
| } | ||
| } | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that was an actual bug discovered by the tests :).