~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/nrefactory/ICSharpCode.NRefactory.Tests/TypeSystem/TypeSystemTests.TestCase.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
ļ»æ// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
 
2
// 
 
3
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
 
4
// software and associated documentation files (the "Software"), to deal in the Software
 
5
// without restriction, including without limitation the rights to use, copy, modify, merge,
 
6
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
 
7
// to whom the Software is furnished to do so, subject to the following conditions:
 
8
// 
 
9
// The above copyright notice and this permission notice shall be included in all copies or
 
10
// substantial portions of the Software.
 
11
// 
 
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
 
13
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 
14
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
 
15
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
 
16
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 
17
// DEALINGS IN THE SOFTWARE.
 
18
 
 
19
using System;
 
20
using System.Collections.Generic;
 
21
using System.Runtime.InteropServices;
 
22
using System.Runtime.CompilerServices;
 
23
 
 
24
[assembly: ICSharpCode.NRefactory.TypeSystem.TestCase.TypeTestAttribute(
 
25
        42, typeof(System.Action<>), typeof(IDictionary<string, IList<NUnit.Framework.TestAttribute>>))]
 
26
 
 
27
[assembly: TypeForwardedTo(typeof(Func<,>))]
 
28
 
 
29
namespace ICSharpCode.NRefactory.TypeSystem.TestCase
 
