summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMatthias Clasen <maclas@gmx.de>2003-12-26 01:04:12 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2003-12-26 01:04:12 +0000
commite09de99eb52e18eb00c9ee7f94544c07526c2c6d (patch)
tree19687bba89d51494a647a4b06c8c399880e3fda3 /tests
parent07cbd50ea880c7d4f0221d171cf8f91d253e51f7 (diff)
New function to call a function for each element of a GPtrArray. (#114790)
Fri Dec 26 02:03:58 2003 Matthias Clasen <maclas@gmx.de> * glib/garray.[hc] (g_ptr_array_foreach): New function to call a function for each element of a GPtrArray. (#114790) * tests/array-test.c (main): Add a test for g_ptr_array_foreach().
Diffstat (limited to 'tests')
-rw-r--r--tests/array-test.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/array-test.c b/tests/array-test.c
index 4f187919b..6d4b5589b 100644
--- a/tests/array-test.c
+++ b/tests/array-test.c
@@ -57,6 +57,15 @@ typedef struct {
} GlibTestInfo;
+static void
+sum_up (gpointer data,
+ gpointer user_data)
+{
+ gint *sum = (gint *)user_data;
+
+ *sum += GPOINTER_TO_INT (data);
+}
+
int
main (int argc,
char *argv[])
@@ -65,6 +74,7 @@ main (int argc,
GArray *garray;
GPtrArray *gparray;
GByteArray *gbarray;
+ gint sum = 0;
/* array tests */
garray = g_array_new (FALSE, FALSE, sizeof (gint));
@@ -93,6 +103,9 @@ main (int argc,
for (i = 0; i < 10000; i++)
if (g_ptr_array_index (gparray, i) != GINT_TO_POINTER (i))
g_print ("array fails: %p ( %p )\n", g_ptr_array_index (gparray, i), GINT_TO_POINTER (i));
+
+ g_ptr_array_foreach (gparray, sum_up, &sum);
+ g_assert (sum == 49995000);
g_ptr_array_free (gparray, TRUE);