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.
27 #include "gs2parser.h"
30 main (int argc
, char *argv
[])
36 char token
[4] = "\x00\x00\x00\x00";
37 rc
= gs2_parser (token
, sizeof (token
), &tok
);
40 printf ("gs2_parser zero rc %d\n", rc
);
43 if (tok
.context_token
!= NULL
||
44 tok
.context_length
!= 0 ||
45 tok
.wrap_token
!= NULL
||
48 printf ("gs2_parser zero failure (%d: %x-%d-%x-%d)\n",
50 tok
.context_token
, tok
.context_length
,
51 tok
.wrap_token
, tok
.wrap_length
);
57 char token
[4] = "\x00\x00\x00\x01";
58 rc
= gs2_parser (token
, sizeof (token
), &tok
);
61 printf ("gs2_parser one-empty rc %d\n", rc
);
67 char token
[4] = "\x00\x00\x00\x04";
68 rc
= gs2_parser (token
, sizeof (token
), &tok
);
71 printf ("gs2_parser four-empty rc %d\n", rc
);
77 char token
[5] = "\x00\x00\x00\x00\x65";
78 rc
= gs2_parser (token
, sizeof (token
), &tok
);
81 printf ("gs2_parser zero-ok rc %d\n", rc
);
84 if (tok
.context_token
!= NULL
||
85 tok
.context_length
!= 0 ||
86 tok
.wrap_token
!= &token
[4] ||
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
);
97 char token
[5] = "\x00\x00\x00\x01\x65";
98 rc
= gs2_parser (token
, sizeof (token
), &tok
);
101 printf ("gs2_parser one-ok rc %d\n", rc
);
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
);
117 char token
[6] = "\x00\x00\x00\x00\xAA\xBB";
118 rc
= gs2_parser (token
, sizeof (token
), &tok
);
121 printf ("gs2_parser zero-two-ok rc %d\n", rc
);
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
);
137 char token
[6] = "\x00\x00\x00\x02\xAA\xAB";
138 rc
= gs2_parser (token
, sizeof (token
), &tok
);
141 printf ("gs2_parser zero-two-ok rc %d\n", rc
);
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
);
157 char token
[6] = "\x00\x00\x00\x01\xAA\xAB";
158 rc
= gs2_parser (token
, sizeof (token
), &tok
);
161 printf ("gs2_parser both rc %d\n", rc
);
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
);
177 char token
[8] = "\x00\x00\x00\x02\xAA\xBA\xAB\xBB";
178 rc
= gs2_parser (token
, sizeof (token
), &tok
);
181 printf ("gs2_parser both2 rc %d\n", rc
);
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
);