changeset 39337:fd1939030d58

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.
author Bruno Haible <bruno@clisp.org>
date Sun, 06 May 2018 13:11:06 +0200
parents a3877e074b79
children 515136fec4cf
files ChangeLog tests/test-digest.h
diffstat 2 files changed, 28 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sun May 06 12:23:55 2018 +0200
+++ b/ChangeLog	Sun May 06 13:11:06 2018 +0200
@@ -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.
--- a/tests/test-digest.h	Sun May 06 12:23:55 2018 +0200
+++ b/tests/test-digest.h	Sun May 06 13:11:06 2018 +0200
@@ -25,7 +25,7 @@
   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 @@
             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 @@
 
         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 @@
             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)
           {