5
// Mike Krüger <mkrueger@xamarin.com>
7
// Copyright (c) 2013 Xamarin Inc. (http://xamarin.com)
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
10
// of this software and associated documentation files (the "Software"), to deal
11
// in the Software without restriction, including without limitation the rights
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13
// copies of the Software, and to permit persons to whom the Software is
14
// furnished to do so, subject to the following conditions:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30
using System.Threading;
31
using ICSharpCode.NRefactory.CSharp.Resolver;
32
using ICSharpCode.NRefactory.TypeSystem;
33
using ICSharpCode.NRefactory.TypeSystem.Implementation;
34
using NUnit.Framework;
35
using ICSharpCode.NRefactory.CSharp.CodeCompletion;
37
namespace ICSharpCode.NRefactory.CSharp.Analysis
40
public class AbiComparerTests
42
AbiCompatibility Check (string before, string after)
44
IProjectContent oldPctx, newPctx;
46
ICSharpCode.NRefactory.CSharp.TypeSystem.CSharpUnresolvedFile file;
47
CodeCompletionBugTests.CreateCompilation (before, out oldPctx, out tree, out file, false);
48
CodeCompletionBugTests.CreateCompilation (after, out newPctx, out tree, out file, false);
49
return new AbiComparer ().Check (oldPctx.CreateCompilation (), newPctx.CreateCompilation ());
53
public void CheckEquality()
55
string a1 = @"namespace Foo { public class Bar { public void FooBar () {} public int Bar2 { get; set;} int removed; } class Removed {} }";
56
string a2 = @"namespace Foo { public class Bar { public void FooBar () {} public int Bar2 { get {} set{}} void Added () {} } class Added {} } namespace Added { class Test { } }";
57
Assert.AreEqual (AbiCompatibility.Equal, Check (a1, a2));
61
public void CheckBigger()
63
string a1 = @"namespace Foo { public class Bar { public void FooBar () {} } }";
64
string a2 = @"namespace Foo { public class Bar { public void FooBar () {} public void BarFoo () {} } }";
65
Assert.AreEqual (AbiCompatibility.Bigger, Check (a1, a2));
69
public void CheckIncompatible()
71
string a1 = @"namespace Foo { public class Bar { public void FooBar () {} } }";
72
string a2 = @"namespace Foo { public class Bar { public void FooBar (int bar) {} } }";
73
Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
77
public void CheckIncompatibleInterfaceChange()
79
string a1 = @"public interface IFoo {}";
80
string a2 = @"public interface IFoo { void Bar (); }";
81
Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
85
public void CheckTypeConstraintChange()
87
string a1 = @"public class IFoo<T> {}";
88
string a2 = @"public class IFoo<T> where T : System.IDisposable {}";
89
Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
93
public void CheckTypeConstraintChangeCase2()
95
string a1 = @"public class IFoo<T> {}";
96
string a2 = @"public class IFoo<T> where T : class {}";
97
Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));
101
public void CheckMethodConstraintChange()
103
string a1 = @"public class IFoo { public void Bar<T> () {} }";
104
string a2 = @"public class IFoo { public void Bar<T> () where T : System.IDisposable {} }";
105
Assert.AreEqual (AbiCompatibility.Incompatible, Check (a1, a2));