changeset 6434:78b571271328

Test more.
author Simon Josefsson <simon@josefsson.org>
date Fri, 28 Oct 2005 12:17:40 +0000
parents 9ae35a6dccf5
children be00741570b7
files ChangeLog tests/test-gc-md4.c tests/test-gc-md5.c tests/test-gc-sha1.c
diffstat 4 files changed, 121 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2005-10-28  Simon Josefsson  <jas@extundo.com>
 
+	* tests/test-gc-md4.c, tests/test-gc-md5.c, tests/test-gc-sha1.c:
+	Test more.
+
 	* tests/test-gc-md2.c, tests/test-md2.c: New files.
 
 	* modules/md2, modules/md2-tests: New files.
--- a/tests/test-gc-md4.c
+++ b/tests/test-gc-md4.c
@@ -29,6 +29,7 @@
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -45,6 +46,7 @@
     const char *expect =
       "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d";
     char out[16];
+    const char *p;
 
     /* MD4 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b */
 
@@ -85,6 +87,43 @@
 	printf ("\n");
 	return 1;
       }
+
+    if (gc_hash_digest_length (GC_MD4) != 16)
+      {
+	printf ("gc_hash_digest_length (GC_MD4) failed\n");
+	return 1;
+      }
+
+    if ((rc = gc_hash_open (GC_MD4, 0, &h)) != GC_OK)
+      {
+	printf ("gc_hash_open(GC_MD4) failed (%d)\n", rc);
+	return 1;
+      }
+
+    gc_hash_write (h, inlen, in);
+
+    p = gc_hash_read (h);
+
+    if (!p)
+      {
+	printf ("gc_hash_read failed\n");
+	return 1;
+      }
+
+    if (memcmp (p, expect, 16) != 0)
+      {
+	size_t i;
+	printf ("md4 1 missmatch. expected:\n");
+	for (i = 0; i < 16; i++)
+	  printf ("%02x ", expect[i] & 0xFF);
+	printf ("\ncomputed:\n");
+	for (i = 0; i < 16; i++)
+	  printf ("%02x ", p[i] & 0xFF);
+	printf ("\n");
+	return 1;
+      }
+
+    gc_hash_close (h);
   }
 
   gc_done ();
--- a/tests/test-gc-md5.c
+++ b/tests/test-gc-md5.c
@@ -29,6 +29,7 @@
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -45,6 +46,7 @@
     char *expect =
       "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00\x7d\xfb\x49\x6c\xca\x67\xe1\x3b";
     char out[16];
+    const char *p;
 
     /* MD5 ("abcdefghijklmnopqrstuvwxyz") = c3fcd3d76192e4007dfb496cca67e13b */
 
@@ -76,7 +78,7 @@
     if (memcmp (out, expect, 16) != 0)
       {
 	size_t i;
-	printf ("md5 1 missmatch. expected:\n");
+	printf ("md5 2 missmatch. expected:\n");
 	for (i = 0; i < 16; i++)
 	  printf ("%02x ", expect[i] & 0xFF);
 	printf ("\ncomputed:\n");
@@ -85,6 +87,43 @@
 	printf ("\n");
 	return 1;
       }
+
+    if (gc_hash_digest_length (GC_MD5) != 16)
+      {
+	printf ("gc_hash_digest_length (GC_MD5) failed\n");
+	return 1;
+      }
+
+    if ((rc = gc_hash_open (GC_MD5, 0, &h)) != GC_OK)
+      {
+	printf ("gc_hash_open(GC_MD5) failed (%d)\n", rc);
+	return 1;
+      }
+
+    gc_hash_write (h, inlen, in);
+
+    p = gc_hash_read (h);
+
+    if (!p)
+      {
+	printf ("gc_hash_read failed\n");
+	return 1;
+      }
+
+    if (memcmp (p, expect, 16) != 0)
+	{
+	size_t i;
+	printf ("md5 3 missmatch. expected:\n");
+	for (i = 0; i < 16; i++)
+	  printf ("%02x ", expect[i] & 0xFF);
+	printf ("\ncomputed:\n");
+	for (i = 0; i < 16; i++)
+	  printf ("%02x ", p[i] & 0xFF);
+	printf ("\n");
+	return 1;
+      }
+
+    gc_hash_close (h);
   }
 
   gc_done ();
--- a/tests/test-gc-sha1.c
+++ b/tests/test-gc-sha1.c
@@ -29,6 +29,7 @@
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -43,6 +44,7 @@
     char *expect = "\x42\x5a\xf1\x2a\x07\x43\x50\x2b"
       "\x32\x2e\x93\xa0\x15\xbc\xf8\x68\xe3\x24\xd5\x6a";
     char out[20];
+    const char *p;
 
     if (gc_sha1 (in, inlen, out) != 0)
       {
@@ -82,6 +84,43 @@
 	printf ("\n");
 	return 1;
       }
+
+    if (gc_hash_digest_length (GC_SHA1) != 20)
+      {
+	printf ("gc_hash_digest_length (GC_SHA1) failed\n");
+	return 1;
+      }
+
+    if ((rc = gc_hash_open (GC_SHA1, 0, &h)) != GC_OK)
+      {
+	printf ("gc_hash_open(GC_SHA1) failed (%d)\n", rc);
+	return 1;
+      }
+
+    gc_hash_write (h, inlen, in);
+
+    p = gc_hash_read (h);
+
+    if (!p)
+      {
+	printf ("gc_hash_read failed\n");
+	return 1;
+      }
+
+    if (memcmp (p, expect, 20) != 0)
+      {
+	size_t i;
+	printf ("sha1 1 missmatch. expected:\n");
+	for (i = 0; i < 20; i++)
+	  printf ("%02x ", expect[i] & 0xFF);
+	printf ("\ncomputed:\n");
+	for (i = 0; i < 20; i++)
+	  printf ("%02x ", p[i] & 0xFF);
+	printf ("\n");
+	return 1;
+      }
+
+    gc_hash_close (h);
   }
 
   gc_done ();