~ubuntu-branches/ubuntu/feisty/apache2/feisty

« back to all changes in this revision

Viewing changes to srclib/apr-util/test/testmd5.c

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Barth
  • Date: 2006-12-09 21:05:45 UTC
  • mfrom: (0.6.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061209210545-h70s0xaqc2v8vqr2
Tags: 2.2.3-3.2
* Non-maintainer upload.
* 043_ajp_connection_reuse: Patch from upstream Bugzilla, fixing a critical
  issue with regard to connection reuse in mod_proxy_ajp.
  Closes: #396265

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
 
2
 * applicable.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *     http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
 
15
 */
 
16
 
 
17
#include <assert.h>
 
18
#include <stdio.h>
 
19
#include <stdlib.h>
 
20
 
 
21
#include "apr_md5.h"
 
22
#include "apr_xlate.h"
 
23
#include "apr_general.h"
 
24
 
 
25
#include "abts.h"
 
26
#include "testutil.h"
 
27
 
 
28
static struct {
 
29
    const char *string;
 
30
    const char *digest;
 
31
} md5sums[] = 
 
32
{
 
33
    {"Jeff was here!",
 
34
     "\xa5\x25\x8a\x89\x11\xb2\x9d\x1f\x81\x75\x96\x3b\x60\x94\x49\xc0"},
 
35
    {"01234567890aBcDeFASDFGHJKLPOIUYTR"
 
36
     "POIUYTREWQZXCVBN  LLLLLLLLLLLLLLL",
 
37
     "\xd4\x1a\x06\x2c\xc5\xfd\x6f\x24\x67\x68\x56\x7c\x40\x8a\xd5\x69"},
 
38
    {"111111118888888888888888*******%%%%%%%%%%#####"
 
39
     "142134u8097289720432098409289nkjlfkjlmn,m..   ",
 
40
     "\xb6\xea\x5b\xe8\xca\x45\x8a\x33\xf0\xf1\x84\x6f\xf9\x65\xa8\xe1"},
 
41
    {"01234567890aBcDeFASDFGHJKLPOIUYTR"
 
42
     "POIUYTREWQZXCVBN  LLLLLLLLLLLLLLL"
 
43
     "01234567890aBcDeFASDFGHJKLPOIUYTR"
 
44
     "POIUYTREWQZXCVBN  LLLLLLLLLLLLLLL"
 
45
     "1",
 
46
     "\xd1\xa1\xc0\x97\x8a\x60\xbb\xfb\x2a\x25\x46\x9d\xa5\xae\xd0\xb0"}
 
47
};
 
48
 
 
49
static int num_sums = sizeof(md5sums) / sizeof(md5sums[0]);
 
50
static int count;
 
51
 
 
52
static void test_md5sum(abts_case *tc, void *data)
 
53
{
 
54
        apr_md5_ctx_t context;
 
55
        unsigned char digest[APR_MD5_DIGESTSIZE];
 
56
        const void *string = md5sums[count].string;
 
57
        const void *sum = md5sums[count].digest;
 
58
        unsigned int len = strlen(string);
 
59
 
 
60
        ABTS_ASSERT(tc, "apr_md5_init", (apr_md5_init(&context) == 0));
 
61
        ABTS_ASSERT(tc, "apr_md5_update", 
 
62
                    (apr_md5_update(&context, string, len) == 0));
 
63
        ABTS_ASSERT(tc, "apr_md5_final", (apr_md5_final(digest, &context)
 
64
                                          == 0));
 
65
        ABTS_ASSERT(tc, "check for correct md5 digest",
 
66
                    (memcmp(digest, sum, APR_MD5_DIGESTSIZE) == 0));
 
67
}
 
68
 
 
69
abts_suite *testmd5(abts_suite *suite)
 
70
{
 
71
        suite = ADD_SUITE(suite);
 
72
        
 
73
        for (count=0; count < num_sums; count++) {
 
74
            abts_run_test(suite, test_md5sum, NULL);
 
75
        }
 
76
 
 
77
        return suite;
 
78
}