{
public abstract Type CreateType();
+ public virtual int? ArrayRank => null;
+
public abstract TypeAttributes Attributes { get; }
public virtual Type BaseType => typeof(object);
public virtual Type[] GenericTypeArguments => new Type[0];
+ public virtual Type GenericTypeDefinition => null;
+
public virtual bool HasElementType => false;
public virtual bool IsArray => false;
Assert.Equal((Attributes & TypeAttributes.Import) != 0, t.IsImport);
Assert.Equal((Attributes & TypeAttributes.Sealed) != 0, t.IsSealed);
Assert.Equal((Attributes & TypeAttributes.SpecialName) != 0, t.IsSpecialName);
- Assert.Equal((Attributes & TypeAttributes.Serializable) != 0 || t.IsEnum, t.IsSerializable);
+ Assert.Equal((Attributes & TypeAttributes.Serializable) != 0 || t.IsEnum || t == typeof(Delegate), t.IsSerializable);
Assert.Equal((Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Class && !t.IsValueType, t.IsClass);
Assert.Equal((Attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface, t.IsInterface);
}
[Fact]
+ public void GetGenericTypeDefinition_Invoke_ReturnsExpected()
+ {
+ if (GenericTypeDefinition != null)
+ {
+ Assert.Equal(GenericTypeDefinition, CreateType().GetGenericTypeDefinition());
+ }
+ else
+ {
+ Assert.Throws<InvalidOperationException>(() => CreateType().GetGenericTypeDefinition());
+ }
+ }
+
+ [Fact]
public void GenericParameterAttributes_Get_ReturnsExpected()
{
if (GenericParameterPosition != null)
}
[Fact]
+ public void GetArrayRank_Invoke_ReturnsExpected()
+ {
+ if (ArrayRank != null)
+ {
+ Assert.Equal(ArrayRank, CreateType().GetArrayRank());
+ }
+ else
+ {
+ AssertExtensions.Throws<ArgumentException>(null, () => CreateType().GetArrayRank());
+ }
+ }
+
+ [Fact]
public void GetElementType_Invoke_ReturnsExpected()
{
Assert.Equal(ElementType, CreateType().GetElementType());
public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed;
public override Type BaseType => typeof(Enum);
-
}
- public class ByteTests : PrimitiveTypeTestBase
+ // Primitives
+ public class StringTypeTests : ClassTypeTestBase
{
- public override Type CreateType() => typeof(byte);
- }
+ public override Type CreateType() => typeof(string);
- public class ByteEnumTests : EnumTypeTestBase
- {
- public override Type CreateType() => typeof(ByteEnum);
+ public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;
}
public class SByteTests : PrimitiveTypeTestBase
public override Type CreateType() => typeof(sbyte);
}
- public class SByteEnumTests : EnumTypeTestBase
- {
- public override Type CreateType() => typeof(SByteEnum);
- }
-
- public class UShortTests : PrimitiveTypeTestBase
- {
- public override Type CreateType() => typeof(ushort);
- }
-
- public class UShortEnumTests : EnumTypeTestBase
+ public class ByteTests : PrimitiveTypeTestBase
{
- public override Type CreateType() => typeof(UShortEnum);
+ public override Type CreateType() => typeof(byte);
}
public class ShortTests : PrimitiveTypeTestBase
public override Type CreateType() => typeof(short);
}
- public class ShortEnumTests : EnumTypeTestBase
- {
- public override Type CreateType() => typeof(ShortEnum);
- }
-
- public class UIntTests : PrimitiveTypeTestBase
- {
- public override Type CreateType() => typeof(uint);
- }
-
- public class UIntEnumTests : EnumTypeTestBase
+ public class UShortTests : PrimitiveTypeTestBase
{
- public override Type CreateType() => typeof(UIntEnum);
+ public override Type CreateType() => typeof(ushort);
}
public class IntTests : PrimitiveTypeTestBase
public override Type CreateType() => typeof(int);
}
- public class IntEnumTests : EnumTypeTestBase
- {
- public override Type CreateType() => typeof(IntEnum);
- }
-
- public class ULongTests : PrimitiveTypeTestBase
- {
- public override Type CreateType() => typeof(ulong);
- }
-
- public class ULongEnumTests : EnumTypeTestBase
+ public class UIntTests : PrimitiveTypeTestBase
{
- public override Type CreateType() => typeof(ULongEnum);
+ public override Type CreateType() => typeof(uint);
}
public class LongTests : PrimitiveTypeTestBase
public override Type CreateType() => typeof(long);
}
- public class LongEnumTests : EnumTypeTestBase
+ public class ULongTests : PrimitiveTypeTestBase
{
- public override Type CreateType() => typeof(LongEnum);
+ public override Type CreateType() => typeof(ulong);
}
- public class DoubleTests : PrimitiveTypeTestBase
+ public class CharTests : PrimitiveTypeTestBase
{
- public override Type CreateType() => typeof(double);
+ public override Type CreateType() => typeof(char);
}
- public class FloatTests : PrimitiveTypeTestBase
+ public class BoolTests : PrimitiveTypeTestBase
{
- public override Type CreateType() => typeof(float);
+ public override Type CreateType() => typeof(bool);
}
- public class BoolTests : PrimitiveTypeTestBase
+ public class FloatTests : PrimitiveTypeTestBase
{
- public override Type CreateType() => typeof(bool);
+ public override Type CreateType() => typeof(float);
}
- public class CharTests : PrimitiveTypeTestBase
+ public class DoubleTests : PrimitiveTypeTestBase
{
- public override Type CreateType() => typeof(char);
+ public override Type CreateType() => typeof(double);
}
public class IntPtrTests : PrimitiveTypeTestBase
public override Type CreateType() => typeof(UIntPtr);
}
- public class ObjectTests : ClassTypeTestBase
+ public class VoidTests : StructTypeTestBase
+ {
+ public override Type CreateType() => typeof(void);
+ }
+
+ public class ObjectTypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(object);
public override Type BaseType => null;
}
- public class ValueTypeTests : ClassTypeTestBase
+ public class ArrayTypeTests : ClassTypeTestBase
+ {
+ public override Type CreateType() => typeof(Array);
+
+ public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;
+ }
+
+ public class ValueTypeTypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(ValueType);
public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;
}
+ public class DelegateTypeTests : ClassTypeTestBase
+ {
+ public override Type CreateType() => typeof(Delegate);
+
+ public override TypeAttributes Attributes => PlatformDetection.IsMonoRuntime
+ ? TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.SequentialLayout | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit
+ : TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit;
+ }
+
public class EnumTypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(Enum);
public override Type BaseType => typeof(ValueType);
}
- public class VoidTests : StructTypeTestBase
+ // Primitives enums
+ public class SByteEnumTests : EnumTypeTestBase
{
- public override Type CreateType() => typeof(void);
+ public override Type CreateType() => typeof(SByteEnum);
}
- public class IntRefTests : TypePropertyTestBase
+ public class ByteEnumTests : EnumTypeTestBase
{
- public override Type CreateType() => typeof(int).MakeByRefType();
-
- public override TypeAttributes Attributes => TypeAttributes.Class;
-
- public override Type BaseType => null;
-
- public override bool IsByRef => true;
+ public override Type CreateType() => typeof(ByteEnum);
+ }
- public override bool IsTypeDefinition => false;
+ public class Int16EnumTests : EnumTypeTestBase
+ {
+ public override Type CreateType() => typeof(Int16Enum);
+ }
- public override bool HasElementType => true;
+ public class UInt16EnumTests : EnumTypeTestBase
+ {
+ public override Type CreateType() => typeof(UInt16Enum);
+ }
- public override Type ElementType => typeof(int);
+ public class Int32EnumTests : EnumTypeTestBase
+ {
+ public override Type CreateType() => typeof(Int32Enum);
}
- public class IntPointerTests : TypePropertyTestBase
+ public class UInt32EnumTests : EnumTypeTestBase
{
- public override Type CreateType() => typeof(int).MakePointerType();
+ public override Type CreateType() => typeof(UInt32Enum);
+ }
- public override TypeAttributes Attributes => TypeAttributes.Class;
+ public class Int64EnumTests : EnumTypeTestBase
+ {
+ public override Type CreateType() => typeof(Int64Enum);
+ }
- public override Type BaseType => null;
+ public class UInt64EnumTests : EnumTypeTestBase
+ {
+ public override Type CreateType() => typeof(UInt64Enum);
+ }
- public override bool IsPointer => true;
+ // Arrays, pointers.
+ public class StringArrayTests : ArrayTypeTestBase
+ {
+ public override Type CreateType() => typeof(string[]);
- public override bool IsTypeDefinition => false;
+ public override int? ArrayRank => 1;
- public override bool HasElementType => true;
+ public override Type ElementType => typeof(string);
- public override Type ElementType => typeof(int);
+ public override bool IsSZArray => true;
}
public class IntArrayTests : ArrayTypeTestBase
{
public override Type CreateType() => typeof(int[]);
- public override Type ElementType => typeof(int);
-
- public override bool IsSZArray => true;
- }
-
- public class MultidimensionalIntArrayTests : ArrayTypeTestBase
- {
- public override Type CreateType() => typeof(int[,]);
+ public override int? ArrayRank => 1;
public override Type ElementType => typeof(int);
- public override bool IsVariableBoundArray => true;
+ public override bool IsSZArray => true;
}
public class ArrayOfArrayTests : ArrayTypeTestBase
{
public override Type CreateType() => typeof(int[][]);
+ public override int? ArrayRank => 1;
+
public override Type ElementType => typeof(int[]);
public override bool IsSZArray => true;
{
public override Type CreateType() => typeof(Outside.Inside[]);
+ public override int? ArrayRank => 1;
+
public override Type ElementType => typeof(Outside.Inside);
public override bool IsSZArray => true;
{
public override Type CreateType() => typeof(Outside<int>.Inside<double>[]);
+ public override int? ArrayRank => 1;
+
public override Type ElementType => typeof(Outside<int>.Inside<double>);
public override bool IsSZArray => true;
}
- public class ArrayTypeTests : ClassTypeTestBase
+ public class NonSzIntArrayTests : ArrayTypeTestBase
{
- public override Type CreateType() => typeof(Array);
+ public override Type CreateType() => typeof(int).MakeArrayType(1);
- public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.Serializable | TypeAttributes.BeforeFieldInit;
+ public override int? ArrayRank => 1;
+
+ public override Type ElementType => typeof(int);
+
+ public override bool IsVariableBoundArray => true;
}
- public class NonGenericClassTests : ClassTypeTestBase
+ public class MultidimensionalIntArrayTests : ArrayTypeTestBase
{
- public override Type CreateType() => typeof(NonGenericClass);
+ public override Type CreateType() => typeof(int[,]);
+
+ public override int? ArrayRank => 2;
+
+ public override Type ElementType => typeof(int);
+
+ public override bool IsVariableBoundArray => true;
}
- public class NonGenericSubClassOfNonGenericTests : ClassTypeTestBase
+ public class IntPointerTests : TypePropertyTestBase
{
- public override Type CreateType() => typeof(NonGenericSubClassOfNonGeneric);
+ public override Type CreateType() => typeof(int).MakePointerType();
- public override Type BaseType => typeof(NonGenericClass);
+ public override TypeAttributes Attributes => TypeAttributes.Class;
+
+ public override Type BaseType => null;
+
+ public override bool IsPointer => true;
+
+ public override bool IsTypeDefinition => false;
+
+ public override bool HasElementType => true;
+
+ public override Type ElementType => typeof(int);
}
- public class TypedReferenceTypeTests : StructTypeTestBase
+ public class IntRefTests : TypePropertyTestBase
{
- public override Type CreateType() => typeof(TypedReference);
+ public override Type CreateType() => typeof(int).MakeByRefType();
+
+ public override TypeAttributes Attributes => TypeAttributes.Class;
+
+ public override Type BaseType => null;
+
+ public override bool IsByRef => true;
+
+ public override bool IsTypeDefinition => false;
+
+ public override bool HasElementType => true;
+
+ public override Type ElementType => typeof(int);
+ }
+
+ // Classes, structs, interfaces, enums
+ public class NonGenericClassTypeTests : ClassTypeTestBase
+ {
+ public override Type CreateType() => typeof(NonGenericClass);
+ }
+
+ public class NonGenericSubClassOfNonGenericTypeTests : ClassTypeTestBase
+ {
+ public override Type CreateType() => typeof(NonGenericSubClassOfNonGeneric);
+
+ public override Type BaseType => typeof(NonGenericClass);
}
- public class GenericClass1Tests : ClassTypeTestBase
+ public class GenericClass1TypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(GenericClass<string>);
public override bool IsTypeDefinition => false;
public override Type[] GenericTypeArguments => new Type[] { typeof(string) };
+
+ public override Type GenericTypeDefinition => typeof(GenericClass<>);
}
- public class GenericClass2Tests : ClassTypeTestBase
+ public class GenericClass2TypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(GenericClass<int, string>);
public override bool IsTypeDefinition => false;
public override Type[] GenericTypeArguments => new Type[] { typeof(int), typeof(string) };
+
+ public override Type GenericTypeDefinition => typeof(GenericClass<,>);
}
- public class OpenGenericClassTests : ClassTypeTestBase
+ public class OpenGenericClassTypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(GenericClass<>);
public override bool IsGenericType => true;
public override bool IsGenericTypeDefinition => true;
+
+ public override Type GenericTypeDefinition => typeof(GenericClass<>);
+ }
+
+ public class OpenGenericNestedClassTypeTests : ClassTypeTestBase
+ {
+ public override Type CreateType() => typeof(GenericClass<>).MakeGenericType(typeof(GenericClass<>));
+
+ public override bool ContainsGenericParameters => true;
+
+ public override bool IsConstructedGenericType => true;
+
+ public override bool IsGenericType => true;
+
+ public override bool IsTypeDefinition => false;
+
+ public override Type[] GenericTypeArguments => new Type[] { typeof(GenericClass<>) };
+
+ public override Type GenericTypeDefinition => typeof(GenericClass<>);
}
- public class NonGenericSubClassOfGenericTests : ClassTypeTestBase
+ public class NonGenericSubClassOfGenericTypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(NonGenericSubClassOfGeneric);
public override bool IsTypeDefinition => false;
public override Type[] GenericTypeArguments => new Type[] { typeof(string) };
+
+ public override Type GenericTypeDefinition => typeof(GenericStruct<>);
}
public class GenericStruct2Tests : StructTypeTestBase
public override bool IsTypeDefinition => false;
public override Type[] GenericTypeArguments => new Type[] { typeof(int), typeof(string) };
+
+ public override Type GenericTypeDefinition => typeof(GenericStruct<,>);
}
public class NonGenericInterfaceTests : InterfaceTypeTestBase
public override bool IsTypeDefinition => false;
public override Type[] GenericTypeArguments => new Type[] { typeof(string) };
+
+ public override Type GenericTypeDefinition => typeof(GenericInterface<>);
}
public class GenericInterface2Tests : InterfaceTypeTestBase
public override bool IsTypeDefinition => false;
public override Type[] GenericTypeArguments => new Type[] { typeof(int), typeof(string) };
+
+ public override Type GenericTypeDefinition => typeof(GenericInterface<,>);
+ }
+
+ public class AbstractClassTypeTests : ClassTypeTestBase
+ {
+ public override Type CreateType() => typeof(AbstractClass);
+
+ public override TypeAttributes Attributes => TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Abstract | TypeAttributes.BeforeFieldInit;
}
public class OpenGenericInterfaceTests : InterfaceTypeTestBase
public override bool IsGenericType => true;
public override bool IsGenericTypeDefinition => true;
+
+ public override Type GenericTypeDefinition => typeof(GenericInterface<>);
}
public class NonGenericNestedTests : TypePropertyTestBase
public override bool IsTypeDefinition => false;
public override Type[] GenericTypeArguments => new Type[] { typeof(int), typeof(double) };
+
+ public override Type GenericTypeDefinition => typeof(Outside<>.Inside<>);
}
public class OpenGenericNestedTests : TypePropertyTestBase
public override bool IsGenericType => true;
public override bool IsGenericTypeDefinition => true;
+
+ public override Type GenericTypeDefinition => typeof(Outside<>.Inside<>);
}
public class GenericTypeParameter1Of1Tests : TypePropertyTestBase
public override int? GenericParameterPosition => 1;
}
- public class MarshalByRefObjectTests : ClassTypeTestBase
+ public class MarshalByRefObjectTypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(MarshalByRefObject);
public override bool IsMarshalByRef => false;
}
- public class ContextBoundObjectTests : ClassTypeTestBase
+ public class ContextBoundObjectTypeTests : ClassTypeTestBase
{
public override Type CreateType() => typeof(ContextBoundObject);
public override bool IsContextful => false;
}
- public enum ByteEnum : byte { }
+ // By-Ref types.
+ public class TypedReferenceTypeTests : StructTypeTestBase
+ {
+ public override Type CreateType() => typeof(TypedReference);
+ }
- public enum SByteEnum : sbyte { }
+ public class ArgIteratorTypeTests : StructTypeTestBase
+ {
+ public override Type CreateType() => typeof(ArgIterator);
- public enum UShortEnum : ushort { }
+ public override TypeAttributes Attributes => PlatformDetection.IsMonoRuntime
+ ? TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit
+ : TypeAttributes.AutoLayout | TypeAttributes.AnsiClass | TypeAttributes.Class | TypeAttributes.Public | TypeAttributes.SequentialLayout | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit;
+ }
- public enum ShortEnum : short { }
+ public class RuntimeArgumentHandleTypeTests : StructTypeTestBase
+ {
+ public override Type CreateType() => typeof(RuntimeArgumentHandle);
+ }
- public enum UIntEnum : uint { }
+ public class SpanIntTypeTests : StructTypeTestBase
+ {
+ public override Type CreateType() => typeof(Span<int>);
+
+ public override Type[] GenericTypeArguments => new Type[] { typeof(int) };
- public enum IntEnum : int { }
+ public override bool IsConstructedGenericType => true;
- public enum ULongEnum : ulong { }
+ public override bool IsGenericType => true;
- public enum LongEnum : long { }
+ public override bool IsTypeDefinition => false;
+
+ public override Type GenericTypeDefinition => typeof(Span<>);
+ }
}
Assert.Null(Type.GetTypeFromHandle(default(RuntimeTypeHandle)));
}
- [Theory]
- [InlineData(typeof(int[]), 1)]
- [InlineData(typeof(int[,,]), 3)]
- public void GetArrayRank_Get_ReturnsExpected(Type t, int expected)
- {
- Assert.Equal(expected, t.GetArrayRank());
- }
-
- [Theory]
- [InlineData(typeof(int))]
- [InlineData(typeof(IList<int>))]
- [InlineData(typeof(IList<>))]
- public void GetArrayRank_NonArrayType_ThrowsArgumentException(Type t)
- {
- AssertExtensions.Throws<ArgumentException>(null, () => t.GetArrayRank());
- }
-
public static IEnumerable<object[]> MakeArrayType_TestData()
{
return new object[][]
Assert.Throws<TypeLoadException>(() => t.MakeArrayType(rank));
}
+ public static IEnumerable<object[]> MakeByRefType_TestData()
+ {
+ return new object[][]
+ {
+ // Primitives
+ new object[] { typeof(string) },
+ new object[] { typeof(sbyte) },
+ new object[] { typeof(byte) },
+ new object[] { typeof(short) },
+ new object[] { typeof(ushort) },
+ new object[] { typeof(int) },
+ new object[] { typeof(uint) },
+ new object[] { typeof(long) },
+ new object[] { typeof(ulong) },
+ new object[] { typeof(char) },
+ new object[] { typeof(bool) },
+ new object[] { typeof(float) },
+ new object[] { typeof(double) },
+ new object[] { typeof(IntPtr) },
+ new object[] { typeof(UIntPtr) },
+ new object[] { typeof(void) },
+
+ // Primitives enums
+ new object[] { typeof(SByteEnum) },
+ new object[] { typeof(ByteEnum) },
+ new object[] { typeof(Int16Enum) },
+ new object[] { typeof(UInt16Enum) },
+ new object[] { typeof(Int32Enum) },
+ new object[] { typeof(UInt32Enum) },
+ new object[] { typeof(Int64Enum) },
+ new object[] { typeof(UInt64Enum) },
+
+ // Array, pointers
+ new object[] { typeof(string[]) },
+ new object[] { typeof(int[]) },
+ new object[] { typeof(int*) },
+
+ // Classes, structs, interfaces, enums
+ new object[] { typeof(NonGenericClass) },
+ new object[] { typeof(GenericClass<int>) },
+ new object[] { typeof(NonGenericStruct) },
+ new object[] { typeof(GenericStruct<int>) },
+ new object[] { typeof(NonGenericInterface) },
+ new object[] { typeof(GenericInterface<int>) },
+ new object[] { typeof(AbstractClass) },
+ new object[] { typeof(StaticClass) },
+
+ // Generic types.
+ new object[] { typeof(GenericClass<>) },
+ new object[] { typeof(GenericClass<>).MakeGenericType(typeof(GenericClass<>)) },
+ new object[] { typeof(GenericClass<>).GetTypeInfo().GetGenericArguments()[0] },
+
+ // By-Ref Like.
+ new object[] { typeof(TypedReference) },
+ new object[] { typeof(ArgIterator) },
+ new object[] { typeof(RuntimeArgumentHandle) },
+ new object[] { typeof(Span<int>) },
+ };
+ }
+
[Theory]
- [InlineData(typeof(int))]
+ [MemberData(nameof(MakeByRefType_TestData))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/37489", TestRuntimes.Mono)]
public void MakeByRefType_Invoke_ReturnsExpected(Type t)
{
- Type tRef1 = t.MakeByRefType();
- Type tRef2 = t.MakeByRefType();
+ Type tPointer = t.MakeByRefType();
+ Assert.Equal(tPointer, t.MakeByRefType());
+
+ Assert.True(tPointer.IsByRef);
+ Assert.False(tPointer.IsPointer);
+ Assert.True(tPointer.HasElementType);
+ Assert.Equal(t, tPointer.GetElementType());
+
+ Assert.Equal(t.ToString() + "&", tPointer.ToString());
+ }
+
+ [Fact]
+ public void MakeByRefType_ByRef_ThrowsTypeLoadException()
+ {
+ Type t = typeof(int).MakeByRefType();
+ Assert.Throws<TypeLoadException>(() => t.MakeByRefType());
+ }
- Assert.Equal(tRef1, tRef2);
+ public static IEnumerable<object[]> MakePointerType_TestData()
+ {
+ return new object[][]
+ {
+ // Primitives
+ new object[] { typeof(string) },
+ new object[] { typeof(sbyte) },
+ new object[] { typeof(byte) },
+ new object[] { typeof(short) },
+ new object[] { typeof(ushort) },
+ new object[] { typeof(int) },
+ new object[] { typeof(uint) },
+ new object[] { typeof(long) },
+ new object[] { typeof(ulong) },
+ new object[] { typeof(char) },
+ new object[] { typeof(bool) },
+ new object[] { typeof(float) },
+ new object[] { typeof(double) },
+ new object[] { typeof(IntPtr) },
+ new object[] { typeof(UIntPtr) },
+ new object[] { typeof(void) },
- Assert.True(tRef1.IsByRef);
- Assert.True(tRef1.HasElementType);
+ // Primitives enums
+ new object[] { typeof(SByteEnum) },
+ new object[] { typeof(ByteEnum) },
+ new object[] { typeof(Int16Enum) },
+ new object[] { typeof(UInt16Enum) },
+ new object[] { typeof(Int32Enum) },
+ new object[] { typeof(UInt32Enum) },
+ new object[] { typeof(Int64Enum) },
+ new object[] { typeof(UInt64Enum) },
- Assert.Equal(t, tRef1.GetElementType());
+ // Array, pointers
+ new object[] { typeof(string[]) },
+ new object[] { typeof(int[]) },
+ new object[] { typeof(int*) },
- string s1 = t.ToString();
- string s2 = tRef1.ToString();
- Assert.Equal(s2, s1 + "&");
+ // Classes, structs, interfaces, enums
+ new object[] { typeof(NonGenericClass) },
+ new object[] { typeof(GenericClass<int>) },
+ new object[] { typeof(NonGenericStruct) },
+ new object[] { typeof(GenericStruct<int>) },
+ new object[] { typeof(NonGenericInterface) },
+ new object[] { typeof(GenericInterface<int>) },
+ new object[] { typeof(AbstractClass) },
+ new object[] { typeof(StaticClass) },
+
+ // Generic types.
+ new object[] { typeof(GenericClass<>) },
+ new object[] { typeof(GenericClass<>).MakeGenericType(typeof(GenericClass<>)) },
+ new object[] { typeof(GenericClass<>).GetTypeInfo().GetGenericArguments()[0] },
+
+ // ByRef Like.
+ new object[] { typeof(TypedReference) },
+ new object[] { typeof(ArgIterator) },
+ new object[] { typeof(RuntimeArgumentHandle) },
+ new object[] { typeof(Span<int>) },
+ };
+ }
+
+ [Theory]
+ [MemberData(nameof(MakePointerType_TestData))]
+ [ActiveIssue("https://github.com/dotnet/runtime/issues/37489", TestRuntimes.Mono)]
+ public void MakePointerType_Invoke_ReturnsExpected(Type t)
+ {
+ Type tPointer = t.MakePointerType();
+ Assert.Equal(tPointer, t.MakePointerType());
+
+ Assert.False(tPointer.IsByRef);
+ Assert.True(tPointer.IsPointer);
+ Assert.True(tPointer.HasElementType);
+ Assert.Equal(t, tPointer.GetElementType());
+
+ Assert.Equal(t.ToString() + "*", tPointer.ToString());
+ }
+
+ [Fact]
+ public void MakePointerType_ByRef_ThrowsTypeLoadException()
+ {
+ Type t = typeof(int).MakeByRefType();
+ Assert.Throws<TypeLoadException>(() => t.MakePointerType());
}
[Theory]
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typegetarrayrank.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typegetelementtype.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typegetgenerictypedefinition.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typehaselementtypeimpl.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typeisbyrefimpl.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typeispointerimpl.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typemakearraytype1.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typemakearraytype2.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typemakebyreftype.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
- <PropertyGroup>
- <OutputType>Exe</OutputType>
- <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
- <CLRTestKind>BuildAndRun</CLRTestKind>
- <CLRTestPriority>1</CLRTestPriority>
- </PropertyGroup>
- <ItemGroup>
- <Compile Include="typemakepointertype.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="$(TestSourceDir)Common/CoreCLRTestLibrary/CoreCLRTestLibrary.csproj" />
- </ItemGroup>
-</Project>
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
-public class TypeGetArrayRank
-{
- #region Private Variables
- private const int c_DEFAULT_ARRAY_DIMENSION = 2;
- #endregion
-
- #region Public Methods
- public bool RunTests()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- retVal = PosTest3() && retVal;
-
- TestLibrary.TestFramework.LogInformation("[Negative]");
- retVal = NegTest1() && retVal;
-
- return retVal;
- }
-
- #region Positive Test Cases
- public bool PosTest1()
- {
- bool retVal = true;
- int size = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: Get rank of an one dimension array");
-
- try
- {
- // Do not make a large array
- size = TestLibrary.Generator.GetByte(-55);
-
- int[] array = new int[size];
- for (int i = 0; i < size; ++i)
- {
- array[i] = TestLibrary.Generator.GetInt32(-55);
- }
-
- Type type = array.GetType();
- int rank = type.GetArrayRank();
- if (rank != 1)
- {
- TestLibrary.TestFramework.LogError("001", "Get rank of an one dimension array returns " + rank.ToString());
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e + "; with size = " + size);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest2()
- {
- bool retVal = true;
- int size = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest2: Get rank of an multiple dimensions array");
-
- try
- {
- // Do not make a large array
- size = TestLibrary.Generator.GetByte(-55);
-
- int[,] array = new int[c_DEFAULT_ARRAY_DIMENSION, size];
- for (int i = 0; i < c_DEFAULT_ARRAY_DIMENSION; ++i)
- {
- for (int j = 0; j < size; ++j)
- {
- array[i, j] = TestLibrary.Generator.GetInt32(-55);
- }
- }
-
- Type type = array.GetType();
- int rank = type.GetArrayRank();
- if (rank != c_DEFAULT_ARRAY_DIMENSION)
- {
- TestLibrary.TestFramework.LogError("003", "Get rank of an multiple dimensions array returns " + rank.ToString());
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e + "; with size = " + size);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest3()
- {
- bool retVal = true;
- int size = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest3: Get rank of an multiple dimensions jagged array");
-
- try
- {
- // Do not make a large array
- size = TestLibrary.Generator.GetByte(-55);
-
- int[][] array = new int[size][];
-
- for (int i = 0; i < size; ++i)
- {
- int subArrayLength = TestLibrary.Generator.GetByte(-55);
- int[] subArray = new int[subArrayLength];
-
- for (int j = 0; j < subArrayLength; ++j)
- {
- subArray[j] = TestLibrary.Generator.GetInt32(-55);
- }
-
- array[i] = subArray;
- }
-
- Type type = array.GetType();
- int rank = type.GetArrayRank();
- if (rank != 1)
- {
- TestLibrary.TestFramework.LogError("005", "Get rank of an multiple dimensions jagged array returns " + rank.ToString());
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
-
- #region Nagetive Test Cases
- public bool NegTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("NegTest1: Check ArgumentException will be thrown");
-
- try
- {
- Type t1 = typeof(Exception);
-
- int returnObject = t1.GetArrayRank();
- TestLibrary.TestFramework.LogError("101", "ArgumentException is not thrown when calling typeof(Exception).GetArrayRank()");
- retVal = false;
- }
- catch (ArgumentException)
- {
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
- #endregion
-
- public static int Main()
- {
- TypeGetArrayRank test = new TypeGetArrayRank();
-
- TestLibrary.TestFramework.BeginTestCase("TypeGetArrayRank");
-
- if (test.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-using System.Globalization;
-using System.Reflection;
-using System.Collections;
-using System.Collections.Generic;
-
-/// <summary>
-///Type.GetGenericTypeDefinition()
-/// </summary>
-public class TypeGetGenericTypeDefinition
-{
- public static int Main()
- {
- TypeGetGenericTypeDefinition tggtd = new TypeGetGenericTypeDefinition();
- TestLibrary.TestFramework.BeginTestCase("TypeGetGenericTypeDefinition");
- if (tggtd.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-
- public bool RunTests()
- {
- bool retVal = true;
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- TestLibrary.TestFramework.LogInformation("[Negtive]");
- retVal = NegTest1() && retVal;
-
- return retVal;
- }
- #region PositiveTesting
- public bool PosTest1()
- {
- bool retVal = true;
- Type tpA;
- Type ActualResult;
- TestLibrary.TestFramework.BeginScenario("PosTest1: the current type's definition has one generic param");
- try
- {
- tpA = typeof(Derived2<Derived>);
- ActualResult = tpA.GetGenericTypeDefinition();
- if(ActualResult != typeof(Derived2<>))
- {
- TestLibrary.TestFramework.LogError("001","the ActualResult is not the ExpectResult");
- retVal = false;
- }
- }
- catch(Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
- retVal = false;
- }
- return retVal;
- }
- public bool PosTest2()
- {
- bool retVal = true;
- Type tpA;
- Type tpB;
- Type ActualResult1;
- Type ActualResult2;
- TestLibrary.TestFramework.BeginScenario("PosTest2: the current type has the same type argument");
- try
- {
- tpA = typeof(Derived2<int>);
- tpB = typeof(Derived2<string>);
- ActualResult1 = tpA.GetGenericTypeDefinition();
- ActualResult2 = tpB.GetGenericTypeDefinition();
- if (ActualResult1 != typeof(Derived2<>) || ActualResult2 != ActualResult1)
- {
- TestLibrary.TestFramework.LogError("003", "the ActualResult is not the ExpectResult");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
- retVal = false;
- }
- return retVal;
- }
- #endregion
- #region NegativeTest
- public bool NegTest1()
- {
- bool retVal = true;
- Type tpA;
- Type ActualResult;
- TestLibrary.TestFramework.BeginScenario("NegTest1: the current object is not generic type");
-
- try
- {
- tpA = typeof(Derived);
- ActualResult = tpA.GetGenericTypeDefinition();
- retVal = false;
- }
- catch (InvalidOperationException) { }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("N001", "Unexpect exception:" + e);
- retVal = false;
- }
- return retVal;
-
- }
- #endregion
- #region UsingForTesting
- public class Base<T, U> { }
- public class Derived : Base<string, int> { }
- public class Derived2<V> : Base<bool, V> { }
- public class G<T> { }
- #endregion
-}
-
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-using System.Globalization;
-using System.Reflection;
-using System.Collections;
-/// <summary>
-///HasElementTypeImpl
-/// </summary>
-public class TypeHasElementTypeImpl
-{
- public static int Main()
- {
- TypeHasElementTypeImpl TypeHasElementTypeImpl = new TypeHasElementTypeImpl();
-
- TestLibrary.TestFramework.BeginTestCase("TypeHasElementTypeImpl");
- if (TypeHasElementTypeImpl.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-
- public bool RunTests()
- {
- bool retVal = true;
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- retVal = PosTest3() && retVal;
- return retVal;
- }
- // Returns true if the expected result is right
- // Returns false if the expected result is wrong
- public bool PosTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: The Type is an array ");
- try
- {
- int[] myArray = new int[5];
- if (!myArray.GetType().HasElementType)
- {
- TestLibrary.TestFramework.LogError("001", "HasElementType should return false." );
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
- retVal = false;
- }
- return retVal;
- }
- // Returns true if the expected result is right
- // Returns false if the expected result is wrong
- public bool PosTest2()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest2: The Type is IntPtr ");
- try
- {
- IntPtr myInt=new IntPtr(5);
- if (myInt.GetType().HasElementType)
- {
- TestLibrary.TestFramework.LogError("001", "HasElementType should return false.");
- retVal = false;
- }
-
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
- retVal = false;
- }
- return retVal;
- }
- // Returns true if the expected result is right
- // Returns false if the expected result is wrong
- public bool PosTest3()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest3: The Type is reference type");
- try
- {
- TestClass myInstance = new TestClass();
- if (myInstance.GetType().HasElementType)
- {
- TestLibrary.TestFramework.LogError("001", "HasElementType should return false.");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
- retVal = false;
- }
- return retVal;
- }
- private void MyMethod(ref TestClass myTest)
- {
-
- }
-
-}
-
-public class TestClass
-{
-
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-using System.Globalization;
-using System.Reflection;
-using System.Collections;
-/// <summary>
-///IsByRefImpl
-/// </summary>
-public class TypeIsByRefImpl
-{
- public static int Main()
- {
- TypeIsByRefImpl TypeIsByRefImpl = new TypeIsByRefImpl();
-
- TestLibrary.TestFramework.BeginTestCase("TypeIsByRefImpl");
- if (TypeIsByRefImpl.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-
- public bool RunTests()
- {
- bool retVal = true;
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- return retVal;
- }
- // Returns true if the expected result is right
- // Returns false if the expected result is wrong
- public bool PosTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: override isByRefImpl and Only these type which BaseType is BaseClass Return true ,TestClass as test object ");
- try
- {
- TestClass myobject = new TestClass();
- if (myobject.GetType().IsByRef)
- {
- TestLibrary.TestFramework.LogError("001", "TestClass is not Passed by reference.");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
- retVal = false;
- }
- return retVal;
- }
-
- // Returns true if the expected result is right
- // Returns false if the expected result is wrong
- public bool PosTest2()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: override isByRefImpl and Only these type which BaseType is BaseClass Return true ,TestClass1 as test object ");
- try
- {
- TestClass1 myobject = new TestClass1();
- if (myobject.GetType().IsByRef)
- {
- TestLibrary.TestFramework.LogError("003", "TestClass1 is not Passed by reference.");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
- retVal = false;
- }
- return retVal;
- }
-
-
-}
-public class BaseClass
-{
-
-}
-public class TestClass : BaseClass
-{
-
-}
-public class TestClass1
-{
-
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
-public struct TestGenericType2
-{
- public void TestMethod<T>()
- {
- }
-}
-
-/// <summary>
-/// IsPointerImpl
-/// </summary>
-public class TypeIsPointerImpl
-{
- #region Private Fields
- private const int c_MIN_STRING_LENGTH = 1;
- private const int c_MAX_STRING_LENGTH = 128;
- #endregion
-
- #region Public Methods
- public bool RunTests()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- retVal = PosTest3() && retVal;
- retVal = PosTest4() && retVal;
-
- TestLibrary.TestFramework.LogInformation("[Negative]");
- retVal = NegTest1() && retVal;
-
- return retVal;
- }
-
- #region Positive Test Cases
- public bool PosTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: IsPointerImpl should return false for value type");
-
- try
- {
- int obj = TestLibrary.Generator.GetInt32(-55);
- Type type = obj.GetType();
-
- if (type.IsPointer)
- {
- TestLibrary.TestFramework.LogError("001", "IsPointerImpl returns true for value type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest2()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest2: IsPointerImpl should return false for reference type");
-
- try
- {
- String obj = TestLibrary.Generator.GetString(-55, false, c_MIN_STRING_LENGTH, c_MAX_STRING_LENGTH);
- Type type = obj.GetType();
-
- if (type.IsPointer)
- {
- TestLibrary.TestFramework.LogError("003", "IsPointerImpl returns true for reference type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest3()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest3: IsPointerImpl should return false for IntPtr");
-
- try
- {
- Type type = typeof(IntPtr);
-
- if (type.IsPointer)
- {
- TestLibrary.TestFramework.LogError("005", "IsPointerImpl returns true for IntPtr");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest4()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest4: IsPointerImpl should return true for a pointer type");
-
- try
- {
- Type type = typeof(int*);
-
- if (!type.IsPointer)
- {
- TestLibrary.TestFramework.LogError("007", "IsPointerImpl returns false for a pointer type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
-
- #region Nagetive Test Cases
- public bool NegTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("NegTest1: IsPointerImpl should return true for type contains generic member");
-
- try
- {
- Type type = typeof(TestGenericType2*);
- if (!type.IsPointer)
- {
- TestLibrary.TestFramework.LogError("101", "IsPointerImpl returns false for type contains generic member");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
- #endregion
-
- public static int Main()
- {
- TypeIsPointerImpl test = new TypeIsPointerImpl();
-
- TestLibrary.TestFramework.BeginTestCase("TypeIsPointerImpl");
-
- if (test.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
-/// <summary>
-/// MakeArrayType()
-/// </summary>
-public class TypeMakeArrayType1
-{
- #region Public Methods
- public bool RunTests()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- retVal = PosTest3() && retVal;
- retVal = PosTest4() && retVal;
- retVal = PosTest5() && retVal;
-
- return retVal;
- }
-
- #region Positive Test Cases
- public bool PosTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: Call MakeArrayType for reference type");
-
- try
- {
- Type type = typeof(String);
- Type arrayType = type.MakeArrayType();
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("001", "Call MakeArrayType for reference type does not make a array type");
- retVal = false;
- break;
- }
-
- if (arrayType.GetArrayRank() != 1)
- {
- TestLibrary.TestFramework.LogError("002", "Call MakeArrayType for reference type does not make a one dimension array type");
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest2()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest2: Call MakeArrayType for value type");
-
- try
- {
- Type type = typeof(Int32);
- Type arrayType = type.MakeArrayType();
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("004", "Call MakeArrayType for value type does not make a array type");
- retVal = false;
- break;
- }
-
- if (arrayType.GetArrayRank() != 1)
- {
- TestLibrary.TestFramework.LogError("005", "Call MakeArrayType for value type does not make a one dimension array type");
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest3()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest3: Call MakeArrayType for pointer type");
-
- try
- {
- Type type = typeof(char *);
- Type arrayType = type.MakeArrayType();
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("007", "Call MakeArrayType for pointer type does not make a array type");
- retVal = false;
- break;
- }
-
- if (arrayType.GetArrayRank() != 1)
- {
- TestLibrary.TestFramework.LogError("008", "Call MakeArrayType for pointer type does not make a one dimension array type");
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("009", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest4()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest4: Call MakeArrayType for value array type");
-
- try
- {
- Type type = typeof(int[]);
- Type arrayType = type.MakeArrayType();
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("010", "Call MakeArrayType for value array type does not make a array type");
- retVal = false;
- break;
- }
-
- if (arrayType.GetArrayRank() != 1)
- {
- TestLibrary.TestFramework.LogError("011", "Call MakeArrayType for value array type does not make a one dimension array type");
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest5()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest5: Call MakeArrayType for reference array type");
-
- try
- {
- Type type = typeof(String[]);
- Type arrayType = type.MakeArrayType();
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("013", "Call MakeArrayType for reference array type does not make a array type");
- retVal = false;
- break;
- }
-
- if (arrayType.GetArrayRank() != 1)
- {
- TestLibrary.TestFramework.LogError("014", "Call MakeArrayType for reference array type does not make a one dimension array type");
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("015", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
- #endregion
-
- public static int Main()
- {
- TypeMakeArrayType1 test = new TypeMakeArrayType1();
-
- TestLibrary.TestFramework.BeginTestCase("TypeMakeArrayType1");
-
- if (test.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
-/// <summary>
-/// MakeArrayType(System.Int32)
-/// </summary>
-public class TypeMakeArrayType2
-{
- #region Private Members
- private const int c_DEFAULT_MULTIPLE_ARRAY_DIMENSION = 4;
- #endregion
-
- #region Public Methods
- public bool RunTests()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- retVal = PosTest3() && retVal;
- retVal = PosTest4() && retVal;
- retVal = PosTest5() && retVal;
- retVal = PosTest6() && retVal;
-
- TestLibrary.TestFramework.LogInformation("[Negative]");
- retVal = NegTest1() && retVal;
- retVal = NegTest2() && retVal;
-
- return retVal;
- }
-
- #region Positive Test Cases
- public bool PosTest1()
- {
- bool retVal = true;
- int desiredDimension = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: Call MakeArrayType to make 1 dimension value type array");
-
- try
- {
- desiredDimension = 1;
- Type type = typeof(Int32);
- Type arrayType = type.MakeArrayType(desiredDimension);
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("001", "Call MakeArrayType for value type does not make a array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- retVal = false;
- break;
- }
-
- int actualDimension = arrayType.GetArrayRank();
- if (actualDimension != desiredDimension)
- {
- TestLibrary.TestFramework.LogError("002", "Call MakeArrayType for value type does not make a one dimension array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString() + "; actualDimension = " + actualDimension.ToString());
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("003", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest2()
- {
- bool retVal = true;
- int desiredDimension = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest2: Call MakeArrayType to make multiple dimensions value type array");
-
- try
- {
- desiredDimension = c_DEFAULT_MULTIPLE_ARRAY_DIMENSION;
- Type type = typeof(Int32);
- Type arrayType = type.MakeArrayType(desiredDimension);
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("004", "Call MakeArrayType for value type does not make a array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- retVal = false;
- break;
- }
-
- int actualDimension = arrayType.GetArrayRank();
- if (actualDimension != desiredDimension)
- {
- TestLibrary.TestFramework.LogError("005", "Call MakeArrayType for value type does not make a one dimension array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString() + "; actualDimension = " + actualDimension.ToString());
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest3()
- {
- bool retVal = true;
- int desiredDimension = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest3: Call MakeArrayType to make multiple dimensions reference type array");
-
- try
- {
- desiredDimension = c_DEFAULT_MULTIPLE_ARRAY_DIMENSION;
- Type type = typeof(String);
- Type arrayType = type.MakeArrayType(desiredDimension);
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("007", "Call MakeArrayType for reference type does not make a array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- retVal = false;
- break;
- }
-
- int actualDimension = arrayType.GetArrayRank();
- if (actualDimension != desiredDimension)
- {
- TestLibrary.TestFramework.LogError("008", "Call MakeArrayType for reference type does not make a multiple dimensions array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString() + "; actualDimension = " + actualDimension.ToString());
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("009", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest4()
- {
- bool retVal = true;
- int desiredDimension = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest4: Call MakeArrayType to make multiple dimensions pointer type array");
-
- try
- {
- desiredDimension = c_DEFAULT_MULTIPLE_ARRAY_DIMENSION;
- Type type = typeof(char *);
- Type arrayType = type.MakeArrayType(desiredDimension);
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("010", "Call MakeArrayType for pointer type does not make a array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- retVal = false;
- break;
- }
-
- int actualDimension = arrayType.GetArrayRank();
- if (actualDimension != desiredDimension)
- {
- TestLibrary.TestFramework.LogError("011", "Call MakeArrayType for pointer type does not make a multiple dimensions array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString() + "; actualDimension = " + actualDimension.ToString());
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("012", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest5()
- {
- bool retVal = true;
- int desiredDimension = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest5: Call MakeArrayType to make multiple dimensions reference array type array");
-
- try
- {
- desiredDimension = c_DEFAULT_MULTIPLE_ARRAY_DIMENSION;
- Type type = typeof(String[]);
- Type arrayType = type.MakeArrayType(desiredDimension);
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("013", "Call MakeArrayType for reference array type does not make a array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- retVal = false;
- break;
- }
-
- int actualDimension = arrayType.GetArrayRank();
- if (actualDimension != desiredDimension)
- {
- TestLibrary.TestFramework.LogError("014", "Call MakeArrayType for reference array type does not make a multiple dimensions array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString() + "; actualDimension = " + actualDimension.ToString());
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("015", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest6()
- {
- bool retVal = true;
- int desiredDimension = 0;
-
- TestLibrary.TestFramework.BeginScenario("PosTest6: Call MakeArrayType to make multiple dimensions value array type array");
-
- try
- {
- desiredDimension = c_DEFAULT_MULTIPLE_ARRAY_DIMENSION;
- Type type = typeof(int[]);
- Type arrayType = type.MakeArrayType(desiredDimension);
-
- do
- {
- if (!arrayType.IsArray)
- {
- TestLibrary.TestFramework.LogError("016", "Call MakeArrayType for value array type does not make a array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- retVal = false;
- break;
- }
-
- int actualDimension = arrayType.GetArrayRank();
- if (actualDimension != desiredDimension)
- {
- TestLibrary.TestFramework.LogError("017", "Call MakeArrayType for value array type does not make a multiple dimensions array type");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString() + "; actualDimension = " + actualDimension.ToString());
- retVal = false;
- break;
- }
- } while (false);
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("018", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] desiredDimension = " + desiredDimension.ToString());
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
-
- #region Nagetive Test Cases
- public bool NegTest1()
- {
- bool retVal = true;
- int rank = 0;
-
- TestLibrary.TestFramework.BeginScenario("NegTest1: IndexOutOfRangeException will be thrown when rank is invalid");
-
- try
- {
- rank = TestLibrary.Generator.GetByte(-55);
- if (rank > 0)
- rank = 0 - rank;
-
- Type type = typeof(Object);
- Type arrayType = type.MakeArrayType(rank);
-
- TestLibrary.TestFramework.LogError("101", "IndexOutOfRangeException is not thrown when rank is invalid");
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] rank = " + rank.ToString());
- retVal = false;
- }
- catch (IndexOutOfRangeException)
- {
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation("[LOCAL VARIABLES] rank = " + rank.ToString());
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool NegTest2()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("NegTest2: IndexOutOfRangeException will be thrown when rank is 0");
-
- try
- {
-
- Type type = typeof(Object);
- Type arrayType = type.MakeArrayType(0);
-
- TestLibrary.TestFramework.LogError("103", "IndexOutOfRangeException is not thrown when rank is 0");
- retVal = false;
- }
- catch (IndexOutOfRangeException)
- {
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("104", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
- #endregion
-
- public static int Main()
- {
- TypeMakeArrayType2 test = new TypeMakeArrayType2();
-
- TestLibrary.TestFramework.BeginTestCase("TypeMakeArrayType2");
-
- if (test.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
-/// <summary>
-/// MakeByRefType()
-/// </summary>
-public class TypeMakeByRefType
-{
- #region Public Methods
- public bool RunTests()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- retVal = PosTest3() && retVal;
- retVal = PosTest4() && retVal;
- retVal = PosTest5() && retVal;
-
- TestLibrary.TestFramework.LogInformation("[Negative]");
- retVal = NegTest1() && retVal;
-
- return retVal;
- }
-
- #region Positive Test Cases
- public bool PosTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: Call MakeByRefType for reference type");
-
- try
- {
- Type type = typeof(String);
- Type refType = type.MakeByRefType();
-
- if (!refType.IsByRef)
- {
- TestLibrary.TestFramework.LogError("001", "Call MakeByRefType for reference type does not make a byref type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest2()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest2: Call MakeByRefType for value type");
-
- try
- {
- Type type = typeof(int);
- Type refType = type.MakeByRefType();
-
- if (!refType.IsByRef)
- {
- TestLibrary.TestFramework.LogError("003", "Call MakeByRefType for value type does not make a byref type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest3()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest3: Call MakeByRefType for value array type");
-
- try
- {
- Type type = typeof(int[]);
- Type refType = type.MakeByRefType();
-
- if (!refType.IsByRef)
- {
- TestLibrary.TestFramework.LogError("005", "Call MakeByRefType for value array type does not make a byref type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest4()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest4: Call MakeByRefType for reference array type");
-
- try
- {
- Type type = typeof(String[]);
- Type refType = type.MakeByRefType();
-
- if (!refType.IsByRef)
- {
- TestLibrary.TestFramework.LogError("007", "Call MakeByRefType for reference array type does not make a byref type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest5()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest5: Call MakeByRefType for pointer type");
-
- try
- {
- Type type = typeof(char *);
- Type refType = type.MakeByRefType();
-
- if (!refType.IsByRef)
- {
- TestLibrary.TestFramework.LogError("009", "Call MakeByRefType for pointer type does not make a byref type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
-
- #region Nagetive Test Cases
- public bool NegTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("NegTest1: TypeLoadException will be thrown when calling MakeByRefType for ByRef type");
-
- try
- {
- Type type = typeof(Object);
- type = type.MakeByRefType();
- Type refType = type.MakeByRefType();
-
- TestLibrary.TestFramework.LogError("101", "TypeLoadException is not thrown when calling MakeByRefType for ByRef type");
- retVal = false;
- }
- catch (TypeLoadException)
- {
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("102", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
- #endregion
-
- public static int Main()
- {
- TypeMakeByRefType test = new TypeMakeByRefType();
-
- TestLibrary.TestFramework.BeginTestCase("TypeMakeByRefType");
-
- if (test.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-}
+++ /dev/null
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-using System;
-
-/// <summary>
-/// MakePointerType
-/// </summary>
-public class TypeMakePointerType
-{
- #region Public Methods
- public bool RunTests()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.LogInformation("[Positive]");
- retVal = PosTest1() && retVal;
- retVal = PosTest2() && retVal;
- retVal = PosTest3() && retVal;
- retVal = PosTest4() && retVal;
- retVal = PosTest5() && retVal;
-
- return retVal;
- }
-
- #region Positive Test Cases
- public bool PosTest1()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest1: Call MakePointerType for a value type");
-
- try
- {
- Type type = typeof(int);
- Type pointerType = type.MakePointerType();
-
- if (!pointerType.IsPointer)
- {
- TestLibrary.TestFramework.LogError("001", "Call MakePointerType for a value type does not make a pointer type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("002", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest2()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest2: Call MakePointerType for a reference type");
-
- try
- {
- Type type = typeof(String);
- Type pointerType = type.MakePointerType();
-
- if (!pointerType.IsPointer)
- {
- TestLibrary.TestFramework.LogError("003", "Call MakePointerType for a reference type does not make a pointer type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("004", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest3()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest3: Call MakePointerType for a value array type");
-
- try
- {
- Type type = typeof(int[]);
- Type pointerType = type.MakePointerType();
-
- if (!pointerType.IsPointer)
- {
- TestLibrary.TestFramework.LogError("005", "Call MakePointerType for a value array type does not make a pointer type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("006", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest4()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest4: Call MakePointerType for a reference array type");
-
- try
- {
- Type type = typeof(String[]);
- Type pointerType = type.MakePointerType();
-
- if (!pointerType.IsPointer)
- {
- TestLibrary.TestFramework.LogError("007", "Call MakePointerType for a reference array type does not make a pointer type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("008", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
-
- public bool PosTest5()
- {
- bool retVal = true;
-
- TestLibrary.TestFramework.BeginScenario("PosTest5: Call MakePointerType for a pointer type");
-
- try
- {
- Type type = typeof(char *);
- Type pointerType = type.MakePointerType();
-
- if (!pointerType.IsPointer)
- {
- TestLibrary.TestFramework.LogError("009", "Call MakePointerType for a pointer type does not make a pointer type");
- retVal = false;
- }
- }
- catch (Exception e)
- {
- TestLibrary.TestFramework.LogError("010", "Unexpected exception: " + e);
- TestLibrary.TestFramework.LogInformation(e.StackTrace);
- retVal = false;
- }
-
- return retVal;
- }
- #endregion
- #endregion
-
- public static int Main()
- {
- TypeMakePointerType test = new TypeMakePointerType();
-
- TestLibrary.TestFramework.BeginTestCase("TypeMakePointerType");
-
- if (test.RunTests())
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("PASS");
- return 100;
- }
- else
- {
- TestLibrary.TestFramework.EndTestCase();
- TestLibrary.TestFramework.LogInformation("FAIL");
- return 0;
- }
- }
-}