gtk+-4.0: Change type of Gdk.Key.* constants to uint
[vala-gnome.git] / tests / objects / methods.vala
blob9a950c322cce070a91708f4ba48a46ba864e2e41
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;
65 string[] array;
67 test_out (out str);
68 assert (str == "hello");
70 test_out_weak (out weak_str);
71 assert (weak_str == "hello");
73 test_out_weak (out str2);
74 assert (str2 == "hello");
76 test_ref (ref str);
77 assert (str == "world");
79 test_ref_weak (ref weak_str);
80 assert (weak_str == "world");
82 test_out_array_no_length (out array);
83 assert (array[0] == "hello");
84 assert (array[1] == "world");
85 assert (array.length < 0);
87 ClassTest.run_test ();
89 return 0;
93 interface Maman.Foo {
94 public void do_action () {
95 stdout.printf (" 2");
99 class Maman.FooBar : Object {
100 public void do_action () {
101 stdout.printf (" BAD");
105 class Maman.SubFooBar : FooBar, Foo {
108 // http://bugzilla.gnome.org/show_bug.cgi?id=523263
110 abstract class Maman.AbstractBase : Object {
111 public abstract void foo ();
114 abstract class Maman.AbstractDerived : AbstractBase {
115 public override void foo () {
119 class Maman.DeepDerived : AbstractDerived {
122 // http://bugzilla.gnome.org/show_bug.cgi?id=528457
123 namespace Maman.BaseAccess {
124 public interface IFoo : Object {
125 public abstract int interface_method ();
127 public abstract int virtual_interface_method ();
130 public class Foo : Object, IFoo {
131 public virtual int virtual_method () {
132 return 1;
135 public int interface_method () {
136 return 2;
139 public virtual int virtual_interface_method () {
140 return 3;
144 public class Bar : Foo {
145 public override int virtual_method () {
146 return base.virtual_method () * 10 + 4;
149 public override int virtual_interface_method () {
150 return base.virtual_interface_method () * 10 + 5;
154 public class FooBar : Foo, IFoo {
155 public int interface_method () {
156 return base.interface_method () * 10 + 6;
159 public int virtual_interface_method () {
160 return -1;
164 public void test () {
165 var bar = new Bar ();
166 var foobar = new FooBar ();
167 assert (bar.virtual_method () == 14);
168 assert (bar.virtual_interface_method () == 35);
169 assert (foobar.interface_method () == 26);
173 void test_out (out string bar) {
174 bar = "hello";
177 void test_out_weak (out weak string bar) {
178 bar = "hello";
181 void test_ref (ref string bar) {
182 assert (bar == "hello");
183 bar = "world";
186 void test_ref_weak (ref weak string bar) {
187 assert (bar == "hello");
188 bar = "world";
191 void test_out_array_no_length ([CCode (array_length = false)] out string[] bar) {
192 bar = {"hello", "world"};
195 class Maman.ClassTest {
196 public class void class_method () {
197 stdout.printf(" OK\n");
200 public void instance_method () {
201 stdout.printf ("Access class method in instance method:");
202 class_method ();
205 class construct {
206 stdout.printf ("Access class method in class constructor:");
207 class_method ();
210 static construct {
211 stdout.printf ("Access class method in static constructor:");
212 class_method ();
215 public static void run_test () {
216 var c = new ClassTest ();
218 stdout.printf ("Access class method by member access:");
219 c.class_method ();
221 c.instance_method ();
225 void main () {
226 Maman.SubBar.main ();