Try to handle "function declaration isn't a prototype" warnings.
[gnutls.git] / tests / utils.c
blob4065973b07af39f0247174b144de4af54b15284f
1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation
4 * Author: Simon Josefsson
6 * This file is part of GNUTLS.
8 * GNUTLS is free software; you can redistribute it and/or modify it
9 * 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.
13 * GNUTLS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GNUTLS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <stdio.h>
28 #include <stdlib.h>
30 #include "utils.h"
32 int debug = 0;
33 int error_count = 0;
34 int break_on_error = 0;
36 char *pkcs3 =
37 "-----BEGIN DH PARAMETERS-----\n"
38 "MIGGAoGAtkxw2jlsVCsrfLqxrN+IrF/3W8vVFvDzYbLmxi2GQv9s/PQGWP1d9i22\n"
39 "P2DprfcJknWt7KhCI1SaYseOQIIIAYP78CfyIpGScW/vS8khrw0rlQiyeCvQgF3O\n"
40 "GeGOEywcw+oQT4SmFOD7H0smJe2CNyjYpexBXQ/A0mbTF9QKm1cCAQU=\n"
41 "-----END DH PARAMETERS-----\n";
43 void
44 fail (const char *format, ...)
46 va_list arg_ptr;
48 va_start (arg_ptr, format);
49 vfprintf (stderr, format, arg_ptr);
50 va_end (arg_ptr);
51 error_count++;
52 if (break_on_error)
53 exit (1);
56 void
57 success (const char *format, ...)
59 va_list arg_ptr;
61 va_start (arg_ptr, format);
62 vfprintf (stdout, format, arg_ptr);
63 va_end (arg_ptr);
66 void
67 escapeprint (const char *str, size_t len)
69 size_t i;
71 printf (" (length %d bytes):\n\t", len);
72 for (i = 0; i < len; i++)
74 if (((str[i] & 0xFF) >= 'A' && (str[i] & 0xFF) <= 'Z') ||
75 ((str[i] & 0xFF) >= 'a' && (str[i] & 0xFF) <= 'z') ||
76 ((str[i] & 0xFF) >= '0' && (str[i] & 0xFF) <= '9')
77 || (str[i] & 0xFF) == ' ' || (str[i] & 0xFF) == '.')
78 printf ("%c", (str[i] & 0xFF));
79 else
80 printf ("\\x%02X", (str[i] & 0xFF));
81 if ((i + 1) % 16 == 0 && (i + 1) < len)
82 printf ("'\n\t'");
84 printf ("\n");
87 void
88 hexprint (const char *str, size_t len)
90 size_t i;
92 printf ("\t;; ");
93 for (i = 0; i < len; i++)
95 printf ("%02x ", (str[i] & 0xFF));
96 if ((i + 1) % 8 == 0)
97 printf (" ");
98 if ((i + 1) % 16 == 0 && i + 1 < len)
99 printf ("\n\t;; ");
101 printf ("\n");
104 void
105 binprint (const char *str, size_t len)
107 size_t i;
109 printf ("\t;; ");
110 for (i = 0; i < len; i++)
112 printf ("%d%d%d%d%d%d%d%d ",
113 (str[i] & 0xFF) & 0x80 ? 1 : 0,
114 (str[i] & 0xFF) & 0x40 ? 1 : 0,
115 (str[i] & 0xFF) & 0x20 ? 1 : 0,
116 (str[i] & 0xFF) & 0x10 ? 1 : 0,
117 (str[i] & 0xFF) & 0x08 ? 1 : 0,
118 (str[i] & 0xFF) & 0x04 ? 1 : 0,
119 (str[i] & 0xFF) & 0x02 ? 1 : 0, (str[i] & 0xFF) & 0x01 ? 1 : 0);
120 if ((i + 1) % 3 == 0)
121 printf (" ");
122 if ((i + 1) % 6 == 0 && i + 1 < len)
123 printf ("\n\t;; ");
125 printf ("\n");
129 main (int argc, char *argv[])
132 if (strcmp (argv[argc - 1], "-v") == 0 ||
133 strcmp (argv[argc - 1], "--verbose") == 0)
134 debug = 1;
135 else if (strcmp (argv[argc - 1], "-b") == 0 ||
136 strcmp (argv[argc - 1], "--break-on-error") == 0)
137 break_on_error = 1;
138 else if (strcmp (argv[argc - 1], "-h") == 0 ||
139 strcmp (argv[argc - 1], "-?") == 0 ||
140 strcmp (argv[argc - 1], "--help") == 0)
142 printf ("Usage: %s [-vbh?] [--verbose] [--break-on-error] [--help]\n",
143 argv[0]);
144 return 1;
146 while (argc-- > 1);
148 doit ();
150 printf ("Self test `%s' finished with %d errors\n", argv[0], error_count);
152 return error_count ? 1 : 0;