X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2Fcorlib%2FTest%2FSystem%2FAppDomainTest.cs;h=9c950226391ce42bf60a5e48f7c724be13bab6ba;hb=17183a6fbf75a5ca960d7541676aea7fd7b09d21;hp=14083841787ff1bad4efc129e4097c0ab54777f0;hpb=0aedc3f6fb2194817c766659c50a7e7f4786672e;p=mono.git diff --git a/mcs/class/corlib/Test/System/AppDomainTest.cs b/mcs/class/corlib/Test/System/AppDomainTest.cs index 14083841787..9c950226391 100644 --- a/mcs/class/corlib/Test/System/AppDomainTest.cs +++ b/mcs/class/corlib/Test/System/AppDomainTest.cs @@ -27,6 +27,8 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // +#if !MOBILE + using NUnit.Framework; using System; using System.Collections; @@ -1832,7 +1834,7 @@ namespace MonoTests.System Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); - Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5"); + Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5"); } } @@ -1848,7 +1850,7 @@ namespace MonoTests.System Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); - Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5"); + Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5"); } } @@ -1865,7 +1867,7 @@ namespace MonoTests.System Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); - Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5"); + Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5"); } } @@ -1883,7 +1885,7 @@ namespace MonoTests.System Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); Assert.IsNull (ex.InnerException, "#3"); Assert.IsNotNull (ex.Message, "#4"); - Assert.IsTrue (ex.Message.IndexOf (Consts.AssemblyCorlib) != -1, "#5"); + Assert.IsTrue (ex.Message.IndexOf (typeof (object).Assembly.FullName) != -1, "#5"); } } #endif @@ -2071,7 +2073,6 @@ namespace MonoTests.System AppDomain.CurrentDomain.ExecuteAssembly ( assembly.Location); Assert.Fail ("#1"); -#if NET_2_0 } catch (MissingMethodException ex) { // Entry point not found in assembly '...' Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); @@ -2079,15 +2080,6 @@ namespace MonoTests.System Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5"); } -#else - } catch (COMException ex) { - // Unspecified error - Assert.AreEqual (typeof (COMException), ex.GetType (), "#2"); - Assert.AreEqual (-2147467259, ex.ErrorCode, "#3"); - Assert.IsNull (ex.InnerException, "#4"); - Assert.IsNotNull (ex.Message, "#5"); - } -#endif } [Test] // ExecuteAssembly (String, Evidence) @@ -2100,7 +2092,6 @@ namespace MonoTests.System assembly.Location, (Evidence) null); Assert.Fail ("#1"); -#if NET_2_0 } catch (MissingMethodException ex) { // Entry point not found in assembly '...' Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); @@ -2108,15 +2099,6 @@ namespace MonoTests.System Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5"); } -#else - } catch (COMException ex) { - // Unspecified error - Assert.AreEqual (typeof (COMException), ex.GetType (), "#2"); - Assert.AreEqual (-2147467259, ex.ErrorCode, "#3"); - Assert.IsNull (ex.InnerException, "#4"); - Assert.IsNotNull (ex.Message, "#5"); - } -#endif } [Test] // ExecuteAssembly (String, Evidence, String []) @@ -2130,7 +2112,6 @@ namespace MonoTests.System (Evidence) null, new string [0]); Assert.Fail ("#1"); -#if NET_2_0 } catch (MissingMethodException ex) { // Entry point not found in assembly '...' Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); @@ -2138,15 +2119,6 @@ namespace MonoTests.System Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5"); } -#else - } catch (COMException ex) { - // Unspecified error - Assert.AreEqual (typeof (COMException), ex.GetType (), "#2"); - Assert.AreEqual (-2147467259, ex.ErrorCode, "#3"); - Assert.IsNull (ex.InnerException, "#4"); - Assert.IsNotNull (ex.Message, "#5"); - } -#endif } [Test] // ExecuteAssembly (String, Evidence, String [], Byte [], AssemblyHashAlgorithm) @@ -2163,7 +2135,6 @@ namespace MonoTests.System (byte []) null, AssemblyHashAlgorithm.SHA1); Assert.Fail ("#1"); -#if NET_2_0 } catch (MissingMethodException ex) { // Entry point not found in assembly '...' Assert.AreEqual (typeof (MissingMethodException), ex.GetType (), "#2"); @@ -2171,15 +2142,6 @@ namespace MonoTests.System Assert.IsNotNull (ex.Message, "#4"); Assert.IsTrue (ex.Message.IndexOf (assembly.FullName) != -1, "#5"); } -#else - } catch (COMException ex) { - // Unspecified error - Assert.AreEqual (typeof (COMException), ex.GetType (), "#2"); - Assert.AreEqual (-2147467259, ex.ErrorCode, "#3"); - Assert.IsNull (ex.InnerException, "#4"); - Assert.IsNotNull (ex.Message, "#5"); - } -#endif } [Test] // bug #79720 @@ -3042,14 +3004,9 @@ namespace MonoTests.System try { AppDomain.CurrentDomain.Load (aname); Assert.Fail ("#C9"); -#if NET_2_0 } catch (SecurityException) { // Invalid assembly public key } -#else - } catch (FileLoadException) { - } -#endif aname = new AssemblyName (); aname.Name = "bug79522C"; @@ -3210,6 +3167,30 @@ namespace MonoTests.System // we have no public way to get the default appdomain } + static bool resolve_called; + + [Test] + public void AssemblyResolveParseError () + { + AppDomain currentDomain = AppDomain.CurrentDomain; + ResolveEventHandler d = ParseErrorResolve; + currentDomain.AssemblyResolve += d; + try { + resolve_called = false; + var a = Assembly.Load ("MyDynamicType, 1.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756"); + Assert.Fail (); + } catch (FileNotFoundException) { + Assert.IsTrue (resolve_called); + } + currentDomain.AssemblyResolve -= d; + } + + static Assembly ParseErrorResolve (object sender, ResolveEventArgs args) + { + resolve_called = true; + return null; + } + [Test] public void ReflectionOnlyGetAssemblies () { @@ -3259,6 +3240,74 @@ namespace MonoTests.System } #endif + public class StuffToPick + { + public StuffToPick () {} + public void Method () {} + public int Property { get; set; } + public event Action Event; + public int Field; + public void GenericMethod () {} + } + + public class StuffToPick + { + public StuffToPick () {} + public void Method () {} + public int Property { get; set; } + public event Action Event; + public int Field; + public void GenericMethod () {} + } + + static void TestSerialization (CrossDomainTester tester, object o) + { + Assert.AreSame (o, tester.ReturnArg0 (o), "serializing_type_" + o.GetType ()); + } + + [Test] //BXC #12611 + public void ReflectionObjectsAreSerializableTest () + { + ad = CreateTestDomain (tempDir, true); + CrossDomainTester tester = CreateCrossDomainTester (ad); + + TestSerialization (tester, typeof (StuffToPick)); + TestSerialization (tester, typeof (StuffToPick).GetConstructor(new Type [0])); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("Method")); + TestSerialization (tester, typeof (StuffToPick).GetProperty ("Property")); + TestSerialization (tester, typeof (StuffToPick).GetEvent ("Event")); + TestSerialization (tester, typeof (StuffToPick).GetField ("Field")); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod")); + + TestSerialization (tester, typeof (StuffToPick<>)); + TestSerialization (tester, typeof (StuffToPick<>).GetConstructor(new Type [0])); + TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("Method")); + TestSerialization (tester, typeof (StuffToPick<>).GetProperty ("Property")); + TestSerialization (tester, typeof (StuffToPick<>).GetEvent ("Event")); + TestSerialization (tester, typeof (StuffToPick<>).GetField ("Field")); + TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod")); + + TestSerialization (tester, typeof (StuffToPick)); + TestSerialization (tester, typeof (StuffToPick).GetConstructor(new Type [0])); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("Method")); + TestSerialization (tester, typeof (StuffToPick).GetProperty ("Property")); + TestSerialization (tester, typeof (StuffToPick).GetEvent ("Event")); + TestSerialization (tester, typeof (StuffToPick).GetField ("Field")); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod")); + } + + [Test] //BXC #12611 + [Category ("NotWorking")] // Serialization can't handle generic methods + public void GenericReflectionObjectsAreSerializableTest () + { + ad = CreateTestDomain (tempDir, true); + CrossDomainTester tester = CreateCrossDomainTester (ad); + + TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))); + TestSerialization (tester, typeof (StuffToPick<>).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))); + TestSerialization (tester, typeof (StuffToPick).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))); + } + private static AppDomain CreateTestDomain (string baseDirectory, bool assemblyResolver) { AppDomainSetup setup = new AppDomainSetup (); @@ -3393,6 +3442,11 @@ namespace MonoTests.System return true; } } + + public object ReturnArg0 (object obj) + { + return obj; + } } [Serializable ()] @@ -3553,3 +3607,5 @@ namespace MonoTests.System static byte [] pk_token = { 0xce, 0x52, 0x76, 0xd8, 0x68, 0x7e, 0Xc6, 0xdc }; } } + +#endif \ No newline at end of file