glib-compat: add g_hash_table_get_keys_as_array() compat function

This commit is contained in:
Beniamino Galvani
2015-09-28 17:05:15 +02:00
parent 804ec6fbcd
commit bd27c110a3
2 changed files with 75 additions and 0 deletions

View File

@@ -4534,6 +4534,41 @@ test_g_ptr_array_insert (void)
/******************************************************************************/
static void
test_g_hash_table_get_keys_as_array (void)
{
GHashTable *table = g_hash_table_new (g_str_hash, g_str_equal);
guint length;
char **keys;
g_hash_table_insert (table, "one", "1");
g_hash_table_insert (table, "two", "2");
g_hash_table_insert (table, "three", "3");
keys = (char **) _nm_g_hash_table_get_keys_as_array (table, &length);
g_assert (keys);
g_assert_cmpuint (length, ==, 3);
g_assert ( !strcmp (keys[0], "one")
|| !strcmp (keys[1], "one")
|| !strcmp (keys[2], "one"));
g_assert ( !strcmp (keys[0], "two")
|| !strcmp (keys[1], "two")
|| !strcmp (keys[2], "two"));
g_assert ( !strcmp (keys[0], "three")
|| !strcmp (keys[1], "three")
|| !strcmp (keys[2], "three"));
g_assert (!keys[3]);
g_free (keys);
g_hash_table_unref (table);
}
/******************************************************************************/
static int
_test_find_binary_search_cmp (gconstpointer a, gconstpointer b, gpointer dummy)
{
@@ -4903,6 +4938,7 @@ int main (int argc, char **argv)
g_test_add_func ("/core/general/_nm_utils_ascii_str_to_int64", test_nm_utils_ascii_str_to_int64);
g_test_add_func ("/core/general/nm_utils_is_power_of_two", test_nm_utils_is_power_of_two);
g_test_add_func ("/core/general/_glib_compat_g_ptr_array_insert", test_g_ptr_array_insert);
g_test_add_func ("/core/general/_glib_compat_g_hash_table_get_keys_as_array", test_g_hash_table_get_keys_as_array);
g_test_add_func ("/core/general/_nm_utils_ptrarray_find_binary_search", test_nm_utils_ptrarray_find_binary_search);
g_test_add_func ("/core/general/_nm_utils_strstrdictkey", test_nm_utils_strstrdictkey);