GType: Fix C warnings for properties in interface_init
[vala-lang.git] / tests / objects / properties.test
blobb8e6f332be60a6236f452f7f7337f712da8d5336
2 Program: test
4 using GLib;
6 public class Sample : Object {
7         private string automatic { get; set; }
9         private string _name;
10         public string name {
11                 get { return _name; }
12                 set { _name = value; }
13         }
15         private string _read_only;
16         public string read_only {
17                 get { return _read_only; }
18         }
20         public Sample (string name) {
21                 this.name = name;
22         }
24         construct {
25                 _automatic = "InitialAutomatic";
26                 _read_only = "InitialReadOnly";
27         }
29         public void run() {
30                 notify += (s, p) => {
31                         stdout.printf("property `%s' has changed!\n",
32                                       p.name);
33                 };
36                 automatic = "TheNewAutomatic";
37                 name = "TheNewName";
39                 // The following statement would be rejected
40                 // read_only = "TheNewReadOnly";
42                 stdout.printf("automatic: %s\n", automatic);
43                 stdout.printf("name: %s\n", name);
44                 stdout.printf("read_only: %s\n", read_only);
45                 stdout.printf("automatic: %s\n", automatic);
46         }
48         static int main (string[] args) {
49                 var test = new Sample("InitialName");
51                 test.run();
53                 Maman.Bar.run ();
55                 stdout.printf ("Interface Properties Test: 1");
57                 Maman.Ibaz ibaz = new Maman.Baz ();
58                 ibaz.simple_method ();
59         
60                 stdout.printf (" 3\n");
62                 return 0;
63         }
66 abstract class Maman.Foo : Object {
67         private int _public_base_property = 2;
68         public int public_base_property {
69                 get {
70                         return _public_base_property;
71                 }
72                 set {
73                         _public_base_property = value;
74                 }
75         }
76         public abstract int abstract_base_property { get; set; }
79 class Maman.Bar : Foo {
80         public int public_property { get; set; default = 3; }
81         public override int abstract_base_property { get; set; }
83         void do_action () {
84                 stdout.printf (" %d %d", public_base_property, public_property);
85                 public_base_property = 4;
86                 public_property = 5;
87                 stdout.printf (" %d %d", public_base_property, public_property);
88         }
90         public static void run () {
91                 stdout.printf ("Property Test: 1");
92                 
93                 var bar = new Bar ();
94                 bar.do_action ();
95                 
96                 Foo foo = bar;
97                 foo.abstract_base_property = 6;
98                 stdout.printf (" %d", foo.abstract_base_property);
100                 stdout.printf (" 7\n");
101         }
104 interface Maman.Ibaz : Object {
105         public abstract int number { get; }
107         public void simple_method () {
108                 int n = number;
109                 stdout.printf (" %d", n);
110         }
113 class Maman.Baz : Object, Ibaz {
114         public int number {
115                 get { return 2; }
116         }