File: test-rfc2231-parser.c

package info (click to toggle)
dovecot 1%3A2.2.27-3%2Bdeb9u5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 48,792 kB
  • sloc: ansic: 430,517; sh: 17,438; makefile: 6,587; cpp: 1,557; perl: 295; python: 67; xml: 44; pascal: 27
file content (51 lines) | stat: -rw-r--r-- 1,132 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* Copyright (c) 2007-2016 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "rfc822-parser.h"
#include "rfc2231-parser.h"
#include "test-common.h"

static void test_rfc2231_parser(void)
{
	const char *input =
		"; key4*=us-ascii''foo"
		"; key*2=ba%"
		"; key2*0=a"
		"; key3*0*=us-ascii'en'xyz"
		"; key*0=\"foo\""
		"; key2*1*=b%25"
		"; key3*1=plop%"
		"; key*1=baz";
	const char *output[] = {
		"key",
		"foobazba%",
		"key2*",
		"''ab%25",
		"key3*",
		"us-ascii'en'xyzplop%25",
		"key4*",
		"us-ascii''foo",
		NULL
	};
	struct rfc822_parser_context parser;
	const char *const *result;
	unsigned int i;

	test_begin("rfc2231 parser");
	rfc822_parser_init(&parser, (const void *)input, strlen(input), NULL);
	test_assert(rfc2231_parse(&parser, &result) == 0);
	for (i = 0; output[i] != NULL && result[i] != NULL; i++)
		test_assert(strcmp(output[i], result[i]) == 0);
	rfc822_parser_deinit(&parser);
	test_assert(output[i] == NULL && result[i] == NULL);
	test_end();
}

int main(void)
{
	static void (*test_functions[])(void) = {
		test_rfc2231_parser,
		NULL
	};
	return test_run(test_functions);
}