Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / regress / lib / libc / string / memcpy / memcpy_test.c
blob72eb6b0947c1a846b4178a824205b58988b6e919
1 #include <sys/types.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <assert.h>
7 #include <md5.h>
9 #define ALIGNMENTS 16
10 #define LENGTHS 4
11 #define BLOCKTYPES 4
13 MD5_CTX mc[1];
15 typedef unsigned char testBlock_t[ALIGNMENTS * LENGTHS];
17 testBlock_t bss1, bss2;
19 unsigned char *start[BLOCKTYPES] = {
20 bss1, bss2
23 char result[100];
24 const char goodResult[] = "7b405d24bc03195474c70ddae9e1f8fb";
26 void runTest(unsigned char *, unsigned char *);
28 int
29 main(int ac, char **av)
31 int i, j;
32 testBlock_t auto1, auto2;
34 start[2] = auto1;
35 start[3] = auto2;
37 srandom(0L);
38 MD5Init(mc);
39 for (i = 0; i < BLOCKTYPES; ++i)
40 for (j = 0; j < BLOCKTYPES; ++j)
41 if (i != j)
42 runTest(start[i], start[j]);
43 MD5End(mc, result);
44 return strcmp(result, goodResult);
47 void runTest(unsigned char *b1, unsigned char *b2)
49 int i, j, k, m;
50 size_t n;
52 for (i = 0; i < ALIGNMENTS; ++i) {
53 for (j = 0; j < ALIGNMENTS; ++j) {
54 k = sizeof(testBlock_t) - (i > j ? i : j);
55 for (m = 0; m < k; ++m) {
56 for (n = 0; n < sizeof(testBlock_t); ++n) {
57 b1[n] = (unsigned char)random();
58 b2[n] = (unsigned char)random();
60 memcpy(b1 + i, b2 + j, m);
61 MD5Update(mc, b1, sizeof(testBlock_t));
62 MD5Update(mc, b2, sizeof(testBlock_t));