blob: 8770f60f8a6562c6640d6bb5d36067c68593e092 (
plain)
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
|
class Foo : Object {
}
void test_glist () {
{
var list = new GLib.List<Foo> ();
var foo = new Foo ();
list.append (foo);
assert (list.length () == 1);
assert (foo.ref_count == 2);
list.remove (foo);
assert (list.length () == 0);
assert (foo.ref_count == 1);
}
{
var list = new GLib.List<Foo> ();
var foo = new Foo ();
list.append (foo);
list.append (foo);
assert (list.length () == 2);
assert (foo.ref_count == 3);
list.remove_all (foo);
assert (list.length () == 0);
assert (foo.ref_count == 1);
}
{
var list = new GLib.List<unowned string> ();
unowned var s = "foo";
list.append (s);
assert (list.length () == 1);
list.remove (s);
assert (list.length () == 0);
list.append (s);
list.remove_all (s);
assert (list.length () == 0);
}
}
void test_gslist () {
{
var list = new GLib.SList<Foo> ();
var foo = new Foo ();
list.append (foo);
assert (list.length () == 1);
assert (foo.ref_count == 2);
list.remove (foo);
assert (list.length () == 0);
assert (foo.ref_count == 1);
}
{
var list = new GLib.SList<Foo> ();
var foo = new Foo ();
list.append (foo);
list.append (foo);
assert (list.length () == 2);
assert (foo.ref_count == 3);
list.remove_all (foo);
assert (list.length () == 0);
assert (foo.ref_count == 1);
}
{
var list = new GLib.SList<unowned string> ();
unowned var s = "foo";
list.append (s);
assert (list.length () == 1);
list.remove (s);
assert (list.length () == 0);
list.append (s);
list.remove_all (s);
assert (list.length () == 0);
}
}
void test_gqueue () {
{
var queue = new GLib.Queue<Foo> ();
var foo = new Foo ();
queue.push_head (foo);
assert (queue.length == 1);
assert (foo.ref_count == 2);
queue.remove (foo);
assert (queue.length == 0);
assert (foo.ref_count == 1);
}
{
var queue = new GLib.Queue<Foo> ();
var foo = new Foo ();
queue.push_head (foo);
queue.push_head (foo);
assert (queue.length == 2);
assert (foo.ref_count == 3);
queue.remove_all (foo);
assert (queue.length == 0);
assert (foo.ref_count == 1);
}
{
var queue = new GLib.Queue<unowned string> ();
unowned var s = "foo";
queue.push_head (s);
assert (queue.length == 1);
queue.remove (s);
assert (queue.length == 0);
queue.push_head (s);
queue.remove_all (s);
assert (queue.length == 0);
}
}
void main () {
test_glist ();
test_gslist ();
test_gqueue ();
}
|