2 // RuntimeMethodHandleTest.cs - Unit tests for System.RuntimeMethodHandle
5 // Gert Driesen <drieseng@users.sourceforge.net>
7 // Copyright (C) 2007 Gert Driesen
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Runtime.Serialization;
32 using System.Runtime.Serialization.Formatters.Binary;
34 using NUnit.Framework;
36 namespace MonoTests.System
39 public class RuntimeMethodHandleTest
42 public void Equals_Object ()
44 Type type = typeof (RuntimeMethodHandleTest);
45 RuntimeMethodHandle rmhA1 = type.GetMethod ("Equals_Object").MethodHandle;
46 RuntimeMethodHandle rmhA2 = type.GetMethod ("Equals_Object").MethodHandle;
47 RuntimeMethodHandle rmhB1 = type.GetMethod ("Equals_RuntimeMethodHandle").MethodHandle;
48 RuntimeMethodHandle rmhB2 = type.GetMethod ("Equals_RuntimeMethodHandle").MethodHandle;
50 Assert.IsTrue (rmhA1.Equals((object) rmhA1), "#1");
51 Assert.IsTrue (rmhA1.Equals ((object) rmhA2), "#2");
52 Assert.IsTrue (rmhB1.Equals ((object) rmhB1), "#3");
53 Assert.IsTrue (rmhB2.Equals ((object) rmhB1), "#4");
54 Assert.IsFalse (rmhA1.Equals ((object) rmhB1), "#5");
55 Assert.IsFalse (rmhB1.Equals ((object) rmhA1), "#6");
56 Assert.IsFalse (rmhA1.Equals (null), "#7");
57 Assert.IsFalse (rmhA1.Equals (5), "#8");
61 public void Equals_RuntimeMethodHandle ()
63 Type type = typeof (RuntimeMethodHandleTest);
64 RuntimeMethodHandle rmhA1 = type.GetMethod ("Equals_Object").MethodHandle;
65 RuntimeMethodHandle rmhA2 = type.GetMethod ("Equals_Object").MethodHandle;
66 RuntimeMethodHandle rmhB1 = type.GetMethod ("Equals_RuntimeMethodHandle").MethodHandle;
67 RuntimeMethodHandle rmhB2 = type.GetMethod ("Equals_RuntimeMethodHandle").MethodHandle;
69 Assert.IsTrue (rmhA1.Equals (rmhA1), "#1");
70 Assert.IsTrue (rmhA1.Equals (rmhA2), "#2");
71 Assert.IsTrue (rmhB1.Equals (rmhB1), "#3");
72 Assert.IsTrue (rmhB2.Equals (rmhB1), "#4");
73 Assert.IsFalse (rmhA1.Equals (rmhB1), "#5");
74 Assert.IsFalse (rmhB1.Equals (rmhA1), "#6");
78 #pragma warning disable 1718
80 public void Operators ()
82 Type type = typeof (RuntimeMethodHandleTest);
83 RuntimeMethodHandle rmhA1 = type.GetMethod ("Operators").MethodHandle;
84 RuntimeMethodHandle rmhA2 = type.GetMethod ("Operators").MethodHandle;
85 RuntimeMethodHandle rmhB1 = type.GetMethod ("Equals_Object").MethodHandle;
86 RuntimeMethodHandle rmhB2 = type.GetMethod ("Equals_Object").MethodHandle;
89 Assert.IsTrue (rmhA1 == rmhA1, "#A1");
90 Assert.IsTrue (rmhA1 == rmhA2, "#A2");
91 Assert.IsTrue (rmhB1 == rmhB1, "#A3");
92 Assert.IsTrue (rmhB2 == rmhB1, "#A4");
93 Assert.IsFalse (rmhA1 == rmhB1, "#A5");
94 Assert.IsFalse (rmhB1 == rmhA1, "#A6");
97 Assert.IsFalse (rmhA1 != rmhA1, "#B1");
98 Assert.IsFalse (rmhA1 != rmhA2, "#B2");
99 Assert.IsFalse (rmhB1 != rmhB1, "#B3");
100 Assert.IsFalse (rmhB2 != rmhB1, "#B4");
101 Assert.IsTrue (rmhA1 != rmhB1, "#B5");
102 Assert.IsTrue (rmhB1 != rmhA1, "#B6");
104 #pragma warning restore 1718
108 [ExpectedException (typeof (SerializationException))]
109 public void Serialization_Of_Empty_Handle ()
111 RuntimeMethodHandle handle = new RuntimeMethodHandle ();
112 new BinaryFormatter ().Serialize (Stream.Null, handle);