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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
#include <ccan/foreach/foreach.h>
#include <ccan/failtest/failtest_override.h>
#include <ccan/failtest/failtest.h>
#include <ccan/tap/tap.h>
#include <stdlib.h>
#include <string.h>
#define CCAN_RFC822_DEBUG
#include <ccan/rfc822/rfc822.h>
#include <ccan/rfc822/rfc822.c>
#include "testdata.h"
#include "helper.h"
const char no_body[] =
"Date: Tue, 22 Feb 2011 00:15:59 +1100\n"
"From: Mister From <from@example.com>\n"
"To: Mizz To <to@example.org>\n"
"Subject: Some subject\n"
"Message-ID: <20110221131559.GA28327@example>\n";
const char truncated[] =
"Date: Tue, 22 Feb 2011 00:15:59 +1100\n"
"From: Mister From <from@example.com>\n"
"To: Mizz To <to@";
static int test_no_body(const char *buf, size_t len)
{
struct rfc822_msg *msg;
struct bytestring body;
int ok = 1;
msg = rfc822_start(NULL, buf, len);
allocation_failure_check();
body = rfc822_body(msg);
allocation_failure_check();
if (body.ptr)
ok = 0;
rfc822_free(msg);
allocation_failure_check();
return ok;
}
static int test_truncated(const char *buf, size_t len)
{
struct rfc822_msg *msg;
struct rfc822_header *h = NULL;
struct bytestring body;
int ok = 1;
msg = rfc822_start(NULL, buf, len);
allocation_failure_check();
do {
h = rfc822_next_header(msg, h);
allocation_failure_check();
} while (h);
body = rfc822_body(msg);
allocation_failure_check();
if (body.ptr)
ok = 0;
rfc822_free(msg);
allocation_failure_check();
return ok;
}
int main(int argc, char *argv[])
{
failtest_setup(argc, argv);
/* This is how many tests you plan to run */
plan_tests(3);
ok1(test_no_body(no_body, sizeof(no_body)));
ok1(test_no_body(truncated, sizeof(truncated)));
ok1(test_truncated(truncated, sizeof(truncated)));
/* This exits depending on whether all tests passed */
failtest_exit(exit_status());
}
|