]> Savannah Git Hosting - gnulib.git/commitdiff
crypto/{md5,sha1,sha256,sha512} tests: Enhance test.
authorBruno Haible <bruno@clisp.org>
Sun, 6 May 2018 11:11:06 +0000 (13:11 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 6 May 2018 11:11:06 +0000 (13:11 +0200)
* tests/test-digest.h (test_digest_on_files): Add a test with a FILE
stream that is not positioned at the beginning.

ChangeLog
tests/test-digest.h

index dd55a444b79cd34bd341be1e32e744b92290f227..49624ecfb2ca1bdeaad70e33cf024460825a7180 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2018-05-06  Bruno Haible  <bruno@clisp.org>
+
+       crypto/{md5,sha1,sha256,sha512} tests: Enhance test.
+       * tests/test-digest.h (test_digest_on_files): Add a test with a FILE
+       stream that is not positioned at the beginning.
+
 2018-05-06  Bruno Haible  <bruno@clisp.org>
 
        af_alg: Add configure option to enable/disable use of Linux crypto API.
index e80e2cf3ba388f1485d28204ee2c5f391e7efec9..e10f571fa540b4f102f62d5568ea20943c409d39 100644 (file)
@@ -25,7 +25,7 @@ test_digest_on_files (int (*streamfunc) (FILE *, void *),
   int pass;
   unlink (TESTFILE);
 
-  for (pass = 0; pass < 3; pass++)
+  for (pass = 0; pass < 4; pass++)
     {
       {
         FILE *fp = fopen (TESTFILE, "wb");
@@ -44,6 +44,10 @@ test_digest_on_files (int (*streamfunc) (FILE *, void *),
             fputs ("The quick brown fox jumps over the lazy dog.\n", fp);
             break;
           case 2:
+            /* Fill the small file, with some header that will be skipped.  */
+            fputs ("ABCDThe quick brown fox jumps over the lazy dog.\n", fp);
+            break;
+          case 3:
             /* Fill the large file (8 MiB).  */
             {
               unsigned int i;
@@ -74,9 +78,9 @@ test_digest_on_files (int (*streamfunc) (FILE *, void *),
 
         switch (pass)
           {
-          case 0: expected = expected_for_empty_file; break;
-          case 1: expected = expected_for_small_file; break;
-          case 2: expected = expected_for_large_file; break;
+          case 0:         expected = expected_for_empty_file; break;
+          case 1: case 2: expected = expected_for_small_file; break;
+          case 3:         expected = expected_for_large_file; break;
           default: abort ();
           }
 
@@ -86,6 +90,20 @@ test_digest_on_files (int (*streamfunc) (FILE *, void *),
             fprintf (stderr, "Could not open file %s.\n", TESTFILE);
             exit (1);
           }
+        switch (pass)
+          {
+          case 2:
+            {
+              char header[4];
+              if (fread (header, 1, sizeof (header), fp) != sizeof (header))
+                {
+                  fprintf (stderr, "Could not read the header of %s.\n",
+                           TESTFILE);
+                  exit (1);
+                }
+            }
+            break;
+          }
         ret = streamfunc (fp, digest);
         if (ret)
           {