PageRenderTime 40ms CodeModel.GetById 33ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/rocks/Test/Mono.Cecil.Tests/TypeReferenceRocksTests.cs

http://github.com/jbevain/cecil
C# | 124 lines | 89 code | 35 blank | 0 comment | 0 complexity | 7f26c996458d70d3aee05ce4aa762c82 MD5 | raw file
  1using System;
  2
  3using Mono.Cecil.Rocks;
  4
  5using NUnit.Framework;
  6
  7namespace Mono.Cecil.Tests {
  8
  9	[TestFixture]
 10	public class TypeReferenceRocksTests {
 11
 12		[Test]
 13		public void MakeArrayType ()
 14		{
 15			var @string = GetTypeReference (typeof (string));
 16
 17			var string_array = @string.MakeArrayType ();
 18
 19			Assert.IsInstanceOf (typeof (ArrayType), string_array);
 20			Assert.AreEqual (1, string_array.Rank);
 21		}
 22
 23		[Test]
 24		public void MakeArrayTypeRank ()
 25		{
 26			var @string = GetTypeReference (typeof (string));
 27
 28			var string_array = @string.MakeArrayType (3);
 29
 30			Assert.IsInstanceOf (typeof (ArrayType), string_array);
 31			Assert.AreEqual (3, string_array.Rank);
 32		}
 33
 34		[Test]
 35		public void MakePointerType ()
 36		{
 37			var @string = GetTypeReference (typeof (string));
 38
 39			var string_ptr = @string.MakePointerType ();
 40
 41			Assert.IsInstanceOf (typeof (PointerType), string_ptr);
 42		}
 43
 44		[Test]
 45		public void MakeByReferenceType ()
 46		{
 47			var @string = GetTypeReference (typeof (string));
 48
 49			var string_byref = @string.MakeByReferenceType ();
 50
 51			Assert.IsInstanceOf (typeof (ByReferenceType), string_byref);
 52		}
 53
 54		class OptionalModifier {}
 55
 56		[Test]
 57		public void MakeOptionalModifierType ()
 58		{
 59			var @string = GetTypeReference (typeof (string));
 60			var modopt = GetTypeReference (typeof (OptionalModifier));
 61
 62			var string_modopt = @string.MakeOptionalModifierType (modopt);
 63
 64			Assert.IsInstanceOf (typeof (OptionalModifierType), string_modopt);
 65			Assert.AreEqual (modopt, string_modopt.ModifierType);
 66		}
 67
 68		class RequiredModifier { }
 69
 70		[Test]
 71		public void MakeRequiredModifierType ()
 72		{
 73			var @string = GetTypeReference (typeof (string));
 74			var modreq = GetTypeReference (typeof (RequiredModifierType));
 75
 76			var string_modreq = @string.MakeRequiredModifierType (modreq);
 77
 78			Assert.IsInstanceOf (typeof (RequiredModifierType), string_modreq);
 79			Assert.AreEqual (modreq, string_modreq.ModifierType);
 80		}
 81
 82		[Test]
 83		public void MakePinnedType ()
 84		{
 85			var byte_array = GetTypeReference (typeof (byte []));
 86
 87			var pinned_byte_array = byte_array.MakePinnedType ();
 88
 89			Assert.IsInstanceOf (typeof (PinnedType), pinned_byte_array);
 90		}
 91
 92		[Test]
 93		public void MakeSentinelType ()
 94		{
 95			var @string = GetTypeReference (typeof (string));
 96
 97			var string_sentinel = @string.MakeSentinelType ();
 98
 99			Assert.IsInstanceOf (typeof (SentinelType), string_sentinel);
100		}
101
102		class Foo<T1, T2> {}
103
104		[Test]
105		public void MakeGenericInstanceType ()
106		{
107			var foo = GetTypeReference (typeof (Foo<,>));
108			var @string = GetTypeReference (typeof (string));
109			var @int = GetTypeReference (typeof (int));
110
111			var foo_string_int = foo.MakeGenericInstanceType (@string, @int);
112
113			Assert.IsInstanceOf (typeof (GenericInstanceType), foo_string_int);
114			Assert.AreEqual (2, foo_string_int.GenericArguments.Count);
115			Assert.AreEqual (@string, foo_string_int.GenericArguments [0]);
116			Assert.AreEqual (@int, foo_string_int.GenericArguments [1]);
117		}
118
119		static TypeReference GetTypeReference (Type type)
120		{
121			return ModuleDefinition.ReadModule (typeof (TypeReferenceRocksTests).Module.FullyQualifiedName).ImportReference (type);
122		}
123	}
124}