From dd2ecf7488190d7ffd7912f6bf81da3560ad3976 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Fri, 3 Aug 2012 18:19:36 +0200 Subject: [PATCH] checksum: Use functions instead of macros when building tests * No need for hard to debug and maintain macros here. https://bugzilla.gnome.org/show_bug.cgi?id=681151 --- glib/tests/checksum.c | 65 ++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/glib/tests/checksum.c b/glib/tests/checksum.c index eb170e2fc..fd2ffb9cf 100644 --- a/glib/tests/checksum.c +++ b/glib/tests/checksum.c @@ -725,30 +725,39 @@ test_checksum_string (gconstpointer d) g_free (checksum); } -#define test(type, length) { \ - ChecksumTest *test; \ - gchar *path; \ - test = g_new0 (ChecksumTest, 1); \ - test->checksum_type = G_CHECKSUM_##type; \ - test->sum = type##_sums[length]; \ - test->length = length; \ - path = g_strdup_printf ("/checksum/%s/%d", #type, length); \ - g_test_add_data_func (path, test, test_checksum); \ - g_free (path); \ - path = g_strdup_printf ("/checksum/%s/reset/%d", #type, length); \ - g_test_add_data_func (path, test, test_checksum_reset); \ - g_free (path); \ +static void +add_checksum_test (GChecksumType type, + const char *type_name, + const char *sum, + gint length) +{ + ChecksumTest *test; + gchar *path; + test = g_new0 (ChecksumTest, 1); + test->checksum_type = type; + test->sum = sum; + test->length = length; + path = g_strdup_printf ("/checksum/%s/%d", type_name, length); + g_test_add_data_func (path, test, test_checksum); + g_free (path); + path = g_strdup_printf ("/checksum/%s/reset/%d", type_name, length); + g_test_add_data_func (path, test, test_checksum_reset); + g_free (path); } -#define test_string(type) { \ - ChecksumStringTest *test; \ - gchar *path; \ - test = g_new0 (ChecksumStringTest, 1); \ - test->checksum_type = G_CHECKSUM_##type; \ - test->sums = type##_sums; \ - path = g_strdup_printf ("/checksum/%s/string", #type); \ - g_test_add_data_func (path, test, test_checksum_string); \ - g_free (path); \ +static void +add_checksum_string_test (GChecksumType type, + const gchar *type_name, + const gchar **sums) +{ + ChecksumStringTest *test; + gchar *path; + test = g_new0 (ChecksumStringTest, 1); + test->checksum_type = type; + test->sums = sums; + path = g_strdup_printf ("/checksum/%s/string", type_name); + g_test_add_data_func (path, test, test_checksum_string); + g_free (path); } static void @@ -768,16 +777,16 @@ main (int argc, char *argv[]) g_test_add_func ("/checksum/unsupported", test_unsupported); for (length = 0; length <= FIXED_LEN; length++) - test (MD5, length); - test_string (MD5); + add_checksum_test (G_CHECKSUM_MD5, "MD5", MD5_sums[length], length); + add_checksum_string_test (G_CHECKSUM_MD5, "MD5", MD5_sums); for (length = 0; length <= FIXED_LEN; length++) - test (SHA1, length); - test_string (SHA1); + add_checksum_test (G_CHECKSUM_SHA1, "SHA1", SHA1_sums[length], length); + add_checksum_string_test (G_CHECKSUM_SHA1, "SHA1", SHA1_sums); for (length = 0; length <= FIXED_LEN; length++) - test (SHA256, length); - test_string (SHA256); + add_checksum_test (G_CHECKSUM_SHA256, "SHA256", SHA256_sums[length], length); + add_checksum_string_test (G_CHECKSUM_SHA256, "SHA256", SHA256_sums); return g_test_run (); }