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

  • Committer: Gustav Hartvigsson
  • Date: 2021-11-15 16:29:17 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20211115162917-yqz4q9epewtpe4p5
Sort of fixed object_to_string ()...
still needs figue out how to do the recurtion propperly.

Show diffs side-by-side

added added

removed removed

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