diff options
author | Matthias Clasen <mclasen@redhat.com> | 2011-06-21 00:54:00 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2011-06-23 00:05:18 -0400 |
commit | 5db5a46c3d8f5beb7f3b6d40b0c727125a626f6f (patch) | |
tree | 3fdb6262e51d172238e206a20450c563ec054e87 /gobject | |
parent | f4da19daa67b3a021563c8185fd094a6e4b907d5 (diff) |
Add tests for GValueArray
Diffstat (limited to 'gobject')
-rw-r--r-- | gobject/tests/valuearray.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/gobject/tests/valuearray.c b/gobject/tests/valuearray.c new file mode 100644 index 000000000..0868caeb9 --- /dev/null +++ b/gobject/tests/valuearray.c @@ -0,0 +1,65 @@ +#include <glib-object.h> + +static gint +cmpint (gconstpointer a, gconstpointer b) +{ + const GValue *aa = a; + const GValue *bb = b; + + return g_value_get_int (aa) - g_value_get_int (bb); +} + +static void +test_basic (void) +{ + GValueArray *a; + GValueArray *a2; + GValue v = { 0, }; + GValue *p; + gint i; + + a = g_value_array_new (20); + + g_value_init (&v, G_TYPE_INT); + for (i = 0; i < 100; i++) + { + g_value_set_int (&v, i); + g_value_array_append (a, &v); + } + + g_assert_cmpint (a->n_values, ==, 100); + p = g_value_array_get_nth (a, 5); + g_assert_cmpint (g_value_get_int (p), ==, 5); + + for (i = 20; i < 100; i+= 5) + g_value_array_remove (a, 100 - i); + + for (i = 100; i < 150; i++) + { + g_value_set_int (&v, i); + g_value_array_prepend (a, &v); + } + + g_value_array_sort (a, cmpint); + for (i = 0; i < a->n_values - 1; i++) + g_assert_cmpint (g_value_get_int (&a->values[i]), <=, g_value_get_int (&a->values[i+1])); + + a2 = g_value_array_copy (a); + for (i = 0; i < a->n_values; i++) + g_assert_cmpint (g_value_get_int (&a->values[i]), ==, g_value_get_int (&a2->values[i])); + + g_value_array_free (a); + g_value_array_free (a2); +} + +int +main (int argc, char *argv[]) +{ + g_type_init (); + + g_test_init (&argc, &argv, NULL); + + g_test_add_func ("/valuearray/basic", test_basic); + + return g_test_run (); +} |