glib/gobject/tests/valuearray.c
Ryan Lortie 1dc774a653 Remove g_type_init() calls
Very many testcases, some GLib tools (resource compiler, etc) and
GApplication were calling g_type_init().

Remove those uses, as they are no longer required.

https://bugzilla.gnome.org/show_bug.cgi?id=686161
2012-10-16 09:39:24 -04:00

65 lines
1.4 KiB
C

#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_30
#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 = G_VALUE_INIT;
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_test_init (&argc, &argv, NULL);
g_test_add_func ("/valuearray/basic", test_basic);
return g_test_run ();
}