* BOO-913: Ensures that there is a parent namespace before attempting to enter it.
[boo.git] / tests / BooCompiler.Tests / SupportingClasses.cs
blob8881a393a6667579fa4f60a17c94873f5533dcec
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 ReturnDucks
52 public class DuckBase {}
54 public class DuckFoo : DuckBase
56 public string Foo() { return "foo"; }
59 public class DuckBar : DuckBase
61 public string Bar() { return "bar"; }
64 [Boo.Lang.DuckTypedAttribute]
65 public DuckBase GetDuck(bool foo)
67 if (foo) return new DuckFoo();
68 return new DuckBar();
72 public struct Point
74 public int x;
75 public int y;
78 public struct Rectangle
80 Point _top;
81 public Point topLeft
83 get { return _top; }
84 set { _top = value; }
88 public struct Vector3
90 public float x, y, z;
93 public class Transform
95 Vector3 _position;
97 public Vector3 position
99 get { return _position; }
100 set { _position = value; }
104 public class BOO313BaseClass
106 Transform _t = new Transform();
107 public Transform transform
109 get { return _t; }
113 public class OutterClass
115 public class InnerClass
117 public static int X = 3;
121 public class OverrideBoolOperator
123 public static implicit operator bool(OverrideBoolOperator instance)
125 Console.WriteLine("OverrideBoolOperator.operator bool");
126 return false;
130 public struct ValueTypeOverrideBoolOperator
132 public static implicit operator bool(ValueTypeOverrideBoolOperator instance)
134 Console.WriteLine("ValueTypeOverrideBoolOperator.operator bool");
135 return false;
139 public class ExtendsOverridenBoolOperator : OverrideBoolOperator
141 [Boo.Lang.DuckTypedAttribute]
142 public ExtendsOverridenBoolOperator GetFoo()
144 return new ExtendsOverridenBoolOperator();
148 public class OverrideEqualityOperators
150 public static bool operator==(OverrideEqualityOperators lhs, OverrideEqualityOperators rhs)
152 if (Object.Equals(null, lhs))
154 Console.WriteLine("lhs is null");
157 if (Object.Equals(null, rhs))
159 Console.WriteLine("rhs is null");
161 return true;
164 public static bool operator!=(OverrideEqualityOperators lhs, OverrideEqualityOperators rhs)
166 if (Object.Equals(null, lhs))
168 Console.WriteLine("lhs is null");
171 if (Object.Equals(null, rhs))
173 Console.WriteLine("rhs is null");
175 return false;
179 public class AmbiguousBase
181 public string Path(string empty)
183 return "Base";
187 public class AmbiguousSub1 : AmbiguousBase
189 public new string Path
193 return "Sub1";
198 public class AmbiguousSub2 : AmbiguousSub1
202 [Flags]
203 public enum TestEnum
205 Foo = 1,
206 Bar = 2,
207 Baz = 4
210 public enum ByteEnum : byte
212 Foo = 1,
213 Bar = 2,
214 Baz = 4
217 public enum SByteEnum : sbyte
219 Foo = -1,
220 Bar = -2,
221 Baz = -4
224 public class Person
226 string _fname;
227 string _lname;
228 uint _age;
230 public Person()
234 public uint Age
238 return _age;
243 _age = value;
247 public string FirstName
251 return _fname;
256 _fname = value;
260 public string LastName
264 return _lname;
269 _lname = value;
274 public class PersonCollection : System.Collections.CollectionBase
276 public PersonCollection()
280 public Person this[int index]
284 return (Person)InnerList[index];
289 InnerList[index] = value;
293 public Person this[string fname]
297 foreach (Person p in InnerList)
299 if (p.FirstName == fname)
301 return p;
304 return null;
309 int index = 0;
310 foreach (Person p in InnerList)
312 if (p.FirstName == fname)
314 InnerList[index] = value;
315 break;
317 ++index;
322 public void Add(Person person)
324 InnerList.Add(person);
328 public class Clickable
330 public Clickable()
334 public event EventHandler Click;
336 public static event EventHandler Idle;
338 public void RaiseClick()
340 if (null != Click)
342 Click(this, EventArgs.Empty);
346 public static void RaiseIdle()
348 if (null != Idle)
350 Idle(null, EventArgs.Empty);
355 public class BaseClass
357 protected BaseClass()
361 protected BaseClass(string message)
363 Console.WriteLine("BaseClass.constructor('{0}')", message);
366 public virtual void Method0()
368 Console.WriteLine("BaseClass.Method0");
371 public virtual void Method0(string text)
373 Console.WriteLine("BaseClass.Method0('{0}')", text);
376 public virtual void Method1()
378 Console.WriteLine("BaseClass.Method1");
381 //for BOO-632 regression test
382 protected int _protectedfield = 0;
383 protected int ProtectedProperty
387 return _protectedfield;
392 _protectedfield = value;
397 public class DerivedClass : BaseClass
399 public DerivedClass()
403 public void Method2()
405 Method0();
406 Method1();
410 public class ClassWithNewMethod : DerivedClass
412 new public void Method2()
414 Console.WriteLine("ClassWithNewMethod.Method2");
418 public class VarArgs
420 public void Method()
422 Console.WriteLine("VarArgs.Method");
425 public void Method(params object[] args)
427 Console.WriteLine("VarArgs.Method({0})", Boo.Lang.Builtins.join(args, ", "));
431 public class Disposable : System.IDisposable
433 public Disposable()
435 Console.WriteLine("Disposable.constructor");
438 public void foo()
440 Console.WriteLine("Disposable.foo");
443 void System.IDisposable.Dispose()
445 Console.WriteLine("Disposable.Dispose");
449 public class Constants
451 public const string StringConstant = "Foo";
453 public const int IntegerConstant = 14;
455 public const uint UnsignedInt = 255;
457 public const ulong UnsignedLong = 297;
460 public class ByRef
462 public static void SetValue(int value, ref int output)
464 output = value;
467 public static void SetRef(object value, ref object output)
469 output = value;
472 public static void ReturnValue(int value, out int output)
474 output = value;
477 public static void ReturnRef(object value, out object output)
479 output = value;
483 public class PointersBase
485 public void Foo(ref int bar)
487 System.Console.WriteLine("PointersBase.Foo(int&)");
490 public unsafe void Foo(int* bar)
492 System.Console.WriteLine("Pointers.Foo(int*)");
496 public class Pointers : PointersBase
498 public new void Foo(ref int bar)
500 System.Console.WriteLine("Pointers.Foo(int&)");
504 public class NoParameterlessConstructor
506 public NoParameterlessConstructor(object param)
511 public abstract class AbstractClass
515 public abstract class AnotherAbstractClass
517 protected abstract string Foo();
519 public virtual string Bar()
521 return "Bar";