apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r106428 - /apr/apr-util/trunk/CHANGES /apr/apr-util/trunk/test/Makefile.in /apr/apr-util/trunk/test/abts_tests.h /apr/apr-util/trunk/test/testmd4.c /apr/apr-util/trunk/test/testmd5.c /apr/apr-util/trunk/test/testutil.h
Date Wed, 24 Nov 2004 16:23:54 GMT
Author: thommay
Date: Wed Nov 24 08:23:52 2004
New Revision: 106428

URL: http://svn.apache.org/viewcvs?view=rev&rev=106428
Log:
Port testmd4 and testmd5 to the new testsuite

 * test/Makefile.in: Stop building testmd* seperately, link them into testall

 * test/abts_tests.h: Add testmd4 and testmd5 to the list of tests to be run

 * test/testmd{4,5}.c: rewrite to use abts.

Modified:
   apr/apr-util/trunk/CHANGES
   apr/apr-util/trunk/test/Makefile.in
   apr/apr-util/trunk/test/abts_tests.h
   apr/apr-util/trunk/test/testmd4.c
   apr/apr-util/trunk/test/testmd5.c
   apr/apr-util/trunk/test/testutil.h

Modified: apr/apr-util/trunk/CHANGES
Url: http://svn.apache.org/viewcvs/apr/apr-util/trunk/CHANGES?view=diff&rev=106428&p1=apr/apr-util/trunk/CHANGES&r1=106427&p2=apr/apr-util/trunk/CHANGES&r2=106428
==============================================================================
--- apr/apr-util/trunk/CHANGES	(original)
+++ apr/apr-util/trunk/CHANGES	Wed Nov 24 08:23:52 2004
@@ -1,5 +1,7 @@
 Changes with APR-util 1.1.0
 
+  *) Port testmd4 and testmd5 to the new test suite. [Thom May]
+
   *) Allow passing NULL inbuf/inbytes_left parameters to
      apr_xlate_conv_buffer(), required to correctly terminate the
      output buffer for some stateful character set encodings.

Modified: apr/apr-util/trunk/test/Makefile.in
Url: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/Makefile.in?view=diff&rev=106428&p1=apr/apr-util/trunk/test/Makefile.in&r1=106427&p2=apr/apr-util/trunk/test/Makefile.in&r2=106428
==============================================================================
--- apr/apr-util/trunk/test/Makefile.in	(original)
+++ apr/apr-util/trunk/test/Makefile.in	Wed Nov 24 08:23:52 2004
@@ -2,7 +2,7 @@
 
 INCLUDES = @APRUTIL_PRIV_INCLUDES@ @APR_INCLUDES@ @APRUTIL_INCLUDES@
 
-PROGRAMS = testall testdbm testdate testmd4 testmd5 testxml testrmm \
+PROGRAMS = testall testdbm testdate testxml testrmm \
 	   testreslist testqueue testxlate
 TARGETS = $(PROGRAMS)
 
@@ -41,16 +41,6 @@
 testxml: $(testxml_OBJECTS) $(testxml_LDADD)
 	$(LINK) $(APRUTIL_LDFLAGS) $(testxml_OBJECTS) $(testxml_LDADD) $(PROGRAM_DEPENDENCIES)
 
-testmd4_OBJECTS = testmd4.lo
-testmd4_LDADD =  $(TARGET_LIB_PATH)
-testmd4: $(testmd4_OBJECTS) $(testmd4_LDADD)
-	$(LINK) $(APRUTIL_LDFLAGS) $(testmd4_OBJECTS) $(testmd4_LDADD) $(PROGRAM_DEPENDENCIES)
-
-testmd5_OBJECTS = testmd5.lo
-testmd5_LDADD =  $(TARGET_LIB_PATH)
-testmd5: $(testmd5_OBJECTS) $(testmd5_LDADD)
-	$(LINK) $(APRUTIL_LDFLAGS) $(testmd5_OBJECTS) $(testmd5_LDADD) $(PROGRAM_DEPENDENCIES)
-
 testrmm_OBJECTS = testrmm.lo
 testrmm_LDADD =  $(TARGET_LIB_PATH)
 testrmm: $(testrmm_OBJECTS) $(testrmm_LDADD)
