glib r7625 - in trunk: . glib tests



Author: matthiasc
Date: Fri Oct 24 04:10:50 2008
New Revision: 7625
URL: http://svn.gnome.org/viewvc/glib?rev=7625&view=rev

Log:
Accept short data


Modified:
   trunk/ChangeLog
   trunk/glib/gchecksum.c
   trunk/tests/checksum-test.c

Modified: trunk/glib/gchecksum.c
==============================================================================
--- trunk/glib/gchecksum.c	(original)
+++ trunk/glib/gchecksum.c	Fri Oct 24 04:10:50 2008
@@ -1389,7 +1389,6 @@
 
   g_return_val_if_fail (IS_VALID_TYPE (checksum_type), NULL);
   g_return_val_if_fail (data != NULL, NULL);
-  g_return_val_if_fail (length > 1, NULL);
 
   checksum = g_checksum_new (checksum_type);
   if (!checksum)

Modified: trunk/tests/checksum-test.c
==============================================================================
--- trunk/tests/checksum-test.c	(original)
+++ trunk/tests/checksum-test.c	Fri Oct 24 04:10:50 2008
@@ -617,11 +617,45 @@
     }
 }
 
+static void
+test_checksum_string (GChecksumType   checksum_type,
+                      const gchar    *type,
+                      const gchar   **sums)
+{
+  int length;
+
+  for (length = 0; length <= FIXED_LEN; length++)
+    {
+      const char *expected = sums[length];
+      char *checksum;
+
+      checksum = g_compute_checksum_for_string (checksum_type,
+                                                FIXED_STR,
+                                                length);
+      if (strcmp (checksum, expected) != 0)
+        {
+          g_print ("Invalid %s checksum for `%.*s' (length %d):\n"
+                   "%s (expecting: %s)\n",
+                   type,
+                   length, FIXED_STR, length,
+                   checksum,
+                   expected);
+          exit (1);
+        }
+
+      g_free (checksum);
+    }
+}
+
 #define test(type, length) test_checksum (G_CHECKSUM_##type,	\
                                           #type, \
                                           type##_sums[length], \
                                           length)
 
+#define test_string(type) test_checksum_string (G_CHECKSUM_##type,	\
+                                                #type, \
+                                                type##_sums)
+
 int
 main (int argc, char *argv[])
 {
@@ -634,5 +668,9 @@
       test (SHA256, length);
     }
 
+  test_string (MD5);
+  test_string (SHA1);
+  test_string (SHA256);
+
   return EXIT_SUCCESS;
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]