Update Hungarian translation
[glib.git] / gobject / tests / value.c
blobb5a136486b55ecf61d57c6f053b4c4fc834341a0
1 #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_30
2 #include <glib-object.h>
4 static void
5 test_value_basic (void)
7 GValue value = G_VALUE_INIT;
9 g_assert_false (G_IS_VALUE (&value));
10 g_assert_false (G_VALUE_HOLDS_INT (&value));
11 g_value_unset (&value);
12 g_assert_false (G_IS_VALUE (&value));
13 g_assert_false (G_VALUE_HOLDS_INT (&value));
15 g_value_init (&value, G_TYPE_INT);
16 g_assert_true (G_IS_VALUE (&value));
17 g_assert_true (G_VALUE_HOLDS_INT (&value));
18 g_assert_false (G_VALUE_HOLDS_UINT (&value));
19 g_assert_cmpint (g_value_get_int (&value), ==, 0);
21 g_value_set_int (&value, 10);
22 g_assert_cmpint (g_value_get_int (&value), ==, 10);
24 g_value_reset (&value);
25 g_assert_true (G_IS_VALUE (&value));
26 g_assert_true (G_VALUE_HOLDS_INT (&value));
27 g_assert_cmpint (g_value_get_int (&value), ==, 0);
29 g_value_unset (&value);
30 g_assert_false (G_IS_VALUE (&value));
31 g_assert_false (G_VALUE_HOLDS_INT (&value));
34 static gint
35 cmpint (gconstpointer a, gconstpointer b)
37 const GValue *aa = a;
38 const GValue *bb = b;
40 return g_value_get_int (aa) - g_value_get_int (bb);
43 static void
44 test_valuearray_basic (void)
46 GValueArray *a;
47 GValueArray *a2;
48 GValue v = G_VALUE_INIT;
49 GValue *p;
50 gint i;
52 a = g_value_array_new (20);
54 g_value_init (&v, G_TYPE_INT);
55 for (i = 0; i < 100; i++)
57 g_value_set_int (&v, i);
58 g_value_array_append (a, &v);
61 g_assert_cmpint (a->n_values, ==, 100);
62 p = g_value_array_get_nth (a, 5);
63 g_assert_cmpint (g_value_get_int (p), ==, 5);
65 for (i = 20; i < 100; i+= 5)
66 g_value_array_remove (a, 100 - i);
68 for (i = 100; i < 150; i++)
70 g_value_set_int (&v, i);
71 g_value_array_prepend (a, &v);
74 g_value_array_sort (a, cmpint);
75 for (i = 0; i < a->n_values - 1; i++)
76 g_assert_cmpint (g_value_get_int (&a->values[i]), <=, g_value_get_int (&a->values[i+1]));
78 a2 = g_value_array_copy (a);
79 for (i = 0; i < a->n_values; i++)
80 g_assert_cmpint (g_value_get_int (&a->values[i]), ==, g_value_get_int (&a2->values[i]));
82 g_value_array_free (a);
83 g_value_array_free (a2);
86 int
87 main (int argc, char *argv[])
89 g_test_init (&argc, &argv, NULL);
91 g_test_add_func ("/value/basic", test_value_basic);
92 g_test_add_func ("/value/array/basic", test_valuearray_basic);
94 return g_test_run ();