@@ -72,7 +62,7 @@
 	$(LINK) $(APRUTIL_LDFLAGS) $(testxlate_OBJECTS) $(testxlate_LDADD) $(PROGRAM_DEPENDENCIES)
 
 testall_OBJECTS = teststrmatch.lo testuri.lo testuuid.lo abts.lo testutil.lo \
-	testbuckets.lo testpass.lo
+	testbuckets.lo testpass.lo testmd4.lo testmd5.lo
 testall_LDADD =  $(TARGET_LIB_PATH)
 testall: $(testall_OBJECTS) $(testall_LDADD)
 	$(LINK) $(APRUTIL_LDFLAGS) $(testall_OBJECTS) $(testall_LDADD) $(PROGRAM_DEPENDENCIES)

Modified: apr/apr-util/trunk/test/abts_tests.h
Url: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/abts_tests.h?view=diff&rev=106428&p1=apr/apr-util/trunk/test/abts_tests.h&r1=106427&p2=apr/apr-util/trunk/test/abts_tests.h&r2=106428
==============================================================================
--- apr/apr-util/trunk/test/abts_tests.h	(original)
+++ apr/apr-util/trunk/test/abts_tests.h	Wed Nov 24 08:23:52 2004
@@ -26,7 +26,9 @@
     {testuri},
     {testuuid},
     {testbuckets},
-    {testpass}
+    {testpass},
+    {testmd4},
+    {testmd5}
 };
 
 #endif /* APR_TEST_INCLUDES */

Modified: apr/apr-util/trunk/test/testmd4.c
Url: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/testmd4.c?view=diff&rev=106428&p1=apr/apr-util/trunk/test/testmd4.c&r1=106427&p2=apr/apr-util/trunk/test/testmd4.c&r2=106428
==============================================================================
--- apr/apr-util/trunk/test/testmd4.c	(original)
+++ apr/apr-util/trunk/test/testmd4.c	Wed Nov 24 08:23:52 2004
@@ -1,4 +1,4 @@
-/* Copyright 2001-2004 The Apache Software Foundation
+/* Copyright 2000-2004 The Apache Software Foundation
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,211 +27,92 @@
  * documentation and/or software.
  */
 
-
-#include "apr.h"
-#include "apr_general.h"
-#include "apr_file_io.h"
-#include "apr_time.h"
-#include "apr_md4.h"
-
+#include <assert.h>
 #include <stdio.h>
-#include <string.h>
 #include <stdlib.h>
 
