2 * Copyright (c) 2006 Sendmail, Inc. and its suppliers.
5 * By using this file, you agree to the terms and conditions set
6 * forth in the LICENSE file which can be found at the top level of
7 * the sendmail distribution.
10 #pragma ident "%Z%%M% %I% %E% SMI"
13 SM_IDSTR(id
, "@(#)$Id: t-qic.c,v 1.9 2006/08/24 21:26:13 ca Exp $")
16 #include <sm/sendmail.h>
17 #include <sm/assert.h>
19 #include <sm/string.h>
22 extern bool SmTestVerbose
;
32 for (i
= 0; s1
[i
] != '\0' && s2
[i
] != '\0'; i
++)
36 fprintf(stderr
, "i=%d, s1[]=%u, s2[]=%u\n",
37 i
, (unsigned char) s1
[i
],
38 (unsigned char) s2
[i
]);
44 fprintf(stderr
, "i=%d, s1[]=%u, s2[]=%u\n",
45 i
, (unsigned char) s1
[i
], (unsigned char) s2
[i
]);
49 char *quote_unquote
__P((char *, char *, int, int));
52 quote_unquote(in
, out
, outlen
, exp
)
63 sm_strlcpy(line_in
, in
, sizeof(line_in
));
64 obp
= quote_internal_chars(in
, out
, &outlen
);
65 bp
= str2prt(line_in
);
66 dequote_internal_chars(obp
, line_back
, sizeof(line_back
));
67 cmp
= strcmp(line_in
, line_back
);
69 if (cmp
!= exp
&& !SmTestVerbose
)
71 fprintf(stderr
, "in: %s\n", bp
);
72 bp
= str2prt(line_back
);
73 fprintf(stderr
, "out:%s\n", bp
);
74 fprintf(stderr
, "cmp=%d\n", cmp
);
75 show_diff(in
, line_back
);
79 fprintf(stderr
, "%s -> ", bp
);
81 fprintf(stderr
, "%s\n", bp
);
82 fprintf(stderr
, "cmp=%d\n", cmp
);
94 typedef struct sm_qic_S sm_qic_T
;
102 char line_in
[1024], line
[256], line_out
[32], *obp
;
106 , { "abcdef", "abcdef", 0 }
107 , { "01234567890123456789", "01234567890123456789", 0 }
108 , { "01234567890123456789\001", "01234567890123456789\001",
110 , { "012345\2067890123456789", "012345\377\2067890123456789",
112 , { "\377", "\377\377", 0 }
113 , { "\240", "\240", 0 }
114 , { "\220", "\377\220", 0 }
115 , { "\240\220", "\240\377\220", 0 }
116 , { "\377\377", "\377\377\377\377", 0 }
117 , { "\377a\377b", "\377\377a\377\377b", 0 }
118 , { "\376a\377b", "\376a\377\377b", 0 }
119 , { "\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237\240",
120 "\377\200\377\201\377\202\377\203\377\204\377\205\377\206\377\207\377\210\377\211\377\212\377\213\377\214\377\215\377\216\377\217\377\220\377\221\377\222\377\223\377\224\377\225\377\226\377\227\377\230\377\231\377\232\377\233\377\234\377\235\377\236\377\237\240",
125 sm_test_begin(argc
, argv
, "test meta quoting");
126 for (i
= 0; i
< sizeof(line_out
); i
++)
128 for (i
= 0; i
< sizeof(line_in
); i
++)
130 for (i
= 0; i
< sizeof(line_in
) / 2; i
++)
139 los
= sizeof(line_out
) / 2;
140 obp
= quote_unquote(line_in
, line_out
, los
, 0);
144 for (i
= 0; i
< sizeof(line_in
); i
++)
146 for (i
= 0; i
< sizeof(line_in
) / 2; i
++)
155 los
= sizeof(line_in
);
156 obp
= quote_unquote(line_in
, line_in
, los
, 0);
160 for (i
= 0; inout
[i
].qic_in
!= NULL
; i
++)
162 los
= sizeof(line_out
) / 2;
163 obp
= quote_unquote(inout
[i
].qic_in
, line_out
, los
,
165 cmp
= strcmp(inout
[i
].qic_out
, obp
);
166 SM_TEST(inout
[i
].qic_exp
== cmp
);
167 if (inout
[i
].qic_exp
!= cmp
&& !SmTestVerbose
)
172 fprintf(stderr
, "got: %s\n", bp
);
173 bp
= str2prt(inout
[i
].qic_out
);
174 fprintf(stderr
, "exp:%s\n", bp
);
175 fprintf(stderr
, "cmp=%d\n", cmp
);
176 show_diff(inout
[i
].qic_in
, inout
[i
].qic_out
);
182 /* use same buffer for in and out */
183 for (i
= 0; inout
[i
].qic_in
!= NULL
; i
++)
187 same
= strcmp(inout
[i
].qic_in
, inout
[i
].qic_out
) == 0;
188 los
= sm_strlcpy(line
, inout
[i
].qic_in
, sizeof(line
));
189 SM_TEST(los
+ 1 < sizeof(line
));
191 obp
= quote_unquote(line
, line
, los
, inout
[i
].qic_exp
);
192 cmp
= strcmp(inout
[i
].qic_out
, obp
);
193 SM_TEST(inout
[i
].qic_exp
== cmp
);
194 if (inout
[i
].qic_exp
!= cmp
&& !SmTestVerbose
)
199 fprintf(stderr
, "got: %s\n", bp
);
200 bp
= str2prt(inout
[i
].qic_out
);
201 fprintf(stderr
, "exp:%s\n", bp
);
202 fprintf(stderr
, "cmp=%d\n", cmp
);
203 show_diff(inout
[i
].qic_in
, inout
[i
].qic_out
);
209 show_diff(obp
, inout
[i
].qic_out
);
214 /* use NULL buffer for out */
215 for (i
= 0; inout
[i
].qic_in
!= NULL
; i
++)
218 obp
= quote_unquote(inout
[i
].qic_in
, NULL
, los
,
220 SM_TEST(obp
!= NULL
);
221 cmp
= strcmp(inout
[i
].qic_out
, obp
);
222 SM_TEST(inout
[i
].qic_exp
== cmp
);
223 if (inout
[i
].qic_exp
!= cmp
&& !SmTestVerbose
)
228 fprintf(stderr
, "got: %s\n", bp
);
229 bp
= str2prt(inout
[i
].qic_out
);
230 fprintf(stderr
, "exp:%s\n", bp
);
231 fprintf(stderr
, "cmp=%d\n", cmp
);
232 show_diff(inout
[i
].qic_in
, inout
[i
].qic_out
);
236 return sm_test_end();