[vala/tintou/garray] tests: add more GLib.Array tests
- From: Corentin Noël <corentinnoel src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/tintou/garray] tests: add more GLib.Array tests
- Date: Fri, 16 Nov 2018 16:38:12 +0000 (UTC)
commit d5564a66833376438abb1958caf441ea73ea369b
Author: Corentin Noël <corentin elementary io>
Date: Fri Nov 16 14:55:00 2018 +0100
tests: add more GLib.Array tests
tests/basic-types/garray.vala | 58 ++++++++++++++++++++++++++++++++++++++++++-
vapi/glib-2.0.vapi | 4 ++-
2 files changed, 60 insertions(+), 2 deletions(-)
---
diff --git a/tests/basic-types/garray.vala b/tests/basic-types/garray.vala
index 055ba6a2a..efc48df9c 100644
--- a/tests/basic-types/garray.vala
+++ b/tests/basic-types/garray.vala
@@ -1,7 +1,12 @@
class Foo : Object {
}
-void main () {
+struct MyStruct {
+ string content;
+ Foo object;
+}
+
+void test_garray () {
var array = new GLib.Array<Foo> ();
var foo = new Foo ();
@@ -22,3 +27,54 @@ void main () {
array.remove_range (0, 1);
assert (foo.ref_count == 1);
}
+
+void test_garray_delete () {
+ var array = new GLib.Array<Foo> ();
+ var foo = new Foo ();
+ array.append_val (foo);
+ array = null;
+ assert (foo.ref_count == 1);
+}
+
+void test_simpletype_garray () {
+ var array = new GLib.Array<int> ();
+ // g_array_append_val() is a macro which uses a reference to the value parameter and thus can't use
constants.
+ // FIXME: allow appending constants in Vala
+ int val = 1;
+ array.prepend_val (val);
+ val++;
+ array.append_val (val);
+ val++;
+ array.insert_val (2, val);
+ assert (array.index (0) == 1);
+ assert (array.index (1) == 2);
+ assert (array.index (2) == 3);
+ assert (array.length == 3);
+}
+
+GLib.Array<MyStruct?> create_struct_garray () {
+ var my_struct = MyStruct ();
+ my_struct.content = "this is a test";
+ my_struct.object = new Foo ();
+ var array = new GLib.Array<MyStruct?> ();
+ array.append_val (my_struct);
+ return array;
+}
+
+void test_struct_garray () {
+ var array = create_struct_garray ();
+ assert (array.length == 1);
+ assert (array.index (0).content == "this is a test");
+ assert (array.index (0).object.ref_count == 1);
+ Foo f = array.index (0).object;
+ assert (f.ref_count == 2);
+ array = null;
+ assert (f.ref_count == 1);
+}
+
+void main () {
+ test_garray ();
+ test_simpletype_garray ();
+ test_struct_garray ();
+ test_garray_delete ();
+}
diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi
index 527115e77..1b61f6635 100644
--- a/vapi/glib-2.0.vapi
+++ b/vapi/glib-2.0.vapi
@@ -5296,6 +5296,7 @@ namespace GLib {
public G remove_index (uint index) {
assert (length > index);
G g = data[index];
+ data[index] = null;
_remove_index (index);
return g;
}
@@ -5303,6 +5304,7 @@ namespace GLib {
public G remove_index_fast (uint index) {
assert (length > index);
G g = data[index];
+ data[index] = null;
_remove_index_fast (index);
return g;
}
@@ -5312,7 +5314,7 @@ namespace GLib {
G[] ga = new G[length];
for (uint i = 0; i < length; i++) {
ga[i] = data[i + index];
- }
+ data[i + index] = null; }
_remove_range (index, length);
return ga;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]