-/*
- * This is a MD4 test program based on the code published in RFC 1320.
- * When run as ./testmd4 -x it should produce the following output:
-
-MD4 test suite:
-MD4 ("") = 31d6cfe0d16ae931b73c59d7e0c089c0
-MD4 ("a") = bde52cb31de33e46245e05fbdbd6fb24
-MD4 ("abc") = a448017aaf21d8525fc10ae87aa6729d
-MD4 ("message digest") = d9130a8164549fe818874806e1c7014b
-MD4 ("abcdefghijklmnopqrstuvwxyz") = d79e1c308aa5bbcdeea8ed63df412da9
-MD4 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789") = 043f8582f241db351ce627e153e7f0e4
-MD4 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
= e33b4ddc9c38f2199c3e7b164fcc0536
-
-*/
-
-/* Length of test block, number of test blocks.
- */
-#define TEST_BLOCK_LEN 1000
-#define TEST_BLOCK_COUNT 1000
-
-apr_pool_t *local_pool;
-apr_file_t *in, *out, *err;
-
-/* Prints a message digest in hexadecimal.
- */
-static void MDPrint (unsigned char digest[APR_MD4_DIGESTSIZE])
-{
-    unsigned int i;
-
-    for (i = 0; i < APR_MD4_DIGESTSIZE; i++)
-        apr_file_printf(out, "%02x", digest[i]);
-}
-
-/* Digests a string and prints the result.
- */
-static void MDString(char *string)
-{
-    apr_md4_ctx_t context;
-    unsigned char digest[APR_MD4_DIGESTSIZE];
-    unsigned int len = strlen(string);
-
-    apr_md4_init(&context);
-    apr_md4_update(&context, (unsigned char *)string, len);
-    apr_md4_final(digest, &context);
-
-    apr_file_printf (out, "MD4 (\"%s\") = ", string);
-    MDPrint(digest);
-    apr_file_printf (out, "\n");
-}
-
-/* Measures the time to digest TEST_BLOCK_COUNT TEST_BLOCK_LEN-byte
-     blocks.
- */
-static void MDTimeTrial(void)
-{
-    apr_md4_ctx_t context;
-    apr_time_t endTime, startTime;
-    apr_interval_time_t timeTaken;
-    unsigned char block[TEST_BLOCK_LEN], digest[APR_MD4_DIGESTSIZE];
-    unsigned int i;
-
-    apr_file_printf(out, "MD4 time trial. Digesting %d %d-byte blocks ...", 
-                     TEST_BLOCK_LEN, TEST_BLOCK_COUNT);
-
-    /* Initialize block */
-    for (i = 0; i < TEST_BLOCK_LEN; i++)
-        block[i] = (unsigned char)(i & 0xff);
-
-    /* Start timer */
-    startTime = apr_time_now();
-
-    /* Digest blocks */
-    apr_md4_init(&context);
-    for (i = 0; i < TEST_BLOCK_COUNT; i++)
-        apr_md4_update(&context, block, TEST_BLOCK_LEN);
-
-    apr_md4_final(digest, &context);
-
-    /* Stop timer */
-    endTime = apr_time_now();
-    timeTaken = endTime - startTime;
-
-    apr_file_printf(out, " done\n");
-    apr_file_printf(out, "Digest = ");
-    MDPrint(digest);
-
-    apr_file_printf(out, "\nTime = %" APR_TIME_T_FMT " seconds\n", timeTaken);
-    apr_file_printf(out, "Speed = % " APR_TIME_T_FMT " bytes/second\n",
-                    TEST_BLOCK_LEN * TEST_BLOCK_COUNT/timeTaken);
-}
+#include "apr_errno.h"
+#include "apr_md4.h"
+#include "apr_file_io.h"
 
