/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#if 0
// This is just too hard to make a test for.
using GLib;

using Vee;
using VQDR.Expression;


class MyTestClass : GLib.Object {
   public int prop_int {get; set;}
   public string prop_string {get; set;}
   public bool prop_bool {get; set;}
}

class MyTestClassString : GLib.Object {
   public string prop_string {get; set;}
}

class MyTestClassInt : GLib.Object {
   public int prop_int {get; set;}
}

class MyTestClassBool : GLib.Object {
   public bool prop_bool {get; set;}
}

class MyTestClassVariant : GLib.Object {
   public GLib.Variant prop_var {get; set;}
}

class MyTestClassA : GLib.Object {
  public int prop_int {get;set;}
}

class MyTestClassB : GLib.Object {
  public MyTestClassA object_prop {get; set;}

  public bool prop_bool {get;set;}
}


void gobject_to_string_test () {
  
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "int", () => {
    var v1 = GLib.Object.new (typeof (MyTestClassInt),
                                     prop_int: 1337);
    string got_string = object_to_string (v1);
    
    debug (got_string);
    
    string expected = "(MyTestClassInt)}\n\t(gint) prop-int: 1337\n}";
    
    debug (expected);
    
    if (expected != got_string) {
      Test.fail ();
      Test.message ("The output sting does not match the expected string.");
    }
  });
  
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "string", () => {
    var v1 = GLib.Object.new (typeof (MyTestClassString),
                                     prop_string: "string");
    
    string got_string = object_to_string (v1);
    
    debug (got_string);
    
    string expected = "(MyTestClassString):\n\t(gchararray) prop-string: string\n";
    
    debug (expected);
    
    if (expected != got_string) {
      Test.fail ();
      Test.message ("The output sting does not match the expected string.");
    }
  });
  
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "bool", () => {
    var v1 = GLib.Object.new (typeof (MyTestClassBool),
                                     prop_bool: true);
    
    string got_string = object_to_string (v1);
    
    debug (got_string);
    
    string expected = "(MyTestClassBool):\n\t(gboolean) prop-bool: true\n";
    
    debug (expected);
    
    if (expected != got_string) {
      Test.fail ();
      Test.message ("The output sting does not match the expected string.");
    }
  });
  
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "variant", () => {
    var my_var = new Variant ("(ssibb)", "aa", "bb", 10, false, true);
    var v1 = GLib.Object.new (typeof (MyTestClassVariant),
                                     prop_var: my_var);
    
    string got_string = object_to_string (v1);
    
    debug (got_string);
    
    string expected = 
"(MyTestClassVariant):
\t(GVariant) prop-var: (ssibb)
\t(
\t\t((s): 'aa')
\t\t((s): 'bb')
\t\t((i): 10)
\t\t((b): false)
\t\t((b): true)
\t)
";
    
    debug (expected);
    
    if (str_cmp (expected, got_string) != 0) {
      Test.fail ();
      Test.message ("The output sting does not match the expected string.");
    }
  });

  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "/nested", () => {
    MyTestClassB obj = new MyTestClassB ();
    obj.object_prop = new MyTestClassA ();

    obj.object_prop.prop_int = 117733;

    obj.prop_bool = true;

    GLib.stdout.printf ("%s\n", object_to_string (obj));

  });

  
}

#endif