Support constructor chain up to GObject using Object (...)
[vala-lang.git] / tests / objects / properties.vala
blobe66ecbeb3c796a61c202a9c06f92248da73f5140
1 using GLib;
3 public class Sample : Object {
4 private string automatic { get; set; }
6 private string _name;
7 public string name {
8 get { return _name; }
9 set { _name = value; }
12 private string _read_only;
13 public string read_only {
14 get { return _read_only; }
17 public Sample (string name) {
18 this.name = name;
21 construct {
22 _automatic = "InitialAutomatic";
23 _read_only = "InitialReadOnly";
26 public void run() {
27 notify += (s, p) => {
28 stdout.printf("property `%s' has changed!\n",
29 p.name);
33 automatic = "TheNewAutomatic";
34 name = "TheNewName";
36 // The following statement would be rejected
37 // read_only = "TheNewReadOnly";
39 stdout.printf("automatic: %s\n", automatic);
40 stdout.printf("name: %s\n", name);
41 stdout.printf("read_only: %s\n", read_only);
42 stdout.printf("automatic: %s\n", automatic);
45 public static int main () {
46 var test = new Sample("InitialName");
48 test.run();
50 Maman.Bar.run ();
52 stdout.printf ("Interface Properties Test: 1");
54 Maman.Ibaz ibaz = new Maman.Baz ();
55 ibaz.simple_method ();
57 stdout.printf (" 3\n");
59 return 0;
63 abstract class Maman.Foo : Object {
64 private int _public_base_property = 2;
65 public int public_base_property {
66 get {
67 return _public_base_property;
69 set {
70 _public_base_property = value;
73 public abstract int abstract_base_property { get; set; }
76 class Maman.Bar : Foo {
77 public int public_property { get; set; default = 3; }
78 public override int abstract_base_property { get; set; }
80 void do_action () {
81 stdout.printf (" %d %d", public_base_property, public_property);
82 public_base_property = 4;
83 public_property = 5;
84 stdout.printf (" %d %d", public_base_property, public_property);
87 public static void run () {
88 stdout.printf ("Property Test: 1");
90 var bar = new Bar ();
91 bar.do_action ();
93 Foo foo = bar;
94 foo.abstract_base_property = 6;
95 stdout.printf (" %d", foo.abstract_base_property);
97 stdout.printf (" 7\n");
101 interface Maman.Ibaz : Object {
102 public abstract int number { get; }
104 public void simple_method () {
105 int n = number;
106 stdout.printf (" %d", n);
110 class Maman.Baz : Object, Ibaz {
111 public int number {
112 get { return 2; }
116 void main () {
117 Sample.main ();