-/* Digests a reference suite of strings and prints the results.
- */
-static void MDTestSuite(void)
-{
-    apr_file_printf(out, "MD4 test suite:\n");
+#include "abts.h"
+#include "testutil.h"
 
-    MDString("");
-    MDString("a");
-    MDString("abc");
-    MDString("message digest");
-    MDString("abcdefghijklmnopqrstuvwxyz");
-    MDString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
-    MDString("12345678901234567890123456789012345678901234567890123456789012345678901234567890");
-}
+static struct {
+        const char *string;
+        const char *md4sum;
+} md4sums[] = 
+{
+/* 
+* Taken from the old md4 test suite.
+* MD4 ("") = 31d6cfe0d16ae931b73c59d7e0c089c0
+* MD4 ("a") = bde52cb31de33e46245e05fbdbd6fb24
+* MD4 ("abc") = a448017aaf21d8525fc10ae87aa6729d
+* MD4 ("message digest") = d9130a8164549fe818874806e1c7014b
+* MD4 ("abcdefghijklmnopqrstuvwxyz") = d79e1c308aa5bbcdeea8ed63df412da9
+* MD4 ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789")
+* MD4 ("12345678901234567890123456789012345678901234567890123456789012345678901234567890")
= e33b4ddc9c38f2199c3e7b164fcc0536
+* 
+*/
+        {"", 
+         "\x31\xd6\xcf\xe0\xd1\x6a\xe9\x31\xb7\x3c\x59\xd7\xe0\xc0\x89\xc0"},
+        {"a", 
+         "\xbd\xe5\x2c\xb3\x1d\xe3\x3e\x46\x24\x5e\x05\xfb\xdb\xd6\xfb\x24"},
+        {"abc", 
+         "\xa4\x48\x01\x7a\xaf\x21\xd8\x52\x5f\xc1\x0a\xe8\x7a\xa6\x72\x9d"},
+        {"message digest", 
+         "\xd9\x13\x0a\x81\x64\x54\x9f\xe8\x18\x87\x48\x06\xe1\xc7\x01\x4b"},
+        {"abcdefghijklmnopqrstuvwxyz", 
+         "\xd7\x9e\x1c\x30\x8a\xa5\xbb\xcd\xee\xa8\xed\x63\xdf\x41\x2d\xa9"},
+        {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", 
+         "\x04\x3f\x85\x82\xf2\x41\xdb\x35\x1c\xe6\x27\xe1\x53\xe7\xf0\xe4"},
+        {"12345678901234567890123456789012345678901234567890123456789012345678901234567890",

+         "\xe3\x3b\x4d\xdc\x9c\x38\xf2\x19\x9c\x3e\x7b\x16\x4f\xcc\x05\x36"}
+};
+
+static int num_sums = sizeof(md4sums) / sizeof(md4sums[0]); 
+static int count;
+
+#if 0
+static int MDStringComp(const void *string, const void *sum)
+{
+        apr_md4_ctx_t context;
+        unsigned char digest[APR_MD4_DIGESTSIZE];
+        unsigned int len = strlen(string);
 
-/* Digests a file and prints the result.
- */
-static void MDFile(char *filename)
-{
-    apr_file_t *file;
-    apr_md4_ctx_t context;
-    apr_size_t len = 1024;
-    unsigned char buffer[1024], digest[APR_MD4_DIGESTSIZE];
-
-    if (apr_file_open(&file, filename, APR_READ, APR_OS_DEFAULT, local_pool) 
-        != APR_SUCCESS)
-        apr_file_printf(err, "%s can't be opened\n", filename);
-    else {
         apr_md4_init(&context);
-        while (apr_file_read(file, buffer, &len) != APR_SUCCESS)
-        {
-            apr_md4_update(&context, buffer, len);
-            len = 1024;
-        }
+        apr_md4_update(&context, (unsigned char *)string, len);
         apr_md4_final(digest, &context);
+        return (memcmp(digest, sum, APR_MD4_DIGESTSIZE));
 
-        apr_file_close(file);
-
-        apr_file_printf(out, "MD4 (%s) = ", filename);
-        MDPrint(digest);
-        apr_file_printf(out, "\n");
-    }
 }
+#endif
 
-/* Digests the standard input and prints the result.
- */
-static void MDFilter(void)
+static void test_md4sum(abts_case *tc, void *data)
 {
-    apr_md4_ctx_t context;
-    apr_size_t len = 16;
-    unsigned char buffer[16], digest[16];
-
-    apr_md4_init(&context);
-    while (apr_file_read(in, buffer, &len) != APR_SUCCESS)
-    {
-        apr_md4_update(&context, buffer, len);
-        len = 16;
-    }
-    apr_md4_update(&context, buffer, len);
-    apr_md4_final(digest, &context);
+        apr_md4_ctx_t context;
+        unsigned char digest[APR_MD4_DIGESTSIZE];
+        const void *string = md4sums[count].string;
+        const void *sum = md4sums[count].md4sum;
+        unsigned int len = strlen(string);
 
-    MDPrint(digest);
-    apr_file_printf(out, "\n");
+        ABTS_ASSERT(tc, "apr_md4_init", (apr_md4_init(&context) == 0));
+        ABTS_ASSERT(tc, "apr_md4_update", 
+                    (apr_md4_update(&context, 
+                                    (unsigned char *)string, len) == 0));
+        
+        ABTS_ASSERT(tc, "apr_md4_final", (apr_md4_final(digest, &context) ==0));
+        ABTS_ASSERT(tc, "check for correct md4 digest", 
+                    (memcmp(digest, sum, APR_MD4_DIGESTSIZE) == 0));
 }
 
-
-/* Main driver.
-
-   Arguments (may be any combination):
-     -sstring - digests string
-     -t       - runs time trial
-     -x       - runs test script
-     filename - digests file
-     (none)   - digests standard input
- */
-int main (int argc, char **argv)
+abts_suite *testmd4(abts_suite *suite)
 {
-    int i;
-
-    apr_initialize();
-    atexit(apr_terminate);
+        suite = ADD_SUITE(suite);
 
-    if (apr_pool_create(&local_pool, NULL) != APR_SUCCESS)
-        exit(-1);
-
-    apr_file_open_stdin(&in, local_pool); 
-    apr_file_open_stdout(&out, local_pool); 
-    apr_file_open_stderr(&err, local_pool); 
-
-    if (argc > 1)
-    {
-        for (i = 1; i < argc; i++)
-            if (argv[i][0] == '-' && argv[i][1] == 's')
-                MDString(argv[i] + 2);
-            else if (strcmp(argv[i], "-t") == 0)
-                MDTimeTrial();
-            else if (strcmp (argv[i], "-x") == 0)
-                MDTestSuite();
-            else
-                MDFile(argv[i]);
-    }
-    else
-        MDFilter();
+        for (count=0; count < num_sums; count++) {
+            abts_run_test(suite, test_md4sum, NULL);
+        }
 
-    return 0;
+        return suite;
 }

Modified: apr/apr-util/trunk/test/testmd5.c
Url: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/testmd5.c?view=diff&rev=106428&p1=apr/apr-util/trunk/test/testmd5.c&r1=106427&p2=apr/apr-util/trunk/test/testmd5.c&r2=106428
==============================================================================
--- apr/apr-util/trunk/test/testmd5.c	(original)
+++ apr/apr-util/trunk/test/testmd5.c	Wed Nov 24 08:23:52 2004
@@ -14,22 +14,20 @@
  */
 
 #include <assert.h>
-#include <stdlib.h>
 #include <stdio.h>
+#include <stdlib.h>
 
 #include "apr_md5.h"
 #include "apr_xlate.h"
 #include "apr_general.h"
-#include "test_apu.h"
 
-int cur; 
+#include "abts.h"
+#include "testutil.h"
 
-struct testcase {
-    const char *s;
+static struct {
+    const char *string;
     const char *digest;
-};
-
-struct testcase testcases[] =
+} md5sums[] = 
 {
     {"Jeff was here!",
      "\xa5\x25\x8a\x89\x11\xb2\x9d\x1f\x81\x75\x96\x3b\x60\x94\x49\xc0"},
@@ -47,95 +45,33 @@
      "\xd1\xa1\xc0\x97\x8a\x60\xbb\xfb\x2a\x25\x46\x9d\xa5\xae\xd0\xb0"}
 };
 