30
{
 
31
        public delegate S GenericDelegate<in T, out S>(T input) where T : S where S : class;
 
32
        
 
33
        public class SimplePublicClass
 
34
        {
 
35
                public void Method() {}
 
36
        }
 
37
        
 
38
        public class TypeTestAttribute : Attribute
 
39
        {
 
40
                public TypeTestAttribute(int a1, Type a2, Type a3) {}
 
41
        }
 
42
        
 
43
        [Params(1, StringComparison.CurrentCulture, null, 4.0, "Test")]
 
44
        public class ParamsAttribute : Attribute
 
45
        {
 
46
                public ParamsAttribute(params object[] x) {}
 
47
                
 
48
                [Params(Property = new string[] { "a", "b" })]
 
49
                public string[] Property { get; set; }
 
50
        }
 
51
        
 
52
        [Double(1)]
 
53
        public class DoubleAttribute : Attribute
 
54
        {
 
55
                public DoubleAttribute(double val) {}
 
56
        }
 
57
        
 
58
        public unsafe class DynamicTest
 
59
        {
 
60
                public dynamic SimpleProperty { get; set; }
 
61
                
 
62
                public List<dynamic> DynamicGenerics1(Action<object, dynamic[], object> param) { return null; }
 
63
                public void DynamicGenerics2(Action<object, dynamic, object> param) { }
 
64
                public void DynamicGenerics3(Action<int, dynamic, object> param) { }
 
65
                public void DynamicGenerics4(Action<int[], dynamic, object> param) { }
 
66
                public void DynamicGenerics5(Action<int*[], dynamic, object> param) { }
 
67
                public void DynamicGenerics6(ref Action<object, dynamic, object> param) { }
 
68
                public void DynamicGenerics7(Action<int[,][], dynamic, object> param) { }
 
69
        }
 
70
        
 
71
        public class GenericClass<A, B> where A : B
 
72
        {
 
73
                public void TestMethod<K, V>(string param) where V: K where K: IComparable<V> {}
 
74
                public void GetIndex<T>(T element) where T : IEquatable<T> {}
 
75
                
 
76
                public NestedEnum EnumField;
 
77
                
 
78
                public A Property { get; set; }
 
79
                
 
80
                public enum NestedEnum {
 
81
                        EnumMember
 
82
                }
 
83
        }
 
84
        
 
85
        public class PropertyTest
 
86
        {
 
87
                public int PropertyWithProtectedSetter { get; protected set; }
 
88
                
 
89
                public object PropertyWithPrivateSetter { get; private set; }
 
90
                
 
91
                public object PropertyWithoutSetter { get { return null; } }
 
92
                
 
93
                public string this[int index] { get { return "Test"; } set {} }
 
94
        }
 
95
        
 
96
        public enum MyEnum : short
 
97
        {
 
98
                First,
 
99
                Second,
 
100
                Flag1 = 0x10,
 
101
                Flag2 = 0x20,
 
102
                CombinedFlags = Flag1 | Flag2
 
103
        }
 
104
        
 
105
        public class Base<T>
 
106
        {
 
107
                public class Nested<X> {}
 
108
                
 
109
                public virtual void GenericMethodWithConstraints<X>(T a) where X : IComparer<T>, new() {}
 
110
        }
 
111
        public class Derived<A, B> : Base<B>
 
112
        {
 
113
                public override void GenericMethodWithConstraints<Y>(B a) { }
 
114
        }
 
115
        
 
116
        public struct MyStructWithCtor
 
117
        {
 
118
                public MyStructWithCtor(int a) {}
 
119
        }
 
120
        
 
121
        public class MyClassWithCtor
 
122
        {
 
123
                private MyClassWithCtor(int a) {}
 
124
        }
 
125
        
 
126
        [Serializable]
 
127
        public class NonCustomAttributes
 
128
        {
 
129
                [NonSerialized]
 
130
                public readonly int NonSerializedField;
 
131
                
 
132
                [DllImport("unmanaged.dll", CharSet = CharSet.Unicode)]
 
133
                [return: MarshalAs(UnmanagedType.Bool)]
 
134
                public static extern bool DllMethod([In, Out] ref int p);
 
135
        }
 
136
        
 
137
        [StructLayout(LayoutKind.Explicit, CharSet = CharSet.Unicode, Pack = 8)]
 
138
        public struct ExplicitFieldLayoutStruct
 
139
        {
 
140
                [FieldOffset(0)]
 
141
                public int Field0;
 
142
                
 
143
                [FieldOffset(100)]
 
144
                public int Field100;
 
145
        }
 
146
        
 
147
        public class ParameterTests
 
148
        {
 
149
                public void MethodWithOutParameter(out int x) { x = 0; }
 
150
                public void MethodWithParamsArray(params object[] x) {}
 
151
                public void MethodWithOptionalParameter(int x = 4) {}
 
152
                public void MethodWithExplicitOptionalParameter([Optional] int x) {}
 
153
                public void MethodWithEnumOptionalParameter(StringComparison x = StringComparison.OrdinalIgnoreCase) {}
 
154
        }
 
155
        
 
156
        [ComImport(), Guid("21B8916C-F28E-11D2-A473-00C04F8EF448"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
 
157
        public interface IAssemblyEnum
 
158
        {
 
159
                [PreserveSig()]
 
160
                int GetNextAssembly(uint dwFlags);
 
161
        }
 
162
        
 
163
        public class ConstantTest
 
164
        {
 
165
                public const int Answer = 42;
 
166
                
 
167
                public const StringComparison EnumFromAnotherAssembly = StringComparison.OrdinalIgnoreCase;
 
168
                
 
169
                public const string NullString = null;
 
170
        }
 
171
        
 
172
        public class OuterGeneric<X>
 
173
        {
 
174
                public class Inner {
 
175
                        public OuterGeneric<X> referenceToOuter;
 
176
                        public Inner(OuterGeneric<X> referenceToOuter) {}
 
177
                }
 
178
                
 
179
                public OuterGeneric<X>.Inner Field1;
 
180
                public Inner Field2;
 
181
                public OuterGeneric<OuterGeneric<X>.Inner>.Inner Field3;
 
182
        }
 
183
        
 
184
        public class ExplicitDisposableImplementation : IDisposable
 
185
        {
 
186
                void IDisposable.Dispose() {}
 
187
        }
 
188
        
 
189
        public interface IGenericInterface<T>
 
190
        {
 
191
                void Test<S>(T a, S b) where S : T;
 
192
                void Test<S>(T a, ref S b);
 
193
        }
 
194
        
 
195
        public class ExplicitGenericInterfaceImplementation : IGenericInterface<string>
 
196
        {
 
197
                void IGenericInterface<string>.Test<T>(string a, T b) {}
 
198
                void IGenericInterface<string>.Test<T>(string a, ref T b) {}
 
199
        }
 
200
        
 
201
        public interface IGenericInterfaceWithUnifiableMethods<T, S>
 
202
        {
 
203
                void Test(T a);
 
204
                void Test(S a);
 
205
        }
 
206
        
 
207
        public class ImplementationOfUnifiedMethods : IGenericInterfaceWithUnifiableMethods<int, int>
 
208
        {
 
209
                public void Test(int a) {}
 
210
        }
 
211
        
 
212
        public class ExplicitGenericInterfaceImplementationWithUnifiableMethods<T, S> : IGenericInterfaceWithUnifiableMethods<T, S>
 
213
        {
 
214
                void IGenericInterfaceWithUnifiableMethods<T, S>.Test(T a) {}
 
215
                void IGenericInterfaceWithUnifiableMethods<T, S>.Test(S a) {}
 
216
        }
 
217
        
 
218
        public partial class PartialClass
 
219
        {
 
220
                partial void PartialMethodWithImplementation(int a);
 
221
                
 
222
                partial void PartialMethodWithImplementation(System.Int32 a)
 
223
                {
 
224
                }
 
225
                
 
226
                partial void PartialMethodWithImplementation(string a);
 
227
                
 
228
                partial void PartialMethodWithImplementation(System.String a)
 
229
                {
 
230
                }
 
231
                
 
232
                partial void PartialMethodWithoutImplementation();
 
233
        }
 
234
        
 
235
        public class ClassWithStaticAndNonStaticMembers
 
236
        {
 
237
                public static event System.EventHandler Event1 { add {} remove{} }
 
238
                public event System.EventHandler Event2 { add {} remove{} }
 
239
                #pragma warning disable 67
 
240
                public static event System.EventHandler Event3;
 
241
                public event System.EventHandler Event4;
 
242
 
 
243
                public static int Prop1 { get { return 0; } set {} }
 
244
                public int Prop2 { get { return 0; } set {} }
 
245
                public static int Prop3 { get; set; }
 
246
                public int Prop4 { get; set; }
 
247
        }
 
248
 
 
249
        public interface IInterfaceWithProperty {
 
250
                int Prop { get; set; }
 
251
        }
 
252
 
 
253
        public class ClassWithVirtualProperty {
 
254
                public virtual int Prop { get; set; }
 
255
        }
 
256
        
 
257
        public class ClassThatOverridesAndSealsVirtualProperty : ClassWithVirtualProperty {
 
258
                public sealed override int Prop { get; set; }
 
259
        }
 
260
 
 
261
        public class ClassThatImplementsProperty : IInterfaceWithProperty {
 
262
                public int Prop { get; set; }
 
263
        }
 
264
 
 
265
        public class ClassThatImplementsPropertyExplicitly : IInterfaceWithProperty {
 
266
                int IInterfaceWithProperty.Prop { get; set; }
 
267
        }
 
268
 
 
269
        public interface IInterfaceWithIndexers {
 
270
                int this[int x] { get; set; }
 
271
                int this[string x] { get; set; }
 
272
                int this[int x, int y] { get; set; }
 
273
        }
 
274
 
 
275
        public interface IGenericInterfaceWithIndexer<T> {
 
276
                int this[T x] { get; set; }
 
277
        }
 
278
 
 
279
        public class ClassThatImplementsIndexers : IInterfaceWithIndexers, IGenericInterfaceWithIndexer<int> {
 
280
                public int this[int x] { get { return 0; } set {} }
 
281
                public int this[string x] { get { return 0; } set {} }
 
282
                public int this[int x, int y] { get { return 0; } set {} }
 
283
        }
 
284
 
 
285
        public class ClassThatImplementsIndexersExplicitly : IInterfaceWithIndexers, IGenericInterfaceWithIndexer<int> {
 
286
                int IInterfaceWithIndexers.this[int x] { get { return 0; } set {} }
 
287
                int IGenericInterfaceWithIndexer<int>.this[int x] { get { return 0; } set {} }
 
288
                int IInterfaceWithIndexers.this[string x] { get { return 0; } set {} }
 
289
                int IInterfaceWithIndexers.this[int x, int y] { get { return 0; } set {} }
 
290
        }
 
291
 
 
292
        public interface IHasEvent {
 
293
                event EventHandler Event;
 
294
        }
 
295
 
 
296
        public class ClassThatImplementsEvent : IHasEvent {
 
297
                public event EventHandler Event;
 
298
        }
 
299
 
 
300
        public class ClassThatImplementsEventWithCustomAccessors : IHasEvent {
 
301
                public event EventHandler Event { add {} remove {} }
 
302
        }
 
303
 
 
304
        public class ClassThatImplementsEventExplicitly : IHasEvent {
 
305
                event EventHandler IHasEvent.Event { add {} remove {} }
 
306
        }
 
307
 
 
308
        public interface IShadowTestBase {
 
309
                void Method();
 
310
                int this[int i] { get; set; }
 
311
                int Prop { get; set; }
 
312
                event EventHandler Evt;
 
313
        }
 
314
 
 
315
        public interface IShadowTestDerived : IShadowTestBase {
 
316
                new void Method();
 
317
                new int this[int i] { get; set; }
 
318
                new int Prop { get; set; }
 
319
                new event EventHandler Evt;
 
320
        }
 
321
        
 
322
        public static class StaticClass {}
 
323
        public abstract class AbstractClass {}
 
324
        
 
325
        public class IndexerNonDefaultName {
 
326
                [IndexerName("Foo")]
 
327
                public int this[int index] {
 
328
                        get { return 0; }
 
329
                }
 
330
        }
 
331
 
 
332
        public class ClassWithMethodThatHasNullableDefaultParameter {
 
333
                public void Foo (int? bar = 42) { }
 
334
        }
 
335
 
 
336
        public class AccessibilityTest
 
337
        {
 
338
                public void Public() {}
 
339
                internal void Internal() {}
 
340
                protected internal void ProtectedInternal() {}
 
341
                internal protected void InternalProtected() {}
 
342
                protected void Protected() {}
 
343
                private void Private() {}
 
344
                void None() {}
 
345
        }
 
346
 
 
347
        public class ConstantFieldTest
 
348
        {
 
349
                public const byte Cb = 42;
 
350
                public const sbyte Csb = 42;
 
351
                public const char Cc = '\x42';
 
352
                public const short Cs = 42;
 
353
                public const ushort Cus = 42;
 
354
                public const int Ci = 42;
 
355
                public const uint Cui = 42;
 
356
                public const long Cl = 42;
 
357
                public const ulong Cul = 42;
 
358
                public const double Cd = 42;
 
359
                public const float Cf = 42;
 
360
                public const decimal Cm = 42;
 
361
                public const string S = "hello, world";
 
362
 
 
363
                public const int SOsb = sizeof(sbyte);
 
364
                public const int SOb  = sizeof(byte);
 
365
                public const int SOs  = sizeof(short);
 
366
                public const int SOus = sizeof(ushort);
 
367
                public const int SOi  = sizeof(int);
 
368
                public const int SOui = sizeof(uint);
 
369
                public const int SOl  = sizeof(long);
 
370
                public const int SOul = sizeof(ulong);
 
371
                public const int SOc  = sizeof(char);
 
372
                public const int SOf  = sizeof(float);
 
373
                public const int SOd  = sizeof(double);
 
374
                public const int SObl = sizeof(bool);
 
375
            public static readonly unsafe int SOe = sizeof(MyEnum);
 
376
        }
 
377
}