/vqdr/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/vqdr/trunk

« back to all changes in this revision

Viewing changes to tests/gobject_to_string.vala

  • Committer: Gustav Hartvigsson
  • Date: 2021-09-11 16:26:54 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20210911162654-rfd097o28o24fxeb
* Mandate ABI stability.
* Make sure comments are avalible in the vapi file

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
using GLib;
 
2
 
 
3
using VQDR.Common.Utils;
 
4
using VQDR.Expression;
 
5
 
 
6
class MyTestClass : GLib.Object {
 
7
   public int prop_int {get; set;}
 
8
   public string prop_string {get; set;}
 
9
   public bool prop_bool {get; set;}
 
10
}
 
11
 
 
12
class MyTestClassString : GLib.Object {
 
13
   public string prop_string {get; set;}
 
14
}
 
15
 
 
16
class MyTestClassInt : GLib.Object {
 
17
   public int prop_int {get; set;}
 
18
}
 
19
 
 
20
class MyTestClassBool : GLib.Object {
 
21
   public bool prop_bool {get; set;}
 
22
}
 
23
 
 
24
class MyTestClassVariant : GLib.Object {
 
25
   public GLib.Variant prop_var {get; set;}
 
26
}
 
27
 
 
28
 
 
29
void gobject_to_string_test () {
 
30
  
 
31
  Test.add_func ("/Common/Utils/gobject_to_string_int", () => {
 
32
    var v1 = GLib.Object.new (typeof (MyTestClassInt),
 
33
                                     prop_int: 1337);
 
34
    string got_string = object_to_string (v1);
 
35
    
 
36
    debug (got_string);
 
37
    
 
38
    string expected = "(MyTestClassInt):\n\t(gint) prop-int: 1337\n";
 
39
    
 
40
    debug (expected);
 
41
    
 
42
    if (expected != got_string) {
 
43
      Test.fail ();
 
44
      Test.message ("The output sting does not match the expected string.");
 
45
    }
 
46
  });
 
47
  
 
48
  Test.add_func ("/Common/Utils/gobject_to_string_string", () => {
 
49
    var v1 = GLib.Object.new (typeof (MyTestClassString),
 
50
                                     prop_string: "string");
 
51
    
 
52
    string got_string = object_to_string (v1);
 
53
    
 
54
    debug (got_string);
 
55
    
 
56
    string expected = "(MyTestClassString):\n\t(gchararray) prop-string: string\n";
 
57
    
 
58
    debug (expected);
 
59
    
 
60
    if (expected != got_string) {
 
61
      Test.fail ();
 
62
      Test.message ("The output sting does not match the expected string.");
 
63
    }
 
64
  });
 
65
  
 
66
  Test.add_func ("/Common/Utils/gobject_to_string_bool", () => {
 
67
    var v1 = GLib.Object.new (typeof (MyTestClassBool),
 
68
                                     prop_bool: true);
 
69
    
 
70
    string got_string = object_to_string (v1);
 
71
    
 
72
    debug (got_string);
 
73
    
 
74
    string expected = "(MyTestClassBool):\n\t(gboolean) prop-bool: true\n";
 
75
    
 
76
    debug (expected);
 
77
    
 
78
    if (expected != got_string) {
 
79
      Test.fail ();
 
80
      Test.message ("The output sting does not match the expected string.");
 
81
    }
 
82
  });
 
83
  
 
84
  Test.add_func ("/Common/Utils/gobject_to_string_variant", () => {
 
85
    var my_var = new Variant ("(ssibb)", "aa", "bb", 10, false, true);
 
86
    var v1 = GLib.Object.new (typeof (MyTestClassVariant),
 
87
                                     prop_var: my_var);
 
88
    
 
89
    string got_string = object_to_string (v1);
 
90
    
 
91
    debug (got_string);
 
92
    
 
93
    string expected = 
 
94
"(MyTestClassVariant):
 
95
\t(GVariant) prop-var: (ssibb)
 
96
\t(
 
97
\t\t((s): 'aa')
 
98
\t\t((s): 'bb')
 
99
\t\t((i): 10)
 
100
\t\t((b): false)
 
101
\t\t((b): true)
 
102
\t)
 
103
";
 
104
    
 
105
    debug (expected);
 
106
    
 
107
    if (str_cmp (expected, got_string) != 0) {
 
108
      Test.fail ();
 
109
      Test.message ("The output sting does not match the expected string.");
 
110
    }
 
111
  });
 
112
  
 
113
}