]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
tests: Extend "GArray" tests to increase coverage
authorRico Tzschichholz <ricotz@ubuntu.com>
Sun, 11 Apr 2021 18:45:59 +0000 (20:45 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 12 Apr 2021 08:16:54 +0000 (10:16 +0200)
tests/basic-types/garray.vala

index 2d2eb008d2a7c32873cc6494be9e96b434be72ea..9f09560a7c8b021ee8aedfe9ca83f1eb5e999197 100644 (file)
@@ -14,17 +14,22 @@ void test_garray () {
 
        array.append_val (foo);
        assert (foo.ref_count == 2);
+       assert (array.index (0) == foo);
        array.remove_index (0);
        assert (foo.ref_count == 1);
 
        array.append_val (foo);
        assert (foo.ref_count == 2);
+       assert (array.index (0) == foo);
        array.remove_index_fast (0);
        assert (foo.ref_count == 1);
 
        array.append_val (foo);
-       assert (foo.ref_count == 2);
-       array.remove_range (0, 1);
+       array.append_val (foo);
+       assert (foo.ref_count == 3);
+       assert (array.index (0) == foo);
+       assert (array.index (1) == foo);
+       array.remove_range (0, 2);
        assert (foo.ref_count == 1);
 }
 
@@ -45,17 +50,21 @@ void test_int_garray () {
 }
 
 GLib.Array<FooStruct?> create_struct_garray () {
-       FooStruct foo = { "foo", new Foo () };
        var array = new GLib.Array<FooStruct?> ();
-       array.append_val (foo);
+       FooStruct foo1 = { "foo", new Foo () };
+       array.append_val (foo1);
+       FooStruct foo2 = { "bar", new Foo () };
+       array.append_val (foo2);
        return array;
 }
 
 void test_struct_garray () {
        var array = create_struct_garray ();
-       assert (array.length == 1);
+       assert (array.length == 2);
        assert (array.index (0).content == "foo");
        assert (array.index (0).object.ref_count == 1);
+       assert (array.index (1).content == "bar");
+       assert (array.index (1).object.ref_count == 1);
        Foo f = array.index (0).object;
        assert (f.ref_count == 2);
        array = null;