bug-gnulib
[Top][All Lists]
Advanced

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

gc self test fixes


From: Simon Josefsson
Subject: gc self test fixes
Date: Fri, 28 Oct 2005 14:17:29 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Installed.

2005-10-28  Simon Josefsson  <address@hidden>

        * tests/test-gc-md4.c, tests/test-gc-md5.c, tests/test-gc-sha1.c:
        Test more.

Index: tests/test-gc-md4.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/tests/test-gc-md4.c,v
retrieving revision 1.2
diff -u -p -r1.2 test-gc-md4.c
--- tests/test-gc-md4.c 18 Oct 2005 23:45:03 -0000      1.2
+++ tests/test-gc-md4.c 28 Oct 2005 12:16:59 -0000
@@ -29,6 +29,7 @@ int
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -45,6 +46,7 @@ main (int argc, char *argv[])
     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 @@ main (int argc, char *argv[])
        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 ();
Index: tests/test-gc-md5.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/tests/test-gc-md5.c,v
retrieving revision 1.2
diff -u -p -r1.2 test-gc-md5.c
--- tests/test-gc-md5.c 18 Oct 2005 23:45:03 -0000      1.2
+++ tests/test-gc-md5.c 28 Oct 2005 12:16:59 -0000
@@ -29,6 +29,7 @@ int
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -45,6 +46,7 @@ main (int argc, char *argv[])
     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 @@ main (int argc, char *argv[])
     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 @@ main (int argc, char *argv[])
        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 ();
Index: tests/test-gc-sha1.c
===================================================================
RCS file: /cvsroot/gnulib/gnulib/tests/test-gc-sha1.c,v
retrieving revision 1.1
diff -u -p -r1.1 test-gc-sha1.c
--- tests/test-gc-sha1.c        17 Oct 2005 14:48:32 -0000      1.1
+++ tests/test-gc-sha1.c        28 Oct 2005 12:16:59 -0000
@@ -29,6 +29,7 @@ int
 main (int argc, char *argv[])
 {
   Gc_rc rc;
+  gc_hash_handle h;
 
   rc = gc_init ();
   if (rc != GC_OK)
@@ -43,6 +44,7 @@ main (int argc, char *argv[])
     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 @@ main (int argc, char *argv[])
        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 ();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]