[vala/wip/foreach: 7/7] tests: Add "GenericArray foreach" tests to increase coverage
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/wip/foreach: 7/7] tests: Add "GenericArray foreach" tests to increase coverage
- Date: Mon, 9 Nov 2020 18:28:16 +0000 (UTC)
commit 37c23f1ed88fc9056ebb0f2d99ef17b93bd78276
Author: Corentin Noël <corentin elementary io>
Date: Mon Nov 9 15:17:37 2020 +0100
tests: Add "GenericArray foreach" tests to increase coverage
tests/basic-types/gptrarray.vala | 48 ++++++++++++++++++++++++++++++++++++++++
tests/control-flow/foreach.vala | 36 ++++++++++++++++++++++++++++++
2 files changed, 84 insertions(+)
---
diff --git a/tests/basic-types/gptrarray.vala b/tests/basic-types/gptrarray.vala
index 6d8aa2d1a..1b5d6c622 100644
--- a/tests/basic-types/gptrarray.vala
+++ b/tests/basic-types/gptrarray.vala
@@ -26,6 +26,30 @@ void main () {
assert (foo3.ref_count == 2);
assert (array.length == 3);
+ int loop_size = 0;
+ foreach (weak Foo element in array) {
+ loop_size++;
+ assert (element.ref_count == 2);
+ switch (loop_size) {
+ case 1: assert (element == foo1); break;
+ case 2: assert (element == foo2); break;
+ case 3: assert (element == foo3); break;
+ }
+ }
+ assert (loop_size == 3);
+
+ loop_size = 0;
+ foreach (Foo element in array) {
+ loop_size++;
+ assert (element.ref_count == 3);
+ switch (loop_size) {
+ case 1: assert (element == foo1); break;
+ case 2: assert (element == foo2); break;
+ case 3: assert (element == foo3); break;
+ }
+ }
+ assert (loop_size == 3);
+
assert (foo2 == array.get (1));
array.set (1, foo4);
assert (foo4 == array.get (1));
@@ -73,6 +97,30 @@ void main () {
assert (foo3.ref_count == 1);
assert (array.length == 3);
+ int loop_size = 0;
+ foreach (weak Foo element in array) {
+ loop_size++;
+ assert (element.ref_count == 1);
+ switch (loop_size) {
+ case 1: assert (element == foo1); break;
+ case 2: assert (element == foo2); break;
+ case 3: assert (element == foo3); break;
+ }
+ }
+ assert (loop_size == 3);
+
+ loop_size = 0;
+ foreach (Foo element in array) {
+ loop_size++;
+ assert (element.ref_count == 2);
+ switch (loop_size) {
+ case 1: assert (element == foo1); break;
+ case 2: assert (element == foo2); break;
+ case 3: assert (element == foo3); break;
+ }
+ }
+ assert (loop_size == 3);
+
assert (foo2 == array.get (1));
array.set (1, foo4);
assert (foo4 == array.get (1));
diff --git a/tests/control-flow/foreach.vala b/tests/control-flow/foreach.vala
index 6a36453fd..052e03d3c 100644
--- a/tests/control-flow/foreach.vala
+++ b/tests/control-flow/foreach.vala
@@ -33,6 +33,41 @@ void test_foreach_gvaluearray () {
test_unowned (array);
}
+void test_generic_array_owned (GenericArray<Value?> array) {
+ uint i = 0;
+
+ foreach (Value? item in array) {
+ i++;
+ }
+
+ assert (i == 3);
+}
+
+void test_generic_array_unowned (GenericArray<Value?> array) {
+ uint i = 0;
+
+ foreach (unowned Value? item in array) {
+ i++;
+ }
+
+ assert (i == 3);
+}
+
+void test_foreach_genericarray () {
+ Value value;
+ var array = new GenericArray<Value?> ();
+
+ value = 1;
+ array.add (value);
+ value = 2.0;
+ array.add (value);
+ value = "three";
+ array.add (value);
+
+ test_generic_array_owned (array);
+ test_generic_array_unowned (array);
+}
+
void test_foreach_multidim_array () {
int[,] foo = { { 1, 2 }, { 3, 4 }, { 5, 6 } };
string result = "";
@@ -70,6 +105,7 @@ void test_foreach_slice_array () {
void main () {
test_foreach_gvaluearray ();
+ test_foreach_genericarray ();
test_foreach_const_array ();
test_foreach_multidim_array ();
test_foreach_slice_array ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]