1 #define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_30
2 #include <glib-object.h>
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
));
35 cmpint (gconstpointer a
, gconstpointer b
)
40 return g_value_get_int (aa
) - g_value_get_int (bb
);
44 test_valuearray_basic (void)
48 GValue v
= G_VALUE_INIT
;
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
);
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
);