From c24c54ae211f0b482693394f71970b182120f2ef Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 6 May 2018 13:11:06 +0200 Subject: [PATCH] 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. --- ChangeLog | 6 ++++++ tests/test-digest.h | 26 ++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index dd55a444b7..49624ecfb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2018-05-06 Bruno Haible + + 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 af_alg: Add configure option to enable/disable use of Linux crypto API. diff --git a/tests/test-digest.h b/tests/test-digest.h index e80e2cf3ba..e10f571fa5 100644 --- a/tests/test-digest.h +++ b/tests/test-digest.h @@ -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) { -- 2.39.5