-static void try(const void *buf, apr_size_t bufLen, apr_xlate_t *xlate,
-                const void *digest)
+static int num_sums = sizeof(md5sums) / sizeof(md5sums[0]);
+static int count;
+
+static void test_md5sum(abts_case *tc, void *data)
 {
-    int i;
-    apr_md5_ctx_t context;
-    unsigned char hash[APR_MD5_DIGESTSIZE];
-    
-    printf("Trying translation %d\n", cur + 1);
-
-    STD_TEST_NEQ("    apr_md5_init", apr_md5_init(&context))
-
-    if (xlate) {
-#if APR_HAS_XLATE
-        STD_TEST_NEQ("    apr_md5_set_xlate", 
-                     apr_md5_set_xlate(&context, xlate))
-#else
-        printf("    Didn't expect a translation handle! Not fatal.\n");
-#endif
-    }
-    
-    STD_TEST_NEQ("    apr_md5_update", apr_md5_update(&context, buf, bufLen))
-    STD_TEST_NEQ("    apr_md5_final", apr_md5_final(hash, &context))
-
-    printf("     (MD5 hash : ");
-    for (i = 0; i < APR_MD5_DIGESTSIZE; i++) {
-        printf("%02x",hash[i]);
-    }
-    
-    printf(")\n");
-
-    printf("%-60s", "    Checking hash against expected");
-    if (memcmp(hash, digest, APR_MD5_DIGESTSIZE)) {
-        /* This is a fatal error...report on stderr */
-        fprintf(stderr, "The digest is not as expected!\n");
-#if 'A' != 0x41
-        fprintf(stderr,
-                "Maybe you didn't tell me what character sets "
-                "to translate between?\n"
-                "The expected digest is based on the string "
-                "being in ASCII.\n");
-#endif
-    }
-    printf("OK\n");
+        apr_md5_ctx_t context;
+        unsigned char digest[APR_MD5_DIGESTSIZE];
+        const void *string = md5sums[count].string;
+        const void *sum = md5sums[count].digest;
+        unsigned int len = strlen(string);
+
+        ABTS_ASSERT(tc, "apr_md5_init", (apr_md5_init(&context) == 0));
+        ABTS_ASSERT(tc, "apr_md5_update", 
+                    (apr_md5_update(&context, string, len) == 0));
+        ABTS_ASSERT(tc, "apr_md5_final", (apr_md5_final(digest, &context)
+                                          == 0));
+        ABTS_ASSERT(tc, "check for correct md5 digest",
+                    (memcmp(digest, sum, APR_MD5_DIGESTSIZE) == 0));
 }
 
