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
This commit is contained in:
Stef Walter
2012-08-03 18:19:36 +02:00
parent 0f6a092cc5
commit dd2ecf7488

View File

@@ -725,30 +725,39 @@ test_checksum_string (gconstpointer d)
g_free (checksum); g_free (checksum);
} }
#define test(type, length) { \ static void
ChecksumTest *test; \ add_checksum_test (GChecksumType type,
gchar *path; \ const char *type_name,
test = g_new0 (ChecksumTest, 1); \ const char *sum,
test->checksum_type = G_CHECKSUM_##type; \ gint length)
test->sum = type##_sums[length]; \ {
test->length = length; \ ChecksumTest *test;
path = g_strdup_printf ("/checksum/%s/%d", #type, length); \ gchar *path;
g_test_add_data_func (path, test, test_checksum); \ test = g_new0 (ChecksumTest, 1);
g_free (path); \ test->checksum_type = type;
path = g_strdup_printf ("/checksum/%s/reset/%d", #type, length); \ test->sum = sum;
g_test_add_data_func (path, test, test_checksum_reset); \ test->length = length;
g_free (path); \ 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) { \ static void
ChecksumStringTest *test; \ add_checksum_string_test (GChecksumType type,
gchar *path; \ const gchar *type_name,
test = g_new0 (ChecksumStringTest, 1); \ const gchar **sums)
test->checksum_type = G_CHECKSUM_##type; \ {
test->sums = type##_sums; \ ChecksumStringTest *test;
path = g_strdup_printf ("/checksum/%s/string", #type); \ gchar *path;
g_test_add_data_func (path, test, test_checksum_string); \ test = g_new0 (ChecksumStringTest, 1);
g_free (path); \ 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 static void
@@ -768,16 +777,16 @@ main (int argc, char *argv[])
g_test_add_func ("/checksum/unsupported", test_unsupported); g_test_add_func ("/checksum/unsupported", test_unsupported);
for (length = 0; length <= FIXED_LEN; length++) for (length = 0; length <= FIXED_LEN; length++)
test (MD5, length); add_checksum_test (G_CHECKSUM_MD5, "MD5", MD5_sums[length], length);
test_string (MD5); add_checksum_string_test (G_CHECKSUM_MD5, "MD5", MD5_sums);
for (length = 0; length <= FIXED_LEN; length++) for (length = 0; length <= FIXED_LEN; length++)
test (SHA1, length); add_checksum_test (G_CHECKSUM_SHA1, "SHA1", SHA1_sums[length], length);
test_string (SHA1); add_checksum_string_test (G_CHECKSUM_SHA1, "SHA1", SHA1_sums);
for (length = 0; length <= FIXED_LEN; length++) for (length = 0; length <= FIXED_LEN; length++)
test (SHA256, length); add_checksum_test (G_CHECKSUM_SHA256, "SHA256", SHA256_sums[length], length);
test_string (SHA256); add_checksum_string_test (G_CHECKSUM_SHA256, "SHA256", SHA256_sums);
return g_test_run (); return g_test_run ();
} }