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
|
using GLib;
using VQDR.Common.Utils;
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;}
}
void gobject_to_string_test () {
Test.add_func ("/Common/Utils/gobject_to_string_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 ("/Common/Utils/gobject_to_string_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 ("/Common/Utils/gobject_to_string_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 ("/Common/Utils/gobject_to_string_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.");
}
});
}
|