/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/libvee/gobject_to_string.vala

  • Committer: Gustav Hartvigsson
  • Date: 2024-12-22 00:30:29 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20241222003029-k74ogrm32zobz325
[General] Split libvee into it's own library.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#if 0
 
2
// This is just too hard to make a test for.
 
3
using GLib;
 
4
 
 
5
using Vee;
 
6
using VQDR.Expression;
 
7
 
 
8
 
 
9
class MyTestClass : GLib.Object {
 
10
   public int prop_int {get; set;}
 
11
   public string prop_string {get; set;}
 
12
   public bool prop_bool {get; set;}
 
13
}
 
14
 
 
15
class MyTestClassString : GLib.Object {
 
16
   public string prop_string {get; set;}
 
17
}
 
18
 
 
19
class MyTestClassInt : GLib.Object {
 
20
   public int prop_int {get; set;}
 
21
}
 
22
 
 
23
class MyTestClassBool : GLib.Object {
 
24
   public bool prop_bool {get; set;}
 
25
}
 
26
 
 
27
class MyTestClassVariant : GLib.Object {
 
28
   public GLib.Variant prop_var {get; set;}
 
29
}
 
30
 
 
31
class MyTestClassA : GLib.Object {
 
32
  public int prop_int {get;set;}
 
33
}
 
34
 
 
35
class MyTestClassB : GLib.Object {
 
36
  public MyTestClassA object_prop {get; set;}
 
37
 
 
38
  public bool prop_bool {get;set;}
 
39
}
 
40
 
 
41
 
 
42
void gobject_to_string_test () {
 
43
  
 
44
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "int", () => {
 
45
    var v1 = GLib.Object.new (typeof (MyTestClassInt),
 
46
                                     prop_int: 1337);
 
47
    string got_string = object_to_string (v1);
 
48
    
 
49
    debug (got_string);
 
50
    
 
51
    string expected = "(MyTestClassInt)}\n\t(gint) prop-int: 1337\n}";
 
52
    
 
53
    debug (expected);
 
54
    
 
55
    if (expected != got_string) {
 
56
      Test.fail ();
 
57
      Test.message ("The output sting does not match the expected string.");
 
58
    }
 
59
  });
 
60
  
 
61
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "string", () => {
 
62
    var v1 = GLib.Object.new (typeof (MyTestClassString),
 
63
                                     prop_string: "string");
 
64
    
 
65
    string got_string = object_to_string (v1);
 
66
    
 
67
    debug (got_string);
 
68
    
 
69
    string expected = "(MyTestClassString):\n\t(gchararray) prop-string: string\n";
 
70
    
 
71
    debug (expected);
 
72
    
 
73
    if (expected != got_string) {
 
74
      Test.fail ();
 
75
      Test.message ("The output sting does not match the expected string.");
 
76
    }
 
77
  });
 
78
  
 
79
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "bool", () => {
 
80
    var v1 = GLib.Object.new (typeof (MyTestClassBool),
 
81
                                     prop_bool: true);
 
82
    
 
83
    string got_string = object_to_string (v1);
 
84
    
 
85
    debug (got_string);
 
86
    
 
87
    string expected = "(MyTestClassBool):\n\t(gboolean) prop-bool: true\n";
 
88
    
 
89
    debug (expected);
 
90
    
 
91
    if (expected != got_string) {
 
92
      Test.fail ();
 
93
      Test.message ("The output sting does not match the expected string.");
 
94
    }
 
95
  });
 
96
  
 
97
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "variant", () => {
 
98
    var my_var = new Variant ("(ssibb)", "aa", "bb", 10, false, true);
 
99
    var v1 = GLib.Object.new (typeof (MyTestClassVariant),
 
100
                                     prop_var: my_var);
 
101
    
 
102
    string got_string = object_to_string (v1);
 
103
    
 
104
    debug (got_string);
 
105
    
 
106
    string expected = 
 
107
"(MyTestClassVariant):
 
108
\t(GVariant) prop-var: (ssibb)
 
109
\t(
 
110
\t\t((s): 'aa')
 
111
\t\t((s): 'bb')
 
112
\t\t((i): 10)
 
113
\t\t((b): false)
 
114
\t\t((b): true)
 
115
\t)
 
116
";
 
117
    
 
118
    debug (expected);
 
119
    
 
120
    if (str_cmp (expected, got_string) != 0) {
 
121
      Test.fail ();
 
122
      Test.message ("The output sting does not match the expected string.");
 
123
    }
 
124
  });
 
125
 
 
126
  Test.add_func (UTIL_TEST_GOBJECT_PREFIX + "/nested", () => {
 
127
    MyTestClassB obj = new MyTestClassB ();
 
128
    obj.object_prop = new MyTestClassA ();
 
129
 
 
130
    obj.object_prop.prop_int = 117733;
 
131
 
 
132
    obj.prop_bool = true;
 
133
 
 
134
    GLib.stdout.printf ("%s\n", object_to_string (obj));
 
135
 
 
136
  });
 
137
 
 
138
  
 
139
}
 
140
 
 
141
#endif