32
32
#include "../libclamav/clamav.h"
33
33
#include "../libclamav/others.h"
34
34
#include "../libclamav/str.h"
35
#include "../libclamav/mbox.h"
36
#include "../libclamav/message.h"
35
37
#include "../libclamav/jsparse/textbuf.h"
36
38
#include "checks.h"
167
#ifdef CHECK_HAVE_LOOPS
168
static struct base64lines {
170
const unsigned char *decoded;
177
{"Zm9vYg==", "foob", 4},
178
{"Zm9vYmFy", "foobar", 6},
179
/* with missing padding */
182
{"Zm9vYg", "foob", 4}
185
START_TEST (test_base64)
187
unsigned char *ret, *ret2;
189
unsigned char buf[1024];
190
const struct base64lines *test = &base64tests[_i];
191
message *m = messageCreate();
192
fail_unless(!!m, "Unable to create message");
194
ret = decodeLine(m, BASE64, test->line, buf, sizeof(buf));
195
fail_unless(!!ret, "unable to decode line");
197
ret2 = base64Flush(m, ret);
203
fail_unless_fmt(len == test->len, "invalid base64 decoded length: %u expected %u (%s)\n",
204
len, test->len, buf);
205
fail_unless_fmt(!memcmp(buf, test->decoded, test->len),
206
"invalid base64 decoded data: %s, expected:%s\n",
165
213
Suite *test_str_suite(void)
167
215
Suite *s = suite_create("str");
168
TCase *tc_cli_unescape, *tc_tbuf, *tc_str;
216
TCase *tc_cli_unescape, *tc_tbuf, *tc_str, *tc_decodeline;
170
218
tc_cli_unescape = tcase_create("cli_unescape");
171
219
suite_add_tcase (s, tc_cli_unescape);
185
233
suite_add_tcase (s, tc_str);
186
234
tcase_add_test(tc_str, hex2str);
236
tc_decodeline = tcase_create("decodeline");
237
suite_add_tcase (s, tc_decodeline);
238
#ifdef CHECK_HAVE_LOOPS
239
tcase_add_loop_test(tc_decodeline, test_base64, 0, sizeof(base64tests)/sizeof(base64tests[0]));