BOO-999
[boo.git] / tests / BooCompiler.Tests / SupportingClasses.cs
blobd29f0fb9648cf432dc90cc680cb6fc72f48e5059
1 #region license
2 // Copyright (c) 2004, Rodrigo B. de Oliveira (rbo@acm.org)
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification,
6 // are permitted provided that the following conditions are met:
7 //
8 // * Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 // * Neither the name of Rodrigo B. de Oliveira nor the names of its
14 // contributors may be used to endorse or promote products derived from this
15 // software without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
21 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #endregion
29 namespace BooCompiler.Tests
31 using System;
33 public class ObsoleteClass
35 [Obsolete("It is." )]
36 public static int Bar = 42;
38 [Obsolete("Indeed it is." )]
39 public static void Foo()
43 [Obsolete("We said so.")]
44 public static int Baz
46 get { return 42; }
50 public class ConditionalClass
52 [System.Diagnostics.Conditional("BOO_COMPILER_TESTS_NOT_DEFINED_CONDITIONAL")]
53 public static void PrintNothing(int i)
55 Console.WriteLine(i);
58 [System.Diagnostics.Conditional("BOO_COMPILER_TESTS_DEFINED_CONDITIONAL")]
59 public static void PrintSomething(string s)
61 Console.WriteLine(s);
64 [System.Diagnostics.Conditional("BOO_COMPILER_TESTS_NOT_DEFINED_CONDITIONAL")]
65 public static void PrintNoT<T>(T s)
67 Console.WriteLine(s);
70 [System.Diagnostics.Conditional("BOO_COMPILER_TESTS_DEFINED_CONDITIONAL")]
71 public static void PrintSomeT<T>(T s)
73 Console.WriteLine(s);
77 public class ReturnDucks
79 public class DuckBase {}
81 public class DuckFoo : DuckBase
83 public string Foo() { return "foo"; }
86 public class DuckBar : DuckBase
88 public string Bar() { return "bar"; }
91 [Boo.Lang.DuckTypedAttribute]
92 public DuckBase GetDuck(bool foo)
94 if (foo) return new DuckFoo();
95 return new DuckBar();
99 public struct Point
101 public int x;
102 public int y;
105 public struct Rectangle
107 Point _top;
108 public Point topLeft
110 get { return _top; }
111 set { _top = value; }
115 public struct Vector3
117 public float x, y, z;
120 public class Transform
122 Vector3 _position;
124 public Vector3 position
126 get { return _position; }
127 set { _position = value; }
131 public class BOO313BaseClass
133 Transform _t = new Transform();
134 public Transform transform
136 get { return _t; }
140 public class OutterClass
142 public class InnerClass
144 public static int X = 3;
148 public class OverrideBoolOperator
150 public static implicit operator bool(OverrideBoolOperator instance)
152 Console.WriteLine("OverrideBoolOperator.operator bool");
153 return false;
157 public struct ValueTypeOverrideBoolOperator
159 public static implicit operator bool(ValueTypeOverrideBoolOperator instance)
161 Console.WriteLine("ValueTypeOverrideBoolOperator.operator bool");
162 return false;
166 public class ExtendsOverridenBoolOperator : OverrideBoolOperator
168 [Boo.Lang.DuckTypedAttribute]
169 public ExtendsOverridenBoolOperator GetFoo()
171 return new ExtendsOverridenBoolOperator();
175 public class OverrideEqualityOperators
177 public static bool operator==(OverrideEqualityOperators lhs, OverrideEqualityOperators rhs)
179 if (Object.Equals(null, lhs))
181 Console.WriteLine("lhs is null");
184 if (Object.Equals(null, rhs))
186 Console.WriteLine("rhs is null");
188 return true;
191 public static bool operator!=(OverrideEqualityOperators lhs, OverrideEqualityOperators rhs)
193 if (Object.Equals(null, lhs))
195 Console.WriteLine("lhs is null");
198 if (Object.Equals(null, rhs))
200 Console.WriteLine("rhs is null");
202 return false;
205 // Just to remove the warnings; non-functional
206 public override bool Equals(object obj)
208 throw new NotImplementedException("This override is for testing purposes only.");
211 // Just to remove the warnings; non-functional
212 public override int GetHashCode()
214 throw new NotImplementedException("This override is for testing purposes only.");
218 public class AmbiguousBase
220 public string Path(string empty)
222 return "Base";
226 public class AmbiguousSub1 : AmbiguousBase
228 public new string Path
232 return "Sub1";
237 public class AmbiguousSub2 : AmbiguousSub1
241 [Flags]
242 public enum TestEnum
244 Foo = 1,
245 Bar = 2,
246 Baz = 4
249 public enum ByteEnum : byte
251 Foo = 1,
252 Bar = 2,
253 Baz = 4
256 public enum SByteEnum : sbyte
258 Foo = -1,
259 Bar = -2,
260 Baz = -4
263 public class Person
265 string _fname;
266 string _lname;
267 uint _age;
269 public Person()
273 public uint Age
277 return _age;
282 _age = value;
286 public string FirstName
290 return _fname;
295 _fname = value;
299 public string LastName
303 return _lname;
308 _lname = value;
313 public class PersonCollection : System.Collections.CollectionBase
315 public PersonCollection()
319 public Person this[int index]
323 return (Person)InnerList[index];
328 InnerList[index] = value;
332 public Person this[string fname]
336 foreach (Person p in InnerList)
338 if (p.FirstName == fname)
340 return p;
343 return null;
348 int index = 0;
349 foreach (Person p in InnerList)
351 if (p.FirstName == fname)
353 InnerList[index] = value;
354 break;
356 ++index;
361 public void Add(Person person)
363 InnerList.Add(person);
367 public class Clickable
369 public Clickable()
373 public event EventHandler Click;
375 public static event EventHandler Idle;
377 public void RaiseClick()
379 if (null != Click)
381 Click(this, EventArgs.Empty);
385 public static void RaiseIdle()
387 if (null != Idle)
389 Idle(null, EventArgs.Empty);
394 public class BaseClass
396 protected BaseClass()
400 protected BaseClass(string message)
402 Console.WriteLine("BaseClass.constructor('{0}')", message);
405 public virtual void Method0()
407 Console.WriteLine("BaseClass.Method0");
410 public virtual void Method0(string text)
412 Console.WriteLine("BaseClass.Method0('{0}')", text);
415 public virtual void Method1()
417 Console.WriteLine("BaseClass.Method1");
420 //for BOO-632 regression test
421 protected int _protectedfield = 0;
422 protected int ProtectedProperty
426 return _protectedfield;
431 _protectedfield = value;
436 public class DerivedClass : BaseClass
438 public DerivedClass()
442 public void Method2()
444 Method0();
445 Method1();
449 public class ClassWithNewMethod : DerivedClass
451 new public void Method2()
453 Console.WriteLine("ClassWithNewMethod.Method2");
457 public class VarArgs
459 public void Method()
461 Console.WriteLine("VarArgs.Method");
464 public void Method(params object[] args)
466 Console.WriteLine("VarArgs.Method({0})", Boo.Lang.Builtins.join(args, ", "));
470 public class Disposable : System.IDisposable
472 public Disposable()
474 Console.WriteLine("Disposable.constructor");
477 public void foo()
479 Console.WriteLine("Disposable.foo");
482 void System.IDisposable.Dispose()
484 Console.WriteLine("Disposable.Dispose");
488 public class Constants
490 public const string StringConstant = "Foo";
492 public const int IntegerConstant = 14;
494 public const uint UnsignedInt = 255;
496 public const ulong UnsignedLong = 297;
499 public class ByRef
501 public static void SetValue(int value, ref int output)
503 output = value;
506 public static void SetRef(object value, ref object output)
508 output = value;
511 public static void ReturnValue(int value, out int output)
513 output = value;
516 public static void ReturnRef(object value, out object output)
518 output = value;
522 public class PointersBase
524 public void Foo(ref int bar)
526 System.Console.WriteLine("PointersBase.Foo(int&)");
529 public unsafe void Foo(int* bar)
531 System.Console.WriteLine("Pointers.Foo(int*)");
535 public class Pointers : PointersBase
537 public new void Foo(ref int bar)
539 System.Console.WriteLine("Pointers.Foo(int&)");
543 public class NoParameterlessConstructor
545 public NoParameterlessConstructor(object param)
550 public abstract class AbstractClass
554 public abstract class AnotherAbstractClass
556 protected abstract string Foo();
558 public virtual string Bar()
560 return "Bar";