libgda-4.0, gedit-2.20: Fix gedit typo and GdaXaTransactionId.data
[vala-lang.git] / tests / objects / methods.vala
blob64fd4f0dea2f1e7b651d2d1fe46b4a8d1036737e
1 using GLib;
3 class Maman.Bar : Object {
4 public void do_action () {
5 stdout.printf (" 2");
8 public static void do_static_action () {
9 stdout.printf (" 2");
12 public virtual void do_virtual_action () {
13 stdout.printf (" BAD");
17 class Maman.SubBar : Bar {
18 public override void do_virtual_action () {
19 stdout.printf (" 2");
22 static void accept_ref_string (ref string str) {
25 static void test_classes_methods_ref_parameters () {
26 string str = "hello";
27 accept_ref_string (ref str);
30 public static int main () {
31 stdout.printf ("Inheritance Test: 1");
33 var bar = new SubBar ();
34 bar.do_action ();
36 stdout.printf (" 3\n");
38 stdout.printf ("Static Inheritance Test: 1");
40 do_static_action ();
42 stdout.printf (" 3\n");
44 stdout.printf ("Virtual Method Test: 1");
46 bar.do_virtual_action ();
48 stdout.printf (" 3\n");
50 // test symbol resolving to check that methods of implemented
51 // interfaces take precedence of methods in base classes
52 stdout.printf ("Interface Inheritance Test: 1");
54 var foobar = new SubFooBar ();
55 foobar.do_action ();
57 stdout.printf (" 3\n");
59 test_classes_methods_ref_parameters ();
61 BaseAccess.test ();
63 string str, str2;
64 weak string weak_str;
66 test_out (out str);
67 assert (str == "hello");
69 test_out_weak (out weak_str);
70 assert (weak_str == "hello");
72 test_out_weak (out str2);
73 assert (str2 == "hello");
75 test_ref (ref str);
76 assert (str == "world");
78 test_ref_weak (ref weak_str);
79 assert (weak_str == "world");
81 ClassTest.run_test ();
83 return 0;
87 interface Maman.Foo {
88 public void do_action () {
89 stdout.printf (" 2");
93 class Maman.FooBar : Object {
94 public void do_action () {
95 stdout.printf (" BAD");
99 class Maman.SubFooBar : FooBar, Foo {
102 // http://bugzilla.gnome.org/show_bug.cgi?id=523263
104 abstract class Maman.AbstractBase : Object {
105 public abstract void foo ();
108 abstract class Maman.AbstractDerived : AbstractBase {
109 public override void foo () {
113 class Maman.DeepDerived : AbstractDerived {
116 // http://bugzilla.gnome.org/show_bug.cgi?id=528457
117 namespace Maman.BaseAccess {
118 public interface IFoo : Object {
119 public abstract int interface_method ();
121 public abstract int virtual_interface_method ();
124 public class Foo : Object, IFoo {
125 public virtual int virtual_method () {
126 return 1;
129 public int interface_method () {
130 return 2;
133 public virtual int virtual_interface_method () {
134 return 3;
138 public class Bar : Foo {
139 public override int virtual_method () {
140 return base.virtual_method () * 10 + 4;
143 public override int virtual_interface_method () {
144 return base.virtual_interface_method () * 10 + 5;
148 public class FooBar : Foo, IFoo {
149 public int interface_method () {
150 return base.interface_method () * 10 + 6;
153 public int virtual_interface_method () {
154 return -1;
158 public void test () {
159 var bar = new Bar ();
160 var foobar = new FooBar ();
161 assert (bar.virtual_method () == 14);
162 assert (bar.virtual_interface_method () == 35);
163 assert (foobar.interface_method () == 26);
167 void test_out (out string bar) {
168 bar = "hello";
171 void test_out_weak (out weak string bar) {
172 bar = "hello";
175 void test_ref (ref string bar) {
176 assert (bar == "hello");
177 bar = "world";
180 void test_ref_weak (ref weak string bar) {
181 assert (bar == "hello");
182 bar = "world";
185 class Maman.ClassTest {
186 public class void class_method () {
187 stdout.printf(" OK\n");
190 public void instance_method () {
191 stdout.printf ("Access class method in instance method:");
192 class_method ();
195 class construct {
196 stdout.printf ("Access class method in class constructor:");
197 class_method ();
200 static construct {
201 stdout.printf ("Access class method in static constructor:");
202 class_method ();
205 public static void run_test () {
206 var c = new ClassTest ();
208 stdout.printf ("Access class method by member access:");
209 c.class_method ();
211 c.instance_method ();
215 void main () {
216 Maman.SubBar.main ();