Add.
[gsasl.git] / lib / gs2 / test-parser.c
blobc5194151cef01cc7fedca71b1005f8756e1f1830
1 /* test-parser.c --- Self tests of GS2 parser & printer.
2 * Copyright (C) 2006 Simon Josefsson
4 * This file is part of GNU SASL Library.
6 * GNU SASL Library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public License
8 * as published by the Free Software Foundation; either version 2.1 of
9 * the License, or (at your option) any later version.
11 * GNU SASL Library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with GNU SASL Library; if not, write to the Free
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
27 #include "gs2parser.h"
29 int
30 main (int argc, char *argv[])
32 struct gs2_token tok;
33 int rc;
36 char token[4] = "\x00\x00\x00\x00";
37 rc = gs2_parser (token, sizeof (token), &tok);
38 if (rc < 0)
40 printf ("gs2_parser zero rc %d\n", rc);
41 abort ();
43 if (tok.context_token != NULL ||
44 tok.context_length != 0 ||
45 tok.wrap_token != NULL ||
46 tok.wrap_length != 0)
48 printf ("gs2_parser zero failure (%d: %x-%d-%x-%d)\n",
49 sizeof (token),
50 tok.context_token, tok.context_length,
51 tok.wrap_token, tok.wrap_length);
52 abort ();
57 char token[4] = "\x00\x00\x00\x01";
58 rc = gs2_parser (token, sizeof (token), &tok);
59 if (rc >= 0)
61 printf ("gs2_parser one-empty rc %d\n", rc);
62 abort ();
67 char token[4] = "\x00\x00\x00\x04";
68 rc = gs2_parser (token, sizeof (token), &tok);
69 if (rc >= 0)
71 printf ("gs2_parser four-empty rc %d\n", rc);
72 abort ();
77 char token[5] = "\x00\x00\x00\x00\x65";
78 rc = gs2_parser (token, sizeof (token), &tok);
79 if (rc < 0)
81 printf ("gs2_parser zero-ok rc %d\n", rc);
82 abort ();
84 if (tok.context_token != NULL ||
85 tok.context_length != 0 ||
86 tok.wrap_token != &token[4] ||
87 tok.wrap_length != 1)
89 printf ("gs2_parser zero-ok failure (%x-%d-%x-%d)\n",
90 tok.context_token, tok.context_length,
91 tok.wrap_token, tok.wrap_length);
92 abort ();
97 char token[5] = "\x00\x00\x00\x01\x65";
98 rc = gs2_parser (token, sizeof (token), &tok);
99 if (rc < 0)
101 printf ("gs2_parser one-ok rc %d\n", rc);
102 abort ();
104 if (tok.context_token != &token[4] ||
105 tok.context_length != 1 ||
106 tok.wrap_token != NULL ||
107 tok.wrap_length != 0)
109 printf ("gs2_parser one-ok failure (%x-%d-%x-%d)\n",
110 tok.context_token, tok.context_length,
111 tok.wrap_token, tok.wrap_length);
112 abort ();
117 char token[6] = "\x00\x00\x00\x00\xAA\xBB";
118 rc = gs2_parser (token, sizeof (token), &tok);
119 if (rc < 0)
121 printf ("gs2_parser zero-two-ok rc %d\n", rc);
122 abort ();
124 if (tok.context_token != NULL ||
125 tok.context_length != 0 ||
126 tok.wrap_token != &token[4] ||
127 tok.wrap_length != 2)
129 printf ("gs2_parser zero-two-ok failure (%x-%d-%x-%d)\n",
130 tok.context_token, tok.context_length,
131 tok.wrap_token, tok.wrap_length);
132 abort ();
137 char token[6] = "\x00\x00\x00\x02\xAA\xAB";
138 rc = gs2_parser (token, sizeof (token), &tok);
139 if (rc < 0)
141 printf ("gs2_parser zero-two-ok rc %d\n", rc);
142 abort ();
144 if (tok.context_token != &token[4] ||
145 tok.context_length != 2 ||
146 tok.wrap_token != NULL ||
147 tok.wrap_length != 0)
149 printf ("gs2_parser zero-two-ok failure (%x-%d-%x-%d)\n",
150 tok.context_token, tok.context_length,
151 tok.wrap_token, tok.wrap_length);
152 abort ();
157 char token[6] = "\x00\x00\x00\x01\xAA\xAB";
158 rc = gs2_parser (token, sizeof (token), &tok);
159 if (rc < 0)
161 printf ("gs2_parser both rc %d\n", rc);
162 abort ();
164 if (tok.context_token != &token[4] ||
165 tok.context_length != 1 ||
166 tok.wrap_token != &token[5] ||
167 tok.wrap_length != 1)
169 printf ("gs2_parser both failure (%x-%d-%x-%d)\n",
170 tok.context_token, tok.context_length,
171 tok.wrap_token, tok.wrap_length);
172 abort ();
177 char token[8] = "\x00\x00\x00\x02\xAA\xBA\xAB\xBB";
178 rc = gs2_parser (token, sizeof (token), &tok);
179 if (rc < 0)
181 printf ("gs2_parser both2 rc %d\n", rc);
182 abort ();
184 if (tok.context_token != &token[4] ||
185 tok.context_length != 2 ||
186 tok.wrap_token != &token[6] ||
187 tok.wrap_length != 2)
189 printf ("gs2_parser both2 failure (%x-%d-%x-%d)\n",
190 tok.context_token, tok.context_length,
191 tok.wrap_token, tok.wrap_length);
192 abort ();
196 return 0;