Debian Codegraph @

test/cryptounittest/tests.h

raw
1 /*
2 *
3 * tests.h
4 *
5 * Copyright (C) 2012 Carlos Alberto Lopez Perez <[email protected]>
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301, USA.
22 *
23 */
24
25 int ntest = 1;
26
27 void hexdump(const unsigned char * buffer, int length)
28 {
29 int i, x = 1;
30
31 for (i = 0; i < length; i++)
32 {
33 printf("%02x ", buffer[i]);
34 if (x > 15)
35 {
36 x = 0;
37 printf("\n");
38 }
39 x++;
40 }
41 printf("\n");
42 }
43
44 int test(const unsigned char * computed,
45 const unsigned char * expected,
46 int length,
47 const char * name)
48 {
49 int z;
50 int error = 0;
51
52 for (z = 0; z < length; z++)
53 if (computed[z] != expected[z]) error = 1;
54
55 if (error == 1)
56 {
57 printf("[%s][Test %d] ERROR: The output don't match. I got:\n",
58 name,
59 ntest++);
60 hexdump(computed, length);
61 printf("And I was expecting:\n");
62 hexdump(expected, length);
63 }
64 else
65 {
66 printf("[%s][Test %d] OK: Output matches :)\n", name, ntest++);
67 }
68
69 return error;
70 }