[glib] Some more hash, utils and checksum tests
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Some more hash, utils and checksum tests
- Date: Wed, 23 Jun 2010 13:27:01 +0000 (UTC)
commit 464b5ff3570fd43fa52b6ec5571a02bd705f9e9c
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Jun 22 22:25:02 2010 -0400
Some more hash, utils and checksum tests
glib/tests/checksum.c | 18 ++++++++-
glib/tests/hash.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++
glib/tests/utils.c | 31 +++++++++++++++
3 files changed, 149 insertions(+), 2 deletions(-)
---
diff --git a/glib/tests/checksum.c b/glib/tests/checksum.c
index 83f9e8d..0e51736 100644
--- a/glib/tests/checksum.c
+++ b/glib/tests/checksum.c
@@ -689,17 +689,22 @@ test_checksum_string (gconstpointer d)
{
const ChecksumStringTest *test = d;
int length;
+ gchar *checksum;
for (length = 0; length <= FIXED_LEN; length++)
{
- char *checksum;
-
checksum = g_compute_checksum_for_string (test->checksum_type,
FIXED_STR,
length);
g_assert_cmpstr (checksum, ==, test->sums[length]);
g_free (checksum);
}
+
+ checksum = g_compute_checksum_for_string (test->checksum_type,
+ FIXED_STR,
+ -1);
+ g_assert_cmpstr (checksum, ==, test->sums[FIXED_LEN]);
+ g_free (checksum);
}
#define test(type, length) { \
@@ -728,6 +733,13 @@ test_checksum_string (gconstpointer d)
g_free (path); \
}
+static void
+test_unsupported (void)
+{
+ g_assert_cmpint (g_checksum_type_get_length (20), ==, -1);
+ g_assert (g_checksum_new (20) == NULL);
+}
+
int
main (int argc, char *argv[])
{
@@ -735,6 +747,8 @@ main (int argc, char *argv[])
g_test_init (&argc, &argv, NULL);
+ g_test_add_func ("/checksum/unsupported", test_unsupported);
+
for (length = 0; length <= FIXED_LEN; length++)
test (MD5, length);
test_string (MD5);
diff --git a/glib/tests/hash.c b/glib/tests/hash.c
index 6dac989..983c4d3 100644
--- a/glib/tests/hash.c
+++ b/glib/tests/hash.c
@@ -379,6 +379,105 @@ static void direct_hash_test (void)
g_hash_table_destroy (h);
}
+static void int64_hash_test (void)
+{
+ gint i, rc;
+ GHashTable *h;
+ gint64 values[20];
+ gint64 key;
+
+ h = g_hash_table_new (g_int64_hash, g_int64_equal);
+ g_assert (h != NULL);
+ for (i=0; i<20; i++)
+ {
+ values[i] = i + 42;
+ g_hash_table_insert (h, &values[i], GINT_TO_POINTER (i + 42));
+ }
+
+ g_assert (g_hash_table_size (h) == 20);
+
+ for (i=0; i<20; i++)
+ {
+ key = i + 42;
+ rc = GPOINTER_TO_INT (g_hash_table_lookup (h, &key));
+
+ g_assert_cmpint (rc, ==, i + 42);
+ }
+
+ g_hash_table_destroy (h);
+}
+
+static void double_hash_test (void)
+{
+ gint i, rc;
+ GHashTable *h;
+ gdouble values[20];
+ gdouble key;
+
+ h = g_hash_table_new (g_double_hash, g_double_equal);
+ g_assert (h != NULL);
+ for (i=0; i<20; i++)
+ {
+ values[i] = i + 42.5;
+ g_hash_table_insert (h, &values[i], GINT_TO_POINTER (i + 42));
+ }
+
+ g_assert (g_hash_table_size (h) == 20);
+
+ for (i=0; i<20; i++)
+ {
+ key = i + 42.5;
+ rc = GPOINTER_TO_INT (g_hash_table_lookup (h, &key));
+
+ g_assert_cmpint (rc, ==, i + 42);
+ }
+
+ g_hash_table_destroy (h);
+}
+
+static void
+string_free (gpointer data)
+{
+ GString *s = data;
+
+ g_string_free (s, TRUE);
+}
+
+static void string_hash_test (void)
+{
+ gint i, rc;
+ GHashTable *h;
+ GString *s;
+
+ h = g_hash_table_new_full ((GHashFunc)g_string_hash, (GEqualFunc)g_string_equal, string_free, NULL);
+ g_assert (h != NULL);
+ for (i=0; i<20; i++)
+ {
+ s = g_string_new ("");
+ g_string_append_printf (s, "%d", i + 42);
+ g_string_append_c (s, '.');
+ g_string_prepend_unichar (s, 0x2301);
+ g_hash_table_insert (h, s, GINT_TO_POINTER (i + 42));
+ }
+
+ g_assert (g_hash_table_size (h) == 20);
+
+ s = g_string_new ("");
+ for (i=0; i<20; i++)
+ {
+ g_string_assign (s, "");
+ g_string_append_printf (s, "%d", i + 42);
+ g_string_append_c (s, '.');
+ g_string_prepend_unichar (s, 0x2301);
+ rc = GPOINTER_TO_INT (g_hash_table_lookup (h, s));
+
+ g_assert_cmpint (rc, ==, i + 42);
+ }
+
+ g_string_free (s, TRUE);
+ g_hash_table_destroy (h);
+}
+
static void
test_hash_misc (void)
{
@@ -518,6 +617,9 @@ main (int argc, char *argv[])
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/int64", int64_hash_test);
+ g_test_add_func ("/hash/double", double_hash_test);
+ g_test_add_func ("/hash/string", string_hash_test);
g_test_add_func ("/hash/ref", test_hash_ref);
return g_test_run ();
diff --git a/glib/tests/utils.c b/glib/tests/utils.c
index e402751..104a51b 100644
--- a/glib/tests/utils.c
+++ b/glib/tests/utils.c
@@ -95,14 +95,45 @@ test_version (void)
GLIB_MICRO_VERSION + 1) != NULL);
}
+static const gchar *argv0;
+
+static void
+test_appname (void)
+{
+ const gchar *prgname;
+ const gchar *appname;
+
+ prgname = g_get_prgname ();
+ appname = g_get_application_name ();
+ g_assert_cmpstr (prgname, ==, argv0);
+ g_assert_cmpstr (appname, ==, prgname);
+
+ g_set_prgname ("prgname");
+
+ prgname = g_get_prgname ();
+ appname = g_get_application_name ();
+ g_assert_cmpstr (prgname, ==, "prgname");
+ g_assert_cmpstr (appname, ==, "prgname");
+
+ g_set_application_name ("appname");
+
+ prgname = g_get_prgname ();
+ appname = g_get_application_name ();
+ g_assert_cmpstr (prgname, ==, "prgname");
+ g_assert_cmpstr (appname, ==, "appname");
+}
+
int
main (int argc,
char *argv[])
{
+ argv0 = argv[0];
+
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/utils/language-names", test_language_names);
g_test_add_func ("/utils/version", test_version);
+ g_test_add_func ("/utils/appname", test_appname);
return g_test_run();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]