Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/cecil.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTautvydas Žilys <tautvydas.zilys@gmail.com>2020-09-16 01:48:36 +0300
committerGitHub <noreply@github.com>2020-09-16 01:48:36 +0300
commit1e3bbed3ef66b79be7818f6c6ecf2ac639ffeb19 (patch)
treefaa9bd53158a19546066706747c9f3c739251b24 /Test/Mono.Cecil.Tests/MethodReferenceComparerTests.cs
parente94d04f9196e3bdec9226bcfb89571249f62b6f3 (diff)
Unity's Windows Runtime changes (#394)
* Implemented Windows Runtime projections for implemented interface overrides. * Don't redirect Windows Runtime projected methods on interfaces. * Add additional test cases for Windows Runtime interface projection. * Fix reading interface impl attributes when using immediate reading mode. * Do not project for windows runtime during read. A type will not be fully initialized during read, so don't attempt to project for Windows runtime until after all of the metadata reading is correct. If a type reading for a module is no completed, a call to BinaryRangeSearch in MetadataSystem can fail, because some of the entries in the types array will still be null. * Fix build warnings. * Remove method that got duplicated during a cherry pick. * Fixed an issue with MethodReferenceComparer where it would incorrectly identify two method references to be the same if they had the same declaring types, the same parameter counts and were both unresolvable. * Sync up latest changes to MethodReferenceComparer and TypeReferenceEquality comparer and also add tests for them. * Fix code formatting. * Remove extra char * Style fix Co-authored-by: Ignas Ziberkas <ignas@unity3d.com> Co-authored-by: Josh Peterson <petersonjm1@gmail.com> Co-authored-by: Jb Evain <jb@evain.net>
Diffstat (limited to 'Test/Mono.Cecil.Tests/MethodReferenceComparerTests.cs')
-rw-r--r--Test/Mono.Cecil.Tests/MethodReferenceComparerTests.cs135
1 files changed, 135 insertions, 0 deletions
diff --git a/Test/Mono.Cecil.Tests/MethodReferenceComparerTests.cs b/Test/Mono.Cecil.Tests/MethodReferenceComparerTests.cs
new file mode 100644
index 0000000..92e5de3
--- /dev/null
+++ b/Test/Mono.Cecil.Tests/MethodReferenceComparerTests.cs
@@ -0,0 +1,135 @@
+using NUnit.Framework;
+using System;
+using System.Linq;
+
+namespace Mono.Cecil.Tests {
+
+ [TestFixture]
+ public class MethodReferenceComparerTests : LoadAssemblyDefinitionForTestsBaseSimple {
+
+ private TypeDefinition _class1;
+ private TypeDefinition _class2;
+
+ [SetUp]
+ public void SetUp ()
+ {
+ SetupAssemblyDefinitions (typeof (MethodReferenceComparerTests).Assembly);
+ _class1 = TypeDefinitionUtils.TypeDefinitionFor (typeof (Class1), _assembly);
+ _class2 = TypeDefinitionUtils.TypeDefinitionFor (typeof (Class2), _assembly);
+ }
+
+ [Test]
+ public void MethodReferenceEqualsMethodDefinition ()
+ {
+ var typeDefinition = TypeDefinitionUtils.TypeDefinitionFor (typeof (Int32), _mscorlib);
+ var method = typeDefinition.Methods.Single (m => m.Name == "GetHashCode");
+ var methodReference = new MethodReference (method.Name, method.ReturnType, method.DeclaringType);
+ methodReference.HasThis = method.HasThis;
+
+ Assert.That (MethodReferenceComparer.AreEqual (method, methodReference), Is.True);
+ }
+
+ [Test]
+ public void VerifyMethodSignatureMatches ()
+ {
+ Assert.IsTrue (CompareSignatures ("MethodWithNoParametersOrReturn"));
+ Assert.IsTrue (CompareSignatures ("GenericMethodWithNoParametersOrReturn"));
+ Assert.IsFalse (CompareSignatures ("MethodWithNoParametersOrReturn", "GenericMethodWithNoParametersOrReturn"));
+
+ Assert.IsTrue (CompareSignatures ("MethodWithIntParameterAndVoidReturn"));
+ }
+
+ [Test]
+ public void VerifySignatureComparisonConsidersStatic ()
+ {
+ Assert.IsTrue (CompareSignatures ("StaticMethodWithNoParametersOrReturn"));
+ Assert.IsTrue (CompareSignatures ("StaticMethodWithNoParametersOrReturn"));
+ Assert.IsFalse (CompareSignatures ("MethodWithNoParametersOrReturn", "StaticMethodWithNoParametersOrReturn"));
+ Assert.IsFalse (CompareSignatures ("GenericMethodWithNoParametersOrReturn", "GenericStaticMethodWithNoParametersOrReturn"));
+ }
+
+ [Test]
+ public void VerifyMethodSignatureWithGenericParameters ()
+ {
+ Assert.IsTrue (CompareSignatures ("GenericMethodWithGenericParameter"));
+ Assert.IsTrue (CompareSignatures ("GenericMethodWithGenericParameterArray"));
+ Assert.IsTrue (CompareSignatures ("GenericMethodWithByReferenceGenericParameter"));
+ Assert.IsTrue (CompareSignatures ("GenericMethodWithGenericInstanceGenericParameter"));
+ }
+
+ [Test]
+ public void VerifyNonResolvableMethodReferencesWithDifferentParameterTypesAreNotEqual ()
+ {
+ var method1 = new MethodReference ("TestMethod", _class1.Module.TypeSystem.Void, _class1);
+ method1.Parameters.Add (new ParameterDefinition (new ByReferenceType (_class1.Module.TypeSystem.Int16)));
+
+ var method2 = new MethodReference ("TestMethod", _class1.Module.TypeSystem.Void, _class1);
+ method2.Parameters.Add (new ParameterDefinition (new ByReferenceType (_class1.Module.TypeSystem.Char)));
+
+ Assert.IsFalse (MethodReferenceComparer.AreEqual (method1, method2));
+ }
+
+ [Test]
+ public void VerifyNonResolvableRecursiveMethodsDontStackOverflow ()
+ {
+ var method1 = new MethodReference ("TestMethod", _class1.Module.TypeSystem.Void, _class1);
+ method1.GenericParameters.Add (new GenericParameter (method1));
+ method1.Parameters.Add (new ParameterDefinition (method1.GenericParameters[0]));
+
+ var method2 = new MethodReference ("TestMethod", _class1.Module.TypeSystem.Void, _class1);
+ method2.GenericParameters.Add (new GenericParameter (method2));
+ method2.Parameters.Add (new ParameterDefinition (method2.GenericParameters[0]));
+
+ Assert.IsTrue (MethodReferenceComparer.AreEqual (method1, method2));
+ }
+
+ bool CompareSignatures (string name)
+ {
+ return CompareSignatures (name, name);
+ }
+
+ bool CompareSignatures (string name1, string name2)
+ {
+ return MethodReferenceComparer.AreSignaturesEqual (GetMethod (_class1, name1), GetMethod (_class2, name2), TypeComparisonMode.SignatureOnly);
+ }
+
+ static MethodDefinition GetMethod (TypeDefinition type, string name)
+ {
+ return type.Methods.Single (m => m.Name == name);
+ }
+
+ class GenericClass<T> {
+
+ }
+
+ class Class1 {
+
+ void MethodWithNoParametersOrReturn () {}
+ void GenericMethodWithNoParametersOrReturn<T> () {}
+ static void StaticMethodWithNoParametersOrReturn () {}
+ static void GenericStaticMethodWithNoParametersOrReturn<T> () {}
+
+ void MethodWithIntParameterAndVoidReturn (int a) {}
+
+ void GenericMethodWithGenericParameter<T> (T t) {}
+ void GenericMethodWithGenericParameterArray<T> (T[] t) {}
+ void GenericMethodWithByReferenceGenericParameter<T> (ref T a) {}
+ void GenericMethodWithGenericInstanceGenericParameter<T> (GenericClass<T> a) {}
+ }
+
+ class Class2 {
+
+ void MethodWithNoParametersOrReturn () {}
+ void GenericMethodWithNoParametersOrReturn<T> () {}
+ static void StaticMethodWithNoParametersOrReturn () {}
+ static void GenericStaticMethodWithNoParametersOrReturn<T> () {}
+
+ void MethodWithIntParameterAndVoidReturn (int a) {}
+
+ void GenericMethodWithGenericParameter<T> (T t) {}
+ void GenericMethodWithGenericParameterArray<T> (T[] t) {}
+ void GenericMethodWithByReferenceGenericParameter<T> (ref T a) {}
+ void GenericMethodWithGenericInstanceGenericParameter<T> (GenericClass<T> a) {}
+ }
+ }
+}