mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-25 21:46:14 +01:00
Move hash tests to the test framework
This commit is contained in:
parent
7d14b5fbf1
commit
2f438f18ae
@ -87,6 +87,9 @@ utf8_misc_LDADD = $(progs_ldadd)
|
||||
TEST_PROGS += checksum
|
||||
checksum_LDADD = $(progs_ldadd)
|
||||
|
||||
TEST_PROGS += hash
|
||||
hash_LDADD = $(progs_ldadd)
|
||||
|
||||
if OS_UNIX
|
||||
|
||||
# some testing of gtester funcitonality
|
||||
|
@ -265,8 +265,10 @@ static gboolean remove_even_foreach (gpointer key,
|
||||
|
||||
|
||||
|
||||
static void second_hash_test (gboolean simple_hash)
|
||||
static void second_hash_test (gconstpointer d)
|
||||
{
|
||||
gboolean simple_hash = GPOINTER_TO_INT (d);
|
||||
|
||||
int i;
|
||||
char key[20] = "", val[20]="", *v, *orig_key, *orig_val;
|
||||
GHashTable *h;
|
||||
@ -377,11 +379,8 @@ static void direct_hash_test (void)
|
||||
g_hash_table_destroy (h);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
static void
|
||||
test_hash_misc (void)
|
||||
{
|
||||
GHashTable *hash_table;
|
||||
gint i;
|
||||
@ -446,14 +445,81 @@ main (int argc,
|
||||
g_assert_not_reached();
|
||||
|
||||
g_hash_table_foreach (hash_table, my_hash_callback_remove_test, NULL);
|
||||
|
||||
|
||||
g_hash_table_destroy (hash_table);
|
||||
}
|
||||
|
||||
second_hash_test (TRUE);
|
||||
second_hash_test (FALSE);
|
||||
direct_hash_test ();
|
||||
static gint destroy_counter;
|
||||
|
||||
return 0;
|
||||
static void
|
||||
value_destroy (gpointer value)
|
||||
{
|
||||
destroy_counter++;
|
||||
}
|
||||
|
||||
static void
|
||||
test_hash_ref (void)
|
||||
{
|
||||
GHashTable *h;
|
||||
GHashTableIter iter;
|
||||
gchar *key, *value;
|
||||
gboolean abc_seen = FALSE;
|
||||
gboolean cde_seen = FALSE;
|
||||
gboolean xyz_seen = FALSE;
|
||||
|
||||
h = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, value_destroy);
|
||||
g_hash_table_insert (h, "abc", "ABC");
|
||||
g_hash_table_insert (h, "cde", "CDE");
|
||||
g_hash_table_insert (h, "xyz", "XYZ");
|
||||
|
||||
g_assert_cmpint (g_hash_table_size (h), == , 3);
|
||||
|
||||
g_hash_table_iter_init (&iter, h);
|
||||
|
||||
while (g_hash_table_iter_next (&iter, (gpointer*)&key, (gpointer*)&value))
|
||||
{
|
||||
if (strcmp (key, "abc") == 0)
|
||||
{
|
||||
g_assert_cmpstr (value, ==, "ABC");
|
||||
abc_seen = TRUE;
|
||||
g_hash_table_iter_steal (&iter);
|
||||
}
|
||||
else if (strcmp (key, "cde") == 0)
|
||||
{
|
||||
g_assert_cmpstr (value, ==, "CDE");
|
||||
cde_seen = TRUE;
|
||||
}
|
||||
else if (strcmp (key, "xyz") == 0)
|
||||
{
|
||||
g_assert_cmpstr (value, ==, "XYZ");
|
||||
xyz_seen = TRUE;
|
||||
}
|
||||
}
|
||||
g_assert_cmpint (destroy_counter, ==, 0);
|
||||
|
||||
g_assert (g_hash_table_iter_get_hash_table (&iter) == h);
|
||||
g_assert (abc_seen && cde_seen && xyz_seen);
|
||||
g_assert_cmpint (g_hash_table_size (h), == , 2);
|
||||
|
||||
g_hash_table_ref (h);
|
||||
g_hash_table_destroy (h);
|
||||
g_assert_cmpint (g_hash_table_size (h), == , 0);
|
||||
g_assert_cmpint (destroy_counter, ==, 2);
|
||||
g_hash_table_insert (h, "uvw", "UVW");
|
||||
g_hash_table_unref (h);
|
||||
g_assert_cmpint (destroy_counter, ==, 3);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/hash/misc", test_hash_misc);
|
||||
g_test_add_data_func ("/hash/one", GINT_TO_POINTER (TRUE), second_hash_test);
|
||||
g_test_add_data_func ("/hash/honeyman", GINT_TO_POINTER (FALSE), second_hash_test);
|
||||
g_test_add_func ("/hash/direct", direct_hash_test);
|
||||
g_test_add_func ("/hash/ref", test_hash_ref);
|
||||
|
||||
return g_test_run ();
|
||||
|
||||
}
|
1
tests/.gitignore
vendored
1
tests/.gitignore
vendored
@ -20,7 +20,6 @@ errorcheck-mutex-test
|
||||
file-test
|
||||
file-test-get-contents
|
||||
gio-test
|
||||
hash-test
|
||||
iochannel-test
|
||||
iochannel-test-outfile
|
||||
list-test
|
||||
|
@ -95,7 +95,6 @@ test_programs = \
|
||||
file-test \
|
||||
env-test \
|
||||
gio-test \
|
||||
hash-test \
|
||||
iochannel-test \
|
||||
list-test \
|
||||
mainloop-test \
|
||||
@ -153,7 +152,6 @@ dirname_test_LDADD = $(progs_ldadd)
|
||||
file_test_LDADD = $(progs_ldadd)
|
||||
env_test_LDADD = $(progs_ldadd)
|
||||
gio_test_LDADD = $(progs_ldadd)
|
||||
hash_test_LDADD = $(progs_ldadd)
|
||||
iochannel_test_LDADD = $(progs_ldadd)
|
||||
list_test_LDADD = $(progs_ldadd)
|
||||
mainloop_test_LDADD = $(thread_ldadd)
|
||||
|
Loading…
Reference in New Issue
Block a user