2 using System.Runtime.InteropServices;
3 using System.Runtime.Remoting;
4 using System.Runtime.Remoting.Channels;
5 using System.Runtime.Remoting.Channels.Tcp;
8 // The class in this namespace is used by the
10 namespace MonoTests.System.ActivatorTestInternal
12 // We need a COM class to test the Activator class
15 public class COMTest: MarshalByRefObject
21 // This property is visible
29 public COMTest(int id)
35 public bool constructorFlag = false;
37 } // MonoTests.System.ActivatorTestInternal namespace
39 namespace MonoTests.System
41 using MonoTests.System.ActivatorTestInternal;
44 public class ActivatorTest
46 public ActivatorTest()
50 [Ignore("Activator.CreateComInstanceForm is not yet implemented")]
51 // This test is ignored for the moment because
52 // CreateComInstanceFrom() is not implemented yet
53 // by the mono Activator class
54 public void CreateComInstanceFrom()
56 ObjectHandle objHandle = Activator.CreateComInstanceFrom(strAssembly ,
58 COMTest objCOMTest = (COMTest) objHandle.Unwrap();
60 Assertion.AssertEquals("#A01",10,objCOMTest.Id);
64 // This method tests CreateInstance()
65 public void CreateInstance()
68 // object CreateInstance(Type type)
69 objCOMTest = (COMTest) Activator.CreateInstance(typeof(COMTest));
70 Assertion.AssertEquals("#A02",
71 "MonoTests.System.ActivatorTestInternal.COMTest",
72 (objCOMTest.GetType()).ToString());
73 // ObjectHandle CreateInstance(string, string)
74 ObjectHandle objHandle;
75 objHandle = Activator.CreateInstance(null ,
76 "MonoTests.System.ActivatorTestInternal.COMTest");
77 objCOMTest = (COMTest) objHandle.Unwrap();
79 Assertion.AssertEquals("#A03", 2, objCOMTest.Id);
80 // object CreateInstance(Type, bool)
81 objCOMTest = (COMTest) Activator.CreateInstance((typeof(COMTest)), false);
82 Assertion.AssertEquals("#A04",
83 "MonoTests.System.ActivatorTestInternal.COMTest",
84 (objCOMTest.GetType()).ToString());
85 // // object CreateInstance(Type, object[])
86 object[] objArray = new object[1];
88 objCOMTest = (COMTest) Activator.CreateInstance((typeof(COMTest)), objArray);
89 Assertion.AssertEquals("#A05", 7, objCOMTest.Id);
90 // Todo: Implemente the test methods for
91 // all the overriden functions using activationAttribute
94 // This method tests GetObject from the Activator class
96 public void GetObject()
98 // object GetObject(Type, string)
100 // This will provide a COMTest object on tcp://localhost:1234/COMTestUri
101 COMTest objCOMTest = new COMTest(8);
102 TcpChannel chnServer = new TcpChannel(1234);
103 ChannelServices.RegisterChannel(chnServer);
104 RemotingServices.SetObjectUriForMarshal(objCOMTest, "COMTestUri");
105 RemotingServices.Marshal(objCOMTest);
107 // This will get the remoting object
108 object objRem = Activator.GetObject(typeof(COMTest),
109 "tcp://localhost:1234/COMTestUri");
110 Assertion.Assert("#A07",objRem != null);
111 COMTest remCOMTest = (COMTest) objRem;
112 Assertion.AssertEquals("#A08", 8, remCOMTest.Id);
114 ChannelServices.UnregisterChannel(chnServer);
115 // Todo: Implemente the test methods for
116 // all the overriden function using activationAttribute
119 // This method tests the CreateInstanceFrom methods
120 // of the Activator class
122 public void CreateInstanceFrom()
124 ObjectHandle objHandle;
125 objHandle = Activator.CreateInstanceFrom(strAssembly ,
126 "MonoTests.System.ActivatorTestInternal.COMTest");
127 Assertion.Assert("#A09", objHandle != null);
129 // Todo: Implement the test methods for
130 // all the overriden function using activationAttribute
133 // The name of the assembly file is incorrect.
134 // I used it to test these classes but you should
135 // replace it with the name of the mono tests assembly file
136 // The name of the assembly is used to get an object through
137 // Activator.CreateInstance(), Activator.CreateComInstanceFrom()...
138 private string strAssembly = "corlib_test.dll";