-int main(int argc, char **argv)
+abts_suite *testmd5(abts_suite *suite)
 {
-    apr_status_t rv;
-    apr_xlate_t *xlate = NULL;
-    apr_pool_t *pool;
-    const char *src = NULL, *dst = NULL;
-
-    switch(argc) {
-    case 1:
-        break;
-    case 3:
-        src = argv[1];
-        dst = argv[2];
-        break;
-    default:
-        fprintf(stderr,
-                "Usage: %s [src-charset dst-charset]\n",
-                argv[0]);
-        exit(1);
-    }
-
-    rv = apr_initialize();
-    assert(!rv);
-    atexit(apr_terminate);
-
-    printf("APR MD5 Test\n============\n\n");
-    STD_TEST_NEQ("Creating pool", apr_pool_create(&pool, NULL))
-
-    if (src) {
-#if APR_HAS_XLATE
-        STD_TEST_NEQ("Opening xlate functions", 
-                     apr_xlate_open(&xlate, dst, src, pool))
-#else
-        /* This isn't a fatal error, so just report it... */
-        printf("APR doesn't implement translation for this "
-               "configuration.\n");
-#endif
-    }
-
-    for (cur = 0; cur < sizeof(testcases) / sizeof(testcases[0]); cur++) {
-        try(testcases[cur].s, strlen(testcases[cur].s), xlate,
-            testcases[cur].digest);
-    }
+        suite = ADD_SUITE(suite);
+        
+        for (count=0; count < num_sums; count++) {
+            abts_run_test(suite, test_md5sum, NULL);
+        }
 
-    printf("\nMD5 Test passed.\n");    
-    return 0;
+        return suite;
 }

Modified: apr/apr-util/trunk/test/testutil.h
Url: http://svn.apache.org/viewcvs/apr/apr-util/trunk/test/testutil.h?view=diff&rev=106428&p1=apr/apr-util/trunk/test/testutil.h&r1=106427&p2=apr/apr-util/trunk/test/testutil.h&r2=106428
==============================================================================
--- apr/apr-util/trunk/test/testutil.h	(original)
+++ apr/apr-util/trunk/test/testutil.h	Wed Nov 24 08:23:52 2004
@@ -47,5 +47,7 @@
 abts_suite *testuuid(abts_suite *suite);
 abts_suite *testbuckets(abts_suite *suite);
 abts_suite *testpass(abts_suite *suite);
+abts_suite *testmd4(abts_suite *suite);
+abts_suite *testmd5(abts_suite *suite);
 
 #endif /* APR_TEST_INCLUDES */

Mime
View raw message