sqlite3: Assorted memory management fixes for strings and blobs.
[vala-lang.git] / tests / objects / methods.vala
blob49834bdd44b3c5a1a0fbfb995e880a009cee9948
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 (str == "hello");
75 test_ref (ref str);
76 assert (str == "world");
78 test_ref_weak (ref weak_str);
79 assert (str == "world");
81 test_ref_weak (ref str2);
82 assert (str == "world");
84 ClassTest.run_test ();
86 return 0;
90 interface Maman.Foo {
91 public void do_action () {
92 stdout.printf (" 2");
96 class Maman.FooBar : Object {
97 public void do_action () {
98 stdout.printf (" BAD");
102 class Maman.SubFooBar : FooBar, Foo {
105 // http://bugzilla.gnome.org/show_bug.cgi?id=523263
107 abstract class Maman.AbstractBase : Object {
108 public abstract void foo ();
111 abstract class Maman.AbstractDerived : AbstractBase {
112 public override void foo () {
116 class Maman.DeepDerived : AbstractDerived {
119 // http://bugzilla.gnome.org/show_bug.cgi?id=528457
120 namespace Maman.BaseAccess {
121 public interface IFoo : Object {
122 public abstract int interface_method ();
124 public abstract int virtual_interface_method ();
127 public class Foo : Object, IFoo {
128 public virtual int virtual_method () {
129 return 1;
132 public int interface_method () {
133 return 2;
136 public virtual int virtual_interface_method () {
137 return 3;
141 public class Bar : Foo {
142 public override int virtual_method () {
143 return base.virtual_method () * 10 + 4;
146 public override int virtual_interface_method () {
147 return base.virtual_interface_method () * 10 + 5;
151 public class FooBar : Foo, IFoo {
152 public int interface_method () {
153 return base.interface_method () * 10 + 6;
156 public int virtual_interface_method () {
157 return -1;
161 public void test () {
162 var bar = new Bar ();
163 var foobar = new FooBar ();
164 assert (bar.virtual_method () == 14);
165 assert (bar.virtual_interface_method () == 35);
166 assert (foobar.interface_method () == 26);
170 void test_out (out string bar) {
171 bar = "hello";
174 void test_out_weak (out weak string bar) {
175 bar = "hello";
178 void test_ref (ref string bar) {
179 assert (bar == "hello");
180 bar = "world";
183 void test_ref_weak (ref weak string bar) {
184 assert (bar == "hello");
185 bar = "world";
188 class Maman.ClassTest {
189 public class void class_method () {
190 stdout.printf(" OK\n");
193 public void instance_method () {
194 stdout.printf ("Access class method in instance method:");
195 class_method ();
198 class construct {
199 stdout.printf ("Access class method in class constructor:");
200 class_method ();
203 static construct {
204 stdout.printf ("Access class method in static constructor:");
205 class_method ();
208 public static void run_test () {
209 var c = new ClassTest ();
211 stdout.printf ("Access class method by member access:");
212 c.class_method ();
214 c.instance_method ();
218 void main () {
219 Maman.SubBar.main ();