More enum docs.
[gnutls.git] / tests / utils.c
blob7e39dff4398257ddc5b324cd31e7f91fb9ff1768
1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010 Free Software
3 * Foundation, Inc.
5 * Author: Simon Josefsson
7 * This file is part of GNUTLS.
9 * GNUTLS is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
14 * GNUTLS is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNUTLS; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 #ifdef HAVE_CONFIG_H
25 # include "config.h"
26 #endif
28 #include <stdio.h>
29 #include <stdlib.h>
31 #include "utils.h"
33 int debug = 0;
34 int error_count = 0;
35 int break_on_error = 0;
37 const char *pkcs3 =
38 "-----BEGIN DH PARAMETERS-----\n"
39 "MIGGAoGAtkxw2jlsVCsrfLqxrN+IrF/3W8vVFvDzYbLmxi2GQv9s/PQGWP1d9i22\n"
40 "P2DprfcJknWt7KhCI1SaYseOQIIIAYP78CfyIpGScW/vS8khrw0rlQiyeCvQgF3O\n"
41 "GeGOEywcw+oQT4SmFOD7H0smJe2CNyjYpexBXQ/A0mbTF9QKm1cCAQU=\n"
42 "-----END DH PARAMETERS-----\n";
44 void
45 fail (const char *format, ...)
47 va_list arg_ptr;
49 va_start (arg_ptr, format);
50 vfprintf (stderr, format, arg_ptr);
51 va_end (arg_ptr);
52 error_count++;
53 if (break_on_error)
54 exit (1);
57 void
58 success (const char *format, ...)
60 va_list arg_ptr;
62 va_start (arg_ptr, format);
63 vfprintf (stdout, format, arg_ptr);
64 va_end (arg_ptr);
67 void
68 escapeprint (const char *str, size_t len)
70 size_t i;
72 printf (" (length %d bytes):\n\t", (int)len);
73 for (i = 0; i < len; i++)
75 if (((str[i] & 0xFF) >= 'A' && (str[i] & 0xFF) <= 'Z') ||
76 ((str[i] & 0xFF) >= 'a' && (str[i] & 0xFF) <= 'z') ||
77 ((str[i] & 0xFF) >= '0' && (str[i] & 0xFF) <= '9')
78 || (str[i] & 0xFF) == ' ' || (str[i] & 0xFF) == '.')
79 printf ("%c", (str[i] & 0xFF));
80 else
81 printf ("\\x%02X", (str[i] & 0xFF));
82 if ((i + 1) % 16 == 0 && (i + 1) < len)
83 printf ("'\n\t'");
85 printf ("\n");
88 void
89 hexprint (const char *str, size_t len)
91 size_t i;
93 printf ("\t;; ");
94 for (i = 0; i < len; i++)
96 printf ("%02x ", (str[i] & 0xFF));
97 if ((i + 1) % 8 == 0)
98 printf (" ");
99 if ((i + 1) % 16 == 0 && i + 1 < len)
100 printf ("\n\t;; ");
102 printf ("\n");
105 void
106 binprint (const char *str, size_t len)
108 size_t i;
110 printf ("\t;; ");
111 for (i = 0; i < len; i++)
113 printf ("%d%d%d%d%d%d%d%d ",
114 (str[i] & 0xFF) & 0x80 ? 1 : 0,
115 (str[i] & 0xFF) & 0x40 ? 1 : 0,
116 (str[i] & 0xFF) & 0x20 ? 1 : 0,
117 (str[i] & 0xFF) & 0x10 ? 1 : 0,
118 (str[i] & 0xFF) & 0x08 ? 1 : 0,
119 (str[i] & 0xFF) & 0x04 ? 1 : 0,
120 (str[i] & 0xFF) & 0x02 ? 1 : 0, (str[i] & 0xFF) & 0x01 ? 1 : 0);
121 if ((i + 1) % 3 == 0)
122 printf (" ");
123 if ((i + 1) % 6 == 0 && i + 1 < len)
124 printf ("\n\t;; ");
126 printf ("\n");
130 main (int argc, char *argv[])
133 if (strcmp (argv[argc - 1], "-v") == 0 ||
134 strcmp (argv[argc - 1], "--verbose") == 0)
135 debug = 1;
136 else if (strcmp (argv[argc - 1], "-b") == 0 ||
137 strcmp (argv[argc - 1], "--break-on-error") == 0)
138 break_on_error = 1;
139 else if (strcmp (argv[argc - 1], "-h") == 0 ||
140 strcmp (argv[argc - 1], "-?") == 0 ||
141 strcmp (argv[argc - 1], "--help") == 0)
143 printf ("Usage: %s [-vbh?] [--verbose] [--break-on-error] [--help]\n",
144 argv[0]);
145 return 1;
147 while (argc-- > 1);
149 doit ();
151 printf ("Self test `%s' finished with %d errors\n", argv[0], error_count);
153 return error_count ? 1 : 0;