Esempio n. 1
0
		public static void __TestIsBaseClassOf ()
		{
			object o1 = new TestA ();
			object o2 = new TestB ();
			object o3 = new TestC ();
			object o4 = new TestD ();
			InternalSystem.Object io1, io2, io3, io4;

			io1 = o1 as InternalSystem.Object;
			io2 = o2 as InternalSystem.Object;
			io3 = o3 as InternalSystem.Object;
			io4 = o4 as InternalSystem.Object;

			Testcase.Test (testdvt == io4.VTable,
				"Runtime", "Bad pointer in object for VTable (valuetype");
			Testcase.Test (testdvt.Type == io4.VTable.Type,
				"Runtime", "Bad pointer in vtable for TypeInfo (valuetype");

			Testcase.Test (io1.VTable != null,
				"Runtime", "InternalObject.VTable should never be null (ref io1)");
			Testcase.Test (io2.VTable != null,
				"Runtime", "InternalObject.VTable should never be null (ref io2)");
			Testcase.Test (io3.VTable != null,
				"Runtime", "InternalObject.VTable should never be null (ref io3)");
			Testcase.Test (io4.VTable != null,
				"Runtime", "InternalObject.VTable should never be null (valuetype io4)");

			Testcase.Test (io1.VTable.Type != null,
				"Runtime", "InternalObject.VTable.Type should never be null (ref io1)");
			Testcase.Test (io2.VTable.Type != null,
				"Runtime", "InternalObject.VTable.Type should never be null (ref io2)");
			Testcase.Test (io3.VTable.Type != null,
				"Runtime", "InternalObject.VTable.Type should never be null (ref io3)");
			Testcase.Test (io4.VTable.Type != null,
				"Runtime", "InternalObject.VTable.Type should never be null (valuetype io4)");

			Testcase.Test (io1.VTable.Type.Assembly != null,
				"Runtime", "InternalObject.VTable.Type.Assembly should never be null (ref io1)");
			Testcase.Test (io2.VTable.Type.Assembly != null,
				"Runtime", "InternalObject.VTable.Type.Assembly should never be null (ref io2)");
			Testcase.Test (io3.VTable.Type.Assembly != null,
				"Runtime", "InternalObject.VTable.Type.Assembly should never be null (ref io3)");
			Testcase.Test (io4.VTable.Type.Assembly != null,
				"Runtime", "InternalObject.VTable.Type.Assembly should never be null (valuetype io4)");

			Testcase.Test (IsValidAssemblyMetadata (io1.VTable.Type.Assembly),
				"Runtime", "InternalObject.VTable.Type.Assembly is listed in the metadata root (ref io1)");
			Testcase.Test (IsValidAssemblyMetadata (io2.VTable.Type.Assembly),
				"Runtime", "InternalObject.VTable.Type.Assembly is listed in the metadata root (ref io2)");
			Testcase.Test (IsValidAssemblyMetadata (io3.VTable.Type.Assembly),
				"Runtime", "InternalObject.VTable.Type.Assembly is listed in the metadata root (ref io3)");
			Testcase.Test (IsValidAssemblyMetadata (io4.VTable.Type.Assembly),
				"Runtime", "InternalObject.VTable.Type.Assembly is listed in the metadata root (valuetype io4)");

			Testcase.Test (io1.VTable.Type.MetadataToken != 0,
				"Runtime", "InternalObject.VTable.Type.MetadataToken should never be 0x0 (ref io1)");
			Testcase.Test (io2.VTable.Type.MetadataToken != 0,
				"Runtime", "InternalObject.VTable.Type.MetadataToken should never be 0x0 (ref io2)");
			Testcase.Test (io3.VTable.Type.MetadataToken != 0,
				"Runtime", "InternalObject.VTable.Type.MetadataToken should never be 0x0 (ref io3)");
			Testcase.Test (io4.VTable.Type.MetadataToken != 0,
				"Runtime", "InternalObject.VTable.Type.MetadataToken should never be 0x0 (valuetype io4)");

			Testcase.Test (HasValidMetadataToken (io1.VTable.Type.Assembly, io1.VTable.Type.MetadataToken),
				"Runtime", "InternalObject.VTable.Type has valid metadata token (ref io1)");
			Testcase.Test (HasValidMetadataToken (io2.VTable.Type.Assembly, io2.VTable.Type.MetadataToken),
				"Runtime", "InternalObject.VTable.Type has valid metadata token (ref io2)");
			Testcase.Test (HasValidMetadataToken (io3.VTable.Type.Assembly, io3.VTable.Type.MetadataToken),
				"Runtime", "InternalObject.VTable.Type has valid metadata token (ref io3)");
			Testcase.Test (HasValidMetadataToken (io4.VTable.Type.Assembly, io4.VTable.Type.MetadataToken),
				"Runtime", "InternalObject.VTable.Type has valid metadata token (valuetype io4)");

			Testcase.Test (Runtime.IsBaseClassOf (io2.VTable.Type, io1.VTable.Type),
				"Runtime", "IsBaseClassOf (new TestB (), new TestA ())");
			Testcase.Test (Runtime.IsBaseClassOf (io1.VTable.Type, io2.VTable.Type) == false,
				"Runtime", "IsBaseClassOf (new TestA (), new TestB ()) should be false");
			Testcase.Test (Runtime.IsBaseClassOf (io3.VTable.Type, io2.VTable.Type),
				"Runtime", "IsBaseClassOf (new TestC (), new TestB ())");
			Testcase.Test (Runtime.IsBaseClassOf (io3.VTable.Type, io1.VTable.Type),
				"Runtime", "IsBaseClassOf (new TestC (), new TestA ())");
			//Testcase.Test (Runtime.IsBaseClassOf (io4.VTable.Type, "System", "ValueType") == false,
			//	"Runtime", "IsBaseClassOf (new TestD (), ('System.ValueType'))");

			Runtime.Free (o1);
			Runtime.Free (o2);
			Runtime.Free (o3);
			Runtime.Free (o4);
		}
Esempio n. 2
0
		public static unsafe void __TestObjectConversion ()
		{
			TestA o1 = new TestA ();
			void *ptr = GetPointerFromObject (o1);
			object o2;

			o1.Member1 = 4;
			o2 = GetObjectFromPointer (ptr);

			Testcase.Test (o1 == o2, "Runtime",
				"Object conversion ((o1 (to) pointer (back to) object) == o1)");
			Testcase.Test (o1 == o2, "Runtime",
				"Object conversion (round trip by-reference comparison)");
			Testcase.Test (o1.Member1 == (o2 as TestA).Member1, "Runtime",
				"Object conversion (member check)");

			(o2 as TestA).Member1 = 6;

			Testcase.Test (o1.Member1 == 6, "Runtime",
				"Object conversion (modify member via second reference, member check)");

			Runtime.Free (o1);
		}