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);
}
#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 ();
}